blob: 70ba9d4ee9782503fa8c626dd3d405d5e36b93c4 [file] [log] [blame]
Marc Zyngierf27bb132012-03-05 11:49:33 +00001/*
2 * Copyright (C) 2012 ARM Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#ifndef __ASM_SYSCALL_H
17#define __ASM_SYSCALL_H
18
19#include <linux/err.h>
20
21
22static inline int syscall_get_nr(struct task_struct *task,
23 struct pt_regs *regs)
24{
25 return regs->syscallno;
26}
27
28static inline void syscall_rollback(struct task_struct *task,
29 struct pt_regs *regs)
30{
31 regs->regs[0] = regs->orig_x0;
32}
33
34
35static inline long syscall_get_error(struct task_struct *task,
36 struct pt_regs *regs)
37{
38 unsigned long error = regs->regs[0];
39 return IS_ERR_VALUE(error) ? error : 0;
40}
41
42static inline long syscall_get_return_value(struct task_struct *task,
43 struct pt_regs *regs)
44{
45 return regs->regs[0];
46}
47
48static inline void syscall_set_return_value(struct task_struct *task,
49 struct pt_regs *regs,
50 int error, long val)
51{
52 regs->regs[0] = (long) error ? error : val;
53}
54
55#define SYSCALL_MAX_ARGS 6
56
57static inline void syscall_get_arguments(struct task_struct *task,
58 struct pt_regs *regs,
59 unsigned int i, unsigned int n,
60 unsigned long *args)
61{
AKASHI Takahiro7b22c032013-10-03 06:47:44 +010062 if (n == 0)
63 return;
64
Marc Zyngierf27bb132012-03-05 11:49:33 +000065 if (i + n > SYSCALL_MAX_ARGS) {
66 unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
67 unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
68 pr_warning("%s called with max args %d, handling only %d\n",
69 __func__, i + n, SYSCALL_MAX_ARGS);
70 memset(args_bad, 0, n_bad * sizeof(args[0]));
71 }
72
73 if (i == 0) {
74 args[0] = regs->orig_x0;
75 args++;
76 i++;
77 n--;
78 }
79
80 memcpy(args, &regs->regs[i], n * sizeof(args[0]));
81}
82
83static inline void syscall_set_arguments(struct task_struct *task,
84 struct pt_regs *regs,
85 unsigned int i, unsigned int n,
86 const unsigned long *args)
87{
AKASHI Takahiro7b22c032013-10-03 06:47:44 +010088 if (n == 0)
89 return;
90
Marc Zyngierf27bb132012-03-05 11:49:33 +000091 if (i + n > SYSCALL_MAX_ARGS) {
92 pr_warning("%s called with max args %d, handling only %d\n",
93 __func__, i + n, SYSCALL_MAX_ARGS);
94 n = SYSCALL_MAX_ARGS - i;
95 }
96
97 if (i == 0) {
98 regs->orig_x0 = args[0];
99 args++;
100 i++;
101 n--;
102 }
103
104 memcpy(&regs->regs[i], args, n * sizeof(args[0]));
105}
106
107#endif /* __ASM_SYSCALL_H */