Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stddef.h> |
| 3 | #include <signal.h> |
Jeff Dike | 63ae2a9 | 2006-03-27 01:14:30 -0800 | [diff] [blame] | 4 | #include <sys/poll.h> |
Jeff Dike | 16dd07b | 2007-05-06 14:51:48 -0700 | [diff] [blame] | 5 | #include <sys/mman.h> |
Jeff Dike | 189872f | 2007-10-16 01:27:14 -0700 | [diff] [blame] | 6 | #include <sys/user.h> |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 7 | #define __FRAME_OFFSETS |
| 8 | #include <asm/ptrace.h> |
Jeff Dike | ba9950c | 2005-05-20 13:59:07 -0700 | [diff] [blame] | 9 | #include <asm/types.h> |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 10 | |
| 11 | #define DEFINE(sym, val) \ |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame^] | 12 | asm volatile("\n->" #sym " %0 " #val : : "i" (val)) |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 13 | |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 14 | #define DEFINE_LONGS(sym, val) \ |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame^] | 15 | asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long))) |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 16 | |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 17 | #define OFFSET(sym, str, mem) \ |
| 18 | DEFINE(sym, offsetof(struct str, mem)); |
| 19 | |
| 20 | void foo(void) |
| 21 | { |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 22 | OFFSET(HOST_SC_TRAPNO, sigcontext, trapno); |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame^] | 23 | OFFSET(HOST_SC_ERR, sigcontext, err); |
| 24 | OFFSET(HOST_SC_CR2, sigcontext, cr2); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 25 | |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame^] | 26 | #ifdef __i386__ |
| 27 | DEFINE_LONGS(HOST_FP_SIZE, sizeof(struct user_fpregs_struct)); |
| 28 | DEFINE_LONGS(HOST_FPX_SIZE, sizeof(struct user_fpxregs_struct)); |
| 29 | |
| 30 | DEFINE(HOST_IP, EIP); |
| 31 | DEFINE(HOST_SP, UESP); |
| 32 | DEFINE(HOST_EFLAGS, EFL); |
| 33 | DEFINE(HOST_EAX, EAX); |
| 34 | DEFINE(HOST_EBX, EBX); |
| 35 | DEFINE(HOST_ECX, ECX); |
| 36 | DEFINE(HOST_EDX, EDX); |
| 37 | DEFINE(HOST_ESI, ESI); |
| 38 | DEFINE(HOST_EDI, EDI); |
| 39 | DEFINE(HOST_EBP, EBP); |
| 40 | DEFINE(HOST_CS, CS); |
| 41 | DEFINE(HOST_SS, SS); |
| 42 | DEFINE(HOST_DS, DS); |
| 43 | DEFINE(HOST_FS, FS); |
| 44 | DEFINE(HOST_ES, ES); |
| 45 | DEFINE(HOST_GS, GS); |
| 46 | #else |
Jeff Dike | e2216fe | 2006-02-07 12:58:43 -0800 | [diff] [blame] | 47 | DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long)); |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 48 | DEFINE_LONGS(HOST_RBX, RBX); |
| 49 | DEFINE_LONGS(HOST_RCX, RCX); |
| 50 | DEFINE_LONGS(HOST_RDI, RDI); |
| 51 | DEFINE_LONGS(HOST_RSI, RSI); |
| 52 | DEFINE_LONGS(HOST_RDX, RDX); |
| 53 | DEFINE_LONGS(HOST_RBP, RBP); |
| 54 | DEFINE_LONGS(HOST_RAX, RAX); |
| 55 | DEFINE_LONGS(HOST_R8, R8); |
| 56 | DEFINE_LONGS(HOST_R9, R9); |
| 57 | DEFINE_LONGS(HOST_R10, R10); |
| 58 | DEFINE_LONGS(HOST_R11, R11); |
| 59 | DEFINE_LONGS(HOST_R12, R12); |
| 60 | DEFINE_LONGS(HOST_R13, R13); |
| 61 | DEFINE_LONGS(HOST_R14, R14); |
| 62 | DEFINE_LONGS(HOST_R15, R15); |
| 63 | DEFINE_LONGS(HOST_ORIG_RAX, ORIG_RAX); |
| 64 | DEFINE_LONGS(HOST_CS, CS); |
| 65 | DEFINE_LONGS(HOST_SS, SS); |
| 66 | DEFINE_LONGS(HOST_EFLAGS, EFLAGS); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 67 | #if 0 |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 68 | DEFINE_LONGS(HOST_FS, FS); |
| 69 | DEFINE_LONGS(HOST_GS, GS); |
| 70 | DEFINE_LONGS(HOST_DS, DS); |
| 71 | DEFINE_LONGS(HOST_ES, ES); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 72 | #endif |
| 73 | |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 74 | DEFINE_LONGS(HOST_IP, RIP); |
| 75 | DEFINE_LONGS(HOST_SP, RSP); |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame^] | 76 | #endif |
Jeff Dike | 63ae2a9 | 2006-03-27 01:14:30 -0800 | [diff] [blame] | 77 | |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame^] | 78 | DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct)); |
Jeff Dike | 63ae2a9 | 2006-03-27 01:14:30 -0800 | [diff] [blame] | 79 | DEFINE(UM_POLLIN, POLLIN); |
| 80 | DEFINE(UM_POLLPRI, POLLPRI); |
| 81 | DEFINE(UM_POLLOUT, POLLOUT); |
Jeff Dike | 16dd07b | 2007-05-06 14:51:48 -0700 | [diff] [blame] | 82 | |
| 83 | DEFINE(UM_PROT_READ, PROT_READ); |
| 84 | DEFINE(UM_PROT_WRITE, PROT_WRITE); |
| 85 | DEFINE(UM_PROT_EXEC, PROT_EXEC); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 86 | } |