Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libc/calls/ntspawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static textwindows ssize_t ntspawn_read(intptr_t fh, char *buf, size_t len) {
uint32_t got;
struct NtOverlapped overlap = {.hEvent = CreateEvent(0, 0, 0, 0)};
ok = overlap.hEvent &&
(ReadFile(fh, buf, len, 0, &overlap) ||
(ReadFile(fh, buf, len, &got, &overlap) ||
GetLastError() == kNtErrorIoPending) &&
GetOverlappedResult(fh, &overlap, &got, true);
if (overlap.hEvent)
Expand Down
8 changes: 3 additions & 5 deletions libc/calls/readwrite-nt.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ sys_readwrite_nt(int fd, void *data, size_t size, ssize_t offset,

// initiate asynchronous i/o operation with win32
struct NtOverlapped overlap = {.hEvent = event, .Pointer = offset};
bool32 ok = ReadOrWriteFile(handle, data, size, 0, &overlap);
uint32_t exchanged = 0;
bool32 ok = ReadOrWriteFile(handle, data, size, &exchanged, &overlap);
if (!ok && GetLastError() == kNtErrorIoPending) {
if (f->flags & _O_NONBLOCK) {
// immediately back out of blocking i/o if non-blocking
Expand Down Expand Up @@ -135,11 +136,8 @@ sys_readwrite_nt(int fd, void *data, size_t size, ssize_t offset,
CancelIoEx(handle, &overlap);
}
}
ok = true;
}
uint32_t exchanged = 0;
if (ok)
ok = GetOverlappedResult(handle, &overlap, &exchanged, true);
}
uint32_t io_error = GetLastError();
CloseHandle(event);

Expand Down
2 changes: 1 addition & 1 deletion libc/calls/winexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ textwindows int IsWindowsExecutable(int64_t handle, const char16_t *path) {
BLOCK_SIGNALS;
struct NtOverlapped overlap = {.hEvent = CreateEvent(0, 0, 0, 0)};
ok = overlap.hEvent &&
(ReadFile(handle, buf, 2, 0, &overlap) ||
(ReadFile(handle, buf, 2, &got, &overlap) ||
GetLastError() == kNtErrorIoPending) &&
GetOverlappedResult(handle, &overlap, &got, true);
CloseHandle(overlap.hEvent);
Expand Down
3 changes: 1 addition & 2 deletions libc/intrin/kprintf.greg.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ ABI void klog(const char *b, size_t n) {
struct NtOverlapped overlap = {.hEvent = ev};
ok = !!__imp_WriteFile(h, b, n, 0, &overlap);
if (!ok && __imp_GetLastError() == kNtErrorIoPending)
ok = true;
ok &= !!__imp_GetOverlappedResult(h, &overlap, &wrote, true);
ok = !!__imp_GetOverlappedResult(h, &overlap, &wrote, true);
if (!ok)
__klog_handle = 0;
__imp_CloseHandle(ev);
Expand Down
2 changes: 1 addition & 1 deletion libc/runtime/winmain.greg.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ abi static void DeduplicateStdioHandles(void) {
int64_t h2 = __imp_GetStdHandle(kNtStdio[j]);
if (h1 == h2) {
int64_t h3;
__imp_DuplicateHandle(-1, h2, -1, &h3, 0, false,
__imp_DuplicateHandle(-1, h2, -1, &h3, 0, true,
kNtDuplicateSameAccess);
__imp_SetStdHandle(kNtStdio[j], h3);
}
Expand Down