]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/asan/TestCases/Linux/clone_test.cc
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
8 // XFAIL: arm-linux-gnueabi
12 #include <sys/syscall.h>
13 #include <sys/types.h>
17 int Child(void *arg
) {
18 char x
[32] = {0}; // Stack gets poisoned.
19 printf("Child: %p\n", x
);
20 _exit(1); // NoReturn, stack will remain unpoisoned unless we do something.
23 int main(int argc
, char **argv
) {
24 const int kStackSize
= 1 << 20;
25 char child_stack
[kStackSize
+ 1];
26 char *sp
= child_stack
+ kStackSize
; // Stack grows down.
27 printf("Parent: %p\n", sp
);
28 pid_t clone_pid
= clone(Child
, sp
, CLONE_FILES
| CLONE_VM
, NULL
);
30 pid_t wait_result
= waitpid(clone_pid
, &status
, __WCLONE
);
31 if (wait_result
< 0) {
35 if (wait_result
== clone_pid
&& WIFEXITED(status
)) {
36 // Make sure the child stack was indeed unpoisoned.
37 for (int i
= 0; i
< kStackSize
; i
++)
39 int ret
= child_stack
[argc
- 1];