Implement pthread_atfork()

If threads are being used, then fork() will now acquire and release and
runtime locks so that fork() may be safely used from threads. This also
makes vfork() thread safe, because pthread mutexes will do nothing when
the process is a child of vfork(). More torture tests have been written
to confirm this all works like a charm. Additionally:

- Invent hexpcpy() api
- Rename nsync_malloc_() to kmalloc()
- Complete posix named semaphore implementation
- Make pthread_create() asynchronous signal safe
- Add rm, rmdir, and touch to command interpreter builtins
- Invent sigisprecious() and modify sigset functions to use it
- Add unit tests for posix_spawn() attributes and fix its bugs

One unresolved problem is the reclaiming of *NSYNC waiter memory in the
forked child processes, within apps which have threads waiting on locks
This commit is contained in:
Justine Tunney 2022-10-16 12:05:08 -07:00
parent 64c284003d
commit 60cb435cb4
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
124 changed files with 2169 additions and 718 deletions

View file

@ -1107,32 +1107,6 @@ syscon pf PF_VSOCK 40 0 0 0 0 0
syscon pf PF_WANPIPE 25 0 0 0 0 0
syscon pf PF_X25 9 0 0 0 0 0
# Eric Allman's exit() codes
#
# - Broadly supported style guideline;
# - Dating back to 1980 in 4.0BSD;
# - That won't be standardized.
#
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary
syscon ex EX_OK 0 0 0 0 0 0 # consensus
syscon ex EX_USAGE 64 64 64 64 64 64 # unix consensus & force NT
syscon ex EX_DATAERR 65 65 65 65 65 65 # unix consensus & force NT
syscon ex EX_NOINPUT 66 66 66 66 66 66 # unix consensus & force NT
syscon ex EX_NOUSER 67 67 67 67 67 67 # unix consensus & force NT
syscon ex EX_NOHOST 68 68 68 68 68 68 # unix consensus & force NT
syscon ex EX_UNAVAILABLE 69 69 69 69 69 69 # unix consensus & force NT
syscon ex EX_SOFTWARE 70 70 70 70 70 70 # unix consensus & force NT
syscon ex EX_OSERR 71 71 71 71 71 71 # unix consensus & force NT
syscon ex EX_OSFILE 72 72 72 72 72 72 # unix consensus & force NT
syscon ex EX_CANTCREAT 73 73 73 73 73 73 # unix consensus & force NT
syscon ex EX_IOERR 74 74 74 74 74 74 # unix consensus & force NT
syscon ex EX_TEMPFAIL 75 75 75 75 75 75 # unix consensus & force NT
syscon ex EX_PROTOCOL 76 76 76 76 76 76 # unix consensus & force NT
syscon ex EX_NOPERM 77 77 77 77 77 77 # unix consensus & force NT
syscon ex EX_CONFIG 78 78 78 78 78 78 # unix consensus & force NT
syscon ex EX__BASE 64 64 64 64 64 64 # unix consensus & force NT
syscon ex EX__MAX 78 78 78 78 78 78 # unix consensus & force NT
# getdents() constants
#
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_DATAERR,65,65,65,65,65,65

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_IOERR,74,74,74,74,74,74

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_NOHOST,68,68,68,68,68,68

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_NOINPUT,66,66,66,66,66,66

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_NOPERM,77,77,77,77,77,77

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_NOUSER,67,67,67,67,67,67

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_OK,0,0,0,0,0,0

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_OSERR,71,71,71,71,71,71

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_OSFILE,72,72,72,72,72,72

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_PROTOCOL,76,76,76,76,76,76

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_SOFTWARE,70,70,70,70,70,70

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_TEMPFAIL,75,75,75,75,75,75

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_UNAVAILABLE,69,69,69,69,69,69

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_USAGE,64,64,64,64,64,64

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX__BASE,64,64,64,64,64,64

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX__MAX,78,78,78,78,78,78

View file

@ -0,0 +1,2 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon limits,LINK_MAX,127,32767,32767,32767,32767,64

View file

@ -1,2 +1,2 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_CANTCREAT,73,73,73,73,73,73
.syscon limits,MAX_CANON,255,1024,255,255,255,255

View file

