diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2015-06-15 21:08:47 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2015-06-15 21:08:47 +0000 |
commit | b64d0b1e6d5f500201d9d91526bc2bf14cb519d5 (patch) | |
tree | d367a76befa617c38aa8f940cee7da3c6cf61808 /compiler-rt/test/safestack/pthread.c | |
parent | c4122c17b473a6f9f2a5940a98939209aaaa3dfc (diff) | |
download | bcm5719-llvm-b64d0b1e6d5f500201d9d91526bc2bf14cb519d5.tar.gz bcm5719-llvm-b64d0b1e6d5f500201d9d91526bc2bf14cb519d5.zip |
Protection against stack-based memory corruption errors using SafeStack: compiler-rt runtime support library
This patch adds runtime support for the Safe Stack protection to compiler-rt
(see http://reviews.llvm.org/D6094 for the detailed description of the
Safe Stack).
This patch is our implementation of the safe stack on top of compiler-rt. The
patch adds basic runtime support for the safe stack to compiler-rt that
manages unsafe stack allocation/deallocation for each thread.
Original patch by Volodymyr Kuznetsov and others at the Dependable Systems
Lab at EPFL; updates and upstreaming by myself.
Differential Revision: http://reviews.llvm.org/D6096
llvm-svn: 239763
Diffstat (limited to 'compiler-rt/test/safestack/pthread.c')
-rw-r--r-- | compiler-rt/test/safestack/pthread.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/compiler-rt/test/safestack/pthread.c b/compiler-rt/test/safestack/pthread.c new file mode 100644 index 00000000000..1687c10a6ef --- /dev/null +++ b/compiler-rt/test/safestack/pthread.c @@ -0,0 +1,40 @@ +// RUN: %clang_safestack %s -pthread -o %t +// RUN: %run %t + +// Test that pthreads receive their own unsafe stack. + +#include <stdlib.h> +#include <string.h> +#include <pthread.h> +#include "utils.h" + +static int ptr_test = 42; + +void *t1_start(void *ptr) +{ + if (ptr != &ptr_test) + abort(); + + // safe stack + int val = ptr_test * 5; + + // unsafe stack + char buffer[8096]; // two pages + memset(buffer, val, sizeof (buffer)); + break_optimization(buffer); + + return ptr; +} + +int main(int argc, char **argv) +{ + pthread_t t1; + void *ptr = NULL; + if (pthread_create(&t1, NULL, t1_start, &ptr_test)) + abort(); + if (pthread_join(t1, &ptr)) + abort(); + if (ptr != &ptr_test) + abort(); + return 0; +} |