xref: /openbmc/linux/arch/x86/include/asm/syscall.h (revision f34f0d3c10eb4d3160fc6fe7a2482cb78d3b0c12)
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 
190f78ff17SBrian Gerst typedef long (*sys_call_ptr_t)(const struct pt_regs *);
201599e8fcSAndi Kleen extern const sys_call_ptr_t sys_call_table[];
21e7b8e675SMike Frysinger 
22034042ccSAndy Lutomirski #if defined(CONFIG_X86_32)
23034042ccSAndy Lutomirski #define ia32_sys_call_table sys_call_table
24dce0aa3bSH. Peter Anvin (Intel) #else
25dce0aa3bSH. Peter Anvin (Intel) /*
26dce0aa3bSH. Peter Anvin (Intel)  * These may not exist, but still put the prototypes in so we
27dce0aa3bSH. Peter Anvin (Intel)  * can use IS_ENABLED().
28dce0aa3bSH. Peter Anvin (Intel)  */
29034042ccSAndy Lutomirski extern const sys_call_ptr_t ia32_sys_call_table[];
306365b842SAndy Lutomirski extern const sys_call_ptr_t x32_sys_call_table[];
316365b842SAndy Lutomirski #endif
326365b842SAndy Lutomirski 
33bb898558SAl Viro /*
3418c1e2c8SRoland McGrath  * Only the low 32 bits of orig_ax are meaningful, so we return int.
3518c1e2c8SRoland McGrath  * This importantly ignores the high bits on 64-bit, so comparisons
3618c1e2c8SRoland McGrath  * sign-extend the low 32 bits.
37bb898558SAl Viro  */
3818c1e2c8SRoland McGrath static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
3918c1e2c8SRoland McGrath {
408b4b9f27SPaul Moore 	return regs->orig_ax;
41bb898558SAl Viro }
42bb898558SAl Viro 
43bb898558SAl Viro static inline void syscall_rollback(struct task_struct *task,
44bb898558SAl Viro 				    struct pt_regs *regs)
45bb898558SAl Viro {
468b4b9f27SPaul Moore 	regs->ax = regs->orig_ax;
47bb898558SAl Viro }
48bb898558SAl Viro 
49bb898558SAl Viro static inline long syscall_get_error(struct task_struct *task,
50bb898558SAl Viro 				     struct pt_regs *regs)
51bb898558SAl Viro {
52bb898558SAl Viro 	unsigned long error = regs->ax;
53bb898558SAl Viro #ifdef CONFIG_IA32_EMULATION
54bb898558SAl Viro 	/*
55bb898558SAl Viro 	 * TS_COMPAT is set for 32-bit syscall entries and then
56bb898558SAl Viro 	 * remains set until we return to user mode.
57bb898558SAl Viro 	 */
5837a8f7c3SAndy Lutomirski 	if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
59bb898558SAl Viro 		/*
60bb898558SAl Viro 		 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
61bb898558SAl Viro 		 * and will match correctly in comparisons.
62bb898558SAl Viro 		 */
63bb898558SAl Viro 		error = (long) (int) error;
64bb898558SAl Viro #endif
65bb898558SAl Viro 	return IS_ERR_VALUE(error) ? error : 0;
66bb898558SAl Viro }
67bb898558SAl Viro 
68bb898558SAl Viro static inline long syscall_get_return_value(struct task_struct *task,
69bb898558SAl Viro 					    struct pt_regs *regs)
70bb898558SAl Viro {
71bb898558SAl Viro 	return regs->ax;
72bb898558SAl Viro }
73bb898558SAl Viro 
74bb898558SAl Viro static inline void syscall_set_return_value(struct task_struct *task,
75bb898558SAl Viro 					    struct pt_regs *regs,
76bb898558SAl Viro 					    int error, long val)
77bb898558SAl Viro {
78bb898558SAl Viro 	regs->ax = (long) error ?: val;
79bb898558SAl Viro }
80bb898558SAl Viro 
81bb898558SAl Viro #ifdef CONFIG_X86_32
82bb898558SAl Viro 
83bb898558SAl Viro static inline void syscall_get_arguments(struct task_struct *task,
84bb898558SAl Viro 					 struct pt_regs *regs,
85bb898558SAl Viro 					 unsigned long *args)
86bb898558SAl Viro {
87b35f549dSSteven Rostedt (Red Hat) 	memcpy(args, &regs->bx, 6 * sizeof(args[0]));
88bb898558SAl Viro }
89bb898558SAl Viro 
9016add411SDmitry V. Levin static inline int syscall_get_arch(struct task_struct *task)
91b7456536SWill Drewry {
92b7456536SWill Drewry 	return AUDIT_ARCH_I386;
93b7456536SWill Drewry }
94b7456536SWill Drewry 
95bb898558SAl Viro #else	 /* CONFIG_X86_64 */
96bb898558SAl Viro 
97bb898558SAl Viro static inline void syscall_get_arguments(struct task_struct *task,
98bb898558SAl Viro 					 struct pt_regs *regs,
99bb898558SAl Viro 					 unsigned long *args)
100bb898558SAl Viro {
101bb898558SAl Viro # ifdef CONFIG_IA32_EMULATION
102b35f549dSSteven Rostedt (Red Hat) 	if (task->thread_info.status & TS_COMPAT) {
103bb898558SAl Viro 		*args++ = regs->bx;
104c3c9897cSLinus Torvalds 		*args++ = regs->cx;
105c3c9897cSLinus Torvalds 		*args++ = regs->dx;
106c3c9897cSLinus Torvalds 		*args++ = regs->si;
107c3c9897cSLinus Torvalds 		*args++ = regs->di;
108b35f549dSSteven Rostedt (Red Hat) 		*args   = regs->bp;
109b35f549dSSteven Rostedt (Red Hat) 	} else
110bb898558SAl Viro # endif
111b35f549dSSteven Rostedt (Red Hat) 	{
112bb898558SAl Viro 		*args++ = regs->di;
113c3c9897cSLinus Torvalds 		*args++ = regs->si;
114c3c9897cSLinus Torvalds 		*args++ = regs->dx;
115c3c9897cSLinus Torvalds 		*args++ = regs->r10;
116c3c9897cSLinus Torvalds 		*args++ = regs->r8;
117b35f549dSSteven Rostedt (Red Hat) 		*args   = regs->r9;
118bb898558SAl Viro 	}
119bb898558SAl Viro }
120bb898558SAl Viro 
12116add411SDmitry V. Levin static inline int syscall_get_arch(struct task_struct *task)
122b7456536SWill Drewry {
123b9d989c7SAndy Lutomirski 	/* x32 tasks should be considered AUDIT_ARCH_X86_64. */
12416add411SDmitry V. Levin 	return (IS_ENABLED(CONFIG_IA32_EMULATION) &&
12516add411SDmitry V. Levin 		task->thread_info.status & TS_COMPAT)
12616add411SDmitry V. Levin 		? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
127b7456536SWill Drewry }
12899ce3255SBenjamin Thiel 
1292978996fSH. Peter Anvin (Intel) void do_syscall_64(struct pt_regs *regs, int nr);
13099ce3255SBenjamin Thiel 
131bb898558SAl Viro #endif	/* CONFIG_X86_32 */
132bb898558SAl Viro 
133*f34f0d3cSArnd Bergmann void do_int80_syscall_32(struct pt_regs *regs);
134*f34f0d3cSArnd Bergmann long do_fast_syscall_32(struct pt_regs *regs);
135*f34f0d3cSArnd Bergmann long do_SYSENTER_32(struct pt_regs *regs);
136*f34f0d3cSArnd Bergmann 
1375e1b0075SH. Peter Anvin #endif	/* _ASM_X86_SYSCALL_H */
138