blob: 5b37b7f952ddffc4cb76b53e590609fcb2d076a5 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Al Viro8d0b9dc2005-05-05 16:15:23 -07002#include <stdio.h>
3#include <stddef.h>
4#include <signal.h>
Jeff Dike63ae2a92006-03-27 01:14:30 -08005#include <sys/poll.h>
Jeff Dike16dd07b2007-05-06 14:51:48 -07006#include <sys/mman.h>
Jeff Dike189872f2007-10-16 01:27:14 -07007#include <sys/user.h>
Al Viro8d0b9dc2005-05-05 16:15:23 -07008#define __FRAME_OFFSETS
Richard Weinberger61e8d462017-07-06 09:35:27 +02009#include <linux/ptrace.h>
Jeff Dikeba9950c2005-05-20 13:59:07 -070010#include <asm/types.h>
Al Viro8d0b9dc2005-05-05 16:15:23 -070011
H. Peter Anvin45db1c62011-12-05 16:08:49 -080012#ifdef __i386__
Andy Lutomirskicfcbadb2016-01-28 15:11:24 -080013#define __SYSCALL_I386(nr, sym, qual) [nr] = 1,
H. Peter Anvin45db1c62011-12-05 16:08:49 -080014static char syscalls[] = {
15#include <asm/syscalls_32.h>
16};
17#else
Andy Lutomirskicfcbadb2016-01-28 15:11:24 -080018#define __SYSCALL_64(nr, sym, qual) [nr] = 1,
H. Peter Anvin45db1c62011-12-05 16:08:49 -080019static char syscalls[] = {
20#include <asm/syscalls_64.h>
21};
22#endif
23
Al Viro8d0b9dc2005-05-05 16:15:23 -070024#define DEFINE(sym, val) \
Al Viro6582b7f2011-08-18 20:03:19 +010025 asm volatile("\n->" #sym " %0 " #val : : "i" (val))
Al Viro8d0b9dc2005-05-05 16:15:23 -070026
Al Viroecba97d2005-09-28 22:27:23 +010027#define DEFINE_LONGS(sym, val) \
Al Viro6582b7f2011-08-18 20:03:19 +010028 asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long)))
Al Viroecba97d2005-09-28 22:27:23 +010029
Al Viro8d0b9dc2005-05-05 16:15:23 -070030void foo(void)
31{
Al Viro6582b7f2011-08-18 20:03:19 +010032#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);
Al Viro3579a382011-08-18 20:10:09 +010039 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);
Al Viro6582b7f2011-08-18 20:03:19 +010046 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);
Al Viro966e8032011-08-18 20:12:19 +010052 DEFINE(HOST_ORIG_AX, ORIG_EAX);
Al Viro6582b7f2011-08-18 20:03:19 +010053#else
Florian Fainelli2fb44602017-07-18 16:43:47 -070054#ifdef FP_XSTATE_MAGIC1
Thomas Meyer6f602afd2017-07-29 17:03:23 +020055 DEFINE_LONGS(HOST_FP_SIZE, 2696);
Florian Fainelli0a987642017-05-25 11:36:26 -070056#else
57 DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
58#endif
Al Viro3579a382011-08-18 20:10:09 +010059 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);
Al Viroecba97d2005-09-28 22:27:23 +010066 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);
Al Viro966e8032011-08-18 20:12:19 +010074 DEFINE_LONGS(HOST_ORIG_AX, ORIG_RAX);
Al Viroecba97d2005-09-28 22:27:23 +010075 DEFINE_LONGS(HOST_CS, CS);
76 DEFINE_LONGS(HOST_SS, SS);
77 DEFINE_LONGS(HOST_EFLAGS, EFLAGS);
Al Viro8d0b9dc2005-05-05 16:15:23 -070078#if 0
Al Viroecba97d2005-09-28 22:27:23 +010079 DEFINE_LONGS(HOST_FS, FS);
80 DEFINE_LONGS(HOST_GS, GS);
81 DEFINE_LONGS(HOST_DS, DS);
82 DEFINE_LONGS(HOST_ES, ES);
Al Viro8d0b9dc2005-05-05 16:15:23 -070083#endif
84
Al Viroecba97d2005-09-28 22:27:23 +010085 DEFINE_LONGS(HOST_IP, RIP);
86 DEFINE_LONGS(HOST_SP, RSP);
Al Viro6582b7f2011-08-18 20:03:19 +010087#endif
Jeff Dike63ae2a92006-03-27 01:14:30 -080088
Al Viro6582b7f2011-08-18 20:03:19 +010089 DEFINE(UM_FRAME_SIZE, sizeof(struct user_regs_struct));
Jeff Dike63ae2a92006-03-27 01:14:30 -080090 DEFINE(UM_POLLIN, POLLIN);
91 DEFINE(UM_POLLPRI, POLLPRI);
92 DEFINE(UM_POLLOUT, POLLOUT);
Jeff Dike16dd07b2007-05-06 14:51:48 -070093
94 DEFINE(UM_PROT_READ, PROT_READ);
95 DEFINE(UM_PROT_WRITE, PROT_WRITE);
96 DEFINE(UM_PROT_EXEC, PROT_EXEC);
H. Peter Anvin45db1c62011-12-05 16:08:49 -080097
98 DEFINE(__NR_syscall_max, sizeof(syscalls) - 1);
99 DEFINE(NR_syscalls, sizeof(syscalls));
Al Viro8d0b9dc2005-05-05 16:15:23 -0700100}