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