2 * Access to user system call parameters and results
4 * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
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.
10 * See asm-generic/syscall.h for descriptions of what we must do here.
13 #ifndef _ASM_X86_SYSCALL_H
14 #define _ASM_X86_SYSCALL_H
16 #include <linux/audit.h>
17 #include <linux/sched.h>
18 #include <linux/err.h>
19 #include <asm/asm-offsets.h> /* For NR_syscalls */
20 #include <asm/thread_info.h> /* for TS_COMPAT */
21 #include <asm/unistd.h>
23 extern const unsigned long sys_call_table[];
26 * Only the low 32 bits of orig_ax are meaningful, so we return int.
27 * This importantly ignores the high bits on 64-bit, so comparisons
28 * sign-extend the low 32 bits.
30 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
32 return regs->orig_ax & __SYSCALL_MASK;
35 static inline void syscall_rollback(struct task_struct *task,
38 regs->ax = regs->orig_ax & __SYSCALL_MASK;
41 static inline long syscall_get_error(struct task_struct *task,
44 unsigned long error = regs->ax;
45 #ifdef CONFIG_IA32_EMULATION
47 * TS_COMPAT is set for 32-bit syscall entries and then
48 * remains set until we return to user mode.
50 if (task_thread_info(task)->status & TS_COMPAT)
52 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
53 * and will match correctly in comparisons.
55 error = (long) (int) error;
57 return IS_ERR_VALUE(error) ? error : 0;
60 static inline long syscall_get_return_value(struct task_struct *task,
66 static inline void syscall_set_return_value(struct task_struct *task,
70 regs->ax = (long) error ?: val;
75 static inline void syscall_get_arguments(struct task_struct *task,
77 unsigned int i, unsigned int n,
81 memcpy(args, ®s->bx + i, n * sizeof(args[0]));
84 static inline void syscall_set_arguments(struct task_struct *task,
86 unsigned int i, unsigned int n,
87 const unsigned long *args)
90 memcpy(®s->bx + i, args, n * sizeof(args[0]));
93 static inline int syscall_get_arch(struct task_struct *task,
96 return AUDIT_ARCH_I386;
99 #else /* CONFIG_X86_64 */
101 static inline void syscall_get_arguments(struct task_struct *task,
102 struct pt_regs *regs,
103 unsigned int i, unsigned int n,
106 # ifdef CONFIG_IA32_EMULATION
107 if (task_thread_info(task)->status & TS_COMPAT)
162 static inline void syscall_set_arguments(struct task_struct *task,
163 struct pt_regs *regs,
164 unsigned int i, unsigned int n,
165 const unsigned long *args)
167 # ifdef CONFIG_IA32_EMULATION
168 if (task_thread_info(task)->status & TS_COMPAT)
223 static inline int syscall_get_arch(struct task_struct *task,
224 struct pt_regs *regs)
226 #ifdef CONFIG_IA32_EMULATION
228 * TS_COMPAT is set for 32-bit syscall entry and then
229 * remains set until we return to user mode.
231 * TIF_IA32 tasks should always have TS_COMPAT set at
234 * x32 tasks should be considered AUDIT_ARCH_X86_64.
236 if (task_thread_info(task)->status & TS_COMPAT)
237 return AUDIT_ARCH_I386;
239 /* Both x32 and x86_64 are considered "64-bit". */
240 return AUDIT_ARCH_X86_64;
242 #endif /* CONFIG_X86_32 */
244 #endif /* _ASM_X86_SYSCALL_H */