Merge branch 'v3.10/topic/misc' into linux-linaro-lsk
[firefly-linux-kernel-4.4.55.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 <linux/err.h>
20
21 extern const void *sys_call_table[];
22
23 static inline int syscall_get_nr(struct task_struct *task,
24                                  struct pt_regs *regs)
25 {
26         return regs->syscallno;
27 }
28
29 static inline void syscall_rollback(struct task_struct *task,
30                                     struct pt_regs *regs)
31 {
32         regs->regs[0] = regs->orig_x0;
33 }
34
35
36 static inline long syscall_get_error(struct task_struct *task,
37                                      struct pt_regs *regs)
38 {
39         unsigned long error = regs->regs[0];
40         return IS_ERR_VALUE(error) ? error : 0;
41 }
42
43 static inline long syscall_get_return_value(struct task_struct *task,
44                                             struct pt_regs *regs)
45 {
46         return regs->regs[0];
47 }
48
49 static inline void syscall_set_return_value(struct task_struct *task,
50                                             struct pt_regs *regs,
51                                             int error, long val)
52 {
53         regs->regs[0] = (long) error ? error : val;
54 }
55
56 #define SYSCALL_MAX_ARGS 6
57
58 static inline void syscall_get_arguments(struct task_struct *task,
59                                          struct pt_regs *regs,
60                                          unsigned int i, unsigned int n,
61                                          unsigned long *args)
62 {
63         if (n == 0)
64                 return;
65
66         if (i + n > SYSCALL_MAX_ARGS) {
67                 unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
68                 unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
69                 pr_warning("%s called with max args %d, handling only %d\n",
70                            __func__, i + n, SYSCALL_MAX_ARGS);
71                 memset(args_bad, 0, n_bad * sizeof(args[0]));
72         }
73
74         if (i == 0) {
75                 args[0] = regs->orig_x0;
76                 args++;
77                 i++;
78                 n--;
79         }
80
81         memcpy(args, &regs->regs[i], n * sizeof(args[0]));
82 }
83
84 static inline void syscall_set_arguments(struct task_struct *task,
85                                          struct pt_regs *regs,
86                                          unsigned int i, unsigned int n,
87                                          const unsigned long *args)
88 {
89         if (n == 0)
90                 return;
91
92         if (i + n > SYSCALL_MAX_ARGS) {
93                 pr_warning("%s called with max args %d, handling only %d\n",
94                            __func__, i + n, SYSCALL_MAX_ARGS);
95                 n = SYSCALL_MAX_ARGS - i;
96         }
97
98         if (i == 0) {
99                 regs->orig_x0 = args[0];
100                 args++;
101                 i++;
102                 n--;
103         }
104
105         memcpy(&regs->regs[i], args, n * sizeof(args[0]));
106 }
107
108 #endif  /* __ASM_SYSCALL_H */