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

@ -19,69 +19,24 @@
#include "libc/calls/struct/sockaddr6.h"
#include "libc/errno.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/macros.internal.h"
#include "libc/sock/sock.h"
#include "libc/sock/sockdebug.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/af.h"
#include "libc/sysv/consts/ipproto.h"
#include "libc/sysv/consts/sock.h"
const char *__describe_socket_family(int family) {
static char buf[12];
if (family == AF_UNIX) return "AF_UNIX";
if (family == AF_INET) return "AF_INET";
if (family == AF_INET6) return "AF_INET6";
FormatInt32(buf, family);
return buf;
}
const char *__describe_socket_type(int type) {
int x;
char *p;
static char buf[12 + 1 + 12 + 1 + 13 + 1];
p = buf;
x = type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK);
if (x == SOCK_STREAM) {
p = stpcpy(p, "SOCK_STREAM");
} else if (x == SOCK_DGRAM) {
p = stpcpy(p, "SOCK_DGRAM");
} else if (x == SOCK_RAW) {
p = stpcpy(p, "SOCK_RAW");
} else if (x == SOCK_RDM) {
p = stpcpy(p, "SOCK_RDM");
} else if (x == SOCK_SEQPACKET) {
p = stpcpy(p, "SOCK_SEQPACKET");
} else {
p = FormatInt32(p, x);
}
if (type & SOCK_CLOEXEC) p = stpcpy(p, "|SOCK_CLOEXEC");
if (type & SOCK_NONBLOCK) p = stpcpy(p, "|SOCK_NONBLOCK");
return buf;
}
const char *__describe_socket_protocol(int family) {
static char buf[12];
if (family == IPPROTO_IP) return "IPPROTO_IP";
if (family == IPPROTO_ICMP) return "IPPROTO_ICMP";
if (family == IPPROTO_TCP) return "IPPROTO_TCP";
if (family == IPPROTO_UDP) return "IPPROTO_UDP";
if (family == IPPROTO_RAW) return "IPPROTO_RAW";
if (family == IPPROTO_IPV6) return "IPPROTO_IPv6";
FormatInt32(buf, family);
return buf;
}
const char *__describe_sockaddr(const struct sockaddr *sa, size_t sasize) {
const char *(DescribeSockaddr)(char buf[128], const struct sockaddr *sa,
size_t sasize) {
int e;
size_t n;
uint16_t port;
char *p, ip[72];
static char buf[128];
e = errno;
stpcpy(buf, "NULL");
if (sa && sasize >= sizeof(sa->sa_family)) {
stpcpy(buf, __describe_socket_family(sa->sa_family));
stpcpy(buf, DescribeSocketFamily(sa->sa_family));
if (sa->sa_family == AF_INET && sasize >= sizeof(struct sockaddr_in)) {
const struct sockaddr_in *in;
in = (const struct sockaddr_in *)sa;
@ -108,7 +63,7 @@ const char *__describe_sockaddr(const struct sockaddr *sa, size_t sasize) {
const struct sockaddr_un *unix;
unix = (const struct sockaddr_un *)sa;
n = strnlen(unix->sun_path, sizeof(unix->sun_path));
n = MIN(n, sizeof(buf) - 1);
n = MIN(n, 128 - 1);
memcpy(buf, unix->sun_path, n);
buf[n] = 0;
}