• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <stddef.h>
3 #include <signal.h>
4 #include <sys/poll.h>
5 #include <sys/mman.h>
6 #include <sys/user.h>
7 #define __FRAME_OFFSETS
8 #include <asm/ptrace.h>
9 #include <asm/types.h>
10 
11 #define DEFINE(sym, val) \
12         asm volatile("\n->" #sym " %0 " #val : : "i" (val))
13 
14 #define DEFINE_LONGS(sym, val) \
15         asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long)))
16 
17 #define OFFSET(sym, str, mem) \
18 	DEFINE(sym, offsetof(struct str, mem));
19 
foo(void)20 void foo(void)
21 {
22 	OFFSET(HOST_SC_CR2, sigcontext, cr2);
23 	OFFSET(HOST_SC_ERR, sigcontext, err);
24 	OFFSET(HOST_SC_TRAPNO, sigcontext, trapno);
25 
26 	DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
27 	DEFINE_LONGS(HOST_RBX, RBX);
28 	DEFINE_LONGS(HOST_RCX, RCX);
29 	DEFINE_LONGS(HOST_RDI, RDI);
30 	DEFINE_LONGS(HOST_RSI, RSI);
31 	DEFINE_LONGS(HOST_RDX, RDX);
32 	DEFINE_LONGS(HOST_RBP, RBP);
33 	DEFINE_LONGS(HOST_RAX, RAX);
34 	DEFINE_LONGS(HOST_R8, R8);
35 	DEFINE_LONGS(HOST_R9, R9);
36 	DEFINE_LONGS(HOST_R10, R10);
37 	DEFINE_LONGS(HOST_R11, R11);
38 	DEFINE_LONGS(HOST_R12, R12);
39 	DEFINE_LONGS(HOST_R13, R13);
40 	DEFINE_LONGS(HOST_R14, R14);
41 	DEFINE_LONGS(HOST_R15, R15);
42 	DEFINE_LONGS(HOST_ORIG_RAX, ORIG_RAX);
43 	DEFINE_LONGS(HOST_CS, CS);
44 	DEFINE_LONGS(HOST_SS, SS);
45 	DEFINE_LONGS(HOST_EFLAGS, EFLAGS);
46 #if 0
47 	DEFINE_LONGS(HOST_FS, FS);
48 	DEFINE_LONGS(HOST_GS, GS);
49 	DEFINE_LONGS(HOST_DS, DS);
50 	DEFINE_LONGS(HOST_ES, ES);
51 #endif
52 
53 	DEFINE_LONGS(HOST_IP, RIP);
54 	DEFINE_LONGS(HOST_SP, RSP);
55 	DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct));
56 
57 	/* XXX Duplicated between i386 and x86_64 */
58 	DEFINE(UM_POLLIN, POLLIN);
59 	DEFINE(UM_POLLPRI, POLLPRI);
60 	DEFINE(UM_POLLOUT, POLLOUT);
61 
62 	DEFINE(UM_PROT_READ, PROT_READ);
63 	DEFINE(UM_PROT_WRITE, PROT_WRITE);
64 	DEFINE(UM_PROT_EXEC, PROT_EXEC);
65 }
66