Make fixes and improvements

- Introduce __assert_disable global
- Improve strsignal() thread safety
- Make system call tracing thread safe
- Fix SO_RCVTIMEO / SO_SNDTIMEO on Windows
- Refactor DescribeFoo() functions into one place
- Fix fork() on Windows when TLS and MAP_STACK exist
- Round upwards in setsockopt(SO_RCVTIMEO) on Windows
- Disable futexes on OpenBSD which seem extremely broken
- Implement a better kludge for monotonic time on Windows
This commit is contained in:
Justine Tunney 2022-06-25 18:17:31 -07:00
parent 5d837c4e7c
commit fbc053e018
186 changed files with 1836 additions and 1325 deletions

View file

@ -3799,9 +3799,7 @@ imp 'WSANSPIoctl' WSANSPIoctl ws2_32 85 8
imp 'WSAPoll' WSAPoll ws2_32 88 3
imp 'WSAProviderCompleteAsyncCall' WSAProviderCompleteAsyncCall ws2_32 89
imp 'WSAProviderConfigChange' WSAProviderConfigChange ws2_32 90 3
imp 'WSARecv' WSARecv ws2_32 91 7
imp 'WSARecvDisconnect' WSARecvDisconnect ws2_32 92 2
imp 'WSARecvFrom' WSARecvFrom ws2_32 93 9
imp 'WSARemoveServiceClass' WSARemoveServiceClass ws2_32 94 1
imp 'WSAResetEvent' WSAResetEvent ws2_32 95 1
imp 'WSASend' WSASend ws2_32 96 7
@ -3817,7 +3815,6 @@ imp 'WSAStartup' WSAStartup ws2_32 115 2
imp 'WSAStringToAddress' WSAStringToAddressW ws2_32 122
imp 'WSAUnadvertiseProvider' WSAUnadvertiseProvider ws2_32 123
imp 'WSAUnhookBlockingHook' WSAUnhookBlockingHook ws2_32 110
imp 'WSAWaitForMultipleEvents' WSAWaitForMultipleEvents ws2_32 124 5
imp 'WSApSetPostRoutine' WSApSetPostRoutine ws2_32 24
imp 'WSCDeinstallProvider' WSCDeinstallProvider ws2_32 125
imp 'WSCDeinstallProvider32' WSCDeinstallProvider32 ws2_32 126
@ -3884,6 +3881,9 @@ imp 'sys_getprotobyname_nt' getprotobyname ws2_32 53
imp 'sys_getprotobynumber_nt' getprotobynumber ws2_32 54
imp 'sys_getservbyname_nt' getservbyname ws2_32 55
imp 'sys_getservbyport_nt' getservbyport ws2_32 56
imp '__WSARecv' WSARecv ws2_32 91 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()

13
libc/nt/struct/fdset.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_FDSET_H_
#define COSMOPOLITAN_LIBC_NT_STRUCT_FDSET_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct NtFdSet {
uint32_t fd_count;
int64_t fd_array[64];
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_FDSET_H_ */

13
libc/nt/struct/iovec.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_IOVEC_H_
#define COSMOPOLITAN_LIBC_NT_STRUCT_IOVEC_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct NtIovec {
uint32_t len;
char *buf;
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_IOVEC_H_ */

13
libc/nt/struct/timeval.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_TIMEVAL_H_
#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEVAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct NtTimeval {
int32_t tv_sec; /* [sic] */
int32_t tv_usec;
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_TIMEVAL_H_ */

View file

@ -1,8 +1,11 @@
#ifndef COSMOPOLITAN_LIBC_NT_WINSOCK_H_
#define COSMOPOLITAN_LIBC_NT_WINSOCK_H_
#include "libc/nt/struct/fdset.h"
#include "libc/nt/struct/guid.h"
#include "libc/nt/struct/iovec.h"
#include "libc/nt/struct/overlapped.h"
#include "libc/nt/struct/pollfd.h"
#include "libc/nt/struct/timeval.h"
#include "libc/sock/sock.h"
/* ░▓█████████████████████████████████████████████▓▒
@ -69,16 +72,6 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct NtTimeval {
int32_t tv_sec; /* [sic] */
int32_t tv_usec;
};
struct NtIovec {
uint32_t len;
char *buf;
};
struct NtMsgHdr {
struct sockaddr *name;
int32_t namelen;
@ -280,11 +273,6 @@ struct NtWsaCompletion {
} Parameters;
};
struct NtFdSet {
uint32_t fd_count;
int64_t fd_array[64];
};
struct NtInterfaceInfo {
uint64_t iiFlags;
struct sockaddr_in iiAddress;
@ -377,17 +365,17 @@ int WSASendTo(uint64_t s, const struct NtIovec *lpBuffers,
int WSAPoll(struct sys_pollfd_nt *inout_fdArray, uint32_t nfds,
signed timeout_ms) paramsnonnull();
int WSARecv(uint64_t s, const struct NtIovec *out_lpBuffers,
int WSARecv(uint64_t s, const struct NtIovec *inout_lpBuffers,
uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
uint32_t *inout_lpFlags,
struct NtOverlapped *opt_inout_lpOverlapped,
const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
paramsnonnull((2, 5));
int WSARecvFrom(uint64_t s, const struct NtIovec *out_lpBuffers,
int WSARecvFrom(uint64_t s, const struct NtIovec *inout_lpBuffers,
uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
uint32_t *inout_lpFlags, void *out_fromsockaddr,
uint32_t *inout_fromsockaddrlen,
uint32_t *opt_inout_fromsockaddrlen,
struct NtOverlapped *opt_inout_lpOverlapped,
const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
paramsnonnull((2, 5));

View file

@ -2,11 +2,11 @@
.imp ws2_32,__imp_WSARecv,WSARecv,91
.text.windows
WSARecv:
__WSARecv:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_WSARecv(%rip),%rax
jmp __sysv2nt8
.endfn WSARecv,globl
.endfn __WSARecv,globl
.previous

View file

@ -2,11 +2,11 @@
.imp ws2_32,__imp_WSARecvFrom,WSARecvFrom,93
.text.windows
WSARecvFrom:
__WSARecvFrom:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_WSARecvFrom(%rip),%rax
jmp __sysv2nt10
.endfn WSARecvFrom,globl
.endfn __WSARecvFrom,globl
.previous

View file

@ -2,11 +2,11 @@
.imp ws2_32,__imp_WSAWaitForMultipleEvents,WSAWaitForMultipleEvents,124
.text.windows
WSAWaitForMultipleEvents:
__WSAWaitForMultipleEvents:
push %rbp
mov %rsp,%rbp
.profilable
mov __imp_WSAWaitForMultipleEvents(%rip),%rax
jmp __sysv2nt6
.endfn WSAWaitForMultipleEvents,globl
.endfn __WSAWaitForMultipleEvents,globl
.previous