Support non-blocking i/o across platforms

This change introduces new tests for `O_NONBLOCK` and `SOCK_NONBLOCK` to
confirm that non-blocking i/o is now working on all supported platforms,
including Windows. For example, you can now say on Windows, MacOS, etc.:

    socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP);

To create a non-blocking IPv4 TCP socket. Or you can enable non-blocking
i/o on an existing socket / pipe / etc. file descriptor by calling fcntl

    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);

This functionality is polyfilled on older Linux kernels too, e.g. RHEL5.
Now that fcntl() support is much better the FIOCLEX / FIONCLEX polyfills
for ioctl() have been removed since they're ugly non-POSIX diameond APIs

This change fixes a weakness in kprintf() that was causing Windows trace
tools to frequently crash.
This commit is contained in:
Justine Tunney 2023-07-23 02:56:47 -07:00
parent 5c9e03e3e0
commit 1d4eb08fa1
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
102 changed files with 678 additions and 331 deletions

View file

@ -3,7 +3,7 @@
.text.windows
.ftrace1
CancelIoEx:
__CancelIoEx:
.ftrace2
#ifdef __x86_64__
push %rbp
@ -14,5 +14,5 @@ CancelIoEx:
mov x0,#0
ret
#endif
.endfn CancelIoEx,globl
.endfn __CancelIoEx,globl
.previous

View file

@ -98,7 +98,6 @@ imp 'CallNamedPipeA' CallNamedPipeA kernel32 110 7
imp 'CallbackMayRunLong' CallbackMayRunLong kernel32 0
imp 'CancelDeviceWakeupRequest' CancelDeviceWakeupRequest kernel32 113
imp 'CancelIo' CancelIo kernel32 0 1
imp 'CancelIoEx' CancelIoEx kernel32 0 2
imp 'CancelSynchronousIo' CancelSynchronousIo kernel32 0 1
imp 'CancelTimerQueueTimer' CancelTimerQueueTimer kernel32 118
imp 'CancelWaitableTimer' CancelWaitableTimer kernel32 0
@ -1097,6 +1096,7 @@ imp 'WriteProfileString' WriteProfileStringW kernel32 1575
imp 'WriteTapemark' WriteTapemark kernel32 1576
imp 'ZombifyActCtx' ZombifyActCtx kernel32 0
imp 'ZombifyActCtxWorker' ZombifyActCtxWorker kernel32 1578
imp '__CancelIoEx' CancelIoEx kernel32 0 2
imp '__CloseHandle' CloseHandle kernel32 0 1
imp '__CreateDirectory' CreateDirectoryW kernel32 0 2
imp '__CreateFile' CreateFileW kernel32 0 7
@ -3228,7 +3228,6 @@ imp 'WSAEnumNetworkEvents' WSAEnumNetworkEvents ws2_32 64 3
imp 'WSAEnumProtocols' WSAEnumProtocolsW ws2_32 66 3
imp 'WSAEventSelect' WSAEventSelect ws2_32 67 3
imp 'WSAGetLastError' WSAGetLastError ws2_32 111 0
imp 'WSAGetOverlappedResult' WSAGetOverlappedResult ws2_32 68 5
imp 'WSAGetQOSByName' WSAGetQOSByName ws2_32 69 3
imp 'WSAGetServiceClassInfo' WSAGetServiceClassInfoW ws2_32 71 4
imp 'WSAGetServiceClassNameByClassId' WSAGetServiceClassNameByClassIdW ws2_32 73 3
@ -3329,6 +3328,7 @@ imp '__WSARecvFrom' WSARecvFrom ws2_32 93 9
imp '__WSAWaitForMultipleEvents' WSAWaitForMultipleEvents ws2_32 124 5
imp '__sys_recv_nt' recv ws2_32 16 4 # we're using WSARecvFrom()
imp '__sys_send_nt' send ws2_32 19 4 # we're using WSASendTo()
imp '__WSAGetOverlappedResult' WSAGetOverlappedResult ws2_32 68 5
# IPHLPAPI.DLL
#

View file

@ -294,7 +294,7 @@ int32_t WSAStartup(uint16_t wVersionRequested, struct NtWsaData *lpWSAData)
paramsnonnull() dontdiscard;
int WSACleanup(void);
int WSAGetLastError(void);
int WSAGetLastError(void) nosideeffect;
void WSASetLastError(int);
int __sys_bind_nt(uint64_t, const void *, int);
@ -343,6 +343,12 @@ int64_t WSAAccept(uint64_t s, struct sockaddr *out_addr,
const uint32_t *opt_dwCallbackData)
paramsnonnull((2)) dontdiscard;
bool32 AcceptEx(int64_t sListenSocket, int64_t sAcceptSocket,
void *out_lpOutputBuffer /*[recvlen+local+remoteaddrlen]*/,
uint32_t dwReceiveDataLength, uint32_t dwLocalAddressLength,
uint32_t dwRemoteAddressLength, uint32_t *out_lpdwBytesReceived,
struct NtOverlapped *inout_lpOverlapped);
int WSASend(uint64_t s, const struct NtIovec *lpBuffers, uint32_t dwBufferCount,
uint32_t *opt_out_lpNumberOfBytesSent, uint32_t dwFlags,
struct NtOverlapped *opt_inout_lpOverlapped,

View file

@ -3,7 +3,7 @@
.text.windows
.ftrace1
WSAGetOverlappedResult:
__WSAGetOverlappedResult:
.ftrace2
#ifdef __x86_64__
push %rbp
@ -14,5 +14,5 @@ WSAGetOverlappedResult:
mov x0,#0
ret
#endif
.endfn WSAGetOverlappedResult,globl
.endfn __WSAGetOverlappedResult,globl
.previous