diff options
author | Vitaly Buka <vitalybuka@google.com> | 2019-01-22 05:23:48 +0000 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2019-01-22 05:23:48 +0000 |
commit | ca5da89cdde6d31218a580dcf331afa3fe4bfdad (patch) | |
tree | be50ff881f78908002ac965d612bd4801488e2ca /lib/safestack | |
parent | 57d44a27887e47bb73572287740093077a23261f (diff) | |
download | compiler-rt-ca5da89cdde6d31218a580dcf331afa3fe4bfdad.tar.gz |
[safestack] Return syscalls for mmap, munmap and mprotect
This function can be already intercepted by instrumented code.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@351783 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/safestack')
-rw-r--r-- | lib/safestack/safestack.cc | 7 | ||||
-rw-r--r-- | lib/safestack/safestack_platform.h | 28 |
2 files changed, 31 insertions, 4 deletions
diff --git a/lib/safestack/safestack.cc b/lib/safestack/safestack.cc index c5622d226..ff840a5c1 100644 --- a/lib/safestack/safestack.cc +++ b/lib/safestack/safestack.cc @@ -17,7 +17,6 @@ #include "safestack_util.h" #include <errno.h> -#include <sys/mman.h> #include <sys/resource.h> #include "interception/interception.h" @@ -94,10 +93,10 @@ __thread size_t unsafe_stack_guard = 0; inline void *unsafe_stack_alloc(size_t size, size_t guard) { SFS_CHECK(size + guard >= size); - void *addr = mmap(nullptr, RoundUpTo(size + guard, pageSize), + void *addr = Mmap(nullptr, RoundUpTo(size + guard, pageSize), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); SFS_CHECK(MAP_FAILED != addr); - mprotect(addr, guard, PROT_NONE); + Mprotect(addr, guard, PROT_NONE); return (char *)addr + guard; } @@ -181,7 +180,7 @@ void thread_cleanup_handler(void *_iter) { thread_stack_ll *stack = *stackp; if (stack->pid != pid || (-1 == TgKill(stack->pid, stack->tid, 0) && errno == ESRCH)) { - munmap(stack->stack_base, stack->size); + Munmap(stack->stack_base, stack->size); *stackp = stack->next; free(stack); } else diff --git a/lib/safestack/safestack_platform.h b/lib/safestack/safestack_platform.h index 6b042f4b4..b906d52d5 100644 --- a/lib/safestack/safestack_platform.h +++ b/lib/safestack/safestack_platform.h @@ -16,6 +16,7 @@ #include "sanitizer_common/sanitizer_platform.h" #include <stdint.h> +#include <sys/mman.h> #include <sys/syscall.h> #include <sys/types.h> #include <unistd.h> @@ -59,6 +60,33 @@ inline int TgKill(pid_t pid, ThreadId tid, int sig) { #endif } +inline void *Mmap(void *addr, size_t length, int prot, int flags, int fd, + off_t offset) { +#if SANITIZER_NETBSD + return mmap(addr, length, prot, flags, fd, offset); +#elif defined(__x86_64__) && (SANITIZER_FREEBSD) + return (void *)__syscall(SYS_mmap, addr, length, prot, flags, fd, offset); +#else + return (void *)syscall(SYS_mmap, addr, length, prot, flags, fd, offset); +#endif +} + +inline int Munmap(void *addr, size_t length) { +#if SANITIZER_NETBSD + return munmap(addr, length); +#else + return syscall(SYS_munmap, addr, length); +#endif +} + +inline int Mprotect(void *addr, size_t length, int prot) { +#if SANITIZER_NETBSD + return mprotect(addr, length, prot); +#else + return syscall(SYS_mprotect, addr, length, prot); +#endif +} + } // namespace safestack #endif // SAFESTACK_PLATFORM_H |