x86/ptrace: Stop setting TS_COMPAT in ptrace code
[deliverable/linux.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
eb974c62
AL
23typedef asmlinkage long (*sys_call_ptr_t)(unsigned long, unsigned long,
24 unsigned long, unsigned long,
25 unsigned long, unsigned long);
1599e8fc 26extern const sys_call_ptr_t sys_call_table[];
e7b8e675 27
034042cc
AL
28#if defined(CONFIG_X86_32)
29#define ia32_sys_call_table sys_call_table
30#define __NR_syscall_compat_max __NR_syscall_max
31#define IA32_NR_syscalls NR_syscalls
32#endif
33
34#if defined(CONFIG_IA32_EMULATION)
35extern const sys_call_ptr_t ia32_sys_call_table[];
36#endif
37
18c1e2c8
RM
38/*
39 * Only the low 32 bits of orig_ax are meaningful, so we return int.
40 * This importantly ignores the high bits on 64-bit, so comparisons
41 * sign-extend the low 32 bits.
42 */
43static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
68bd0f4e 44{
8b4b9f27 45 return regs->orig_ax;
68bd0f4e
RM
46}
47
48static inline void syscall_rollback(struct task_struct *task,
49 struct pt_regs *regs)
50{
8b4b9f27 51 regs->ax = regs->orig_ax;
68bd0f4e
RM
52}
53
54static inline long syscall_get_error(struct task_struct *task,
55 struct pt_regs *regs)
56{
57 unsigned long error = regs->ax;
58#ifdef CONFIG_IA32_EMULATION
59 /*
60 * TS_COMPAT is set for 32-bit syscall entries and then
61 * remains set until we return to user mode.
62 */
609c19a3 63 if (task_thread_info(task)->status & (TS_COMPAT|TS_I386_REGS_POKED))
68bd0f4e
RM
64 /*
65 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
66 * and will match correctly in comparisons.
67 */
68 error = (long) (int) error;
69#endif
4ab4ba32 70 return IS_ERR_VALUE(error) ? error : 0;
68bd0f4e
RM
71}
72
73static inline long syscall_get_return_value(struct task_struct *task,
74 struct pt_regs *regs)
75{
76 return regs->ax;
77}
78
79static inline void syscall_set_return_value(struct task_struct *task,
80 struct pt_regs *regs,
81 int error, long val)
82{
83 regs->ax = (long) error ?: val;
84}
85
86#ifdef CONFIG_X86_32
87
88static inline void syscall_get_arguments(struct task_struct *task,
89 struct pt_regs *regs,
90 unsigned int i, unsigned int n,
91 unsigned long *args)
92{
93 BUG_ON(i + n > 6);
94 memcpy(args, &regs->bx + i, n * sizeof(args[0]));
95}
96
97static inline void syscall_set_arguments(struct task_struct *task,
98 struct pt_regs *regs,
99 unsigned int i, unsigned int n,
100 const unsigned long *args)
101{
102 BUG_ON(i + n > 6);
103 memcpy(&regs->bx + i, args, n * sizeof(args[0]));
104}
105
5e937a9a 106static inline int syscall_get_arch(void)
b7456536
WD
107{
108 return AUDIT_ARCH_I386;
109}
110
68bd0f4e
RM
111#else /* CONFIG_X86_64 */
112
113static inline void syscall_get_arguments(struct task_struct *task,
114 struct pt_regs *regs,
115 unsigned int i, unsigned int n,
116 unsigned long *args)
117{
118# ifdef CONFIG_IA32_EMULATION
119 if (task_thread_info(task)->status & TS_COMPAT)
746e7cef
RM
120 switch (i) {
121 case 0:
68bd0f4e 122 if (!n--) break;
746e7cef
RM
123 *args++ = regs->bx;
124 case 1:
68bd0f4e 125 if (!n--) break;
746e7cef
RM
126 *args++ = regs->cx;
127 case 2:
68bd0f4e 128 if (!n--) break;
746e7cef 129 *args++ = regs->dx;
68bd0f4e
RM
130 case 3:
131 if (!n--) break;
746e7cef
RM
132 *args++ = regs->si;
133 case 4:
68bd0f4e 134 if (!n--) break;
746e7cef
RM
135 *args++ = regs->di;
136 case 5:
68bd0f4e 137 if (!n--) break;
746e7cef
RM
138 *args++ = regs->bp;
139 case 6:
68bd0f4e
RM
140 if (!n--) break;
141 default:
142 BUG();
143 break;
144 }
145 else
146# endif
746e7cef
RM
147 switch (i) {
148 case 0:
68bd0f4e 149 if (!n--) break;
746e7cef
RM
150 *args++ = regs->di;
151 case 1:
68bd0f4e 152 if (!n--) break;
746e7cef
RM
153 *args++ = regs->si;
154 case 2:
68bd0f4e 155 if (!n--) break;
746e7cef 156 *args++ = regs->dx;
68bd0f4e
RM
157 case 3:
158 if (!n--) break;
746e7cef
RM
159 *args++ = regs->r10;
160 case 4:
68bd0f4e 161 if (!n--) break;
746e7cef
RM
162 *args++ = regs->r8;
163 case 5:
68bd0f4e 164 if (!n--) break;
746e7cef
RM
165 *args++ = regs->r9;
166 case 6:
68bd0f4e
RM
167 if (!n--) break;
168 default:
169 BUG();
170 break;
171 }
172}
173
174static inline void syscall_set_arguments(struct task_struct *task,
175 struct pt_regs *regs,
176 unsigned int i, unsigned int n,
177 const unsigned long *args)
178{
179# ifdef CONFIG_IA32_EMULATION
180 if (task_thread_info(task)->status & TS_COMPAT)
746e7cef
RM
181 switch (i) {
182 case 0:
68bd0f4e 183 if (!n--) break;
746e7cef
RM
184 regs->bx = *args++;
185 case 1:
68bd0f4e 186 if (!n--) break;
746e7cef
RM
187 regs->cx = *args++;
188 case 2:
68bd0f4e 189 if (!n--) break;
746e7cef 190 regs->dx = *args++;
68bd0f4e
RM
191 case 3:
192 if (!n--) break;
746e7cef
RM
193 regs->si = *args++;
194 case 4:
68bd0f4e 195 if (!n--) break;
746e7cef
RM
196 regs->di = *args++;
197 case 5:
68bd0f4e 198 if (!n--) break;
746e7cef
RM
199 regs->bp = *args++;
200 case 6:
68bd0f4e
RM
201 if (!n--) break;
202 default:
203 BUG();
746e7cef 204 break;
68bd0f4e
RM
205 }
206 else
207# endif
746e7cef
RM
208 switch (i) {
209 case 0:
68bd0f4e 210 if (!n--) break;
746e7cef
RM
211 regs->di = *args++;
212 case 1:
68bd0f4e 213 if (!n--) break;
746e7cef
RM
214 regs->si = *args++;
215 case 2:
68bd0f4e 216 if (!n--) break;
746e7cef 217 regs->dx = *args++;
68bd0f4e
RM
218 case 3:
219 if (!n--) break;
746e7cef
RM
220 regs->r10 = *args++;
221 case 4:
68bd0f4e 222 if (!n--) break;
746e7cef
RM
223 regs->r8 = *args++;
224 case 5:
68bd0f4e 225 if (!n--) break;
746e7cef
RM
226 regs->r9 = *args++;
227 case 6:
68bd0f4e
RM
228 if (!n--) break;
229 default:
230 BUG();
746e7cef 231 break;
68bd0f4e
RM
232 }
233}
234
5e937a9a 235static inline int syscall_get_arch(void)
b7456536
WD
236{
237#ifdef CONFIG_IA32_EMULATION
238 /*
239 * TS_COMPAT is set for 32-bit syscall entry and then
240 * remains set until we return to user mode.
241 *
b7456536
WD
242 * x32 tasks should be considered AUDIT_ARCH_X86_64.
243 */
5e937a9a 244 if (task_thread_info(current)->status & TS_COMPAT)
b7456536
WD
245 return AUDIT_ARCH_I386;
246#endif
247 /* Both x32 and x86_64 are considered "64-bit". */
248 return AUDIT_ARCH_X86_64;
249}
68bd0f4e
RM
250#endif /* CONFIG_X86_32 */
251
5e1b0075 252#endif /* _ASM_X86_SYSCALL_H */
This page took 0.450872 seconds and 5 git commands to generate.