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 typedef long (*sys_call_ptr_t
)(const struct pt_regs
*);
20 extern const sys_call_ptr_t sys_call_table
[];
22 #if defined(CONFIG_X86_32)
23 #define ia32_sys_call_table sys_call_table
26 #if defined(CONFIG_IA32_EMULATION)
27 extern const sys_call_ptr_t ia32_sys_call_table
[];
30 #ifdef CONFIG_X86_X32_ABI
31 extern const sys_call_ptr_t x32_sys_call_table
[];
35 * Only the low 32 bits of orig_ax are meaningful, so we return int.
36 * This importantly ignores the high bits on 64-bit, so comparisons
37 * sign-extend the low 32 bits.
39 static inline int syscall_get_nr(struct task_struct
*task
, struct pt_regs
*regs
)
44 static inline void syscall_rollback(struct task_struct
*task
,
47 regs
->ax
= regs
->orig_ax
;
50 static inline long syscall_get_error(struct task_struct
*task
,
53 unsigned long error
= regs
->ax
;
54 #ifdef CONFIG_IA32_EMULATION
56 * TS_COMPAT is set for 32-bit syscall entries and then
57 * remains set until we return to user mode.
59 if (task
->thread_info
.status
& (TS_COMPAT
|TS_I386_REGS_POKED
))
61 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
62 * and will match correctly in comparisons.
64 error
= (long) (int) error
;
66 return IS_ERR_VALUE(error
) ? error
: 0;
69 static inline long syscall_get_return_value(struct task_struct
*task
,
75 static inline void syscall_set_return_value(struct task_struct
*task
,
79 regs
->ax
= (long) error
?: val
;
84 static inline void syscall_get_arguments(struct task_struct
*task
,
88 memcpy(args
, ®s
->bx
, 6 * sizeof(args
[0]));
91 static inline void syscall_set_arguments(struct task_struct
*task
,
93 unsigned int i
, unsigned int n
,
94 const unsigned long *args
)
97 memcpy(®s
->bx
+ i
, args
, n
* sizeof(args
[0]));
100 static inline int syscall_get_arch(struct task_struct
*task
)
102 return AUDIT_ARCH_I386
;
105 #else /* CONFIG_X86_64 */
107 static inline void syscall_get_arguments(struct task_struct
*task
,
108 struct pt_regs
*regs
,
111 # ifdef CONFIG_IA32_EMULATION
112 if (task
->thread_info
.status
& TS_COMPAT
) {
131 static inline void syscall_set_arguments(struct task_struct
*task
,
132 struct pt_regs
*regs
,
133 const unsigned long *args
)
135 # ifdef CONFIG_IA32_EMULATION
136 if (task
->thread_info
.status
& TS_COMPAT
) {
155 static inline int syscall_get_arch(struct task_struct
*task
)
157 /* x32 tasks should be considered AUDIT_ARCH_X86_64. */
158 return (IS_ENABLED(CONFIG_IA32_EMULATION
) &&
159 task
->thread_info
.status
& TS_COMPAT
)
160 ? AUDIT_ARCH_I386
: AUDIT_ARCH_X86_64
;
163 void do_syscall_64(unsigned long nr
, struct pt_regs
*regs
);
164 void do_int80_syscall_32(struct pt_regs
*regs
);
165 long do_fast_syscall_32(struct pt_regs
*regs
);
167 #endif /* CONFIG_X86_32 */
169 #endif /* _ASM_X86_SYSCALL_H */