summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authoririri <iri@konnichiwastevenspielbergde.su>2018-10-13 13:58:52 -0700
committerOri Bernstein <ori@eigenstate.org>2018-10-18 23:21:10 -0700
commit2d9fe7100209acb431e392d58e4cf4eccfde00b7 (patch)
tree888cd09a78c8d75a53f474f3c4802fb914a6bff7 /mk
parentb17873ed4e6a14786758fd68290ef572b0b88f10 (diff)
downloadmc-2d9fe7100209acb431e392d58e4cf4eccfde00b7.tar.gz
Add thread-local storage for POSIX-y platforms.
This patch implements thread-local storage by using a segment register to store pointers to regions of memory unique to each thread. In spawned threads, this region starts above the top of the stack, while in the main thread, this region is initially statically allocated so it can be used in `__init__` functions and dynamically reallocated if it needs to grow beyond 8 slots. The api consists of 3 functions: `tlsalloc()`, which must be called from the main thread, allocates a slot and returns a key to be used with `settls(k, v)` and `gettls(k)`. Each thread inherits its tls slots from the thread that spawned it and any slot added after a given thread is spawned is not available in that thread. Adding tls regions gives threads an easy way to get their own tids, allowing us to add some basic correctness checks to the mutex code. A pointer to the base of the stack and the size of the mapping are also stored in the tls region, making it easy to support user-specified stack sizes in the future. Changes from previous version: - Fixed size of main tls static allocation. - More comments, less magic. - Fixed typo in start+osx-x64.s exit+{freebsd,linux,openbsd}-x64.s - `gettlskey` renamed to `tlsalloc`. - `key` is now `tlskey(@a#)`, improving safety. - Test is slightly less bad.
Diffstat (limited to 'mk')
-rwxr-xr-xmk/bootstrap/bootstrap+Darwin-x86_64.sh11
-rwxr-xr-xmk/bootstrap/bootstrap+FreeBSD-amd64.sh12
-rwxr-xr-xmk/bootstrap/bootstrap+Linux-x86_64.sh12
-rwxr-xr-xmk/bootstrap/bootstrap+NetBSD-amd64.sh12
-rwxr-xr-xmk/bootstrap/bootstrap+OpenBSD-amd64.sh12
5 files changed, 39 insertions, 20 deletions
diff --git a/mk/bootstrap/bootstrap+Darwin-x86_64.sh b/mk/bootstrap/bootstrap+Darwin-x86_64.sh
index 9e63957..3bc1f36 100755
--- a/mk/bootstrap/bootstrap+Darwin-x86_64.sh
+++ b/mk/bootstrap/bootstrap+Darwin-x86_64.sh
@@ -7,6 +7,7 @@ set -x
as -g -o mbld/cpufeatures.o mbld/cpufeatures+posixy-x64.s
as -g -o lib/thread/start.o lib/thread/start+osx-x64.s
as -g -o lib/thread/atomic-impl.o lib/thread/atomic-impl+x64.s
+ as -g -o lib/thread/tls-impl.o lib/thread/tls-impl+osx-x64.s
as -g -o lib/std/getbp.o lib/std/getbp+posixy-x64.s
$pwd/6/6m -I lib/sys lib/std/option.myr
$pwd/6/6m -I lib/sys lib/std/traits.myr
@@ -120,16 +121,18 @@ set -x
$pwd/6/6m -I lib/std -I lib/sys lib/bio/puti.myr
ar -rcs lib/bio/libbio.a lib/bio/puti.o lib/bio/geti.o lib/bio/fd.o lib/bio/mem.o lib/bio/bio.o lib/bio/types.o lib/bio/iter.o
$pwd/muse/muse -o lib/bio/libbio.use -p bio lib/bio/puti.use lib/bio/geti.use lib/bio/fd.use lib/bio/mem.use lib/bio/bio.use lib/bio/types.use lib/bio/iter.use
- $pwd/6/6m -I lib/sys -I lib/std lib/thread/spawn+osx.myr
- $pwd/6/6m -I lib/sys -I lib/std lib/thread/ncpu.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/common.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/atomic.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/types+osx.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/tls+osx.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/spawn+osx.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/ncpu.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/futex+osx.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/sem.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/mutex.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/hookstd.myr
- ar -rcs lib/thread/libthread.a lib/thread/mutex.o lib/thread/atomic.o lib/thread/atomic-impl.o lib/thread/hookstd.o lib/thread/sem.o lib/thread/common.o lib/thread/ncpu.o lib/thread/start.o lib/thread/futex.o lib/thread/spawn.o
- $pwd/muse/muse -o lib/thread/libthread.use -p thread lib/thread/mutex.use lib/thread/atomic.use lib/thread/hookstd.use lib/thread/sem.use lib/thread/common.use lib/thread/ncpu.use lib/thread/futex.use lib/thread/spawn.use
+ ar -rcs lib/thread/libthread.a lib/thread/mutex.o lib/thread/atomic.o lib/thread/atomic-impl.o lib/thread/types.o lib/thread/tls.o lib/thread/tls-impl.o lib/thread/hookstd.o lib/thread/sem.o lib/thread/common.o lib/thread/ncpu.o lib/thread/start.o lib/thread/futex.o lib/thread/spawn.o
+ $pwd/muse/muse -o lib/thread/libthread.use -p thread lib/thread/mutex.use lib/thread/atomic.use lib/thread/types.use lib/thread/tls.use lib/thread/hookstd.use lib/thread/sem.use lib/thread/common.use lib/thread/ncpu.use lib/thread/futex.use lib/thread/spawn.use
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/opts.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/syssel.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/libs.myr
diff --git a/mk/bootstrap/bootstrap+FreeBSD-amd64.sh b/mk/bootstrap/bootstrap+FreeBSD-amd64.sh
index b5c62b1..dd835cd 100755
--- a/mk/bootstrap/bootstrap+FreeBSD-amd64.sh
+++ b/mk/bootstrap/bootstrap+FreeBSD-amd64.sh
@@ -7,6 +7,7 @@ set -x
as -g -o mbld/cpufeatures.o mbld/cpufeatures+posixy-x64.s
as -g -o lib/thread/exit.o lib/thread/exit+freebsd-x64.s
as -g -o lib/thread/atomic-impl.o lib/thread/atomic-impl+x64.s
+ as -g -o lib/thread/tls-impl.o lib/thread/tls-impl+fsbase-x64.s
as -g -o lib/std/getbp.o lib/std/getbp+posixy-x64.s
$pwd/6/6m -I lib/sys lib/std/option.myr
$pwd/6/6m -I lib/sys lib/std/traits.myr
@@ -120,16 +121,19 @@ set -x
$pwd/6/6m -I lib/std -I lib/sys lib/bio/puti.myr
ar -rcs lib/bio/libbio.a lib/bio/puti.o lib/bio/geti.o lib/bio/fd.o lib/bio/mem.o lib/bio/bio.o lib/bio/types.o lib/bio/iter.o
$pwd/muse/muse -o lib/bio/libbio.use -p bio lib/bio/puti.use lib/bio/geti.use lib/bio/fd.use lib/bio/mem.use lib/bio/bio.use lib/bio/types.use lib/bio/iter.use
- $pwd/6/6m -I lib/sys -I lib/std lib/thread/spawn+freebsd.myr
- $pwd/6/6m -I lib/sys -I lib/std lib/thread/ncpu+freebsd.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/common.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/atomic.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/types+fsbase.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/fsbase+freebsd.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/tls+fsbase.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/spawn+freebsd.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/ncpu+freebsd.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/futex+freebsd.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/sem.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/mutex.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/hookstd.myr
- ar -rcs lib/thread/libthread.a lib/thread/mutex.o lib/thread/atomic.o lib/thread/atomic-impl.o lib/thread/hookstd.o lib/thread/sem.o lib/thread/common.o lib/thread/ncpu.o lib/thread/exit.o lib/thread/futex.o lib/thread/spawn.o
- $pwd/muse/muse -o lib/thread/libthread.use -p thread lib/thread/mutex.use lib/thread/atomic.use lib/thread/hookstd.use lib/thread/sem.use lib/thread/common.use lib/thread/ncpu.use lib/thread/futex.use lib/thread/spawn.use
+ ar -rcs lib/thread/libthread.a lib/thread/mutex.o lib/thread/atomic.o lib/thread/atomic-impl.o lib/thread/types.o lib/thread/fsbase.o lib/thread/tls.o lib/thread/tls-impl.o lib/thread/hookstd.o lib/thread/sem.o lib/thread/common.o lib/thread/ncpu.o lib/thread/exit.o lib/thread/futex.o lib/thread/spawn.o
+ $pwd/muse/muse -o lib/thread/libthread.use -p thread lib/thread/mutex.use lib/thread/atomic.use lib/thread/types.use lib/thread/fsbase.use lib/thread/tls.use lib/thread/hookstd.use lib/thread/sem.use lib/thread/common.use lib/thread/ncpu.use lib/thread/futex.use lib/thread/spawn.use
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/opts.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/syssel.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/libs.myr
diff --git a/mk/bootstrap/bootstrap+Linux-x86_64.sh b/mk/bootstrap/bootstrap+Linux-x86_64.sh
index 0b5b761..c3282de 100755
--- a/mk/bootstrap/bootstrap+Linux-x86_64.sh
+++ b/mk/bootstrap/bootstrap+Linux-x86_64.sh
@@ -7,6 +7,7 @@ set -x
as -g -o mbld/cpufeatures.o mbld/cpufeatures+posixy-x64.s
as -g -o lib/thread/exit.o lib/thread/exit+linux-x64.s
as -g -o lib/thread/atomic-impl.o lib/thread/atomic-impl+x64.s
+ as -g -o lib/thread/tls-impl.o lib/thread/tls-impl+fsbase-x64.s
as -g -o lib/std/getbp.o lib/std/getbp+posixy-x64.s
$pwd/6/6m -I lib/sys lib/std/option.myr
$pwd/6/6m -I lib/sys lib/std/traits.myr
@@ -120,16 +121,19 @@ set -x
$pwd/6/6m -I lib/std -I lib/sys lib/bio/puti.myr
ar -rcs lib/bio/libbio.a lib/bio/puti.o lib/bio/geti.o lib/bio/fd.o lib/bio/mem.o lib/bio/bio.o lib/bio/types.o lib/bio/iter.o
$pwd/muse/muse -o lib/bio/libbio.use -p bio lib/bio/puti.use lib/bio/geti.use lib/bio/fd.use lib/bio/mem.use lib/bio/bio.use lib/bio/types.use lib/bio/iter.use
- $pwd/6/6m -I lib/sys -I lib/std lib/thread/spawn+linux.myr
- $pwd/6/6m -I lib/sys -I lib/std lib/thread/ncpu+linux.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/common.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/atomic.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/types+fsbase.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/fsbase+linux.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/tls+fsbase.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/spawn+linux.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/ncpu+linux.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/futex+linux.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/sem.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/mutex.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/hookstd.myr
- ar -rcs lib/thread/libthread.a lib/thread/mutex.o lib/thread/atomic.o lib/thread/atomic-impl.o lib/thread/hookstd.o lib/thread/sem.o lib/thread/common.o lib/thread/ncpu.o lib/thread/exit.o lib/thread/futex.o lib/thread/spawn.o
- $pwd/muse/muse -o lib/thread/libthread.use -p thread lib/thread/mutex.use lib/thread/atomic.use lib/thread/hookstd.use lib/thread/sem.use lib/thread/common.use lib/thread/ncpu.use lib/thread/futex.use lib/thread/spawn.use
+ ar -rcs lib/thread/libthread.a lib/thread/mutex.o lib/thread/atomic.o lib/thread/atomic-impl.o lib/thread/types.o lib/thread/fsbase.o lib/thread/tls.o lib/thread/tls-impl.o lib/thread/hookstd.o lib/thread/sem.o lib/thread/common.o lib/thread/ncpu.o lib/thread/exit.o lib/thread/futex.o lib/thread/spawn.o
+ $pwd/muse/muse -o lib/thread/libthread.use -p thread lib/thread/mutex.use lib/thread/atomic.use lib/thread/types.use lib/thread/fsbase.use lib/thread/tls.use lib/thread/hookstd.use lib/thread/sem.use lib/thread/common.use lib/thread/ncpu.use lib/thread/futex.use lib/thread/spawn.use
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/opts.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/syssel.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/libs.myr
diff --git a/mk/bootstrap/bootstrap+NetBSD-amd64.sh b/mk/bootstrap/bootstrap+NetBSD-amd64.sh
index ae560c0..a81f8c3 100755
--- a/mk/bootstrap/bootstrap+NetBSD-amd64.sh
+++ b/mk/bootstrap/bootstrap+NetBSD-amd64.sh
@@ -6,6 +6,7 @@ set -x
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/config.myr
as -g -o mbld/cpufeatures.o mbld/cpufeatures+posixy-x64.s
as -g -o lib/thread/atomic-impl.o lib/thread/atomic-impl+x64.s
+ as -g -o lib/thread/tls-impl.o lib/thread/tls-impl+fsbase-x64.s
as -g -o lib/std/getbp.o lib/std/getbp+posixy-x64.s
$pwd/6/6m -I lib/sys lib/std/option.myr
$pwd/6/6m -I lib/sys lib/std/traits.myr
@@ -119,15 +120,18 @@ set -x
$pwd/6/6m -I lib/std -I lib/sys lib/bio/puti.myr
ar -rcs lib/bio/libbio.a lib/bio/puti.o lib/bio/geti.o lib/bio/fd.o lib/bio/mem.o lib/bio/bio.o lib/bio/types.o lib/bio/iter.o
$pwd/muse/muse -o lib/bio/libbio.use -p bio lib/bio/puti.use lib/bio/geti.use lib/bio/fd.use lib/bio/mem.use lib/bio/bio.use lib/bio/types.use lib/bio/iter.use
- $pwd/6/6m -I lib/sys -I lib/std lib/thread/spawn+netbsd.myr
- $pwd/6/6m -I lib/sys -I lib/std lib/thread/ncpu.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/common.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/atomic.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/types+fsbase.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/fsbase+netbsd.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/tls+fsbase.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/spawn+netbsd.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/ncpu.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/sem.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/mutex.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/hookstd.myr
- ar -rcs lib/thread/libthread.a lib/thread/mutex.o lib/thread/atomic.o lib/thread/atomic-impl.o lib/thread/hookstd.o lib/thread/sem.o lib/thread/common.o lib/thread/ncpu.o lib/thread/spawn.o
- $pwd/muse/muse -o lib/thread/libthread.use -p thread lib/thread/mutex.use lib/thread/atomic.use lib/thread/hookstd.use lib/thread/sem.use lib/thread/common.use lib/thread/ncpu.use lib/thread/spawn.use
+ ar -rcs lib/thread/libthread.a lib/thread/mutex.o lib/thread/atomic.o lib/thread/atomic-impl.o lib/thread/types.o lib/thread/fsbase.o lib/thread/tls.o lib/thread/tls-impl.o lib/thread/hookstd.o lib/thread/sem.o lib/thread/common.o lib/thread/ncpu.o lib/thread/spawn.o
+ $pwd/muse/muse -o lib/thread/libthread.use -p thread lib/thread/mutex.use lib/thread/atomic.use lib/thread/types.use lib/thread/fsbase.use lib/thread/tls.use lib/thread/hookstd.use lib/thread/sem.use lib/thread/common.use lib/thread/ncpu.use lib/thread/spawn.use
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/opts.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/syssel.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/libs.myr
diff --git a/mk/bootstrap/bootstrap+OpenBSD-amd64.sh b/mk/bootstrap/bootstrap+OpenBSD-amd64.sh
index 65c45cc..ad09785 100755
--- a/mk/bootstrap/bootstrap+OpenBSD-amd64.sh
+++ b/mk/bootstrap/bootstrap+OpenBSD-amd64.sh
@@ -7,6 +7,7 @@ set -x
as -g -o mbld/cpufeatures.o mbld/cpufeatures+posixy-x64.s
as -g -o lib/thread/exit.o lib/thread/exit+openbsd-x64.s
as -g -o lib/thread/atomic-impl.o lib/thread/atomic-impl+x64.s
+ as -g -o lib/thread/tls-impl.o lib/thread/tls-impl+fsbase-x64.s
as -g -o lib/std/getbp.o lib/std/getbp+posixy-x64.s
$pwd/6/6m -I lib/sys lib/std/option.myr
$pwd/6/6m -I lib/sys lib/std/traits.myr
@@ -120,16 +121,19 @@ set -x
$pwd/6/6m -I lib/std -I lib/sys lib/bio/puti.myr
ar -rcs lib/bio/libbio.a lib/bio/puti.o lib/bio/geti.o lib/bio/fd.o lib/bio/mem.o lib/bio/bio.o lib/bio/types.o lib/bio/iter.o
$pwd/muse/muse -o lib/bio/libbio.use -p bio lib/bio/puti.use lib/bio/geti.use lib/bio/fd.use lib/bio/mem.use lib/bio/bio.use lib/bio/types.use lib/bio/iter.use
- $pwd/6/6m -I lib/sys -I lib/std lib/thread/spawn+openbsd.myr
- $pwd/6/6m -I lib/sys -I lib/std lib/thread/ncpu+openbsd.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/common.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/atomic.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/types+fsbase.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/fsbase+openbsd.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/tls+fsbase.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/spawn+openbsd.myr
+ $pwd/6/6m -I lib/sys -I lib/std lib/thread/ncpu+openbsd.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/futex+openbsd:6.2.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/sem.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/mutex.myr
$pwd/6/6m -I lib/sys -I lib/std lib/thread/hookstd.myr
- ar -rcs lib/thread/libthread.a lib/thread/mutex.o lib/thread/atomic.o lib/thread/atomic-impl.o lib/thread/hookstd.o lib/thread/sem.o lib/thread/common.o lib/thread/ncpu.o lib/thread/exit.o lib/thread/futex.o lib/thread/spawn.o
- $pwd/muse/muse -o lib/thread/libthread.use -p thread lib/thread/mutex.use lib/thread/atomic.use lib/thread/hookstd.use lib/thread/sem.use lib/thread/common.use lib/thread/ncpu.use lib/thread/futex.use lib/thread/spawn.use
+ ar -rcs lib/thread/libthread.a lib/thread/mutex.o lib/thread/atomic.o lib/thread/atomic-impl.o lib/thread/types.o lib/thread/fsbase.o lib/thread/tls.o lib/thread/tls-impl.o lib/thread/hookstd.o lib/thread/sem.o lib/thread/common.o lib/thread/ncpu.o lib/thread/exit.o lib/thread/futex.o lib/thread/spawn.o
+ $pwd/muse/muse -o lib/thread/libthread.use -p thread lib/thread/mutex.use lib/thread/atomic.use lib/thread/types.use lib/thread/fsbase.use lib/thread/tls.use lib/thread/hookstd.use lib/thread/sem.use lib/thread/common.use lib/thread/ncpu.use lib/thread/futex.use lib/thread/spawn.use
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/opts.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/syssel.myr
$pwd/6/6m -I lib/sys -I lib/std -I lib/bio -I lib/regex -I lib/thread mbld/libs.myr