summaryrefslogtreecommitdiff
path: root/src/thread/__unmapself.c
diff options
context:
space:
mode:
authorVladimir Azarov <avm@intermediate-node.net>2024-10-01 15:47:05 +0200
committerVladimir Azarov <avm@intermediate-node.net>2024-10-01 15:47:05 +0200
commit4abab5ad6c8465a7528ccdd5f49367da05f78bbd (patch)
treeebf009bf1376a5a223a915bc27cbbd791a1316bc /src/thread/__unmapself.c
Initial version
Diffstat (limited to 'src/thread/__unmapself.c')
-rw-r--r--src/thread/__unmapself.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/thread/__unmapself.c b/src/thread/__unmapself.c
new file mode 100644
index 0000000..31d94e6
--- /dev/null
+++ b/src/thread/__unmapself.c
@@ -0,0 +1,24 @@
+#include "pthread_impl.h"
+#include "atomic.h"
+#include "syscall.h"
+/* cheat and reuse CRTJMP macro from dynlink code */
+#include "dynlink.h"
+
+static void *unmap_base;
+static size_t unmap_size;
+static char shared_stack[256];
+
+static void do_unmap()
+{
+ __syscall(SYS_munmap, unmap_base, unmap_size);
+ __syscall(SYS_exit);
+}
+
+void __unmapself(void *base, size_t size)
+{
+ char *stack = shared_stack + sizeof shared_stack;
+ stack -= (uintptr_t)stack % 16;
+ unmap_base = base;
+ unmap_size = size;
+ CRTJMP(do_unmap, stack);
+}