119e2e172SRalf Baechle /* 2c0ff3c53SRalf Baechle * Access to user system call parameters and results 3c0ff3c53SRalf Baechle * 419e2e172SRalf Baechle * This file is subject to the terms and conditions of the GNU General Public 519e2e172SRalf Baechle * License. See the file "COPYING" in the main directory of this archive 619e2e172SRalf Baechle * for more details. 719e2e172SRalf Baechle * 8c0ff3c53SRalf Baechle * See asm-generic/syscall.h for descriptions of what we must do here. 9c0ff3c53SRalf Baechle * 1019e2e172SRalf Baechle * Copyright (C) 2012 Ralf Baechle <ralf@linux-mips.org> 1119e2e172SRalf Baechle */ 1219e2e172SRalf Baechle 1319e2e172SRalf Baechle #ifndef __ASM_MIPS_SYSCALL_H 1419e2e172SRalf Baechle #define __ASM_MIPS_SYSCALL_H 1519e2e172SRalf Baechle 16f5179287SRalf Baechle #include <linux/compiler.h> 17579ec9e1SEric Paris #include <uapi/linux/audit.h> 18bec9b2b2SRalf Baechle #include <linux/elf-em.h> 19c0ff3c53SRalf Baechle #include <linux/kernel.h> 20c0ff3c53SRalf Baechle #include <linux/sched.h> 21c0ff3c53SRalf Baechle #include <linux/uaccess.h> 22c0ff3c53SRalf Baechle #include <asm/ptrace.h> 234c21b8fdSMarkos Chandras #include <asm/unistd.h> 244c21b8fdSMarkos Chandras 254c21b8fdSMarkos Chandras #ifndef __NR_syscall /* Only defined if _MIPS_SIM == _MIPS_SIM_ABI32 */ 264c21b8fdSMarkos Chandras #define __NR_syscall 4000 274c21b8fdSMarkos Chandras #endif 28c0ff3c53SRalf Baechle 29de8cd0dcSJames Hogan static inline bool mips_syscall_is_indirect(struct task_struct *task, 30de8cd0dcSJames Hogan struct pt_regs *regs) 31de8cd0dcSJames Hogan { 32de8cd0dcSJames Hogan /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */ 33de8cd0dcSJames Hogan return (IS_ENABLED(CONFIG_32BIT) || 34de8cd0dcSJames Hogan test_tsk_thread_flag(task, TIF_32BIT_REGS)) && 35de8cd0dcSJames Hogan (regs->regs[2] == __NR_syscall); 36de8cd0dcSJames Hogan } 37de8cd0dcSJames Hogan 38c0ff3c53SRalf Baechle static inline long syscall_get_nr(struct task_struct *task, 39c0ff3c53SRalf Baechle struct pt_regs *regs) 40c0ff3c53SRalf Baechle { 41c2d9f177SLars Persson return current_thread_info()->syscall; 42c0ff3c53SRalf Baechle } 43c0ff3c53SRalf Baechle 44de8cd0dcSJames Hogan static inline void mips_syscall_update_nr(struct task_struct *task, 45de8cd0dcSJames Hogan struct pt_regs *regs) 46de8cd0dcSJames Hogan { 47de8cd0dcSJames Hogan /* 48de8cd0dcSJames Hogan * v0 is the system call number, except for O32 ABI syscall(), where it 49de8cd0dcSJames Hogan * ends up in a0. 50de8cd0dcSJames Hogan */ 51de8cd0dcSJames Hogan if (mips_syscall_is_indirect(task, regs)) 52de8cd0dcSJames Hogan task_thread_info(task)->syscall = regs->regs[4]; 53de8cd0dcSJames Hogan else 54de8cd0dcSJames Hogan task_thread_info(task)->syscall = regs->regs[2]; 55de8cd0dcSJames Hogan } 56de8cd0dcSJames Hogan 57c0ff3c53SRalf Baechle static inline unsigned long mips_get_syscall_arg(unsigned long *arg, 58c0ff3c53SRalf Baechle struct task_struct *task, struct pt_regs *regs, unsigned int n) 59c0ff3c53SRalf Baechle { 6063238f2cSGuenter Roeck unsigned long usp __maybe_unused = regs->regs[29]; 61c0ff3c53SRalf Baechle 62c0ff3c53SRalf Baechle switch (n) { 63c0ff3c53SRalf Baechle case 0: case 1: case 2: case 3: 64c0ff3c53SRalf Baechle *arg = regs->regs[4 + n]; 65c0ff3c53SRalf Baechle 66c0ff3c53SRalf Baechle return 0; 67c0ff3c53SRalf Baechle 68c0ff3c53SRalf Baechle #ifdef CONFIG_32BIT 69c0ff3c53SRalf Baechle case 4: case 5: case 6: case 7: 7086ca57b5SLars Persson return get_user(*arg, (int *)usp + n); 71c0ff3c53SRalf Baechle #endif 72c0ff3c53SRalf Baechle 73c0ff3c53SRalf Baechle #ifdef CONFIG_64BIT 74c0ff3c53SRalf Baechle case 4: case 5: case 6: case 7: 75c0ff3c53SRalf Baechle #ifdef CONFIG_MIPS32_O32 76c50cbd85SDmitry V. Levin if (test_tsk_thread_flag(task, TIF_32BIT_REGS)) 7786ca57b5SLars Persson return get_user(*arg, (int *)usp + n); 78c0ff3c53SRalf Baechle else 79c0ff3c53SRalf Baechle #endif 80c0ff3c53SRalf Baechle *arg = regs->regs[4 + n]; 81c0ff3c53SRalf Baechle 82c0ff3c53SRalf Baechle return 0; 83c0ff3c53SRalf Baechle #endif 84c0ff3c53SRalf Baechle 85c0ff3c53SRalf Baechle default: 86c0ff3c53SRalf Baechle BUG(); 87c0ff3c53SRalf Baechle } 88f5179287SRalf Baechle 89f5179287SRalf Baechle unreachable(); 90c0ff3c53SRalf Baechle } 91c0ff3c53SRalf Baechle 921d7bf993SRalf Baechle static inline long syscall_get_return_value(struct task_struct *task, 931d7bf993SRalf Baechle struct pt_regs *regs) 941d7bf993SRalf Baechle { 951d7bf993SRalf Baechle return regs->regs[2]; 961d7bf993SRalf Baechle } 971d7bf993SRalf Baechle 9822feadbeSMarkos Chandras static inline void syscall_rollback(struct task_struct *task, 9922feadbeSMarkos Chandras struct pt_regs *regs) 10022feadbeSMarkos Chandras { 10122feadbeSMarkos Chandras /* Do nothing */ 10222feadbeSMarkos Chandras } 10322feadbeSMarkos Chandras 1041d7bf993SRalf Baechle static inline void syscall_set_return_value(struct task_struct *task, 1051d7bf993SRalf Baechle struct pt_regs *regs, 1061d7bf993SRalf Baechle int error, long val) 1071d7bf993SRalf Baechle { 1081d7bf993SRalf Baechle if (error) { 1091d7bf993SRalf Baechle regs->regs[2] = -error; 110becddba9SJames Hogan regs->regs[7] = 1; 1111d7bf993SRalf Baechle } else { 1121d7bf993SRalf Baechle regs->regs[2] = val; 1131d7bf993SRalf Baechle regs->regs[7] = 0; 1141d7bf993SRalf Baechle } 1151d7bf993SRalf Baechle } 1161d7bf993SRalf Baechle 117c0ff3c53SRalf Baechle static inline void syscall_get_arguments(struct task_struct *task, 118c0ff3c53SRalf Baechle struct pt_regs *regs, 119c0ff3c53SRalf Baechle unsigned int i, unsigned int n, 120c0ff3c53SRalf Baechle unsigned long *args) 121c0ff3c53SRalf Baechle { 122c0ff3c53SRalf Baechle int ret; 123de8cd0dcSJames Hogan 124de8cd0dcSJames Hogan /* O32 ABI syscall() */ 125de8cd0dcSJames Hogan if (mips_syscall_is_indirect(task, regs)) 1264c21b8fdSMarkos Chandras i++; 127c0ff3c53SRalf Baechle 128c0ff3c53SRalf Baechle while (n--) 129a8031d2cSMarkos Chandras ret |= mips_get_syscall_arg(args++, task, regs, i++); 130c0ff3c53SRalf Baechle 131c0ff3c53SRalf Baechle /* 132c0ff3c53SRalf Baechle * No way to communicate an error because this is a void function. 133c0ff3c53SRalf Baechle */ 134c0ff3c53SRalf Baechle #if 0 135c0ff3c53SRalf Baechle return ret; 136c0ff3c53SRalf Baechle #endif 137c0ff3c53SRalf Baechle } 138c0ff3c53SRalf Baechle 13919e2e172SRalf Baechle extern const unsigned long sys_call_table[]; 14019e2e172SRalf Baechle extern const unsigned long sys32_call_table[]; 14119e2e172SRalf Baechle extern const unsigned long sysn32_call_table[]; 14219e2e172SRalf Baechle 143*16add411SDmitry V. Levin static inline int syscall_get_arch(struct task_struct *task) 144bec9b2b2SRalf Baechle { 145ce5d1128SEric Paris int arch = AUDIT_ARCH_MIPS; 146bec9b2b2SRalf Baechle #ifdef CONFIG_64BIT 147*16add411SDmitry V. Levin if (!test_tsk_thread_flag(task, TIF_32BIT_REGS)) { 148bec9b2b2SRalf Baechle arch |= __AUDIT_ARCH_64BIT; 14940381529SMarkos Chandras /* N32 sets only TIF_32BIT_ADDR */ 150*16add411SDmitry V. Levin if (test_tsk_thread_flag(task, TIF_32BIT_ADDR)) 151f2d0801fSMarkos Chandras arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32; 15240381529SMarkos Chandras } 153bec9b2b2SRalf Baechle #endif 154bec9b2b2SRalf Baechle #if defined(__LITTLE_ENDIAN) 155bec9b2b2SRalf Baechle arch |= __AUDIT_ARCH_LE; 156bec9b2b2SRalf Baechle #endif 157bec9b2b2SRalf Baechle return arch; 158bec9b2b2SRalf Baechle } 159bec9b2b2SRalf Baechle 16019e2e172SRalf Baechle #endif /* __ASM_MIPS_SYSCALL_H */ 161