syscalls: Remove start and number from syscall_get_arguments() args
[linux-block.git] / arch / x86 / include / asm / syscall.h
CommitLineData
68bd0f4e
RM
1/*
2 * Access to user system call parameters and results
3 *
18c1e2c8 4 * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
68bd0f4e
RM
5 *
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU General Public License v.2.
9 *
10 * See asm-generic/syscall.h for descriptions of what we must do here.
11 */
12
5e1b0075
PA
13#ifndef _ASM_X86_SYSCALL_H
14#define _ASM_X86_SYSCALL_H
68bd0f4e 15
579ec9e1 16#include <uapi/linux/audit.h>
68bd0f4e 17#include <linux/sched.h>
4ab4ba32 18#include <linux/err.h>
72142fd4 19#include <asm/asm-offsets.h> /* For NR_syscalls */
b7456536 20#include <asm/thread_info.h> /* for TS_COMPAT */
fca460f9 21#include <asm/unistd.h>
68bd0f4e 22
f8781c4a 23#ifdef CONFIG_X86_64
fa697140
DB
24typedef asmlinkage long (*sys_call_ptr_t)(const struct pt_regs *);
25#else
eb974c62
AL
26typedef asmlinkage long (*sys_call_ptr_t)(unsigned long, unsigned long,
27 unsigned long, unsigned long,
28 unsigned long, unsigned long);
f8781c4a 29#endif /* CONFIG_X86_64 */
1599e8fc 30extern const sys_call_ptr_t sys_call_table[];
e7b8e675 31
034042cc
AL
32#if defined(CONFIG_X86_32)
33#define ia32_sys_call_table sys_call_table
34#define __NR_syscall_compat_max __NR_syscall_max
35#define IA32_NR_syscalls NR_syscalls
36#endif
37
38#if defined(CONFIG_IA32_EMULATION)
39extern const sys_call_ptr_t ia32_sys_call_table[];
40#endif
41
18c1e2c8
RM
42/*
43 * Only the low 32 bits of orig_ax are meaningful, so we return int.
44 * This importantly ignores the high bits on 64-bit, so comparisons
45 * sign-extend the low 32 bits.
46 */
47static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
68bd0f4e 48{
8b4b9f27 49 return regs->orig_ax;
68bd0f4e
RM
50}
51
52static inline void syscall_rollback(struct task_struct *task,
53 struct pt_regs *regs)
54{
8b4b9f27 55 regs->ax = regs->orig_ax;
68bd0f4e
RM
56}
57
58static inline long syscall_get_error(struct task_struct *task,
59 struct pt_regs *regs)
60{
61 unsigned long error = regs->ax;
62#ifdef CONFIG_IA32_EMULATION
63 /*
64 * TS_COMPAT is set for 32-bit syscall entries and then
65 * remains set until we return to user mode.
66 */
37a8f7c3 67 if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
68bd0f4e
RM
68 /*
69 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
70 * and will match correctly in comparisons.
71 */
72 error = (long) (int) error;
73#endif
4ab4ba32 74 return IS_ERR_VALUE(error) ? error : 0;
68bd0f4e
RM
75}
76
77static inline long syscall_get_return_value(struct task_struct *task,
78 struct pt_regs *regs)
79{
80 return regs->ax;
81}
82
83static inline void syscall_set_return_value(struct task_struct *task,
84 struct pt_regs *regs,
85 int error, long val)
86{
87 regs->ax = (long) error ?: val;
88}
89
90#ifdef CONFIG_X86_32
91
92static inline void syscall_get_arguments(struct task_struct *task,
93 struct pt_regs *regs,
68bd0f4e
RM
94 unsigned long *args)
95{
b35f549d 96 memcpy(args, &regs->bx, 6 * sizeof(args[0]));
68bd0f4e
RM
97}
98
99static inline void syscall_set_arguments(struct task_struct *task,
100 struct pt_regs *regs,
101 unsigned int i, unsigned int n,
102 const unsigned long *args)
103{
104 BUG_ON(i + n > 6);
105 memcpy(&regs->bx + i, args, n * sizeof(args[0]));
106}
107
5e937a9a 108static inline int syscall_get_arch(void)
b7456536
WD
109{
110 return AUDIT_ARCH_I386;
111}
112
68bd0f4e
RM
113#else /* CONFIG_X86_64 */
114
115static inline void syscall_get_arguments(struct task_struct *task,
116 struct pt_regs *regs,
68bd0f4e
RM
117 unsigned long *args)
118{
119# ifdef CONFIG_IA32_EMULATION
b35f549d
SRRH
120 if (task->thread_info.status & TS_COMPAT) {
121 *args++ = regs->bx;
122 *args++ = regs->cx;
123 *args++ = regs->dx;
124 *args++ = regs->si;
125 *args++ = regs->di;
126 *args = regs->bp;
127 } else
68bd0f4e 128# endif
b35f549d
SRRH
129 {
130 *args++ = regs->di;
131 *args++ = regs->si;
132 *args++ = regs->dx;
133 *args++ = regs->r10;
134 *args++ = regs->r8;
135 *args = regs->r9;
136 }
68bd0f4e
RM
137}
138
139static inline void syscall_set_arguments(struct task_struct *task,
140 struct pt_regs *regs,
141 unsigned int i, unsigned int n,
142 const unsigned long *args)
143{
144# ifdef CONFIG_IA32_EMULATION
37a8f7c3 145 if (task->thread_info.status & TS_COMPAT)
746e7cef
RM
146 switch (i) {
147 case 0:
68bd0f4e 148 if (!n--) break;
746e7cef
RM
149 regs->bx = *args++;
150 case 1:
68bd0f4e 151 if (!n--) break;
746e7cef
RM
152 regs->cx = *args++;
153 case 2:
68bd0f4e 154 if (!n--) break;
746e7cef 155 regs->dx = *args++;
68bd0f4e
RM
156 case 3:
157 if (!n--) break;
746e7cef
RM
158 regs->si = *args++;
159 case 4:
68bd0f4e 160 if (!n--) break;
746e7cef
RM
161 regs->di = *args++;
162 case 5:
68bd0f4e 163 if (!n--) break;
746e7cef
RM
164 regs->bp = *args++;
165 case 6:
68bd0f4e
RM
166 if (!n--) break;
167 default:
168 BUG();
746e7cef 169 break;
68bd0f4e
RM
170 }
171 else
172# endif
746e7cef
RM
173 switch (i) {
174 case 0:
68bd0f4e 175 if (!n--) break;
746e7cef
RM
176 regs->di = *args++;
177 case 1:
68bd0f4e 178 if (!n--) break;
746e7cef
RM
179 regs->si = *args++;
180 case 2:
68bd0f4e 181 if (!n--) break;
746e7cef 182 regs->dx = *args++;
68bd0f4e
RM
183 case 3:
184 if (!n--) break;
746e7cef
RM
185 regs->r10 = *args++;
186 case 4:
68bd0f4e 187 if (!n--) break;
746e7cef
RM
188 regs->r8 = *args++;
189 case 5:
68bd0f4e 190 if (!n--) break;
746e7cef
RM
191 regs->r9 = *args++;
192 case 6:
68bd0f4e
RM
193 if (!n--) break;
194 default:
195 BUG();
746e7cef 196 break;
68bd0f4e
RM
197 }
198}
199
5e937a9a 200static inline int syscall_get_arch(void)
b7456536 201{
b9d989c7
AL
202 /* x32 tasks should be considered AUDIT_ARCH_X86_64. */
203 return in_ia32_syscall() ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
b7456536 204}
68bd0f4e
RM
205#endif /* CONFIG_X86_32 */
206
5e1b0075 207#endif /* _ASM_X86_SYSCALL_H */