1
2
3
4
5
6
7
8
9
10#ifndef _ASM_X86_SYSCALL_H
11#define _ASM_X86_SYSCALL_H
12
13#include <uapi/linux/audit.h>
14#include <linux/sched.h>
15#include <linux/err.h>
16#include <asm/thread_info.h>
17#include <asm/unistd.h>
18
19typedef long (*sys_call_ptr_t)(const struct pt_regs *);
20extern const sys_call_ptr_t sys_call_table[];
21
22#if defined(CONFIG_X86_32)
23#define ia32_sys_call_table sys_call_table
24#else
25
26
27
28
29extern const sys_call_ptr_t ia32_sys_call_table[];
30extern const sys_call_ptr_t x32_sys_call_table[];
31#endif
32
33
34
35
36
37
38static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
39{
40 return regs->orig_ax;
41}
42
43static inline void syscall_rollback(struct task_struct *task,
44 struct pt_regs *regs)
45{
46 regs->ax = regs->orig_ax;
47}
48
49static inline long syscall_get_error(struct task_struct *task,
50 struct pt_regs *regs)
51{
52 unsigned long error = regs->ax;
53#ifdef CONFIG_IA32_EMULATION
54
55
56
57
58 if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
59
60
61
62
63 error = (long) (int) error;
64#endif
65 return IS_ERR_VALUE(error) ? error : 0;
66}
67
68static inline long syscall_get_return_value(struct task_struct *task,
69 struct pt_regs *regs)
70{
71 return regs->ax;
72}
73
74static inline void syscall_set_return_value(struct task_struct *task,
75 struct pt_regs *regs,
76 int error, long val)
77{
78 regs->ax = (long) error ?: val;
79}
80
81#ifdef CONFIG_X86_32
82
83static inline void syscall_get_arguments(struct task_struct *task,
84 struct pt_regs *regs,
85 unsigned long *args)
86{
87 memcpy(args, ®s->bx, 6 * sizeof(args[0]));
88}
89
90static inline void syscall_set_arguments(struct task_struct *task,
91 struct pt_regs *regs,
92 unsigned int i, unsigned int n,
93 const unsigned long *args)
94{
95 BUG_ON(i + n > 6);
96 memcpy(®s->bx + i, args, n * sizeof(args[0]));
97}
98
99static inline int syscall_get_arch(struct task_struct *task)
100{
101 return AUDIT_ARCH_I386;
102}
103
104#else
105
106static inline void syscall_get_arguments(struct task_struct *task,
107 struct pt_regs *regs,
108 unsigned long *args)
109{
110# ifdef CONFIG_IA32_EMULATION
111 if (task->thread_info.status & TS_COMPAT) {
112 *args++ = regs->bx;
113 *args++ = regs->cx;
114 *args++ = regs->dx;
115 *args++ = regs->si;
116 *args++ = regs->di;
117 *args = regs->bp;
118 } else
119# endif
120 {
121 *args++ = regs->di;
122 *args++ = regs->si;
123 *args++ = regs->dx;
124 *args++ = regs->r10;
125 *args++ = regs->r8;
126 *args = regs->r9;
127 }
128}
129
130static inline void syscall_set_arguments(struct task_struct *task,
131 struct pt_regs *regs,
132 const unsigned long *args)
133{
134# ifdef CONFIG_IA32_EMULATION
135 if (task->thread_info.status & TS_COMPAT) {
136 regs->bx = *args++;
137 regs->cx = *args++;
138 regs->dx = *args++;
139 regs->si = *args++;
140 regs->di = *args++;
141 regs->bp = *args;
142 } else
143# endif
144 {
145 regs->di = *args++;
146 regs->si = *args++;
147 regs->dx = *args++;
148 regs->r10 = *args++;
149 regs->r8 = *args++;
150 regs->r9 = *args;
151 }
152}
153
154static inline int syscall_get_arch(struct task_struct *task)
155{
156
157 return (IS_ENABLED(CONFIG_IA32_EMULATION) &&
158 task->thread_info.status & TS_COMPAT)
159 ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
160}
161
162void do_syscall_64(struct pt_regs *regs, int nr);
163void do_int80_syscall_32(struct pt_regs *regs);
164long do_fast_syscall_32(struct pt_regs *regs);
165
166#endif
167
168#endif
169