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 | |
H. Peter Anvin | 45db1c6 | 2011-12-05 16:08:49 -0800 | [diff] [blame] | 11 | #ifdef __i386__ |
Andy Lutomirski | cfcbadb | 2016-01-28 15:11:24 -0800 | [diff] [blame] | 12 | #define __SYSCALL_I386(nr, sym, qual) [nr] = 1, |
H. Peter Anvin | 45db1c6 | 2011-12-05 16:08:49 -0800 | [diff] [blame] | 13 | static char syscalls[] = { |
| 14 | #include <asm/syscalls_32.h> |
| 15 | }; |
| 16 | #else |
Andy Lutomirski | cfcbadb | 2016-01-28 15:11:24 -0800 | [diff] [blame] | 17 | #define __SYSCALL_64(nr, sym, qual) [nr] = 1, |
H. Peter Anvin | 45db1c6 | 2011-12-05 16:08:49 -0800 | [diff] [blame] | 18 | static char syscalls[] = { |
| 19 | #include <asm/syscalls_64.h> |
| 20 | }; |
| 21 | #endif |
| 22 | |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 23 | #define DEFINE(sym, val) \ |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame] | 24 | asm volatile("\n->" #sym " %0 " #val : : "i" (val)) |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 25 | |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 26 | #define DEFINE_LONGS(sym, val) \ |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame] | 27 | asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long))) |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 28 | |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 29 | void foo(void) |
| 30 | { |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame] | 31 | #ifdef __i386__ |
| 32 | DEFINE_LONGS(HOST_FP_SIZE, sizeof(struct user_fpregs_struct)); |
| 33 | DEFINE_LONGS(HOST_FPX_SIZE, sizeof(struct user_fpxregs_struct)); |
| 34 | |
| 35 | DEFINE(HOST_IP, EIP); |
| 36 | DEFINE(HOST_SP, UESP); |
| 37 | DEFINE(HOST_EFLAGS, EFL); |
Al Viro | 3579a38 | 2011-08-18 20:10:09 +0100 | [diff] [blame] | 38 | DEFINE(HOST_AX, EAX); |
| 39 | DEFINE(HOST_BX, EBX); |
| 40 | DEFINE(HOST_CX, ECX); |
| 41 | DEFINE(HOST_DX, EDX); |
| 42 | DEFINE(HOST_SI, ESI); |
| 43 | DEFINE(HOST_DI, EDI); |
| 44 | DEFINE(HOST_BP, EBP); |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame] | 45 | DEFINE(HOST_CS, CS); |
| 46 | DEFINE(HOST_SS, SS); |
| 47 | DEFINE(HOST_DS, DS); |
| 48 | DEFINE(HOST_FS, FS); |
| 49 | DEFINE(HOST_ES, ES); |
| 50 | DEFINE(HOST_GS, GS); |
Al Viro | 966e803 | 2011-08-18 20:12:19 +0100 | [diff] [blame] | 51 | DEFINE(HOST_ORIG_AX, ORIG_EAX); |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame] | 52 | #else |
Thomas Meyer | 535d4c0 | 2017-07-29 17:03:23 +0200 | [diff] [blame] | 53 | #ifdef FP_XSTATE_MAGIC1 |
| 54 | DEFINE_LONGS(HOST_FP_SIZE, 2696); |
Florian Fainelli | bf81c7a | 2017-05-25 11:36:26 -0700 | [diff] [blame] | 55 | #else |
| 56 | DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long)); |
| 57 | #endif |
Al Viro | 3579a38 | 2011-08-18 20:10:09 +0100 | [diff] [blame] | 58 | DEFINE_LONGS(HOST_BX, RBX); |
| 59 | DEFINE_LONGS(HOST_CX, RCX); |
| 60 | DEFINE_LONGS(HOST_DI, RDI); |
| 61 | DEFINE_LONGS(HOST_SI, RSI); |
| 62 | DEFINE_LONGS(HOST_DX, RDX); |
| 63 | DEFINE_LONGS(HOST_BP, RBP); |
| 64 | DEFINE_LONGS(HOST_AX, RAX); |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 65 | DEFINE_LONGS(HOST_R8, R8); |
| 66 | DEFINE_LONGS(HOST_R9, R9); |
| 67 | DEFINE_LONGS(HOST_R10, R10); |
| 68 | DEFINE_LONGS(HOST_R11, R11); |
| 69 | DEFINE_LONGS(HOST_R12, R12); |
| 70 | DEFINE_LONGS(HOST_R13, R13); |
| 71 | DEFINE_LONGS(HOST_R14, R14); |
| 72 | DEFINE_LONGS(HOST_R15, R15); |
Al Viro | 966e803 | 2011-08-18 20:12:19 +0100 | [diff] [blame] | 73 | DEFINE_LONGS(HOST_ORIG_AX, ORIG_RAX); |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 74 | DEFINE_LONGS(HOST_CS, CS); |
| 75 | DEFINE_LONGS(HOST_SS, SS); |
| 76 | DEFINE_LONGS(HOST_EFLAGS, EFLAGS); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 77 | #if 0 |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 78 | DEFINE_LONGS(HOST_FS, FS); |
| 79 | DEFINE_LONGS(HOST_GS, GS); |
| 80 | DEFINE_LONGS(HOST_DS, DS); |
| 81 | DEFINE_LONGS(HOST_ES, ES); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 82 | #endif |
| 83 | |
Al Viro | ecba97d | 2005-09-28 22:27:23 +0100 | [diff] [blame] | 84 | DEFINE_LONGS(HOST_IP, RIP); |
| 85 | DEFINE_LONGS(HOST_SP, RSP); |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame] | 86 | #endif |
Jeff Dike | 63ae2a9 | 2006-03-27 01:14:30 -0800 | [diff] [blame] | 87 | |
Al Viro | 6582b7f | 2011-08-18 20:03:19 +0100 | [diff] [blame] | 88 | DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct)); |
Jeff Dike | 63ae2a9 | 2006-03-27 01:14:30 -0800 | [diff] [blame] | 89 | DEFINE(UM_POLLIN, POLLIN); |
| 90 | DEFINE(UM_POLLPRI, POLLPRI); |
| 91 | DEFINE(UM_POLLOUT, POLLOUT); |
Jeff Dike | 16dd07b | 2007-05-06 14:51:48 -0700 | [diff] [blame] | 92 | |
| 93 | DEFINE(UM_PROT_READ, PROT_READ); |
| 94 | DEFINE(UM_PROT_WRITE, PROT_WRITE); |
| 95 | DEFINE(UM_PROT_EXEC, PROT_EXEC); |
H. Peter Anvin | 45db1c6 | 2011-12-05 16:08:49 -0800 | [diff] [blame] | 96 | |
| 97 | DEFINE(__NR_syscall_max, sizeof(syscalls) - 1); |
| 98 | DEFINE(NR_syscalls, sizeof(syscalls)); |
Al Viro | 8d0b9dc | 2005-05-05 16:15:23 -0700 | [diff] [blame] | 99 | } |