[compiler-rt] r351783 - [safestack] Return syscalls for mmap, munmap and mprotect
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 21 21:23:48 PST 2019
Author: vitalybuka
Date: Mon Jan 21 21:23:48 2019
New Revision: 351783
URL: http://llvm.org/viewvc/llvm-project?rev=351783&view=rev
Log:
[safestack] Return syscalls for mmap, munmap and mprotect
This function can be already intercepted by instrumented code.
Modified:
compiler-rt/trunk/lib/safestack/safestack.cc
compiler-rt/trunk/lib/safestack/safestack_platform.h
Modified: compiler-rt/trunk/lib/safestack/safestack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/safestack/safestack.cc?rev=351783&r1=351782&r2=351783&view=diff
==============================================================================
--- compiler-rt/trunk/lib/safestack/safestack.cc (original)
+++ compiler-rt/trunk/lib/safestack/safestack.cc Mon Jan 21 21:23:48 2019
@@ -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
Modified: compiler-rt/trunk/lib/safestack/safestack_platform.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/safestack/safestack_platform.h?rev=351783&r1=351782&r2=351783&view=diff
==============================================================================
--- compiler-rt/trunk/lib/safestack/safestack_platform.h (original)
+++ compiler-rt/trunk/lib/safestack/safestack_platform.h Mon Jan 21 21:23:48 2019
@@ -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 ti
#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
More information about the llvm-commits
mailing list