summaryrefslogtreecommitdiff
path: root/lib/thread/exit+openbsd-x64.s
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-04-22 19:29:39 -0700
committerOri Bernstein <ori@eigenstate.org>2018-04-22 19:29:39 -0700
commit4ac578a191635f9728dc66dd99b22cc54692b4ef (patch)
tree3dc934a23ce92cd52f53a566c49569778eddc73b /lib/thread/exit+openbsd-x64.s
parent3d71446ecb6569add0d9eaf2e7e4a05d99bd2625 (diff)
downloadmc-4ac578a191635f9728dc66dd99b22cc54692b4ef.tar.gz
Add a special exit stack to our thread library.
Because OpenBSD wants a valid stack pointer in any code that enters the kernel, unmapping our stack as part of exiting the process is rather unreliable. This change allocates a stack page that we can switch to when a thread is deallocating itself, which keeps the kernel happy.
Diffstat (limited to 'lib/thread/exit+openbsd-x64.s')
-rw-r--r--lib/thread/exit+openbsd-x64.s7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/thread/exit+openbsd-x64.s b/lib/thread/exit+openbsd-x64.s
index 23f92b5..6421cc3 100644
--- a/lib/thread/exit+openbsd-x64.s
+++ b/lib/thread/exit+openbsd-x64.s
@@ -10,6 +10,13 @@ thread$exit:
andq $~0xfff,%rdi /* align it */
addq $0x1000,%rdi
+ /*
+ Because OpenBSD wants a valid stack whenever
+ we enter the kernel, we need to toss a preallocated
+ stack pointer into %rsp.
+ */
+ movq thread$exitstk,%rsp
+
/* munmap(base, size) */
movq $73,%rax /* munmap */
movq -8(%rdi),%rsi /* size */