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 <uapi/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>
24 typedef asmlinkage long (*sys_call_ptr_t)(const struct pt_regs *);
26 typedef asmlinkage long (*sys_call_ptr_t)(unsigned long, unsigned long,
27 unsigned long, unsigned long,
28 unsigned long, unsigned long);
29 #endif /* CONFIG_X86_64 */
30 extern const sys_call_ptr_t sys_call_table[];
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
38 #if defined(CONFIG_IA32_EMULATION)
39 extern const sys_call_ptr_t ia32_sys_call_table[];
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.
47 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
52 static inline void syscall_rollback(struct task_struct *task,
55 regs->ax = regs->orig_ax;
58 static inline long syscall_get_error(struct task_struct *task,
61 unsigned long error = regs->ax;
62 #ifdef CONFIG_IA32_EMULATION
64 * TS_COMPAT is set for 32-bit syscall entries and then
65 * remains set until we return to user mode.
67 if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
69 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
70 * and will match correctly in comparisons.
72 error = (long) (int) error;
74 return IS_ERR_VALUE(error) ? error : 0;
77 static inline long syscall_get_return_value(struct task_struct *task,
83 static inline void syscall_set_return_value(struct task_struct *task,
87 regs->ax = (long) error ?: val;
92 static inline void syscall_get_arguments(struct task_struct *task,
94 unsigned int i, unsigned int n,
98 memcpy(args, ®s->bx + i, n * sizeof(args[0]));
101 static inline void syscall_set_arguments(struct task_struct *task,
102 struct pt_regs *regs,
103 unsigned int i, unsigned int n,
104 const unsigned long *args)
107 memcpy(®s->bx + i, args, n * sizeof(args[0]));
110 static inline int syscall_get_arch(void)
112 return AUDIT_ARCH_I386;
115 #else /* CONFIG_X86_64 */
117 static inline void syscall_get_arguments(struct task_struct *task,
118 struct pt_regs *regs,
119 unsigned int i, unsigned int n,
122 # ifdef CONFIG_IA32_EMULATION
123 if (task->thread_info.status & TS_COMPAT)
178 static inline void syscall_set_arguments(struct task_struct *task,
179 struct pt_regs *regs,
180 unsigned int i, unsigned int n,
181 const unsigned long *args)
183 # ifdef CONFIG_IA32_EMULATION
184 if (task->thread_info.status & TS_COMPAT)
239 static inline int syscall_get_arch(void)
241 /* x32 tasks should be considered AUDIT_ARCH_X86_64. */
242 return in_ia32_syscall() ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
244 #endif /* CONFIG_X86_32 */
246 #endif /* _ASM_X86_SYSCALL_H */