about summary refs log tree commit diff
path: root/src/mman
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-09-27 13:50:29 -0400
committerRich Felker <dalias@aerifal.cx>2011-09-27 13:50:29 -0400
commit60164570111873175111cf8a5b973375e492eee9 (patch)
tree1557931c4e0bacd2be217965be08031d5e3a4e51 /src/mman
parent3f39c9b3130cd6c142d358159879b799370a6663 (diff)
downloadmusl-60164570111873175111cf8a5b973375e492eee9.tar.gz
musl-60164570111873175111cf8a5b973375e492eee9.tar.xz
musl-60164570111873175111cf8a5b973375e492eee9.zip
process-shared barrier support, based on discussion with bdonlan
this implementation is rather heavy-weight, but it's the first
solution i've found that's actually correct. all waiters actually wait
twice at the barrier so that they can synchronize exit, and they hold
a "vm lock" that prevents changes to virtual memory mappings (and
blocks pthread_barrier_destroy) until all waiters are finished
inspecting the barrier.

thus, it is safe for any thread to destroy and/or unmap the barrier's
memory as soon as pthread_barrier_wait returns, without further
synchronization.
Diffstat (limited to 'src/mman')
-rw-r--r--src/mman/mmap.c13
-rw-r--r--src/mman/munmap.c11
2 files changed, 21 insertions, 3 deletions
diff --git a/src/mman/mmap.c b/src/mman/mmap.c
index 883acb28..fd2bb07e 100644
--- a/src/mman/mmap.c
+++ b/src/mman/mmap.c
@@ -5,16 +5,25 @@
 #include "syscall.h"
 #include "libc.h"
 
+static void dummy1(int x) { }
+static void dummy0(void) { }
+weak_alias(dummy1, __vm_lock);
+weak_alias(dummy0, __vm_unlock);
+
 void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
 {
+	void *ret;
 	if (sizeof(off_t) > sizeof(long))
 		if (((long)off & 0xfff) | ((long)((unsigned long long)off>>(12 + 8*(sizeof(off_t)-sizeof(long))))))
 			start = (void *)-1;
+	if (flags & MAP_FIXED) __vm_lock(-1);
 #ifdef SYS_mmap2
-	return (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off>>12);
+	ret = (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off>>12);
 #else
-	return (void *)syscall(SYS_mmap, start, len, prot, flags, fd, off);
+	ret = (void *)syscall(SYS_mmap, start, len, prot, flags, fd, off);
 #endif
+	if (flags & MAP_FIXED) __vm_unlock();
+	return ret;
 }
 
 weak_alias(__mmap, mmap);
diff --git a/src/mman/munmap.c b/src/mman/munmap.c
index ab7da9e2..91aefd40 100644
--- a/src/mman/munmap.c
+++ b/src/mman/munmap.c
@@ -3,9 +3,18 @@
 #include "syscall.h"
 #include "libc.h"
 
+static void dummy1(int x) { }
+static void dummy0(void) { }
+weak_alias(dummy1, __vm_lock);
+weak_alias(dummy0, __vm_unlock);
+
 int __munmap(void *start, size_t len)
 {
-	return syscall(SYS_munmap, start, len);
+	int ret;
+	__vm_lock(-1);
+	ret = syscall(SYS_munmap, start, len);
+	__vm_unlock();
+	return ret;
 }
 
 weak_alias(__munmap, munmap);