blob: 6499d93ae68d7096d63416a349d9afcdcc0cb3ae [file] [log] [blame]
Ralf Baechle19e2e172012-07-13 23:38:17 +02001/*
Ralf Baechlec0ff3c52012-08-17 08:22:04 +02002 * Access to user system call parameters and results
3 *
Ralf Baechle19e2e172012-07-13 23:38:17 +02004 * 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 Baechlec0ff3c52012-08-17 08:22:04 +02008 * See asm-generic/syscall.h for descriptions of what we must do here.
9 *
Ralf Baechle19e2e172012-07-13 23:38:17 +020010 * 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 Baechlef5179282014-02-10 18:00:17 +010016#include <linux/compiler.h>
Eric Paris579ec9e2014-03-11 12:55:42 -040017#include <uapi/linux/audit.h>
Ralf Baechlebec9b2b2012-09-26 20:16:47 +020018#include <linux/elf-em.h>
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020019#include <linux/kernel.h>
20#include <linux/sched.h>
21#include <linux/uaccess.h>
22#include <asm/ptrace.h>
Markos Chandras4c21b8f2014-01-22 14:40:03 +000023#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 Baechlec0ff3c52012-08-17 08:22:04 +020028
29static inline long syscall_get_nr(struct task_struct *task,
30 struct pt_regs *regs)
31{
Lars Perssonc2d9f172015-02-03 17:08:17 +010032 return current_thread_info()->syscall;
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020033}
34
35static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
36 struct task_struct *task, struct pt_regs *regs, unsigned int n)
37{
Guenter Roeck63238f22013-11-25 15:21:00 -080038 unsigned long usp __maybe_unused = regs->regs[29];
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020039
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:
Lars Persson86ca57b2014-03-17 12:14:13 +010048 return get_user(*arg, (int *)usp + n);
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020049#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))
Lars Persson86ca57b2014-03-17 12:14:13 +010055 return get_user(*arg, (int *)usp + n);
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020056 else
57#endif
58 *arg = regs->regs[4 + n];
59
60 return 0;
61#endif
62
63 default:
64 BUG();
65 }
Ralf Baechlef5179282014-02-10 18:00:17 +010066
67 unreachable();
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020068}
69
Ralf Baechle1d7bf992013-09-06 20:24:48 +020070static inline long syscall_get_return_value(struct task_struct *task,
71 struct pt_regs *regs)
72{
73 return regs->regs[2];
74}
75
Markos Chandras22feadb2014-01-22 14:39:58 +000076static inline void syscall_rollback(struct task_struct *task,
77 struct pt_regs *regs)
78{
79 /* Do nothing */
80}
81
Ralf Baechle1d7bf992013-09-06 20:24:48 +020082static 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
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020095static 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{
Ralf Baechlec0ff3c52012-08-17 08:22:04 +0200100 int ret;
Markos Chandras4c21b8f2014-01-22 14:40:03 +0000101 /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */
102 if ((config_enabled(CONFIG_32BIT) ||
103 test_tsk_thread_flag(task, TIF_32BIT_REGS)) &&
104 (regs->regs[2] == __NR_syscall)) {
105 i++;
106 n++;
107 }
Ralf Baechlec0ff3c52012-08-17 08:22:04 +0200108
109 while (n--)
Markos Chandrasa8031d22014-01-22 14:39:57 +0000110 ret |= mips_get_syscall_arg(args++, task, regs, i++);
Ralf Baechlec0ff3c52012-08-17 08:22:04 +0200111
112 /*
113 * No way to communicate an error because this is a void function.
114 */
115#if 0
116 return ret;
117#endif
118}
119
Ralf Baechle19e2e172012-07-13 23:38:17 +0200120extern const unsigned long sys_call_table[];
121extern const unsigned long sys32_call_table[];
122extern const unsigned long sysn32_call_table[];
123
Eric Paris5e937a92014-03-11 12:48:43 -0400124static inline int syscall_get_arch(void)
Ralf Baechlebec9b2b2012-09-26 20:16:47 +0200125{
Eric Parisce5d1122014-03-11 13:50:46 -0400126 int arch = AUDIT_ARCH_MIPS;
Ralf Baechlebec9b2b2012-09-26 20:16:47 +0200127#ifdef CONFIG_64BIT
Markos Chandras40381522014-07-24 12:10:01 +0100128 if (!test_thread_flag(TIF_32BIT_REGS)) {
Markos Chandras6e345742014-01-22 14:39:59 +0000129 arch |= __AUDIT_ARCH_64BIT;
Markos Chandras40381522014-07-24 12:10:01 +0100130 /* N32 sets only TIF_32BIT_ADDR */
131 if (test_thread_flag(TIF_32BIT_ADDR))
132 arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32;
133 }
Ralf Baechlebec9b2b2012-09-26 20:16:47 +0200134#endif
135#if defined(__LITTLE_ENDIAN)
136 arch |= __AUDIT_ARCH_LE;
137#endif
138 return arch;
139}
140
Ralf Baechle19e2e172012-07-13 23:38:17 +0200141#endif /* __ASM_MIPS_SYSCALL_H */