Get threads working on all platforms

We now have a high-quality clone() implementation for creating
lightweight threads on Linux/Windows/FreeBSD/NetBSD/OpenBSD.
This commit is contained in:
Justine Tunney 2022-05-12 17:52:13 -07:00
parent 4e62cefa6e
commit fec396037a
43 changed files with 850 additions and 532 deletions

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/macros.internal.inc"
.scall __tfork,0xfff008ffffffffff,globl

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/macros.internal.inc"
.scall getcontext,0x133fff1a5fffffff,globl

View file

@ -0,0 +1,2 @@
.include "o/libc/sysv/macros.internal.inc"
.scall sys_getcontext,0x133fff1a5fffffff,globl,hidden

View file

@ -0,0 +1,2 @@
.include "o/libc/sysv/macros.internal.inc"
.scall sys_tgkill,0xfffffffffffff0ea,globl,hidden

View file

@ -0,0 +1,2 @@
.include "o/libc/sysv/macros.internal.inc"
.scall sys_tkill,0x13e0771b121690c8,globl,hidden

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/macros.internal.inc"
.scall tgkill,0xfffffffffffff0ea,globl

View file

@ -1,2 +0,0 @@
.include "o/libc/sysv/macros.internal.inc"
.scall tkill,0xfffffffffffff0c8,globl

View file

@ -218,7 +218,7 @@ syscon compat O_LARGEFILE 0 0 0 0 0 0 #
# the revolutionary praxis of malloc()
#
# group name GNU/Systemd XNU's Not UNIX! FreeBSD OpenBSD NetBSD The New Technology Commentary
syscon compat MAP_FILE 0 0 0 0 0 0 # consensus
syscon mmap MAP_FILE 0 0 0 0 0 0 # consensus
syscon mmap MAP_SHARED 1 1 1 1 1 1 # forced consensus & faked nt
syscon mmap MAP_PRIVATE 2 2 2 2 2 2 # forced consensus & faked nt
syscon mmap MAP_STACK 6 6 6 6 6 6 # our definition
@ -2318,9 +2318,7 @@ syscon nr __NR_access_extended 0xfff 0x200011c 0xfff 0xfff 0xfff 0xff
syscon nr __NR_audit_session_join 0xfff 0x20001ad 0xfff 0xfff 0xfff 0xfff
syscon nr __NR_audit_session_port 0xfff 0x20001b0 0xfff 0xfff 0xfff 0xfff
syscon nr __NR_audit_session_self 0xfff 0x20001ac 0xfff 0xfff 0xfff 0xfff
syscon nr __NR_bsdthread_create 0xfff 0x2000168 0xfff 0xfff 0xfff 0xfff
syscon nr __NR_bsdthread_ctl 0xfff 0x20001de 0xfff 0xfff 0xfff 0xfff
syscon nr __NR_bsdthread_register 0xfff 0x200016e 0xfff 0xfff 0xfff 0xfff
syscon nr __NR_bsdthread_terminate 0xfff 0x2000169 0xfff 0xfff 0xfff 0xfff
syscon nr __NR_change_fdguard_np 0xfff 0x20001bc 0xfff 0xfff 0xfff 0xfff
syscon nr __NR_chmod_extended 0xfff 0x200011a 0xfff 0xfff 0xfff 0xfff

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon nr,__NR_bsdthread_create,0xfff,0x2000168,0xfff,0xfff,0xfff,0xfff

View file

@ -1,2 +0,0 @@
#include "libc/sysv/consts/syscon.internal.h"
.syscon nr,__NR_bsdthread_register,0xfff,0x200016e,0xfff,0xfff,0xfff,0xfff

View file

