Make improvements

- Clean up sigaction() code
- Add a port scanner example
- Introduce a ParseCidr() API
- Clean up our futex abstraction code
- Fix a harmless integer overflow in ParseIp()
- Use kernel semaphores on NetBSD to make threads much faster
This commit is contained in:
Justine Tunney 2022-11-07 02:22:09 -08:00
parent 539bddce8c
commit c995838e5c
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
107 changed files with 1085 additions and 492 deletions

View file

@ -1,16 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_FREEBSD_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_FREEBSD_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
struct sigset_freebsd {
uint32_t sig[4];
};
struct sigaction_freebsd {
intptr_t sa_handler;
uint32_t sa_flags;
struct sigset_freebsd sa_mask;
};
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_FREEBSD_H_ */

View file

@ -1,17 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_LINUX_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_LINUX_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
struct sigset_linux {
uint32_t sig[2];
};
struct sigaction_linux {
intptr_t sa_handler;
uint64_t sa_flags;
void (*sa_restorer)(void);
struct sigset_linux sa_mask;
};
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_LINUX_H_ */

View file

@ -1,18 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_NETBSD_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_NETBSD_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct sigset_netbsd {
uint32_t sig[4];
};
struct sigaction_netbsd {
intptr_t sa_handler;
struct sigset_netbsd sa_mask;
uint32_t sa_flags;
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_NETBSD_H_ */

View file

@ -1,16 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_OPENBSD_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_OPENBSD_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
struct sigset_openbsd {
uint32_t sig[1];
};
struct sigaction_openbsd {
intptr_t sa_handler;
struct sigset_openbsd sa_mask;
int32_t sa_flags;
};
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_OPENBSD_H_ */

View file

@ -1,27 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_XNU_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_XNU_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
struct __darwin_ucontext;
struct __darwin_siginfo;
struct sigset_xnu {
uint32_t sig[1];
};
struct sigaction_xnu_in {
intptr_t sa_handler;
void (*sa_restorer)(void *, int, int, const struct __darwin_siginfo *,
const struct __darwin_ucontext *);
struct sigset_xnu sa_mask;
int32_t sa_flags;
};
struct sigaction_xnu_out {
intptr_t sa_handler;
struct sigset_xnu sa_mask;
int32_t sa_flags;
};
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_XNU_H_ */

View file

@ -20,7 +20,6 @@ struct sigaction { /* cosmo abi */
uint64_t sa_flags;
void (*sa_restorer)(void);
struct sigset sa_mask;
int64_t __pad;
};
sighandler_t signal(int, sighandler_t);

View file

@ -1,10 +1,65 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_INTERNAL_H_
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/mem/alloca.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct sigaction_linux {
void *sa_handler;
uint64_t sa_flags;
void *sa_restorer;
uint32_t sa_mask[2];
};
struct sigaction_freebsd {
void *sa_handler;
uint32_t sa_flags;
uint32_t sa_mask[4];
};
struct sigaction_openbsd {
void *sa_handler;
uint32_t sa_mask[1];
uint32_t sa_flags;
};
struct sigaction_netbsd {
void *sa_handler;
uint32_t sa_mask[4];
uint32_t sa_flags;
};
struct sigaction_xnu_in {
void *sa_handler;
void *sa_restorer;
uint32_t sa_mask[1];
uint32_t sa_flags;
};
struct sigaction_xnu_out {
void *sa_handler;
uint32_t sa_mask[1];
uint32_t sa_flags;
};
union metasigaction {
struct sigaction cosmo;
struct sigaction_linux linux;
struct sigaction_freebsd freebsd;
struct sigaction_openbsd openbsd;
struct sigaction_netbsd netbsd;
struct sigaction_xnu_in xnu_in;
struct sigaction_xnu_out xnu_out;
};
void __sigenter_xnu(int, struct siginfo *, void *) hidden;
void __sigenter_wsl(int, struct siginfo *, void *) hidden;
void __sigenter_netbsd(int, struct siginfo *, void *) hidden;
void __sigenter_freebsd(int, struct siginfo *, void *) hidden;
void __sigenter_openbsd(int, struct siginfo *, void *) hidden;
const char *DescribeSigaction(char[256], int, const struct sigaction *);
#define DescribeSigaction(rc, sa) DescribeSigaction(alloca(256), rc, sa)

View file

@ -1,7 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_INTERNAL_H_
#include "libc/calls/struct/sigaction-xnu.internal.h"
#include "libc/calls/struct/siginfo-xnu.internal.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/mem/alloca.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)

View file

@ -14,12 +14,13 @@ int sys_clock_gettime_nt(int, struct timespec *) hidden;
int sys_clock_gettime_xnu(int, struct timespec *) hidden;
int sys_clock_nanosleep(int, int, const struct timespec *, struct timespec *) hidden;
int sys_clock_nanosleep_nt(int, int, const struct timespec *, struct timespec *) hidden;
int sys_clock_nanosleep_xnu(int, int, const struct timespec *, struct timespec *) hidden;
int sys_clock_nanosleep_openbsd(int, int, const struct timespec *, struct timespec *) hidden;
int sys_clock_nanosleep_xnu(int, int, const struct timespec *, struct timespec *) hidden;
int sys_futimens(int, const struct timespec[2]) hidden;
int sys_nanosleep(const struct timespec *, struct timespec *) hidden;
int sys_nanosleep_nt(const struct timespec *, struct timespec *) hidden;
int sys_nanosleep_xnu(const struct timespec *, struct timespec *) hidden;
int sys_sem_timedwait(int64_t, const struct timespec *) hidden;
int sys_utimensat(int, const char *, const struct timespec[2], int) hidden;
int sys_utimensat_nt(int, const char *, const struct timespec[2], int) hidden;
int sys_utimensat_xnu(int, const char *, const struct timespec[2], int) hidden;

View file

@ -17,6 +17,8 @@ int lutimes(const char *, const struct timeval[2]);
int utimes(const char *, const struct timeval[2]);
int timeval_cmp(struct timeval, struct timeval) pureconst;
struct timeval timeval_frommicros(int64_t) pureconst;
struct timeval timeval_frommillis(int64_t) pureconst;
struct timeval timeval_add(struct timeval, struct timeval) pureconst;
struct timeval timeval_sub(struct timeval, struct timeval) pureconst;
struct timeval timespec_totimeval(struct timespec) pureconst;

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_FREEBSD_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_UCONTEXT_FREEBSD_INTERNAL_H_
#include "libc/calls/struct/sigaction-freebsd.internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -52,7 +51,7 @@ struct mcontext_freebsd {
};
struct ucontext_freebsd {
struct sigset_freebsd uc_sigmask;
uint32_t uc_sigmask[4];
struct mcontext_freebsd uc_mcontext;
struct ucontext_freebsd *uc_link;
struct stack_freebsd uc_stack;