summaryrefslogtreecommitdiffstats
path: root/contrib/compiler-rt/lib/safestack
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2016-02-06 13:39:20 +0000
committerdim <dim@FreeBSD.org>2016-02-06 13:39:20 +0000
commit9c27ec33f2c82fe6c60c9c375a88f96a1e10a6a2 (patch)
tree4efb8604227ede935238eb1c67b626da1265d459 /contrib/compiler-rt/lib/safestack
parentaef1771e36f9842a113b9905d0d5926fe9d694aa (diff)
parent75958af7df18c2ae942829da1a8cf3b5bbcaeff6 (diff)
downloadFreeBSD-src-9c27ec33f2c82fe6c60c9c375a88f96a1e10a6a2.zip
FreeBSD-src-9c27ec33f2c82fe6c60c9c375a88f96a1e10a6a2.tar.gz
Merge compiler-rt release_38 branch r258968.
Note that there is still a problem on amd64, causing SIGBUS in the early startup of Address Sanitizer. This is being investigated.
Diffstat (limited to 'contrib/compiler-rt/lib/safestack')
-rw-r--r--contrib/compiler-rt/lib/safestack/CMakeLists.txt28
-rw-r--r--contrib/compiler-rt/lib/safestack/safestack.cc9
2 files changed, 7 insertions, 30 deletions
diff --git a/contrib/compiler-rt/lib/safestack/CMakeLists.txt b/contrib/compiler-rt/lib/safestack/CMakeLists.txt
deleted file mode 100644
index 1c15d07..0000000
--- a/contrib/compiler-rt/lib/safestack/CMakeLists.txt
+++ /dev/null
@@ -1,28 +0,0 @@
-add_custom_target(safestack)
-
-set(SAFESTACK_SOURCES safestack.cc)
-
-include_directories(..)
-
-set(SAFESTACK_CFLAGS ${SANITIZER_COMMON_CFLAGS})
-
-if(APPLE)
- # Build universal binary on APPLE.
- add_compiler_rt_osx_static_runtime(clang_rt.safestack_osx
- ARCH ${SAFESTACK_SUPPORTED_ARCH}
- SOURCES ${SAFESTACK_SOURCES}
- $<TARGET_OBJECTS:RTInterception.osx>
- $<TARGET_OBJECTS:RTSanitizerCommon.osx>
- CFLAGS ${SAFESTACK_CFLAGS})
- add_dependencies(safestack clang_rt.safestack_osx)
-else()
- # Otherwise, build separate libraries for each target.
- foreach(arch ${SAFESTACK_SUPPORTED_ARCH})
- add_compiler_rt_runtime(clang_rt.safestack-${arch} ${arch} STATIC
- SOURCES ${SAFESTACK_SOURCES}
- $<TARGET_OBJECTS:RTInterception.${arch}>
- $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
- CFLAGS ${SAFESTACK_CFLAGS})
- add_dependencies(safestack clang_rt.safestack-${arch})
- endforeach()
-endif()
diff --git a/contrib/compiler-rt/lib/safestack/safestack.cc b/contrib/compiler-rt/lib/safestack/safestack.cc
index 504bd3c..92c24b3 100644
--- a/contrib/compiler-rt/lib/safestack/safestack.cc
+++ b/contrib/compiler-rt/lib/safestack/safestack.cc
@@ -18,6 +18,7 @@
#include <pthread.h>
#include <stddef.h>
#include <stdint.h>
+#include <unistd.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/user.h>
@@ -68,6 +69,9 @@ const unsigned kStackAlign = 16;
/// size rlimit is set to infinity.
const unsigned kDefaultUnsafeStackSize = 0x2800000;
+/// Runtime page size obtained through sysconf
+static unsigned pageSize;
+
// TODO: To make accessing the unsafe stack pointer faster, we plan to
// eventually store it directly in the thread control block data structure on
// platforms where this structure is pointed to by %fs or %gs. This is exactly
@@ -171,7 +175,7 @@ INTERCEPTOR(int, pthread_create, pthread_t *thread,
size_t size = 0;
size_t guard = 0;
- if (attr != NULL) {
+ if (attr) {
pthread_attr_getstacksize(attr, &size);
pthread_attr_getguardsize(attr, &guard);
} else {
@@ -185,7 +189,7 @@ INTERCEPTOR(int, pthread_create, pthread_t *thread,
CHECK_NE(size, 0);
CHECK_EQ((size & (kStackAlign - 1)), 0);
- CHECK_EQ((guard & (PAGE_SIZE - 1)), 0);
+ CHECK_EQ((guard & (pageSize - 1)), 0);
void *addr = unsafe_stack_alloc(size, guard);
struct tinfo *tinfo =
@@ -217,6 +221,7 @@ void __safestack_init() {
void *addr = unsafe_stack_alloc(size, guard);
unsafe_stack_setup(addr, size, guard);
+ pageSize = sysconf(_SC_PAGESIZE);
// Initialize pthread interceptors for thread allocation
INTERCEPT_FUNCTION(pthread_create);
OpenPOWER on IntegriCloud