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