Merge tag 'tty-5.1-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
[sfrench/cifs-2.6.git] / arch / arm64 / include / asm / syscall.h
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
19 #include <uapi/linux/audit.h>
20 #include <linux/compat.h>
21 #include <linux/err.h>
22
23 typedef long (*syscall_fn_t)(struct pt_regs *regs);
24
25 extern const syscall_fn_t sys_call_table[];
26
27 #ifdef CONFIG_COMPAT
28 extern const syscall_fn_t compat_sys_call_table[];
29 #endif
30
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 long *args)
69 {
70         args[0] = regs->orig_x0;
71         args++;
72
73         memcpy(args, &regs->regs[1], 5 * sizeof(args[0]));
74 }
75
76 static inline void syscall_set_arguments(struct task_struct *task,
77                                          struct pt_regs *regs,
78                                          const unsigned long *args)
79 {
80         regs->orig_x0 = args[0];
81         args++;
82
83         memcpy(&regs->regs[1], args, 5 * sizeof(args[0]));
84 }
85
86 /*
87  * We don't care about endianness (__AUDIT_ARCH_LE bit) here because
88  * AArch64 has the same system calls both on little- and big- endian.
89  */
90 static inline int syscall_get_arch(void)
91 {
92         if (is_compat_task())
93                 return AUDIT_ARCH_ARM;
94
95         return AUDIT_ARCH_AARCH64;
96 }
97
98 #endif  /* __ASM_SYSCALL_H */