diff options
Diffstat (limited to 'test/asan/TestCases/Linux/ptrace.cc')
-rw-r--r-- | test/asan/TestCases/Linux/ptrace.cc | 93 |
1 files changed, 81 insertions, 12 deletions
diff --git a/test/asan/TestCases/Linux/ptrace.cc b/test/asan/TestCases/Linux/ptrace.cc index 6840ebe28bfd3..d87d90be4753c 100644 --- a/test/asan/TestCases/Linux/ptrace.cc +++ b/test/asan/TestCases/Linux/ptrace.cc @@ -1,9 +1,9 @@ // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316 // XFAIL: android +// XFAIL: mips // // RUN: %clangxx_asan -O0 %s -o %t && %run %t // RUN: %clangxx_asan -DPOSITIVE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s -// REQUIRES: x86_64-supported-target,i386-supported-target #include <assert.h> #include <stdio.h> @@ -12,6 +12,55 @@ #include <sys/user.h> #include <sys/wait.h> #include <unistd.h> +#include <sys/uio.h> // for iovec +#include <elf.h> // for NT_PRSTATUS +#ifdef __aarch64__ +# include <asm/ptrace.h> +#endif + +#if defined(__i386__) || defined(__x86_64__) +typedef user_regs_struct regs_struct; +typedef user_fpregs_struct fpregs_struct; +#if defined(__i386__) +#define REG_IP eip +#else +#define REG_IP rip +#endif +#define PRINT_REG_PC(__regs) printf ("%lx\n", (unsigned long) (__regs.REG_IP)) +#define PRINT_REG_FP(__fpregs) printf ("%lx\n", (unsigned long) (__fpregs.cwd)) +#define __PTRACE_FPREQUEST PTRACE_GETFPREGS + +#elif defined(__aarch64__) +typedef struct user_pt_regs regs_struct; +typedef struct user_fpsimd_state fpregs_struct; +#define PRINT_REG_PC(__regs) printf ("%x\n", (unsigned) (__regs.pc)) +#define PRINT_REG_FP(__fpregs) printf ("%x\n", (unsigned) (__fpregs.fpsr)) +#define ARCH_IOVEC_FOR_GETREGSET + +#elif defined(__powerpc64__) +typedef struct pt_regs regs_struct; +typedef elf_fpregset_t fpregs_struct; +#define PRINT_REG_PC(__regs) printf ("%lx\n", (unsigned long) (__regs.nip)) +#define PRINT_REG_FP(__fpregs) printf ("%lx\n", (elf_greg_t)fpregs[32]) +#define ARCH_IOVEC_FOR_GETREGSET + +#elif defined(__mips__) +typedef struct pt_regs regs_struct; +typedef elf_fpregset_t fpregs_struct; +#define PRINT_REG_PC(__regs) printf ("%lx\n", (unsigned long) (__regs.cp0_epc)) +#define PRINT_REG_FP(__fpregs) printf ("%lx\n", (elf_greg_t) (__fpregs[32])) +#define __PTRACE_FPREQUEST PTRACE_GETFPREGS + +#elif defined(__arm__) +# include <asm/ptrace.h> +# include <sys/procfs.h> +typedef struct pt_regs regs_struct; +typedef char fpregs_struct[ARM_VFPREGS_SIZE]; +#define PRINT_REG_PC(__regs) printf ("%x\n", (unsigned) (__regs.ARM_pc)) +#define PRINT_REG_FP(__fpregs) printf ("%x\n", (unsigned) (__fpregs + 32 * 8)) +#define __PTRACE_FPREQUEST PTRACE_GETVFPREGS +#endif + int main(void) { pid_t pid; @@ -21,28 +70,48 @@ int main(void) { execl("/bin/true", "true", NULL); } else { wait(NULL); - user_regs_struct regs; + regs_struct regs; + regs_struct* volatile pregs = ®s; +#ifdef ARCH_IOVEC_FOR_GETREGSET + struct iovec regset_io; +#endif int res; - user_regs_struct * volatile pregs = ®s; + #ifdef POSITIVE ++pregs; #endif - res = ptrace(PTRACE_GETREGS, pid, NULL, pregs); + +#ifdef ARCH_IOVEC_FOR_GETREGSET +# define __PTRACE_REQUEST PTRACE_GETREGSET +# define __PTRACE_ARGS (void*)NT_PRSTATUS, (void*)®set_io + regset_io.iov_base = pregs; + regset_io.iov_len = sizeof(regs_struct); +#else +# define __PTRACE_REQUEST PTRACE_GETREGS +# define __PTRACE_ARGS NULL, pregs +#endif + res = ptrace((enum __ptrace_request)__PTRACE_REQUEST, pid, __PTRACE_ARGS); // CHECK: AddressSanitizer: stack-buffer-overflow // CHECK: {{.*ptrace.cc:}}[[@LINE-2]] assert(!res); -#ifdef __x86_64__ - printf("%lx\n", (unsigned long)regs.rip); + PRINT_REG_PC(regs); + + fpregs_struct fpregs; +#ifdef ARCH_IOVEC_FOR_GETREGSET +# define __PTRACE_FPREQUEST PTRACE_GETREGSET +# define __PTRACE_FPARGS (void*)NT_PRSTATUS, (void*)®set_io + regset_io.iov_base = &fpregs; + regset_io.iov_len = sizeof(fpregs_struct); + res = ptrace((enum __ptrace_request)PTRACE_GETREGSET, pid, (void*)NT_FPREGSET, + (void*)®set_io); #else - printf("%lx\n", regs.eip); +# define __PTRACE_FPARGS NULL, &fpregs #endif - - user_fpregs_struct fpregs; - res = ptrace(PTRACE_GETFPREGS, pid, NULL, &fpregs); + res = ptrace((enum __ptrace_request)__PTRACE_FPREQUEST, pid, __PTRACE_FPARGS); assert(!res); - printf("%lx\n", (unsigned long)fpregs.cwd); + PRINT_REG_FP(fpregs); -#ifndef __x86_64__ +#ifdef __i386__ user_fpxregs_struct fpxregs; res = ptrace(PTRACE_GETFPXREGS, pid, NULL, &fpxregs); assert(!res); |