path: root/lib/sys/sys+openbsd-x64.myr
diff options
authoririri <>2018-10-13 13:58:52 -0700
committerOri Bernstein <>2018-10-18 23:21:10 -0700
commit2d9fe7100209acb431e392d58e4cf4eccfde00b7 (patch)
tree888cd09a78c8d75a53f474f3c4802fb914a6bff7 /lib/sys/sys+openbsd-x64.myr
parentb17873ed4e6a14786758fd68290ef572b0b88f10 (diff)
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 'lib/sys/sys+openbsd-x64.myr')
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/sys/sys+openbsd-x64.myr b/lib/sys/sys+openbsd-x64.myr
index a260134..d840608 100644
--- a/lib/sys/sys+openbsd-x64.myr
+++ b/lib/sys/sys+openbsd-x64.myr
@@ -215,7 +215,7 @@ pkg sys =
const Mfixed : mopt = 0x10
const Mfile : mopt = 0x0
const Manon : mopt = 0x1000
- const Mstack : mopt = 0x4000
+ const Mstack : mopt = 0x0
const Mnoreplace : mopt = 0x0800
/* file types */