Ralf Baechle | 19e2e17 | 2012-07-13 23:38:17 +0200 | [diff] [blame] | 1 | /* |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 2 | * Access to user system call parameters and results |
| 3 | * |
Ralf Baechle | 19e2e17 | 2012-07-13 23:38:17 +0200 | [diff] [blame] | 4 | * This file is subject to the terms and conditions of the GNU General Public |
| 5 | * License. See the file "COPYING" in the main directory of this archive |
| 6 | * for more details. |
| 7 | * |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 8 | * See asm-generic/syscall.h for descriptions of what we must do here. |
| 9 | * |
Ralf Baechle | 19e2e17 | 2012-07-13 23:38:17 +0200 | [diff] [blame] | 10 | * Copyright (C) 2012 Ralf Baechle <ralf@linux-mips.org> |
| 11 | */ |
| 12 | |
| 13 | #ifndef __ASM_MIPS_SYSCALL_H |
| 14 | #define __ASM_MIPS_SYSCALL_H |
| 15 | |
Ralf Baechle | f517928 | 2014-02-10 18:00:17 +0100 | [diff] [blame] | 16 | #include <linux/compiler.h> |
Eric Paris | 579ec9e | 2014-03-11 12:55:42 -0400 | [diff] [blame] | 17 | #include <uapi/linux/audit.h> |
Ralf Baechle | bec9b2b | 2012-09-26 20:16:47 +0200 | [diff] [blame] | 18 | #include <linux/elf-em.h> |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/uaccess.h> |
| 22 | #include <asm/ptrace.h> |
Markos Chandras | 4c21b8f | 2014-01-22 14:40:03 +0000 | [diff] [blame] | 23 | #include <asm/unistd.h> |
| 24 | |
| 25 | #ifndef __NR_syscall /* Only defined if _MIPS_SIM == _MIPS_SIM_ABI32 */ |
| 26 | #define __NR_syscall 4000 |
| 27 | #endif |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 28 | |
James Hogan | de8cd0d | 2017-08-11 21:56:52 +0100 | [diff] [blame^] | 29 | static inline bool mips_syscall_is_indirect(struct task_struct *task, |
| 30 | struct pt_regs *regs) |
| 31 | { |
| 32 | /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */ |
| 33 | return (IS_ENABLED(CONFIG_32BIT) || |
| 34 | test_tsk_thread_flag(task, TIF_32BIT_REGS)) && |
| 35 | (regs->regs[2] == __NR_syscall); |
| 36 | } |
| 37 | |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 38 | static inline long syscall_get_nr(struct task_struct *task, |
| 39 | struct pt_regs *regs) |
| 40 | { |
Lars Persson | c2d9f17 | 2015-02-03 17:08:17 +0100 | [diff] [blame] | 41 | return current_thread_info()->syscall; |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 42 | } |
| 43 | |
James Hogan | de8cd0d | 2017-08-11 21:56:52 +0100 | [diff] [blame^] | 44 | static inline void mips_syscall_update_nr(struct task_struct *task, |
| 45 | struct pt_regs *regs) |
| 46 | { |
| 47 | /* |
| 48 | * v0 is the system call number, except for O32 ABI syscall(), where it |
| 49 | * ends up in a0. |
| 50 | */ |
| 51 | if (mips_syscall_is_indirect(task, regs)) |
| 52 | task_thread_info(task)->syscall = regs->regs[4]; |
| 53 | else |
| 54 | task_thread_info(task)->syscall = regs->regs[2]; |
| 55 | } |
| 56 | |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 57 | static inline unsigned long mips_get_syscall_arg(unsigned long *arg, |
| 58 | struct task_struct *task, struct pt_regs *regs, unsigned int n) |
| 59 | { |
Guenter Roeck | 63238f2 | 2013-11-25 15:21:00 -0800 | [diff] [blame] | 60 | unsigned long usp __maybe_unused = regs->regs[29]; |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 61 | |
| 62 | switch (n) { |
| 63 | case 0: case 1: case 2: case 3: |
| 64 | *arg = regs->regs[4 + n]; |
| 65 | |
| 66 | return 0; |
| 67 | |
| 68 | #ifdef CONFIG_32BIT |
| 69 | case 4: case 5: case 6: case 7: |
Lars Persson | 86ca57b | 2014-03-17 12:14:13 +0100 | [diff] [blame] | 70 | return get_user(*arg, (int *)usp + n); |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 71 | #endif |
| 72 | |
| 73 | #ifdef CONFIG_64BIT |
| 74 | case 4: case 5: case 6: case 7: |
| 75 | #ifdef CONFIG_MIPS32_O32 |
| 76 | if (test_thread_flag(TIF_32BIT_REGS)) |
Lars Persson | 86ca57b | 2014-03-17 12:14:13 +0100 | [diff] [blame] | 77 | return get_user(*arg, (int *)usp + n); |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 78 | else |
| 79 | #endif |
| 80 | *arg = regs->regs[4 + n]; |
| 81 | |
| 82 | return 0; |
| 83 | #endif |
| 84 | |
| 85 | default: |
| 86 | BUG(); |
| 87 | } |
Ralf Baechle | f517928 | 2014-02-10 18:00:17 +0100 | [diff] [blame] | 88 | |
| 89 | unreachable(); |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Ralf Baechle | 1d7bf99 | 2013-09-06 20:24:48 +0200 | [diff] [blame] | 92 | static inline long syscall_get_return_value(struct task_struct *task, |
| 93 | struct pt_regs *regs) |
| 94 | { |
| 95 | return regs->regs[2]; |
| 96 | } |
| 97 | |
Markos Chandras | 22feadb | 2014-01-22 14:39:58 +0000 | [diff] [blame] | 98 | static inline void syscall_rollback(struct task_struct *task, |
| 99 | struct pt_regs *regs) |
| 100 | { |
| 101 | /* Do nothing */ |
| 102 | } |
| 103 | |
Ralf Baechle | 1d7bf99 | 2013-09-06 20:24:48 +0200 | [diff] [blame] | 104 | static inline void syscall_set_return_value(struct task_struct *task, |
| 105 | struct pt_regs *regs, |
| 106 | int error, long val) |
| 107 | { |
| 108 | if (error) { |
| 109 | regs->regs[2] = -error; |
James Hogan | becddba | 2017-06-29 10:12:35 +0100 | [diff] [blame] | 110 | regs->regs[7] = 1; |
Ralf Baechle | 1d7bf99 | 2013-09-06 20:24:48 +0200 | [diff] [blame] | 111 | } else { |
| 112 | regs->regs[2] = val; |
| 113 | regs->regs[7] = 0; |
| 114 | } |
| 115 | } |
| 116 | |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 117 | static inline void syscall_get_arguments(struct task_struct *task, |
| 118 | struct pt_regs *regs, |
| 119 | unsigned int i, unsigned int n, |
| 120 | unsigned long *args) |
| 121 | { |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 122 | int ret; |
James Hogan | de8cd0d | 2017-08-11 21:56:52 +0100 | [diff] [blame^] | 123 | |
| 124 | /* O32 ABI syscall() */ |
| 125 | if (mips_syscall_is_indirect(task, regs)) |
Markos Chandras | 4c21b8f | 2014-01-22 14:40:03 +0000 | [diff] [blame] | 126 | i++; |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 127 | |
| 128 | while (n--) |
Markos Chandras | a8031d2 | 2014-01-22 14:39:57 +0000 | [diff] [blame] | 129 | ret |= mips_get_syscall_arg(args++, task, regs, i++); |
Ralf Baechle | c0ff3c5 | 2012-08-17 08:22:04 +0200 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * No way to communicate an error because this is a void function. |
| 133 | */ |
| 134 | #if 0 |
| 135 | return ret; |
| 136 | #endif |
| 137 | } |
| 138 | |
Ralf Baechle | 19e2e17 | 2012-07-13 23:38:17 +0200 | [diff] [blame] | 139 | extern const unsigned long sys_call_table[]; |
| 140 | extern const unsigned long sys32_call_table[]; |
| 141 | extern const unsigned long sysn32_call_table[]; |
| 142 | |
Eric Paris | 5e937a9 | 2014-03-11 12:48:43 -0400 | [diff] [blame] | 143 | static inline int syscall_get_arch(void) |
Ralf Baechle | bec9b2b | 2012-09-26 20:16:47 +0200 | [diff] [blame] | 144 | { |
Eric Paris | ce5d112 | 2014-03-11 13:50:46 -0400 | [diff] [blame] | 145 | int arch = AUDIT_ARCH_MIPS; |
Ralf Baechle | bec9b2b | 2012-09-26 20:16:47 +0200 | [diff] [blame] | 146 | #ifdef CONFIG_64BIT |
Markos Chandras | 4038152 | 2014-07-24 12:10:01 +0100 | [diff] [blame] | 147 | if (!test_thread_flag(TIF_32BIT_REGS)) { |
Markos Chandras | 6e34574 | 2014-01-22 14:39:59 +0000 | [diff] [blame] | 148 | arch |= __AUDIT_ARCH_64BIT; |
Markos Chandras | 4038152 | 2014-07-24 12:10:01 +0100 | [diff] [blame] | 149 | /* N32 sets only TIF_32BIT_ADDR */ |
| 150 | if (test_thread_flag(TIF_32BIT_ADDR)) |
| 151 | arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32; |
| 152 | } |
Ralf Baechle | bec9b2b | 2012-09-26 20:16:47 +0200 | [diff] [blame] | 153 | #endif |
| 154 | #if defined(__LITTLE_ENDIAN) |
| 155 | arch |= __AUDIT_ARCH_LE; |
| 156 | #endif |
| 157 | return arch; |
| 158 | } |
| 159 | |
Ralf Baechle | 19e2e17 | 2012-07-13 23:38:17 +0200 | [diff] [blame] | 160 | #endif /* __ASM_MIPS_SYSCALL_H */ |