aboutsummaryrefslogtreecommitdiffstats
path: root/lib/safestack
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-28 11:06:48 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-28 11:06:48 +0000
commit93c1b73a09a52d4a265f683bf1954b08bb430049 (patch)
tree5543464d74945196cc890e9d9099e5d0660df7eb /lib/safestack
parent0d8e7490d6e8a13a8f0977d9b7771803b9f64ea0 (diff)
downloadsrc-93c1b73a09a52d4a265f683bf1954b08bb430049.tar.gz
src-93c1b73a09a52d4a265f683bf1954b08bb430049.zip
Vendor import of compiler-rt trunk r338150:vendor/compiler-rt/compiler-rt-trunk-r338150
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=336817 svn path=/vendor/compiler-rt/compiler-rt-trunk-r338150/; revision=336818; tag=vendor/compiler-rt/compiler-rt-trunk-r338150
Diffstat (limited to 'lib/safestack')
-rw-r--r--lib/safestack/.clang-format1
-rw-r--r--lib/safestack/safestack.cc30
2 files changed, 27 insertions, 4 deletions
diff --git a/lib/safestack/.clang-format b/lib/safestack/.clang-format
index f6cb8ad931f5..560308c91dee 100644
--- a/lib/safestack/.clang-format
+++ b/lib/safestack/.clang-format
@@ -1 +1,2 @@
BasedOnStyle: Google
+AllowShortIfStatementsOnASingleLine: false
diff --git a/lib/safestack/safestack.cc b/lib/safestack/safestack.cc
index d783cd5a9b29..8af93624b991 100644
--- a/lib/safestack/safestack.cc
+++ b/lib/safestack/safestack.cc
@@ -171,11 +171,13 @@ static void thread_cleanup_handler(void *_iter) {
}
}
+static void EnsureInterceptorsInitialized();
+
/// Intercept thread creation operation to allocate and setup the unsafe stack
INTERCEPTOR(int, pthread_create, pthread_t *thread,
const pthread_attr_t *attr,
void *(*start_routine)(void*), void *arg) {
-
+ EnsureInterceptorsInitialized();
size_t size = 0;
size_t guard = 0;
@@ -207,6 +209,19 @@ INTERCEPTOR(int, pthread_create, pthread_t *thread,
return REAL(pthread_create)(thread, attr, thread_start, tinfo);
}
+static BlockingMutex interceptor_init_lock(LINKER_INITIALIZED);
+static bool interceptors_inited = false;
+
+static void EnsureInterceptorsInitialized() {
+ BlockingMutexLock lock(&interceptor_init_lock);
+ if (interceptors_inited) return;
+
+ // Initialize pthread interceptors for thread allocation
+ INTERCEPT_FUNCTION(pthread_create);
+
+ interceptors_inited = true;
+}
+
extern "C" __attribute__((visibility("default")))
#if !SANITIZER_CAN_USE_PREINIT_ARRAY
// On ELF platforms, the constructor is invoked using .preinit_array (see below)
@@ -227,9 +242,6 @@ void __safestack_init() {
unsafe_stack_setup(addr, size, guard);
pageSize = sysconf(_SC_PAGESIZE);
- // Initialize pthread interceptors for thread allocation
- INTERCEPT_FUNCTION(pthread_create);
-
// Setup the cleanup handler
pthread_key_create(&thread_cleanup_key, thread_cleanup_handler);
}
@@ -245,6 +257,16 @@ __attribute__((section(".preinit_array"),
#endif
extern "C"
+ __attribute__((visibility("default"))) void *__get_unsafe_stack_bottom() {
+ return unsafe_stack_start;
+}
+
+extern "C"
+ __attribute__((visibility("default"))) void *__get_unsafe_stack_top() {
+ return (char*)unsafe_stack_start + unsafe_stack_size;
+}
+
+extern "C"
__attribute__((visibility("default"))) void *__get_unsafe_stack_start() {
return unsafe_stack_start;
}