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> |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 6 | #define __FRAME_OFFSETS |
| 7 | #include <asm/ptrace.h> |
Jeff Dike | ba9950c | 2005-05-20 13:59:07 -0700 | [diff] [blame] | 8 | #include <asm/types.h> |
| 9 | /* For some reason, x86_64 defines u64 and u32 only in <pci/types.h>, which I |
| 10 | * refuse to include here, even though they're used throughout the headers. |
| 11 | * These are used in asm/user.h, and that include can't be avoided because of |
| 12 | * the sizeof(struct user_regs_struct) below. |
| 13 | */ |
| 14 | typedef __u64 u64; |
| 15 | typedef __u32 u32; |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 16 | #include <asm/user.h> |
| 17 | |
| 18 | #define DEFINE(sym, val) \ |
| 19 | asm volatile("\n->" #sym " %0 " #val : : "i" (val)) |
| 20 | |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 21 | #define DEFINE_LONGS(sym, val) \ |
| 22 | asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long))) |
| 23 | |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 24 | #define OFFSET(sym, str, mem) \ |
| 25 | DEFINE(sym, offsetof(struct str, mem)); |
| 26 | |
| 27 | void foo(void) |
| 28 | { |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 29 | OFFSET(HOST_SC_RBX, sigcontext, rbx); |
| 30 | OFFSET(HOST_SC_RCX, sigcontext, rcx); |
| 31 | OFFSET(HOST_SC_RDX, sigcontext, rdx); |
| 32 | OFFSET(HOST_SC_RSI, sigcontext, rsi); |
| 33 | OFFSET(HOST_SC_RDI, sigcontext, rdi); |
| 34 | OFFSET(HOST_SC_RBP, sigcontext, rbp); |
| 35 | OFFSET(HOST_SC_RAX, sigcontext, rax); |
| 36 | OFFSET(HOST_SC_R8, sigcontext, r8); |
| 37 | OFFSET(HOST_SC_R9, sigcontext, r9); |
| 38 | OFFSET(HOST_SC_R10, sigcontext, r10); |
| 39 | OFFSET(HOST_SC_R11, sigcontext, r11); |
| 40 | OFFSET(HOST_SC_R12, sigcontext, r12); |
| 41 | OFFSET(HOST_SC_R13, sigcontext, r13); |
| 42 | OFFSET(HOST_SC_R14, sigcontext, r14); |
| 43 | OFFSET(HOST_SC_R15, sigcontext, r15); |
| 44 | OFFSET(HOST_SC_IP, sigcontext, rip); |
| 45 | OFFSET(HOST_SC_SP, sigcontext, rsp); |
| 46 | OFFSET(HOST_SC_CR2, sigcontext, cr2); |
| 47 | OFFSET(HOST_SC_ERR, sigcontext, err); |
| 48 | OFFSET(HOST_SC_TRAPNO, sigcontext, trapno); |
| 49 | OFFSET(HOST_SC_CS, sigcontext, cs); |
| 50 | OFFSET(HOST_SC_FS, sigcontext, fs); |
| 51 | OFFSET(HOST_SC_GS, sigcontext, gs); |
| 52 | OFFSET(HOST_SC_EFLAGS, sigcontext, eflags); |
| 53 | OFFSET(HOST_SC_SIGMASK, sigcontext, oldmask); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 54 | #if 0 |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 55 | OFFSET(HOST_SC_ORIG_RAX, sigcontext, orig_rax); |
| 56 | OFFSET(HOST_SC_DS, sigcontext, ds); |
| 57 | OFFSET(HOST_SC_ES, sigcontext, es); |
| 58 | OFFSET(HOST_SC_SS, sigcontext, ss); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 59 | #endif |
| 60 | |
Jeff Dike | e2216fe | 2006-02-07 12:58:43 -0800 | [diff] [blame] | 61 | DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long)); |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 62 | DEFINE(HOST_XFP_SIZE, 0); |
| 63 | DEFINE_LONGS(HOST_RBX, RBX); |
| 64 | DEFINE_LONGS(HOST_RCX, RCX); |
| 65 | DEFINE_LONGS(HOST_RDI, RDI); |
| 66 | DEFINE_LONGS(HOST_RSI, RSI); |
| 67 | DEFINE_LONGS(HOST_RDX, RDX); |
| 68 | DEFINE_LONGS(HOST_RBP, RBP); |
| 69 | DEFINE_LONGS(HOST_RAX, RAX); |
| 70 | DEFINE_LONGS(HOST_R8, R8); |
| 71 | DEFINE_LONGS(HOST_R9, R9); |
| 72 | DEFINE_LONGS(HOST_R10, R10); |
| 73 | DEFINE_LONGS(HOST_R11, R11); |
| 74 | DEFINE_LONGS(HOST_R12, R12); |
| 75 | DEFINE_LONGS(HOST_R13, R13); |
| 76 | DEFINE_LONGS(HOST_R14, R14); |
| 77 | DEFINE_LONGS(HOST_R15, R15); |
| 78 | DEFINE_LONGS(HOST_ORIG_RAX, ORIG_RAX); |
| 79 | DEFINE_LONGS(HOST_CS, CS); |
| 80 | DEFINE_LONGS(HOST_SS, SS); |
| 81 | DEFINE_LONGS(HOST_EFLAGS, EFLAGS); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 82 | #if 0 |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 83 | DEFINE_LONGS(HOST_FS, FS); |
| 84 | DEFINE_LONGS(HOST_GS, GS); |
| 85 | DEFINE_LONGS(HOST_DS, DS); |
| 86 | DEFINE_LONGS(HOST_ES, ES); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 87 | #endif |
| 88 | |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 89 | DEFINE_LONGS(HOST_IP, RIP); |
| 90 | DEFINE_LONGS(HOST_SP, RSP); |
| 91 | DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct)); |
Jeff Dike | 63ae2a9 | 2006-03-27 01:14:30 -0800 | [diff] [blame] | 92 | |
| 93 | /* XXX Duplicated between i386 and x86_64 */ |
| 94 | DEFINE(UM_POLLIN, POLLIN); |
| 95 | DEFINE(UM_POLLPRI, POLLPRI); |
| 96 | DEFINE(UM_POLLOUT, POLLOUT); |
Jeff Dike | 16dd07b | 2007-05-06 14:51:48 -0700 | [diff] [blame^] | 97 | |
| 98 | DEFINE(UM_PROT_READ, PROT_READ); |
| 99 | DEFINE(UM_PROT_WRITE, PROT_WRITE); |
| 100 | DEFINE(UM_PROT_EXEC, PROT_EXEC); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 101 | } |