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/thread_info.h> /* for TS_COMPAT */
17 #include <asm/unistd.h>
19 /* This is used purely for kernel/trace/trace_syscalls.c */
20 typedef long (*sys_call_ptr_t)(const struct pt_regs *);
21 extern const sys_call_ptr_t sys_call_table[];
24 * These may not exist, but still put the prototypes in so we
25 * can use IS_ENABLED().
27 extern long ia32_sys_call(const struct pt_regs *, unsigned int nr);
28 extern long x32_sys_call(const struct pt_regs *, unsigned int nr);
29 extern long x64_sys_call(const struct pt_regs *, unsigned int nr);
32 * Only the low 32 bits of orig_ax are meaningful, so we return int.
33 * This importantly ignores the high bits on 64-bit, so comparisons
34 * sign-extend the low 32 bits.
36 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
41 static inline void syscall_rollback(struct task_struct *task,
44 regs->ax = regs->orig_ax;
47 static inline long syscall_get_error(struct task_struct *task,
50 unsigned long error = regs->ax;
51 #ifdef CONFIG_IA32_EMULATION
53 * TS_COMPAT is set for 32-bit syscall entries and then
54 * remains set until we return to user mode.
56 if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
58 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
59 * and will match correctly in comparisons.
61 error = (long) (int) error;
63 return IS_ERR_VALUE(error) ? error : 0;
66 static inline long syscall_get_return_value(struct task_struct *task,
72 static inline void syscall_set_return_value(struct task_struct *task,
76 regs->ax = (long) error ?: val;
81 static inline void syscall_get_arguments(struct task_struct *task,
85 memcpy(args, ®s->bx, 6 * sizeof(args[0]));
88 static inline int syscall_get_arch(struct task_struct *task)
90 return AUDIT_ARCH_I386;
93 #else /* CONFIG_X86_64 */
95 static inline void syscall_get_arguments(struct task_struct *task,
99 # ifdef CONFIG_IA32_EMULATION
100 if (task->thread_info.status & TS_COMPAT) {
119 static inline int syscall_get_arch(struct task_struct *task)
121 /* x32 tasks should be considered AUDIT_ARCH_X86_64. */
122 return (IS_ENABLED(CONFIG_IA32_EMULATION) &&
123 task->thread_info.status & TS_COMPAT)
124 ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
127 void do_syscall_64(struct pt_regs *regs, int nr);
128 void do_int80_syscall_32(struct pt_regs *regs);
129 long do_fast_syscall_32(struct pt_regs *regs);
130 void do_int80_emulation(struct pt_regs *regs);
132 #endif /* CONFIG_X86_32 */
134 #endif /* _ASM_X86_SYSCALL_H */