@ -404,9 +404,7 @@ extern const long __NR_access_extended;
extern const long __NR_audit_session_join;
extern const long __NR_audit_session_port;
extern const long __NR_audit_session_self;
extern const long __NR_bsdthread_create;
extern const long __NR_bsdthread_ctl;
extern const long __NR_bsdthread_register;
extern const long __NR_bsdthread_terminate;
extern const long __NR_change_fdguard_np;
extern const long __NR_chmod_extended;
@ -1101,7 +1099,6 @@ COSMOPOLITAN_C_END_
#define __NR_pidfd_send_signal SYMBOLIC(__NR_pidfd_send_signal)
#define __NR_io_uring_setup SYMBOLIC(__NR_io_uring_setup)
#define __NR_io_uring_enter SYMBOLIC(__NR_io_uring_enter)
#define __NR_io_uring_register SYMBOLIC(__NR_io_uring_register)
#define __NR_pledge SYMBOLIC(__NR_pledge)
#define __NR_msyscall SYMBOLIC(__NR_msyscall)
#define __NR_ktrace SYMBOLIC(__NR_ktrace)
@ -1173,7 +1170,6 @@ COSMOPOLITAN_C_END_
#define __NR_audit_session_join SYMBOLIC(__NR_audit_session_join)
#define __NR_audit_session_port SYMBOLIC(__NR_audit_session_port)
#define __NR_audit_session_self SYMBOLIC(__NR_audit_session_self)
#define __NR_bsdthread_create SYMBOLIC(__NR_bsdthread_create)
#define __NR_bsdthread_ctl SYMBOLIC(__NR_bsdthread_ctl)
#define __NR_bsdthread_register SYMBOLIC(__NR_bsdthread_register)
#define __NR_bsdthread_terminate SYMBOLIC(__NR_bsdthread_terminate)

View file

@ -99,7 +99,7 @@ scall __sys_wait4 0x1c100b007200703d globl hidden
scall sys_kill 0x02507a025202503e globl hidden # kill(pid, sig, 1) b/c xnu
scall sys_killpg 0xffffff092fffffff globl hidden
scall sys_clone 0x11fffffffffff038 globl hidden
scall tkill 0xfffffffffffff0c8 globl
scall sys_tkill 0x13e0771b121690c8 globl hidden # thr_kill() on freebsd; _lwp_kill() on netbsd; thrkill() on openbsd where arg3 should be 0; bsdthread_terminate() on XNU which only has 1 arg
scall futex 0xfff053fffffff0ca globl
scall set_robust_list 0xfffffffffffff111 globl
scall get_robust_list 0xfffffffffffff112 globl
@ -265,7 +265,7 @@ scall clock_settime 0x1ac0580e9ffff0e3 globl
scall sys_clock_gettime 0x1ab0570e8ffff0e4 globl hidden # Linux 2.6+ (c. 2003); XNU uses magic address
scall clock_getres 0x1ad0590eaffff0e5 globl
scall clock_nanosleep 0xffffff0f4ffff0e6 globl
scall tgkill 0xfffffffffffff0ea globl
scall sys_tgkill 0xfffffffffffff0ea globl hidden
scall mbind 0xfffffffffffff0ed globl
scall set_mempolicy 0xfffffffffffff0ee globl
scall get_mempolicy 0xfffffffffffff0ef globl
@ -658,7 +658,7 @@ scall fhlink 0xffffff235fffffff globl
scall fhlinkat 0xffffff236fffffff globl
scall fhreadlink 0xffffff237fffffff globl
scall getaudit 0xffffff1c1fffffff globl
scall getcontext 0x133fff1a5fffffff globl
scall sys_getcontext 0x133fff1a5fffffff globl hidden
#scall getdomainname 0xffff00a2ffffffff globl
scall getfhat 0xffffff234fffffff globl
scall gethostid 0xffffff08efffffff globl
@ -756,7 +756,6 @@ scall wait 0xffffff054fffffff globl
scall wait6 0x1e1fff214fffffff globl
scall yield 0xffffff141fffffff globl
#──────────────────────────OPENBSD───────────────────────────
scall __tfork 0xfff008ffffffffff globl
scall __thrsleep 0xfff05effffffffff globl
scall __thrwakeup 0xfff12dffffffffff globl
scall __threxit 0xfff12effffffffff globl