Commit | Line | Data |
---|---|---|
19e2e172 | 1 | /* |
c0ff3c53 RB |
2 | * Access to user system call parameters and results |
3 | * | |
19e2e172 RB |
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 | * | |
c0ff3c53 RB |
8 | * See asm-generic/syscall.h for descriptions of what we must do here. |
9 | * | |
19e2e172 RB |
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 | ||
f5179287 | 16 | #include <linux/compiler.h> |
579ec9e1 | 17 | #include <uapi/linux/audit.h> |
bec9b2b2 | 18 | #include <linux/elf-em.h> |
c0ff3c53 RB |
19 | #include <linux/kernel.h> |
20 | #include <linux/sched.h> | |
21 | #include <linux/uaccess.h> | |
22 | #include <asm/ptrace.h> | |
4c21b8fd MC |
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 | |
c0ff3c53 RB |
28 | |
29 | static inline long syscall_get_nr(struct task_struct *task, | |
30 | struct pt_regs *regs) | |
31 | { | |
c2d9f177 | 32 | return current_thread_info()->syscall; |
c0ff3c53 RB |
33 | } |
34 | ||
35 | static inline unsigned long mips_get_syscall_arg(unsigned long *arg, | |
36 | struct task_struct *task, struct pt_regs *regs, unsigned int n) | |
37 | { | |
63238f2c | 38 | unsigned long usp __maybe_unused = regs->regs[29]; |
c0ff3c53 RB |
39 | |
40 | switch (n) { | |
41 | case 0: case 1: case 2: case 3: | |
42 | *arg = regs->regs[4 + n]; | |
43 | ||
44 | return 0; | |
45 | ||
46 | #ifdef CONFIG_32BIT | |
47 | case 4: case 5: case 6: case 7: | |
86ca57b5 | 48 | return get_user(*arg, (int *)usp + n); |
c0ff3c53 RB |
49 | #endif |
50 | ||
51 | #ifdef CONFIG_64BIT | |
52 | case 4: case 5: case 6: case 7: | |
53 | #ifdef CONFIG_MIPS32_O32 | |
54 | if (test_thread_flag(TIF_32BIT_REGS)) | |
86ca57b5 | 55 | return get_user(*arg, (int *)usp + n); |
c0ff3c53 RB |
56 | else |
57 | #endif | |
58 | *arg = regs->regs[4 + n]; | |
59 | ||
60 | return 0; | |
61 | #endif | |
62 | ||
63 | default: | |
64 | BUG(); | |
65 | } | |
f5179287 RB |
66 | |
67 | unreachable(); | |
c0ff3c53 RB |
68 | } |
69 | ||
1d7bf993 RB |
70 | static inline long syscall_get_return_value(struct task_struct *task, |
71 | struct pt_regs *regs) | |
72 | { | |
73 | return regs->regs[2]; | |
74 | } | |
75 | ||
22feadbe MC |
76 | static inline void syscall_rollback(struct task_struct *task, |
77 | struct pt_regs *regs) | |
78 | { | |
79 | /* Do nothing */ | |
80 | } | |
81 | ||
1d7bf993 RB |
82 | static inline void syscall_set_return_value(struct task_struct *task, |
83 | struct pt_regs *regs, | |
84 | int error, long val) | |
85 | { | |
86 | if (error) { | |
87 | regs->regs[2] = -error; | |
88 | regs->regs[7] = -1; | |
89 | } else { | |
90 | regs->regs[2] = val; | |
91 | regs->regs[7] = 0; | |
92 | } | |
93 | } | |
94 | ||
c0ff3c53 RB |
95 | static inline void syscall_get_arguments(struct task_struct *task, |
96 | struct pt_regs *regs, | |
97 | unsigned int i, unsigned int n, | |
98 | unsigned long *args) | |
99 | { | |
c0ff3c53 | 100 | int ret; |
4c21b8fd | 101 | /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */ |
97f2645f | 102 | if ((IS_ENABLED(CONFIG_32BIT) || |
4c21b8fd | 103 | test_tsk_thread_flag(task, TIF_32BIT_REGS)) && |
f4dce1ff | 104 | (regs->regs[2] == __NR_syscall)) |
4c21b8fd | 105 | i++; |
c0ff3c53 RB |
106 | |
107 | while (n--) | |
a8031d2c | 108 | ret |= mips_get_syscall_arg(args++, task, regs, i++); |
c0ff3c53 RB |
109 | |
110 | /* | |
111 | * No way to communicate an error because this is a void function. | |
112 | */ | |
113 | #if 0 | |
114 | return ret; | |
115 | #endif | |
116 | } | |
117 | ||
19e2e172 RB |
118 | extern const unsigned long sys_call_table[]; |
119 | extern const unsigned long sys32_call_table[]; | |
120 | extern const unsigned long sysn32_call_table[]; | |
121 | ||
5e937a9a | 122 | static inline int syscall_get_arch(void) |
bec9b2b2 | 123 | { |
ce5d1128 | 124 | int arch = AUDIT_ARCH_MIPS; |
bec9b2b2 | 125 | #ifdef CONFIG_64BIT |
40381529 | 126 | if (!test_thread_flag(TIF_32BIT_REGS)) { |
6e345746 | 127 | arch |= __AUDIT_ARCH_64BIT; |
40381529 MC |
128 | /* N32 sets only TIF_32BIT_ADDR */ |
129 | if (test_thread_flag(TIF_32BIT_ADDR)) | |
130 | arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32; | |
131 | } | |
bec9b2b2 RB |
132 | #endif |
133 | #if defined(__LITTLE_ENDIAN) | |
134 | arch |= __AUDIT_ARCH_LE; | |
135 | #endif | |
136 | return arch; | |
137 | } | |
138 | ||
19e2e172 | 139 | #endif /* __ASM_MIPS_SYSCALL_H */ |