1 // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 2 // XFAIL: android 3 // 4 // RUN: %clangxx_asan -O0 %s -o %t && %run %t 5 // RUN: %clangxx_asan -DPOSITIVE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 6 // XFAIL: arm-linux-gnueabi 7 8 #include <assert.h> 9 #include <stdio.h> 10 #include <sys/ptrace.h> 11 #include <sys/types.h> 12 #include <sys/user.h> 13 #include <sys/wait.h> 14 #include <unistd.h> 15 16 int main(void) { 17 pid_t pid; 18 pid = fork(); 19 if (pid == 0) { // child 20 ptrace(PTRACE_TRACEME, 0, NULL, NULL); 21 execl("/bin/true", "true", NULL); 22 } else { 23 wait(NULL); 24 user_regs_struct regs; 25 int res; 26 user_regs_struct * volatile pregs = ®s; 27 #ifdef POSITIVE 28 ++pregs; 29 #endif 30 res = ptrace(PTRACE_GETREGS, pid, NULL, pregs); 31 // CHECK: AddressSanitizer: stack-buffer-overflow 32 // CHECK: {{.*ptrace.cc:}}[[@LINE-2]] 33 assert(!res); 34 #if __WORDSIZE == 64 35 printf("%zx\n", regs.rip); 36 #else 37 printf("%lx\n", regs.eip); 38 #endif 39 40 user_fpregs_struct fpregs; 41 res = ptrace(PTRACE_GETFPREGS, pid, NULL, &fpregs); 42 assert(!res); 43 printf("%lx\n", (unsigned long)fpregs.cwd); 44 45 #if __WORDSIZE == 32 46 user_fpxregs_struct fpxregs; 47 res = ptrace(PTRACE_GETFPXREGS, pid, NULL, &fpxregs); 48 assert(!res); 49 printf("%lx\n", (unsigned long)fpxregs.mxcsr); 50 #endif 51 52 ptrace(PTRACE_CONT, pid, NULL, NULL); 53 wait(NULL); 54 } 55 return 0; 56 } 57