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>
23 typedef asmlinkage long (*sys_call_ptr_t)(unsigned long, unsigned long,
24 unsigned long, unsigned long,
25 unsigned long, unsigned long);
26 extern const sys_call_ptr_t sys_call_table[];
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
34 #if defined(CONFIG_IA32_EMULATION)
35 extern const sys_call_ptr_t ia32_sys_call_table[];
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.
43 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
48 static inline void syscall_rollback(struct task_struct *task,
51 regs->ax = regs->orig_ax;
54 static inline long syscall_get_error(struct task_struct *task,
57 unsigned long error = regs->ax;
58 #ifdef CONFIG_IA32_EMULATION
60 * TS_COMPAT is set for 32-bit syscall entries and then
61 * remains set until we return to user mode.
63 if (task->thread.status & (TS_COMPAT|TS_I386_REGS_POKED))
65 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
66 * and will match correctly in comparisons.
68 error = (long) (int) error;
70 return IS_ERR_VALUE(error) ? error : 0;
73 static inline long syscall_get_return_value(struct task_struct *task,
79 static inline void syscall_set_return_value(struct task_struct *task,
83 regs->ax = (long) error ?: val;
88 static inline void syscall_get_arguments(struct task_struct *task,
90 unsigned int i, unsigned int n,
94 memcpy(args, ®s->bx + i, n * sizeof(args[0]));
97 static inline void syscall_set_arguments(struct task_struct *task,
99 unsigned int i, unsigned int n,
100 const unsigned long *args)
103 memcpy(®s->bx + i, args, n * sizeof(args[0]));
106 static inline int syscall_get_arch(void)
108 return AUDIT_ARCH_I386;
111 #else /* CONFIG_X86_64 */
113 static inline void syscall_get_arguments(struct task_struct *task,
114 struct pt_regs *regs,
115 unsigned int i, unsigned int n,
118 # ifdef CONFIG_IA32_EMULATION
119 if (task->thread.status & TS_COMPAT)
174 static 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)
179 # ifdef CONFIG_IA32_EMULATION
180 if (task->thread.status & TS_COMPAT)
235 static inline int syscall_get_arch(void)
237 /* x32 tasks should be considered AUDIT_ARCH_X86_64. */
238 return in_ia32_syscall() ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
240 #endif /* CONFIG_X86_32 */
242 #endif /* _ASM_X86_SYSCALL_H */