1 // Regression test for:
2 // http://code.google.com/p/address-sanitizer/issues/detail?id=37
4 // RUN: %clangxx_asan -O0 %s -o %t && %run %t | FileCheck %s
5 // RUN: %clangxx_asan -O1 %s -o %t && %run %t | FileCheck %s
6 // RUN: %clangxx_asan -O2 %s -o %t && %run %t | FileCheck %s
7 // RUN: %clangxx_asan -O3 %s -o %t && %run %t | FileCheck %s
11 #include <sys/syscall.h>
12 #include <sys/types.h>
16 int Child(void *arg
) {
17 char x
[32] = {0}; // Stack gets poisoned.
18 printf("Child: %p\n", x
);
19 _exit(1); // NoReturn, stack will remain unpoisoned unless we do something.
22 int main(int argc
, char **argv
) {
23 const int kStackSize
= 1 << 20;
24 char __attribute__((aligned(16))) child_stack
[kStackSize
+ 1];
25 char *sp
= child_stack
+ kStackSize
; // Stack grows down.
26 printf("Parent: %p\n", sp
);
27 pid_t clone_pid
= clone(Child
, sp
, CLONE_FILES
| CLONE_VM
, NULL
);
29 pid_t wait_result
= waitpid(clone_pid
, &status
, __WCLONE
);
30 if (wait_result
< 0) {
34 if (wait_result
== clone_pid
&& WIFEXITED(status
)) {
35 // Make sure the child stack was indeed unpoisoned.
36 for (int i
= 0; i
< kStackSize
; i
++)
38 int ret
= child_stack
[argc
- 1];