xref: /linux/arch/x86/um/user-offsets.c (revision 906fd46a65383cd639e5eec72a047efc33045d86)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <stdio.h>
3 #include <stddef.h>
4 #include <signal.h>
5 #include <poll.h>
6 #include <sys/mman.h>
7 #include <sys/user.h>
8 #define __FRAME_OFFSETS
9 #include <linux/ptrace.h>
10 #include <asm/types.h>
11 #include <linux/kbuild.h>
12 
13 #define DEFINE_LONGS(sym, val)	\
14 	COMMENT(#val " / sizeof(unsigned long)");	\
15 	DEFINE(sym, val / sizeof(unsigned long))
16 
17 /* workaround for a warning with -Wmissing-prototypes */
18 void foo(void);
19 
20 void foo(void)
21 {
22 #ifdef __i386__
23 	DEFINE_LONGS(HOST_FP_SIZE, sizeof(struct user_fpregs_struct));
24 	DEFINE_LONGS(HOST_FPX_SIZE, sizeof(struct user_fpxregs_struct));
25 
26 	DEFINE(HOST_IP, EIP);
27 	DEFINE(HOST_SP, UESP);
28 	DEFINE(HOST_EFLAGS, EFL);
29 	DEFINE(HOST_AX, EAX);
30 	DEFINE(HOST_BX, EBX);
31 	DEFINE(HOST_CX, ECX);
32 	DEFINE(HOST_DX, EDX);
33 	DEFINE(HOST_SI, ESI);
34 	DEFINE(HOST_DI, EDI);
35 	DEFINE(HOST_BP, EBP);
36 	DEFINE(HOST_CS, CS);
37 	DEFINE(HOST_SS, SS);
38 	DEFINE(HOST_DS, DS);
39 	DEFINE(HOST_FS, FS);
40 	DEFINE(HOST_ES, ES);
41 	DEFINE(HOST_GS, GS);
42 	DEFINE(HOST_ORIG_AX, ORIG_EAX);
43 #else
44 #ifdef FP_XSTATE_MAGIC1
45 	DEFINE_LONGS(HOST_FP_SIZE, 2696);
46 #else
47 	DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
48 #endif
49 	DEFINE_LONGS(HOST_BX, RBX);
50 	DEFINE_LONGS(HOST_CX, RCX);
51 	DEFINE_LONGS(HOST_DI, RDI);
52 	DEFINE_LONGS(HOST_SI, RSI);
53 	DEFINE_LONGS(HOST_DX, RDX);
54 	DEFINE_LONGS(HOST_BP, RBP);
55 	DEFINE_LONGS(HOST_AX, RAX);
56 	DEFINE_LONGS(HOST_R8, R8);
57 	DEFINE_LONGS(HOST_R9, R9);
58 	DEFINE_LONGS(HOST_R10, R10);
59 	DEFINE_LONGS(HOST_R11, R11);
60 	DEFINE_LONGS(HOST_R12, R12);
61 	DEFINE_LONGS(HOST_R13, R13);
62 	DEFINE_LONGS(HOST_R14, R14);
63 	DEFINE_LONGS(HOST_R15, R15);
64 	DEFINE_LONGS(HOST_ORIG_AX, ORIG_RAX);
65 	DEFINE_LONGS(HOST_CS, CS);
66 	DEFINE_LONGS(HOST_SS, SS);
67 	DEFINE_LONGS(HOST_EFLAGS, EFLAGS);
68 #if 0
69 	DEFINE_LONGS(HOST_FS, FS);
70 	DEFINE_LONGS(HOST_GS, GS);
71 	DEFINE_LONGS(HOST_DS, DS);
72 	DEFINE_LONGS(HOST_ES, ES);
73 #endif
74 
75 	DEFINE_LONGS(HOST_IP, RIP);
76 	DEFINE_LONGS(HOST_SP, RSP);
77 #endif
78 
79 	DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct));
80 	DEFINE(UM_POLLIN, POLLIN);
81 	DEFINE(UM_POLLPRI, POLLPRI);
82 	DEFINE(UM_POLLOUT, POLLOUT);
83 
84 	DEFINE(UM_PROT_READ, PROT_READ);
85 	DEFINE(UM_PROT_WRITE, PROT_WRITE);
86 	DEFINE(UM_PROT_EXEC, PROT_EXEC);
87 }
88