@ -1,2 +1,2 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon ex,EX_CONFIG,78,78,78,78,78,78
.syscon limits,MAX_INPUT,255,1024,255,255,255,255

View file

@ -1,25 +1,29 @@
#ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_CPIO_H_
#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CPIO_H_
#define C_IXOTH 0000001
#define C_IWOTH 0000002
#define C_IROTH 0000004
#define C_IXGRP 0000010
#define C_IWGRP 0000020
#define C_IRGRP 0000040
#define C_IXUSR 0000100
#define C_IWUSR 0000200
#define C_IRUSR 0000400
#define C_ISVTX 0001000
#define C_ISGID 0002000
#define C_ISUID 0004000
#define C_ISFIFO 0010000
#define C_ISCHR 0020000
#define C_ISDIR 0040000
#define C_ISBLK 0060000
#define C_ISREG 0100000
#define C_ISCTG 0110000
#define C_ISLNK 0120000
#define MAGIC "070707"
#define C_IRUSR 000400
#define C_IWUSR 000200
#define C_IXUSR 000100
#define C_IRGRP 000040
#define C_IWGRP 000020
#define C_IXGRP 000010
#define C_IROTH 000004
#define C_IWOTH 000002
#define C_IXOTH 000001
#define C_ISUID 004000
#define C_ISGID 002000
#define C_ISVTX 001000
#define C_ISBLK 060000
#define C_ISCHR 020000
#define C_ISDIR 040000
#define C_ISFIFO 010000
#define C_ISSOCK 0140000
#define C_ISLNK 0120000
#define C_ISCTG 0110000
#define C_ISREG 0100000
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_CPIO_H_ */

View file

@ -1,48 +1,32 @@
#ifndef COSMOPOLITAN_LIBC_SYSV_CONSTS_EX_H_
#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EX_H_
#include "libc/runtime/symbolic.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
extern const int EX_CANTCREAT;
extern const int EX_CONFIG;
extern const int EX_DATAERR;
extern const int EX_IOERR;
extern const int EX_NOHOST;
extern const int EX_NOINPUT;
extern const int EX_NOPERM;
extern const int EX_NOUSER;
extern const int EX_OK;
extern const int EX_OSERR;
extern const int EX_OSFILE;
extern const int EX_PROTOCOL;
extern const int EX_SOFTWARE;
extern const int EX_TEMPFAIL;
extern const int EX_UNAVAILABLE;
extern const int EX_USAGE;
extern const int EX__BASE;
extern const int EX__MAX;
/**
* @fileoverview Eric Allman's exit() codes
*
* - Broadly supported style guideline;
* - Dating back to 1980 in 4.0BSD;
* - That won't be standardized.
*
*/
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#define EX_CANTCREAT LITERALLY(73)
#define EX_CONFIG LITERALLY(78)
#define EX_DATAERR LITERALLY(65)
#define EX_IOERR LITERALLY(74)
#define EX_NOHOST LITERALLY(68)
#define EX_NOINPUT LITERALLY(66)
#define EX_NOPERM LITERALLY(77)
#define EX_NOUSER LITERALLY(67)
#define EX_OK LITERALLY(0)
#define EX_OSERR LITERALLY(71)
#define EX_OSFILE LITERALLY(72)
#define EX_PROTOCOL LITERALLY(76)
#define EX_SOFTWARE LITERALLY(70)
#define EX_TEMPFAIL LITERALLY(75)
#define EX_UNAVAILABLE LITERALLY(69)
#define EX_USAGE LITERALLY(64)
#define EX__BASE LITERALLY(64)
#define EX__MAX LITERALLY(78)
#define EX_CANTCREAT 73
#define EX_CONFIG 78
#define EX_DATAERR 65
#define EX_IOERR 74
#define EX_NOHOST 68
#define EX_NOINPUT 66
#define EX_NOPERM 77
#define EX_NOUSER 67
#define EX_OK 0
#define EX_OSERR 71
#define EX_OSFILE 72
#define EX_PROTOCOL 76
#define EX_SOFTWARE 70
#define EX_TEMPFAIL 75
#define EX_UNAVAILABLE 69
#define EX_USAGE 64
#define EX__BASE 64
#define EX__MAX 78
#endif /* COSMOPOLITAN_LIBC_SYSV_CONSTS_EX_H_ */