2 * Copyright (C) 2012 ARM Ltd.
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.
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.
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/>.
16 #ifndef __ASM_SYSCALL_H
17 #define __ASM_SYSCALL_H
19 #include <uapi/linux/audit.h>
20 #include <linux/compat.h>
21 #include <linux/err.h>
23 extern const void *sys_call_table
[];
25 static inline int syscall_get_nr(struct task_struct
*task
,
28 return regs
->syscallno
;
31 static inline void syscall_rollback(struct task_struct
*task
,
34 regs
->regs
[0] = regs
->orig_x0
;
38 static inline long syscall_get_error(struct task_struct
*task
,
41 unsigned long error
= regs
->regs
[0];
42 return IS_ERR_VALUE(error
) ? error
: 0;
45 static inline long syscall_get_return_value(struct task_struct
*task
,
51 static inline void syscall_set_return_value(struct task_struct
*task
,
55 regs
->regs
[0] = (long) error
? error
: val
;
58 #define SYSCALL_MAX_ARGS 6
60 static inline void syscall_get_arguments(struct task_struct
*task
,
62 unsigned int i
, unsigned int n
,
68 if (i
+ n
> SYSCALL_MAX_ARGS
) {
69 unsigned long *args_bad
= args
+ SYSCALL_MAX_ARGS
- i
;
70 unsigned int n_bad
= n
+ i
- SYSCALL_MAX_ARGS
;
71 pr_warning("%s called with max args %d, handling only %d\n",
72 __func__
, i
+ n
, SYSCALL_MAX_ARGS
);
73 memset(args_bad
, 0, n_bad
* sizeof(args
[0]));
77 args
[0] = regs
->orig_x0
;
83 memcpy(args
, ®s
->regs
[i
], n
* sizeof(args
[0]));
86 static inline void syscall_set_arguments(struct task_struct
*task
,
88 unsigned int i
, unsigned int n
,
89 const unsigned long *args
)
94 if (i
+ n
> SYSCALL_MAX_ARGS
) {
95 pr_warning("%s called with max args %d, handling only %d\n",
96 __func__
, i
+ n
, SYSCALL_MAX_ARGS
);
97 n
= SYSCALL_MAX_ARGS
- i
;
101 regs
->orig_x0
= args
[0];
107 memcpy(®s
->regs
[i
], args
, n
* sizeof(args
[0]));
111 * We don't care about endianness (__AUDIT_ARCH_LE bit) here because
112 * AArch64 has the same system calls both on little- and big- endian.
114 static inline int syscall_get_arch(void)
116 if (is_compat_task())
117 return AUDIT_ARCH_ARM
;
119 return AUDIT_ARCH_AARCH64
;
122 #endif /* __ASM_SYSCALL_H */