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,
96 memcpy(args, ®s->bx, 6 * sizeof(args[0]));
99 static 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)
105 memcpy(®s->bx + i, args, n * sizeof(args[0]));
108 static inline int syscall_get_arch(void)
110 return AUDIT_ARCH_I386;
113 #else /* CONFIG_X86_64 */
115 static inline void syscall_get_arguments(struct task_struct *task,
116 struct pt_regs *regs,
119 # ifdef CONFIG_IA32_EMULATION
120 if (task->thread_info.status & TS_COMPAT) {
139 static inline void syscall_set_arguments(struct task_struct *task,
140 struct pt_regs *regs,
141 const unsigned long *args)
143 # ifdef CONFIG_IA32_EMULATION
144 if (task->thread_info.status & TS_COMPAT) {
163 static inline int syscall_get_arch(void)
165 /* x32 tasks should be considered AUDIT_ARCH_X86_64. */
166 return in_ia32_syscall() ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
168 #endif /* CONFIG_X86_32 */
170 #endif /* _ASM_X86_SYSCALL_H */