summaryrefslogtreecommitdiff
path: root/support
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 /support
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 'support')
-rw-r--r--support/syscall-gen/types+freebsd-x64.frag8
-rw-r--r--support/syscall-gen/types+linux-x64.frag7
2 files changed, 15 insertions, 0 deletions
diff --git a/support/syscall-gen/types+freebsd-x64.frag b/support/syscall-gen/types+freebsd-x64.frag
index f899053..5ed178c 100644
--- a/support/syscall-gen/types+freebsd-x64.frag
+++ b/support/syscall-gen/types+freebsd-x64.frag
@@ -32,6 +32,7 @@ type id = int64
type cpulevel = int
type cpusetid = int
type idtype = int
+type sysarchop = int
type acltype = int
type acltag = uint32
@@ -796,5 +797,12 @@ const Sigthr : signo = 32 /* reserved by thread library. */
const Siglwp : signo = Sigthr
const Siglibrt : signo = 33 /* reserved by real-time library. */
+/* sysarch ops */
+const Archamd64getfs : sysarchop = 128
+const Archamd64setfs : sysarchop = 129
+const Archamd64getgs : sysarchop = 130
+const Archamd64setgs : sysarchop = 131
+const Archamd64getxfpu : sysarchop = 131
+
extern const syscall : (sc:scno, args:... -> int64)
extern var __cenvp : byte##
diff --git a/support/syscall-gen/types+linux-x64.frag b/support/syscall-gen/types+linux-x64.frag
index 9e90a5a..966de30 100644
--- a/support/syscall-gen/types+linux-x64.frag
+++ b/support/syscall-gen/types+linux-x64.frag
@@ -38,6 +38,7 @@ type fallocmode = uint32
type mfdflags = uint32
type aiocontext = uint64
type msg = void#
+type arch_prctlop = uint64
type clock = union
@@ -584,6 +585,12 @@ const Seekend : whence = 2
/* return value for a failed mapping */
const Mapbad : byte# = (-1 : byte#)
+/* arch_prctl ops */
+const Archsetgs : arch_prctlop = 0x1001
+const Archsetfs : arch_prctlop = 0x1002
+const Archgetfs : arch_prctlop = 0x1003
+const Archgetgs : arch_prctlop = 0x1004
+
/* signal flags */
const Sanocldstop : sigflags = 0x00000001
const Sanocldwait : sigflags = 0x00000002