Commit | Line | Data |
---|---|---|
f27bb139 MZ |
1 | /* |
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 | ||
875cbf3e AT |
19 | #include <uapi/linux/audit.h> |
20 | #include <linux/compat.h> | |
f27bb139 MZ |
21 | #include <linux/err.h> |
22 | ||
4378a7d4 | 23 | typedef long (*syscall_fn_t)(struct pt_regs *regs); |
27d83e68 MR |
24 | |
25 | extern const syscall_fn_t sys_call_table[]; | |
f27bb139 | 26 | |
3b714275 MR |
27 | #ifdef CONFIG_COMPAT |
28 | extern const syscall_fn_t compat_sys_call_table[]; | |
29 | #endif | |
30 | ||
f27bb139 MZ |
31 | static inline int syscall_get_nr(struct task_struct *task, |
32 | struct pt_regs *regs) | |
33 | { | |
34 | return regs->syscallno; | |
35 | } | |
36 | ||
37 | static inline void syscall_rollback(struct task_struct *task, | |
38 | struct pt_regs *regs) | |
39 | { | |
40 | regs->regs[0] = regs->orig_x0; | |
41 | } | |
42 | ||
43 | ||
44 | static inline long syscall_get_error(struct task_struct *task, | |
45 | struct pt_regs *regs) | |
46 | { | |
47 | unsigned long error = regs->regs[0]; | |
48 | return IS_ERR_VALUE(error) ? error : 0; | |
49 | } | |
50 | ||
51 | static inline long syscall_get_return_value(struct task_struct *task, | |
52 | struct pt_regs *regs) | |
53 | { | |
54 | return regs->regs[0]; | |
55 | } | |
56 | ||
57 | static inline void syscall_set_return_value(struct task_struct *task, | |
58 | struct pt_regs *regs, | |
59 | int error, long val) | |
60 | { | |
61 | regs->regs[0] = (long) error ? error : val; | |
62 | } | |
63 | ||
64 | #define SYSCALL_MAX_ARGS 6 | |
65 | ||
66 | static inline void syscall_get_arguments(struct task_struct *task, | |
67 | struct pt_regs *regs, | |
68 | unsigned int i, unsigned int n, | |
69 | unsigned long *args) | |
70 | { | |
7b22c035 AT |
71 | if (n == 0) |
72 | return; | |
73 | ||
f27bb139 MZ |
74 | if (i + n > SYSCALL_MAX_ARGS) { |
75 | unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i; | |
76 | unsigned int n_bad = n + i - SYSCALL_MAX_ARGS; | |
77 | pr_warning("%s called with max args %d, handling only %d\n", | |
78 | __func__, i + n, SYSCALL_MAX_ARGS); | |
79 | memset(args_bad, 0, n_bad * sizeof(args[0])); | |
80 | } | |
81 | ||
82 | if (i == 0) { | |
83 | args[0] = regs->orig_x0; | |
84 | args++; | |
85 | i++; | |
86 | n--; | |
87 | } | |
88 | ||
89 | memcpy(args, ®s->regs[i], n * sizeof(args[0])); | |
90 | } | |
91 | ||
92 | static inline void syscall_set_arguments(struct task_struct *task, | |
93 | struct pt_regs *regs, | |
94 | unsigned int i, unsigned int n, | |
95 | const unsigned long *args) | |
96 | { | |
7b22c035 AT |
97 | if (n == 0) |
98 | return; | |
99 | ||
f27bb139 MZ |
100 | if (i + n > SYSCALL_MAX_ARGS) { |
101 | pr_warning("%s called with max args %d, handling only %d\n", | |
102 | __func__, i + n, SYSCALL_MAX_ARGS); | |
103 | n = SYSCALL_MAX_ARGS - i; | |
104 | } | |
105 | ||
106 | if (i == 0) { | |
107 | regs->orig_x0 = args[0]; | |
108 | args++; | |
109 | i++; | |
110 | n--; | |
111 | } | |
112 | ||
113 | memcpy(®s->regs[i], args, n * sizeof(args[0])); | |
114 | } | |
115 | ||
875cbf3e AT |
116 | /* |
117 | * We don't care about endianness (__AUDIT_ARCH_LE bit) here because | |
118 | * AArch64 has the same system calls both on little- and big- endian. | |
119 | */ | |
16add411 | 120 | static inline int syscall_get_arch(struct task_struct *task) |
875cbf3e | 121 | { |
16add411 | 122 | if (is_compat_thread(task_thread_info(task))) |
875cbf3e AT |
123 | return AUDIT_ARCH_ARM; |
124 | ||
125 | return AUDIT_ARCH_AARCH64; | |
126 | } | |
127 | ||
f27bb139 | 128 | #endif /* __ASM_SYSCALL_H */ |