mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-29 16:29:00 -04:00

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
32 lines
572 B
C
32 lines
572 B
C
// RUN: %clang_safestack %s -pthread -o %t
|
|
// RUN: not --crash %run %t
|
|
|
|
// Test that unsafe stacks are deallocated correctly on thread exit.
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <pthread.h>
|
|
|
|
enum { kBufferSize = (1 << 15) };
|
|
|
|
void *t1_start(void *ptr)
|
|
{
|
|
char buffer[kBufferSize];
|
|
return buffer;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
pthread_t t1;
|
|
char *buffer = NULL;
|
|
|
|
if (pthread_create(&t1, NULL, t1_start, NULL))
|
|
abort();
|
|
if (pthread_join(t1, &buffer))
|
|
abort();
|
|
|
|
// should segfault here
|
|
memset(buffer, 0, kBufferSize);
|
|
return 0;
|
|
}
|