Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1398)

Unified Diff: fusl/src/thread/__unmapself.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/thread/__tls_get_addr.c ('k') | fusl/src/thread/__wait.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/thread/__unmapself.c
diff --git a/fusl/src/thread/__unmapself.c b/fusl/src/thread/__unmapself.c
new file mode 100644
index 0000000000000000000000000000000000000000..1d3bee1d9b0404494db6d2745e31ebe780ed682e
--- /dev/null
+++ b/fusl/src/thread/__unmapself.c
@@ -0,0 +1,29 @@
+#include "pthread_impl.h"
+#include "atomic.h"
+#include "syscall.h"
+/* cheat and reuse CRTJMP macro from dynlink code */
+#include "dynlink.h"
+
+static volatile int lock;
+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)
+{
+ int tid=__pthread_self()->tid;
+ char *stack = shared_stack + sizeof shared_stack;
+ stack -= (uintptr_t)stack % 16;
+ while (lock || a_cas(&lock, 0, tid))
+ a_spin();
+ __syscall(SYS_set_tid_address, &lock);
+ unmap_base = base;
+ unmap_size = size;
+ CRTJMP(do_unmap, stack);
+}
« no previous file with comments | « fusl/src/thread/__tls_get_addr.c ('k') | fusl/src/thread/__wait.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698