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 24*dce0aa3bSH. Peter Anvin (Intel) #else 25*dce0aa3bSH. Peter Anvin (Intel) /* 26*dce0aa3bSH. Peter Anvin (Intel) * These may not exist, but still put the prototypes in so we 27*dce0aa3bSH. Peter Anvin (Intel) * can use IS_ENABLED(). 28*dce0aa3bSH. 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, ®s->bx, 6 * sizeof(args[0])); 88bb898558SAl Viro } 89bb898558SAl Viro 90bb898558SAl Viro static inline void syscall_set_arguments(struct task_struct *task, 91bb898558SAl Viro struct pt_regs *regs, 92bb898558SAl Viro unsigned int i, unsigned int n, 93bb898558SAl Viro const unsigned long *args) 94bb898558SAl Viro { 95bb898558SAl Viro BUG_ON(i + n > 6); 96bb898558SAl Viro memcpy(®s->bx + i, args, n * sizeof(args[0])); 97bb898558SAl Viro } 98bb898558SAl Viro 9916add411SDmitry V. Levin static inline int syscall_get_arch(struct task_struct *task) 100b7456536SWill Drewry { 101b7456536SWill Drewry return AUDIT_ARCH_I386; 102b7456536SWill Drewry } 103b7456536SWill Drewry 104bb898558SAl Viro #else /* CONFIG_X86_64 */ 105bb898558SAl Viro 106bb898558SAl Viro static inline void syscall_get_arguments(struct task_struct *task, 107bb898558SAl Viro struct pt_regs *regs, 108bb898558SAl Viro unsigned long *args) 109bb898558SAl Viro { 110bb898558SAl Viro # ifdef CONFIG_IA32_EMULATION 111b35f549dSSteven Rostedt (Red Hat) if (task->thread_info.status & TS_COMPAT) { 112bb898558SAl Viro *args++ = regs->bx; 113c3c9897cSLinus Torvalds *args++ = regs->cx; 114c3c9897cSLinus Torvalds *args++ = regs->dx; 115c3c9897cSLinus Torvalds *args++ = regs->si; 116c3c9897cSLinus Torvalds *args++ = regs->di; 117b35f549dSSteven Rostedt (Red Hat) *args = regs->bp; 118b35f549dSSteven Rostedt (Red Hat) } else 119bb898558SAl Viro # endif 120b35f549dSSteven Rostedt (Red Hat) { 121bb898558SAl Viro *args++ = regs->di; 122c3c9897cSLinus Torvalds *args++ = regs->si; 123c3c9897cSLinus Torvalds *args++ = regs->dx; 124c3c9897cSLinus Torvalds *args++ = regs->r10; 125c3c9897cSLinus Torvalds *args++ = regs->r8; 126b35f549dSSteven Rostedt (Red Hat) *args = regs->r9; 127bb898558SAl Viro } 128bb898558SAl Viro } 129bb898558SAl Viro 130bb898558SAl Viro static inline void syscall_set_arguments(struct task_struct *task, 131bb898558SAl Viro struct pt_regs *regs, 132bb898558SAl Viro const unsigned long *args) 133bb898558SAl Viro { 134bb898558SAl Viro # ifdef CONFIG_IA32_EMULATION 13532d92586SSteven Rostedt (VMware) if (task->thread_info.status & TS_COMPAT) { 136bb898558SAl Viro regs->bx = *args++; 137c3c9897cSLinus Torvalds regs->cx = *args++; 138c3c9897cSLinus Torvalds regs->dx = *args++; 139c3c9897cSLinus Torvalds regs->si = *args++; 140c3c9897cSLinus Torvalds regs->di = *args++; 14132d92586SSteven Rostedt (VMware) regs->bp = *args; 14232d92586SSteven Rostedt (VMware) } else 143bb898558SAl Viro # endif 14432d92586SSteven Rostedt (VMware) { 145bb898558SAl Viro regs->di = *args++; 146c3c9897cSLinus Torvalds regs->si = *args++; 147c3c9897cSLinus Torvalds regs->dx = *args++; 148c3c9897cSLinus Torvalds regs->r10 = *args++; 149c3c9897cSLinus Torvalds regs->r8 = *args++; 15032d92586SSteven Rostedt (VMware) regs->r9 = *args; 151bb898558SAl Viro } 152bb898558SAl Viro } 153bb898558SAl Viro 15416add411SDmitry V. Levin static inline int syscall_get_arch(struct task_struct *task) 155b7456536SWill Drewry { 156b9d989c7SAndy Lutomirski /* x32 tasks should be considered AUDIT_ARCH_X86_64. */ 15716add411SDmitry V. Levin return (IS_ENABLED(CONFIG_IA32_EMULATION) && 15816add411SDmitry V. Levin task->thread_info.status & TS_COMPAT) 15916add411SDmitry V. Levin ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64; 160b7456536SWill Drewry } 16199ce3255SBenjamin Thiel 1623e5e7f77SH. Peter Anvin (Intel) void do_syscall_64(struct pt_regs *regs, unsigned long nr); 16399ce3255SBenjamin Thiel void do_int80_syscall_32(struct pt_regs *regs); 16499ce3255SBenjamin Thiel long do_fast_syscall_32(struct pt_regs *regs); 16599ce3255SBenjamin Thiel 166bb898558SAl Viro #endif /* CONFIG_X86_32 */ 167bb898558SAl Viro 1685e1b0075SH. Peter Anvin #endif /* _ASM_X86_SYSCALL_H */ 169