summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/mman
diff options
context:
space:
mode:
Diffstat (limited to 'libc-top-half/musl/src/mman')
-rw-r--r--libc-top-half/musl/src/mman/madvise.c9
-rw-r--r--libc-top-half/musl/src/mman/mincore.c8
-rw-r--r--libc-top-half/musl/src/mman/mlock.c11
-rw-r--r--libc-top-half/musl/src/mman/mlockall.c7
-rw-r--r--libc-top-half/musl/src/mman/mmap.c41
-rw-r--r--libc-top-half/musl/src/mman/mprotect.c13
-rw-r--r--libc-top-half/musl/src/mman/mremap.c32
-rw-r--r--libc-top-half/musl/src/mman/msync.c7
-rw-r--r--libc-top-half/musl/src/mman/munlock.c7
-rw-r--r--libc-top-half/musl/src/mman/munlockall.c7
-rw-r--r--libc-top-half/musl/src/mman/munmap.c13
-rw-r--r--libc-top-half/musl/src/mman/posix_madvise.c9
-rw-r--r--libc-top-half/musl/src/mman/shm_open.c43
13 files changed, 207 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/mman/madvise.c b/libc-top-half/musl/src/mman/madvise.c
new file mode 100644
index 0000000..e0c7c0e
--- /dev/null
+++ b/libc-top-half/musl/src/mman/madvise.c
@@ -0,0 +1,9 @@
+#include <sys/mman.h>
+#include "syscall.h"
+
+int __madvise(void *addr, size_t len, int advice)
+{
+ return syscall(SYS_madvise, addr, len, advice);
+}
+
+weak_alias(__madvise, madvise);
diff --git a/libc-top-half/musl/src/mman/mincore.c b/libc-top-half/musl/src/mman/mincore.c
new file mode 100644
index 0000000..4bb19f8
--- /dev/null
+++ b/libc-top-half/musl/src/mman/mincore.c
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE
+#include <sys/mman.h>
+#include "syscall.h"
+
+int mincore (void *addr, size_t len, unsigned char *vec)
+{
+ return syscall(SYS_mincore, addr, len, vec);
+}
diff --git a/libc-top-half/musl/src/mman/mlock.c b/libc-top-half/musl/src/mman/mlock.c
new file mode 100644
index 0000000..71af582
--- /dev/null
+++ b/libc-top-half/musl/src/mman/mlock.c
@@ -0,0 +1,11 @@
+#include <sys/mman.h>
+#include "syscall.h"
+
+int mlock(const void *addr, size_t len)
+{
+#ifdef SYS_mlock
+ return syscall(SYS_mlock, addr, len);
+#else
+ return syscall(SYS_mlock2, addr, len, 0);
+#endif
+}
diff --git a/libc-top-half/musl/src/mman/mlockall.c b/libc-top-half/musl/src/mman/mlockall.c
new file mode 100644
index 0000000..0ba4e66
--- /dev/null
+++ b/libc-top-half/musl/src/mman/mlockall.c
@@ -0,0 +1,7 @@
+#include <sys/mman.h>
+#include "syscall.h"
+
+int mlockall(int flags)
+{
+ return syscall(SYS_mlockall, flags);
+}
diff --git a/libc-top-half/musl/src/mman/mmap.c b/libc-top-half/musl/src/mman/mmap.c
new file mode 100644
index 0000000..eff88d8
--- /dev/null
+++ b/libc-top-half/musl/src/mman/mmap.c
@@ -0,0 +1,41 @@
+#include <unistd.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <stdint.h>
+#include <limits.h>
+#include "syscall.h"
+
+static void dummy(void) { }
+weak_alias(dummy, __vm_wait);
+
+#define UNIT SYSCALL_MMAP2_UNIT
+#define OFF_MASK ((-0x2000ULL << (8*sizeof(syscall_arg_t)-1)) | (UNIT-1))
+
+void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
+{
+ long ret;
+ if (off & OFF_MASK) {
+ errno = EINVAL;
+ return MAP_FAILED;
+ }
+ if (len >= PTRDIFF_MAX) {
+ errno = ENOMEM;
+ return MAP_FAILED;
+ }
+ if (flags & MAP_FIXED) {
+ __vm_wait();
+ }
+#ifdef SYS_mmap2
+ ret = __syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT);
+#else
+ ret = __syscall(SYS_mmap, start, len, prot, flags, fd, off);
+#endif
+ /* Fixup incorrect EPERM from kernel. */
+ if (ret == -EPERM && !start && (flags&MAP_ANON) && !(flags&MAP_FIXED))
+ ret = -ENOMEM;
+ return (void *)__syscall_ret(ret);
+}
+
+weak_alias(__mmap, mmap);
+
+weak_alias(mmap, mmap64);
diff --git a/libc-top-half/musl/src/mman/mprotect.c b/libc-top-half/musl/src/mman/mprotect.c
new file mode 100644
index 0000000..535787b
--- /dev/null
+++ b/libc-top-half/musl/src/mman/mprotect.c
@@ -0,0 +1,13 @@
+#include <sys/mman.h>
+#include "libc.h"
+#include "syscall.h"
+
+int __mprotect(void *addr, size_t len, int prot)
+{
+ size_t start, end;
+ start = (size_t)addr & -PAGE_SIZE;
+ end = (size_t)((char *)addr + len + PAGE_SIZE-1) & -PAGE_SIZE;
+ return syscall(SYS_mprotect, start, end-start, prot);
+}
+
+weak_alias(__mprotect, mprotect);
diff --git a/libc-top-half/musl/src/mman/mremap.c b/libc-top-half/musl/src/mman/mremap.c
new file mode 100644
index 0000000..cc6991a
--- /dev/null
+++ b/libc-top-half/musl/src/mman/mremap.c
@@ -0,0 +1,32 @@
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include "syscall.h"
+
+static void dummy(void) { }
+weak_alias(dummy, __vm_wait);
+
+void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...)
+{
+ va_list ap;
+ void *new_addr = 0;
+
+ if (new_len >= PTRDIFF_MAX) {
+ errno = ENOMEM;
+ return MAP_FAILED;
+ }
+
+ if (flags & MREMAP_FIXED) {
+ __vm_wait();
+ va_start(ap, flags);
+ new_addr = va_arg(ap, void *);
+ va_end(ap);
+ }
+
+ return (void *)syscall(SYS_mremap, old_addr, old_len, new_len, flags, new_addr);
+}
+
+weak_alias(__mremap, mremap);
diff --git a/libc-top-half/musl/src/mman/msync.c b/libc-top-half/musl/src/mman/msync.c
new file mode 100644
index 0000000..fcd8cdf
--- /dev/null
+++ b/libc-top-half/musl/src/mman/msync.c
@@ -0,0 +1,7 @@
+#include <sys/mman.h>
+#include "syscall.h"
+
+int msync(void *start, size_t len, int flags)
+{
+ return syscall_cp(SYS_msync, start, len, flags);
+}
diff --git a/libc-top-half/musl/src/mman/munlock.c b/libc-top-half/musl/src/mman/munlock.c
new file mode 100644
index 0000000..2cccef0
--- /dev/null
+++ b/libc-top-half/musl/src/mman/munlock.c
@@ -0,0 +1,7 @@
+#include <sys/mman.h>
+#include "syscall.h"
+
+int munlock(const void *addr, size_t len)
+{
+ return syscall(SYS_munlock, addr, len);
+}
diff --git a/libc-top-half/musl/src/mman/munlockall.c b/libc-top-half/musl/src/mman/munlockall.c
new file mode 100644
index 0000000..6e9d39d
--- /dev/null
+++ b/libc-top-half/musl/src/mman/munlockall.c
@@ -0,0 +1,7 @@
+#include <sys/mman.h>
+#include "syscall.h"
+
+int munlockall(void)
+{
+ return syscall(SYS_munlockall);
+}
diff --git a/libc-top-half/musl/src/mman/munmap.c b/libc-top-half/musl/src/mman/munmap.c
new file mode 100644
index 0000000..2bf83bb
--- /dev/null
+++ b/libc-top-half/musl/src/mman/munmap.c
@@ -0,0 +1,13 @@
+#include <sys/mman.h>
+#include "syscall.h"
+
+static void dummy(void) { }
+weak_alias(dummy, __vm_wait);
+
+int __munmap(void *start, size_t len)
+{
+ __vm_wait();
+ return syscall(SYS_munmap, start, len);
+}
+
+weak_alias(__munmap, munmap);
diff --git a/libc-top-half/musl/src/mman/posix_madvise.c b/libc-top-half/musl/src/mman/posix_madvise.c
new file mode 100644
index 0000000..e5e5acb
--- /dev/null
+++ b/libc-top-half/musl/src/mman/posix_madvise.c
@@ -0,0 +1,9 @@
+#define _GNU_SOURCE
+#include <sys/mman.h>
+#include "syscall.h"
+
+int posix_madvise(void *addr, size_t len, int advice)
+{
+ if (advice == MADV_DONTNEED) return 0;
+ return -__syscall(SYS_madvise, addr, len, advice);
+}
diff --git a/libc-top-half/musl/src/mman/shm_open.c b/libc-top-half/musl/src/mman/shm_open.c
new file mode 100644
index 0000000..79784bd
--- /dev/null
+++ b/libc-top-half/musl/src/mman/shm_open.c
@@ -0,0 +1,43 @@
+#include <sys/mman.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <limits.h>
+#include <pthread.h>
+
+char *__shm_mapname(const char *name, char *buf)
+{
+ char *p;
+ while (*name == '/') name++;
+ if (*(p = __strchrnul(name, '/')) || p==name ||
+ (p-name <= 2 && name[0]=='.' && p[-1]=='.')) {
+ errno = EINVAL;
+ return 0;
+ }
+ if (p-name > NAME_MAX) {
+ errno = ENAMETOOLONG;
+ return 0;
+ }
+ memcpy(buf, "/dev/shm/", 9);
+ memcpy(buf+9, name, p-name+1);
+ return buf;
+}
+
+int shm_open(const char *name, int flag, mode_t mode)
+{
+ int cs;
+ char buf[NAME_MAX+10];
+ if (!(name = __shm_mapname(name, buf))) return -1;
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
+ int fd = open(name, flag|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK, mode);
+ pthread_setcancelstate(cs, 0);
+ return fd;
+}
+
+int shm_unlink(const char *name)
+{
+ char buf[NAME_MAX+10];
+ if (!(name = __shm_mapname(name, buf))) return -1;
+ return unlink(name);
+}