1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Access to user system call parameters and results
5 * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
7 * See asm-generic/syscall.h for descriptions of what we must do here.
10 #ifndef _ASM_X86_SYSCALL_H
11 #define _ASM_X86_SYSCALL_H
13 #include <uapi/linux/audit.h>
14 #include <linux/sched.h>
15 #include <linux/err.h>
16 #include <asm/asm-offsets.h> /* For NR_syscalls */
17 #include <asm/thread_info.h> /* for TS_COMPAT */
18 #include <asm/unistd.h>
21 typedef asmlinkage long (*sys_call_ptr_t)(const struct pt_regs *);
23 typedef asmlinkage long (*sys_call_ptr_t)(unsigned long, unsigned long,
24 unsigned long, unsigned long,
25 unsigned long, unsigned long);
26 #endif /* CONFIG_X86_64 */
27 extern const sys_call_ptr_t sys_call_table[];
29 #if defined(CONFIG_X86_32)
30 #define ia32_sys_call_table sys_call_table
31 #define __NR_syscall_compat_max __NR_syscall_max
32 #define IA32_NR_syscalls NR_syscalls
35 #if defined(CONFIG_IA32_EMULATION)
36 extern const sys_call_ptr_t ia32_sys_call_table[];
40 * Only the low 32 bits of orig_ax are meaningful, so we return int.
41 * This importantly ignores the high bits on 64-bit, so comparisons
42 * sign-extend the low 32 bits.
44 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
49 static inline void syscall_rollback(struct task_struct *task,
52 regs->ax = regs->orig_ax;
55 static inline long syscall_get_error(struct task_struct *task,
58 unsigned long error = regs->ax;
59 #ifdef CONFIG_IA32_EMULATION
61 * TS_COMPAT is set for 32-bit syscall entries and then
62 * remains set until we return to user mode.
64 if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
66 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
67 * and will match correctly in comparisons.
69 error = (long) (int) error;
71 return IS_ERR_VALUE(error) ? error : 0;
74 static inline long syscall_get_return_value(struct task_struct *task,
80 static inline void syscall_set_return_value(struct task_struct *task,
84 regs->ax = (long) error ?: val;
89 static inline void syscall_get_arguments(struct task_struct *task,
93 memcpy(args, ®s->bx, 6 * sizeof(args[0]));
96 static inline void syscall_set_arguments(struct task_struct *task,
98 unsigned int i, unsigned int n,
99 const unsigned long *args)
102 memcpy(®s->bx + i, args, n * sizeof(args[0]));
105 static inline int syscall_get_arch(struct task_struct *task)
107 return AUDIT_ARCH_I386;
110 #else /* CONFIG_X86_64 */
112 static inline void syscall_get_arguments(struct task_struct *task,
113 struct pt_regs *regs,
116 # ifdef CONFIG_IA32_EMULATION
117 if (task->thread_info.status & TS_COMPAT) {
136 static inline void syscall_set_arguments(struct task_struct *task,
137 struct pt_regs *regs,
138 const unsigned long *args)
140 # ifdef CONFIG_IA32_EMULATION
141 if (task->thread_info.status & TS_COMPAT) {
160 static inline int syscall_get_arch(struct task_struct *task)
162 /* x32 tasks should be considered AUDIT_ARCH_X86_64. */
163 return (IS_ENABLED(CONFIG_IA32_EMULATION) &&
164 task->thread_info.status & TS_COMPAT)
165 ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
167 #endif /* CONFIG_X86_32 */
169 #endif /* _ASM_X86_SYSCALL_H */