blob: 93b3b86c293c854538fb33f5b7b45e162e7b8471 [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{
Markos Chandras4c21b8f2014-01-22 14:40:03 +000032 /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */
33 if ((config_enabled(CONFIG_32BIT) ||
34 test_tsk_thread_flag(task, TIF_32BIT_REGS)) &&
35 (regs->regs[2] == __NR_syscall))
36 return regs->regs[4];
37 else
38 return regs->regs[2];
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020039}
40
41static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
42 struct task_struct *task, struct pt_regs *regs, unsigned int n)
43{
Guenter Roeck63238f22013-11-25 15:21:00 -080044 unsigned long usp __maybe_unused = regs->regs[29];
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020045
46 switch (n) {
47 case 0: case 1: case 2: case 3:
48 *arg = regs->regs[4 + n];
49
50 return 0;
51
52#ifdef CONFIG_32BIT
53 case 4: case 5: case 6: case 7:
Lars Persson86ca57b2014-03-17 12:14:13 +010054 return get_user(*arg, (int *)usp + n);
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020055#endif
56
57#ifdef CONFIG_64BIT
58 case 4: case 5: case 6: case 7:
59#ifdef CONFIG_MIPS32_O32
60 if (test_thread_flag(TIF_32BIT_REGS))
Lars Persson86ca57b2014-03-17 12:14:13 +010061 return get_user(*arg, (int *)usp + n);
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020062 else
63#endif
64 *arg = regs->regs[4 + n];
65
66 return 0;
67#endif
68
69 default:
70 BUG();
71 }
Ralf Baechlef5179282014-02-10 18:00:17 +010072
73 unreachable();
Ralf Baechlec0ff3c52012-08-17 08:22:04 +020074}
75
Ralf Baechle1d7bf992013-09-06 20:24:48 +020076static inline long syscall_get_return_value(struct task_struct *task,
77 struct pt_regs *regs)
78{
79 return regs->regs[2];
80}
81
Markos Chandras22feadb2014-01-22 14:39:58 +000082static inline void syscall_rollback(struct task_struct *task,
83 struct pt_regs *regs)
84{
85 /* Do nothing */
86}
87
Ralf Baechle1d7bf992013-09-06 20:24:48 +020088static inline void syscall_set_return_value(struct task_struct *task,
89 struct pt_regs *regs,
90 int error, long val)
91{
92 if (error) {
93 regs->regs[2] = -error;
94 regs->regs[7] = -1;
95 } else {
96 regs->regs[2] = val;
97 regs->regs[7] = 0;
98 }
99}
100
Ralf Baechlec0ff3c52012-08-17 08:22:04 +0200101static inline void syscall_get_arguments(struct task_struct *task,
102 struct pt_regs *regs,
103 unsigned int i, unsigned int n,
104 unsigned long *args)
105{
Ralf Baechlec0ff3c52012-08-17 08:22:04 +0200106 int ret;
Markos Chandras4c21b8f2014-01-22 14:40:03 +0000107 /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */
108 if ((config_enabled(CONFIG_32BIT) ||
109 test_tsk_thread_flag(task, TIF_32BIT_REGS)) &&
110 (regs->regs[2] == __NR_syscall)) {
111 i++;
112 n++;
113 }
Ralf Baechlec0ff3c52012-08-17 08:22:04 +0200114
115 while (n--)
Markos Chandrasa8031d22014-01-22 14:39:57 +0000116 ret |= mips_get_syscall_arg(args++, task, regs, i++);
Ralf Baechlec0ff3c52012-08-17 08:22:04 +0200117
118 /*
119 * No way to communicate an error because this is a void function.
120 */
121#if 0
122 return ret;
123#endif
124}
125
Ralf Baechle19e2e172012-07-13 23:38:17 +0200126extern const unsigned long sys_call_table[];
127extern const unsigned long sys32_call_table[];
128extern const unsigned long sysn32_call_table[];
129
Eric Paris5e937a92014-03-11 12:48:43 -0400130static inline int syscall_get_arch(void)
Ralf Baechlebec9b2b2012-09-26 20:16:47 +0200131{
Eric Parisce5d1122014-03-11 13:50:46 -0400132 int arch = AUDIT_ARCH_MIPS;
Ralf Baechlebec9b2b2012-09-26 20:16:47 +0200133#ifdef CONFIG_64BIT
Linus Torvalds0b747172014-04-12 12:38:53 -0700134 if (!test_thread_flag(TIF_32BIT_REGS))
Markos Chandras6e345742014-01-22 14:39:59 +0000135 arch |= __AUDIT_ARCH_64BIT;
Markos Chandrasf2d08012014-04-22 15:40:36 +0100136 if (test_thread_flag(TIF_32BIT_ADDR))
137 arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32;
Ralf Baechlebec9b2b2012-09-26 20:16:47 +0200138#endif
139#if defined(__LITTLE_ENDIAN)
140 arch |= __AUDIT_ARCH_LE;
141#endif
142 return arch;
143}
144
Ralf Baechle19e2e172012-07-13 23:38:17 +0200145#endif /* __ASM_MIPS_SYSCALL_H */