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 19*0f78ff17SBrian 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 24034042ccSAndy Lutomirski #endif 25034042ccSAndy Lutomirski 26034042ccSAndy Lutomirski #if defined(CONFIG_IA32_EMULATION) 27034042ccSAndy Lutomirski extern const sys_call_ptr_t ia32_sys_call_table[]; 28034042ccSAndy Lutomirski #endif 29034042ccSAndy Lutomirski 306365b842SAndy Lutomirski #ifdef CONFIG_X86_X32_ABI 316365b842SAndy Lutomirski extern const sys_call_ptr_t x32_sys_call_table[]; 326365b842SAndy Lutomirski #endif 336365b842SAndy Lutomirski 34bb898558SAl Viro /* 3518c1e2c8SRoland McGrath * Only the low 32 bits of orig_ax are meaningful, so we return int. 3618c1e2c8SRoland McGrath * This importantly ignores the high bits on 64-bit, so comparisons 3718c1e2c8SRoland McGrath * sign-extend the low 32 bits. 38bb898558SAl Viro */ 3918c1e2c8SRoland McGrath static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) 4018c1e2c8SRoland McGrath { 418b4b9f27SPaul Moore return regs->orig_ax; 42bb898558SAl Viro } 43bb898558SAl Viro 44bb898558SAl Viro static inline void syscall_rollback(struct task_struct *task, 45bb898558SAl Viro struct pt_regs *regs) 46bb898558SAl Viro { 478b4b9f27SPaul Moore regs->ax = regs->orig_ax; 48bb898558SAl Viro } 49bb898558SAl Viro 50bb898558SAl Viro static inline long syscall_get_error(struct task_struct *task, 51bb898558SAl Viro struct pt_regs *regs) 52bb898558SAl Viro { 53bb898558SAl Viro unsigned long error = regs->ax; 54bb898558SAl Viro #ifdef CONFIG_IA32_EMULATION 55bb898558SAl Viro /* 56bb898558SAl Viro * TS_COMPAT is set for 32-bit syscall entries and then 57bb898558SAl Viro * remains set until we return to user mode. 58bb898558SAl Viro */ 5937a8f7c3SAndy Lutomirski if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED)) 60bb898558SAl Viro /* 61bb898558SAl Viro * Sign-extend the value so (int)-EFOO becomes (long)-EFOO 62bb898558SAl Viro * and will match correctly in comparisons. 63bb898558SAl Viro */ 64bb898558SAl Viro error = (long) (int) error; 65bb898558SAl Viro #endif 66bb898558SAl Viro return IS_ERR_VALUE(error) ? error : 0; 67bb898558SAl Viro } 68bb898558SAl Viro 69bb898558SAl Viro static inline long syscall_get_return_value(struct task_struct *task, 70bb898558SAl Viro struct pt_regs *regs) 71bb898558SAl Viro { 72bb898558SAl Viro return regs->ax; 73bb898558SAl Viro } 74bb898558SAl Viro 75bb898558SAl Viro static inline void syscall_set_return_value(struct task_struct *task, 76bb898558SAl Viro struct pt_regs *regs, 77bb898558SAl Viro int error, long val) 78bb898558SAl Viro { 79bb898558SAl Viro regs->ax = (long) error ?: val; 80bb898558SAl Viro } 81bb898558SAl Viro 82bb898558SAl Viro #ifdef CONFIG_X86_32 83bb898558SAl Viro 84bb898558SAl Viro static inline void syscall_get_arguments(struct task_struct *task, 85bb898558SAl Viro struct pt_regs *regs, 86bb898558SAl Viro unsigned long *args) 87bb898558SAl Viro { 88b35f549dSSteven Rostedt (Red Hat) memcpy(args, ®s->bx, 6 * sizeof(args[0])); 89bb898558SAl Viro } 90bb898558SAl Viro 91bb898558SAl Viro static inline void syscall_set_arguments(struct task_struct *task, 92bb898558SAl Viro struct pt_regs *regs, 93bb898558SAl Viro unsigned int i, unsigned int n, 94bb898558SAl Viro const unsigned long *args) 95bb898558SAl Viro { 96bb898558SAl Viro BUG_ON(i + n > 6); 97bb898558SAl Viro memcpy(®s->bx + i, args, n * sizeof(args[0])); 98bb898558SAl Viro } 99bb898558SAl Viro 10016add411SDmitry V. Levin static inline int syscall_get_arch(struct task_struct *task) 101b7456536SWill Drewry { 102b7456536SWill Drewry return AUDIT_ARCH_I386; 103b7456536SWill Drewry } 104b7456536SWill Drewry 105bb898558SAl Viro #else /* CONFIG_X86_64 */ 106bb898558SAl Viro 107bb898558SAl Viro static inline void syscall_get_arguments(struct task_struct *task, 108bb898558SAl Viro struct pt_regs *regs, 109bb898558SAl Viro unsigned long *args) 110bb898558SAl Viro { 111bb898558SAl Viro # ifdef CONFIG_IA32_EMULATION 112b35f549dSSteven Rostedt (Red Hat) if (task->thread_info.status & TS_COMPAT) { 113bb898558SAl Viro *args++ = regs->bx; 114c3c9897cSLinus Torvalds *args++ = regs->cx; 115c3c9897cSLinus Torvalds *args++ = regs->dx; 116c3c9897cSLinus Torvalds *args++ = regs->si; 117c3c9897cSLinus Torvalds *args++ = regs->di; 118b35f549dSSteven Rostedt (Red Hat) *args = regs->bp; 119b35f549dSSteven Rostedt (Red Hat) } else 120bb898558SAl Viro # endif 121b35f549dSSteven Rostedt (Red Hat) { 122bb898558SAl Viro *args++ = regs->di; 123c3c9897cSLinus Torvalds *args++ = regs->si; 124c3c9897cSLinus Torvalds *args++ = regs->dx; 125c3c9897cSLinus Torvalds *args++ = regs->r10; 126c3c9897cSLinus Torvalds *args++ = regs->r8; 127b35f549dSSteven Rostedt (Red Hat) *args = regs->r9; 128bb898558SAl Viro } 129bb898558SAl Viro } 130bb898558SAl Viro 131bb898558SAl Viro static inline void syscall_set_arguments(struct task_struct *task, 132bb898558SAl Viro struct pt_regs *regs, 133bb898558SAl Viro const unsigned long *args) 134bb898558SAl Viro { 135bb898558SAl Viro # ifdef CONFIG_IA32_EMULATION 13632d92586SSteven Rostedt (VMware) if (task->thread_info.status & TS_COMPAT) { 137bb898558SAl Viro regs->bx = *args++; 138c3c9897cSLinus Torvalds regs->cx = *args++; 139c3c9897cSLinus Torvalds regs->dx = *args++; 140c3c9897cSLinus Torvalds regs->si = *args++; 141c3c9897cSLinus Torvalds regs->di = *args++; 14232d92586SSteven Rostedt (VMware) regs->bp = *args; 14332d92586SSteven Rostedt (VMware) } else 144bb898558SAl Viro # endif 14532d92586SSteven Rostedt (VMware) { 146bb898558SAl Viro regs->di = *args++; 147c3c9897cSLinus Torvalds regs->si = *args++; 148c3c9897cSLinus Torvalds regs->dx = *args++; 149c3c9897cSLinus Torvalds regs->r10 = *args++; 150c3c9897cSLinus Torvalds regs->r8 = *args++; 15132d92586SSteven Rostedt (VMware) regs->r9 = *args; 152bb898558SAl Viro } 153bb898558SAl Viro } 154bb898558SAl Viro 15516add411SDmitry V. Levin static inline int syscall_get_arch(struct task_struct *task) 156b7456536SWill Drewry { 157b9d989c7SAndy Lutomirski /* x32 tasks should be considered AUDIT_ARCH_X86_64. */ 15816add411SDmitry V. Levin return (IS_ENABLED(CONFIG_IA32_EMULATION) && 15916add411SDmitry V. Levin task->thread_info.status & TS_COMPAT) 16016add411SDmitry V. Levin ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64; 161b7456536SWill Drewry } 162bb898558SAl Viro #endif /* CONFIG_X86_32 */ 163bb898558SAl Viro 1645e1b0075SH. Peter Anvin #endif /* _ASM_X86_SYSCALL_H */ 165