Use *NSYNC for POSIX threads locking APIs

Condition variables, barriers, and r/w locks now work very well.
This commit is contained in:
Justine Tunney 2022-09-11 11:02:07 -07:00
parent 3de35e196c
commit b5cb71ab84
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
197 changed files with 3734 additions and 3817 deletions

View file

@ -579,7 +579,7 @@ syscon sicode SYS_USER_DISPATCH 2 -1 -1 -1 -1 -1 # SIGSYS; syscall
# sigaltstack() values
#
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary
syscon ss SIGSTKSZ 8192 131072 34816 28672 28672 8192 # overlaid with STACKSIZE; you need to #undef SIGSTKSZ to access this symbol
syscon ss SIGSTKSZ 8192 131072 34816 28672 28672 8192 # overlaid with FRAMESIZE; you need to #undef SIGSTKSZ to access this symbol
syscon ss MINSIGSTKSZ 2048 32768 2048 12288 8192 2048 # overlaid with 32768; you need to #undef MINSIGSTKSZ to access this symbol
syscon ss SS_ONSTACK 1 1 1 1 1 1 # unix consensus
syscon ss SS_DISABLE 2 4 4 4 4 2 # bsd consensus
@ -1316,9 +1316,9 @@ syscon rusage RUSAGE_BOTH -2 99 99 99 99 99 # woop
#
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary
syscon futex FUTEX_WAIT 0 0 0 1 0 0
syscon futex FUTEX_WAKE 1 0 0 2 1 0
syscon futex FUTEX_REQUEUE 3 0 0 3 3 0
syscon futex FUTEX_PRIVATE_FLAG 128 0 0 128 128 0
syscon futex FUTEX_WAKE 1 0 0 2 0 0
syscon futex FUTEX_REQUEUE 3 0 0 3 0 0
syscon futex FUTEX_PRIVATE_FLAG 128 0 0 128 0 0
# lio_listio() magnums
#
@ -1336,7 +1336,7 @@ syscon sched SCHED_OTHER 0 127 2 127 0 127 # standard round-robin
syscon sched SCHED_FIFO 1 127 1 127 1 127 # [real-time] first-in, first-out policy
syscon sched SCHED_RR 2 127 3 127 2 127 # [real-time] round-robin policy
syscon sched SCHED_BATCH 3 127 2 127 0 127 # for "batch" style execution of processes; polyfilled as SCHED_OTHER on non-Linux
𝔰𝔶𝔰𝔠𝔬𝔫 sched SCHED_IDLE 5 127 2 127 0 127 # for running very low priority background jobs; polyfilled as SCHED_OTHER on non-Linux
syscon sched SCHED_IDLE 5 127 2 127 0 127 # for running very low priority background jobs; polyfilled as SCHED_OTHER on non-Linux
syscon sched SCHED_DEADLINE 6 127 127 127 127 127 # can only be set by sched_setattr()
syscon sched SCHED_RESET_ON_FORK 0x40000000 0 0 0 0 0 # Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork(); no-op on non-Linux
@ -1847,7 +1847,7 @@ syscon nr __NR_kill 0x003e 0x2000025 0x0025 0x007a 0x025 0xfff
syscon nr __NR_killpg 0xfff 0xfff 0x0092 0xfff 0xfff 0xfff
syscon nr __NR_clone 0x0038 0xfff 0xfff 0xfff 0x11f 0xfff
syscon nr __NR_tkill 0x00c8 0xfff 0xfff 0xfff 0xfff 0xfff
syscon nr __NR_futex 0x00ca 0xfff 0xfff 0x0053 0x0a6 0xfff
syscon nr __NR_futex 0x00ca 0xfff 0xfff 0x0053 0xfff 0xfff
syscon nr __NR_set_robust_list 0x0111 0xfff 0xfff 0xfff 0x0a7 0xfff
syscon nr __NR_get_robust_list 0x0112 0xfff 0xfff 0xfff 0x0a8 0xfff
syscon nr __NR_uname 0x003f 0xfff 0x00a4 0xfff 0xfff 0xfff

View file

@ -1,2 +1,2 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon futex,FUTEX_PRIVATE_FLAG,128,0,0,128,128,0
.syscon futex,FUTEX_PRIVATE_FLAG,128,0,0,128,0,0

View file

