12522fe45SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2bb898558SAl Viro /*
3bb898558SAl Viro * Access to user system call parameters and results
4bb898558SAl Viro *
518c1e2c8SRoland McGrath * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
6bb898558SAl Viro *
7bb898558SAl Viro * See asm-generic/syscall.h for descriptions of what we must do here.
8bb898558SAl Viro */
9bb898558SAl Viro
105e1b0075SH. Peter Anvin #ifndef _ASM_X86_SYSCALL_H
115e1b0075SH. Peter Anvin #define _ASM_X86_SYSCALL_H
12bb898558SAl Viro
13579ec9e1SEric Paris #include <uapi/linux/audit.h>
14bb898558SAl Viro #include <linux/sched.h>
15bb898558SAl Viro #include <linux/err.h>
16b7456536SWill Drewry #include <asm/thread_info.h> /* for TS_COMPAT */
17fca460f9SH. Peter Anvin #include <asm/unistd.h>
18bb898558SAl Viro
19eb0f175bSLinus Torvalds /* This is used purely for kernel/trace/trace_syscalls.c */
200f78ff17SBrian Gerst typedef long (*sys_call_ptr_t)(const struct pt_regs *);
211599e8fcSAndi Kleen extern const sys_call_ptr_t sys_call_table[];
22e7b8e675SMike Frysinger
23dce0aa3bSH. Peter Anvin (Intel) /*
24dce0aa3bSH. Peter Anvin (Intel) * These may not exist, but still put the prototypes in so we
25dce0aa3bSH. Peter Anvin (Intel) * can use IS_ENABLED().
26dce0aa3bSH. Peter Anvin (Intel) */
27eb0f175bSLinus Torvalds extern long ia32_sys_call(const struct pt_regs *, unsigned int nr);
28eb0f175bSLinus Torvalds extern long x32_sys_call(const struct pt_regs *, unsigned int nr);
29eb0f175bSLinus Torvalds extern long x64_sys_call(const struct pt_regs *, unsigned int nr);
306365b842SAndy Lutomirski
31bb898558SAl Viro /*
3218c1e2c8SRoland McGrath * Only the low 32 bits of orig_ax are meaningful, so we return int.
3318c1e2c8SRoland McGrath * This importantly ignores the high bits on 64-bit, so comparisons
3418c1e2c8SRoland McGrath * sign-extend the low 32 bits.
35bb898558SAl Viro */
syscall_get_nr(struct task_struct * task,struct pt_regs * regs)3618c1e2c8SRoland McGrath static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
3718c1e2c8SRoland McGrath {
388b4b9f27SPaul Moore return regs->orig_ax;
39bb898558SAl Viro }
40bb898558SAl Viro
syscall_rollback(struct task_struct * task,struct pt_regs * regs)41bb898558SAl Viro static inline void syscall_rollback(struct task_struct *task,
42bb898558SAl Viro struct pt_regs *regs)
43bb898558SAl Viro {
448b4b9f27SPaul Moore regs->ax = regs->orig_ax;
45bb898558SAl Viro }
46bb898558SAl Viro
syscall_get_error(struct task_struct * task,struct pt_regs * regs)47bb898558SAl Viro static inline long syscall_get_error(struct task_struct *task,
48bb898558SAl Viro struct pt_regs *regs)
49bb898558SAl Viro {
50bb898558SAl Viro unsigned long error = regs->ax;
51bb898558SAl Viro #ifdef CONFIG_IA32_EMULATION
52bb898558SAl Viro /*
53bb898558SAl Viro * TS_COMPAT is set for 32-bit syscall entries and then
54bb898558SAl Viro * remains set until we return to user mode.
55bb898558SAl Viro */
5637a8f7c3SAndy Lutomirski if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
57bb898558SAl Viro /*
58bb898558SAl Viro * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
59bb898558SAl Viro * and will match correctly in comparisons.
60bb898558SAl Viro */
61bb898558SAl Viro error = (long) (int) error;
62bb898558SAl Viro #endif
63bb898558SAl Viro return IS_ERR_VALUE(error) ? error : 0;
64bb898558SAl Viro }
65bb898558SAl Viro
syscall_get_return_value(struct task_struct * task,struct pt_regs * regs)66bb898558SAl Viro static inline long syscall_get_return_value(struct task_struct *task,
67bb898558SAl Viro struct pt_regs *regs)
68bb898558SAl Viro {
69bb898558SAl Viro return regs->ax;
70bb898558SAl Viro }
71bb898558SAl Viro
syscall_set_return_value(struct task_struct * task,struct pt_regs * regs,int error,long val)72bb898558SAl Viro static inline void syscall_set_return_value(struct task_struct *task,
73bb898558SAl Viro struct pt_regs *regs,
74bb898558SAl Viro int error, long val)
75bb898558SAl Viro {
76bb898558SAl Viro regs->ax = (long) error ?: val;
77bb898558SAl Viro }
78bb898558SAl Viro
79bb898558SAl Viro #ifdef CONFIG_X86_32
80bb898558SAl Viro
syscall_get_arguments(struct task_struct * task,struct pt_regs * regs,unsigned long * args)81bb898558SAl Viro static inline void syscall_get_arguments(struct task_struct *task,
82bb898558SAl Viro struct pt_regs *regs,
83bb898558SAl Viro unsigned long *args)
84bb898558SAl Viro {
85*2de5fd83SKees Cook args[0] = regs->bx;
86*2de5fd83SKees Cook args[1] = regs->cx;
87*2de5fd83SKees Cook args[2] = regs->dx;
88*2de5fd83SKees Cook args[3] = regs->si;
89*2de5fd83SKees Cook args[4] = regs->di;
90*2de5fd83SKees Cook args[5] = regs->bp;
91bb898558SAl Viro }
92bb898558SAl Viro
syscall_get_arch(struct task_struct * task)9316add411SDmitry V. Levin static inline int syscall_get_arch(struct task_struct *task)
94b7456536SWill Drewry {
95b7456536SWill Drewry return AUDIT_ARCH_I386;
96b7456536SWill Drewry }
97b7456536SWill Drewry
98bb898558SAl Viro #else /* CONFIG_X86_64 */
99bb898558SAl Viro
syscall_get_arguments(struct task_struct * task,struct pt_regs * regs,unsigned long * args)100bb898558SAl Viro static inline void syscall_get_arguments(struct task_struct *task,
101bb898558SAl Viro struct pt_regs *regs,
102bb898558SAl Viro unsigned long *args)
103bb898558SAl Viro {
104bb898558SAl Viro # ifdef CONFIG_IA32_EMULATION
105b35f549dSSteven Rostedt (Red Hat) if (task->thread_info.status & TS_COMPAT) {
106bb898558SAl Viro *args++ = regs->bx;
107c3c9897cSLinus Torvalds *args++ = regs->cx;
108c3c9897cSLinus Torvalds *args++ = regs->dx;
109c3c9897cSLinus Torvalds *args++ = regs->si;
110c3c9897cSLinus Torvalds *args++ = regs->di;
111b35f549dSSteven Rostedt (Red Hat) *args = regs->bp;
112b35f549dSSteven Rostedt (Red Hat) } else
113bb898558SAl Viro # endif
114b35f549dSSteven Rostedt (Red Hat) {
115bb898558SAl Viro *args++ = regs->di;
116c3c9897cSLinus Torvalds *args++ = regs->si;
117c3c9897cSLinus Torvalds *args++ = regs->dx;
118c3c9897cSLinus Torvalds *args++ = regs->r10;
119c3c9897cSLinus Torvalds *args++ = regs->r8;
120b35f549dSSteven Rostedt (Red Hat) *args = regs->r9;
121bb898558SAl Viro }
122bb898558SAl Viro }
123bb898558SAl Viro
syscall_get_arch(struct task_struct * task)12416add411SDmitry V. Levin static inline int syscall_get_arch(struct task_struct *task)
125b7456536SWill Drewry {
126b9d989c7SAndy Lutomirski /* x32 tasks should be considered AUDIT_ARCH_X86_64. */
12716add411SDmitry V. Levin return (IS_ENABLED(CONFIG_IA32_EMULATION) &&
12816add411SDmitry V. Levin task->thread_info.status & TS_COMPAT)
12916add411SDmitry V. Levin ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
130b7456536SWill Drewry }
13199ce3255SBenjamin Thiel
1322978996fSH. Peter Anvin (Intel) void do_syscall_64(struct pt_regs *regs, int nr);
133eb36b0dcSPawan Gupta void do_int80_emulation(struct pt_regs *regs);
13499ce3255SBenjamin Thiel
135bb898558SAl Viro #endif /* CONFIG_X86_32 */
136bb898558SAl Viro
137f34f0d3cSArnd Bergmann void do_int80_syscall_32(struct pt_regs *regs);
138f34f0d3cSArnd Bergmann long do_fast_syscall_32(struct pt_regs *regs);
139f34f0d3cSArnd Bergmann long do_SYSENTER_32(struct pt_regs *regs);
140f34f0d3cSArnd Bergmann
1415e1b0075SH. Peter Anvin #endif /* _ASM_X86_SYSCALL_H */
142