@ -1,2 +1,2 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon futex,FUTEX_REQUEUE,3,0,0,3,3,0
.syscon futex,FUTEX_REQUEUE,3,0,0,3,0,0

View file

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

View file

@ -1,2 +1,2 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon misc,SOMAXCONN,0x80,0x80,0x80,0x80,0x80,0x7fffffff
.syscon limits,SOMAXCONN,4096,128,128,128,128,2147483647

View file

@ -1,2 +1,2 @@
.include "o/libc/sysv/consts/syscon.internal.inc"
.syscon nr,__NR_futex,0x00ca,0xfff,0xfff,0x0053,0x0a6,0xfff
.syscon nr,__NR_futex,0x00ca,0xfff,0xfff,0x0053,0xfff,0xfff

View file

@ -2,21 +2,25 @@
#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FUTEX_H_
#include "libc/runtime/symbolic.h"
#define FUTEX_WAIT SYMBOLIC(FUTEX_WAIT)
#define FUTEX_WAKE SYMBOLIC(FUTEX_WAKE)
#define FUTEX_REQUEUE SYMBOLIC(FUTEX_REQUEUE)
#define FUTEX_PRIVATE_FLAG SYMBOLIC(FUTEX_PRIVATE_FLAG)
#define FUTEX_WAIT SYMBOLIC(FUTEX_WAIT)
#define FUTEX_WAKE SYMBOLIC(FUTEX_WAKE)
#define FUTEX_REQUEUE SYMBOLIC(FUTEX_REQUEUE)
#define FUTEX_PRIVATE_FLAG 128
#define FUTEX_WAIT_PRIVATE (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
#define FUTEX_WAKE_PRIVATE (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)
#define FUTEX_WAIT_BITSET 9
#define FUTEX_CLOCK_REALTIME 256
#define FUTEX_BITSET_MATCH_ANY 0xffffffff
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
extern const int FUTEX_WAIT;
extern const int FUTEX_WAKE;
extern const int FUTEX_REQUEUE;
extern const int FUTEX_PRIVATE_FLAG;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -10,7 +10,7 @@ extern const int SS_DISABLE;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#define SIGSTKSZ STACKSIZE
#define SIGSTKSZ FRAMESIZE
#define MINSIGSTKSZ 32768
#define SS_ONSTACK 1
#define SS_DISABLE SS_DISABLE

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/atomic.h"
#include "libc/runtime/runtime.h"
/**
@ -40,4 +41,4 @@
* under normal circumstances, `__strace` should only be either zero or
* one.
*/
_Atomic(int) __strace;
atomic_int __strace;

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/macros.internal.h"
.privileged
@ -32,12 +33,52 @@
// @param %rsi,%rdx,%rcx,%r8,%r9 may supply parameters 1 through 5
// @param sixth is optionally pushed on the stack before call
// @return %rax has result, or -1 w/ errno on failure
syscall:mov %rdi,%rax
mov %rsi,%rdi
mov %rdx,%rsi
mov %rcx,%rdx
mov %r8,%rcx # intended
mov %r9,%r8
mov 8(%rsp),%r9
jmp *__systemfive(%rip)
syscall:
push %rbp
mov %rsp,%rbp
.profilable
// slide arguments into their right places
mov %rdi,%rax # nr
mov %rsi,%rdi # arg 1
mov %rdx,%rsi # arg 2
mov %rcx,%rdx # arg 3
mov %r8,%rcx # arg 4
mov %r9,%r8 # arg 5
mov 16(%rbp),%r9 # arg 6
push 32(%rbp) # arg 8
push 24(%rbp) # arg 7
// convert from consts.sh to syscalls.sh encoding
push %rcx
mov __hostos(%rip),%cl
test $LINUX,%cl
jnz 2f
1: test $FREEBSD,%cl
jz 1f
shl $4*7,%rax
jmp 2f
1: test $OPENBSD,%cl
jz 1f
shl $4*10,%rax
jmp 2f
1: test $NETBSD,%cl
jz 1f
shl $4*13,%rax
jmp 2f
1: test $XNU,%cl
jz 2f
mov %eax,%ecx
and $0x0f000000,%ecx
and $0x00000fff,%eax
shl $4*3,%eax
or %ecx,%eax
2: pop %rcx
// trigger the system call
call *__systemfive(%rip)
// clean up stack and return
leave
ret
.endfn syscall,globl