1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
23extern const void *sys_call_table[];
24
25static inline int syscall_get_nr(struct task_struct *task,
26 struct pt_regs *regs)
27{
28 return regs->syscallno;
29}
30
31static inline void syscall_rollback(struct task_struct *task,
32 struct pt_regs *regs)
33{
34 regs->regs[0] = regs->orig_x0;
35}
36
37
38static inline long syscall_get_error(struct task_struct *task,
39 struct pt_regs *regs)
40{
41 unsigned long error = regs->regs[0];
42 return IS_ERR_VALUE(error) ? error : 0;
43}
44
45static inline long syscall_get_return_value(struct task_struct *task,
46 struct pt_regs *regs)
47{
48 return regs->regs[0];
49}
50
51static inline void syscall_set_return_value(struct task_struct *task,
52 struct pt_regs *regs,
53 int error, long val)
54{
55 regs->regs[0] = (long) error ? error : val;
56}
57
58#define SYSCALL_MAX_ARGS 6
59
60static inline void syscall_get_arguments(struct task_struct *task,
61 struct pt_regs *regs,
62 unsigned int i, unsigned int n,
63 unsigned long *args)
64{
65 if (n == 0)
66 return;
67
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]));
74 }
75
76 if (i == 0) {
77 args[0] = regs->orig_x0;
78 args++;
79 i++;
80 n--;
81 }
82
83 memcpy(args, ®s->regs[i], n * sizeof(args[0]));
84}
85
86static inline void syscall_set_arguments(struct task_struct *task,
87 struct pt_regs *regs,
88 unsigned int i, unsigned int n,
89 const unsigned long *args)
90{
91 if (n == 0)
92 return;
93
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;
98 }
99
100 if (i == 0) {
101 regs->orig_x0 = args[0];
102 args++;
103 i++;
104 n--;
105 }
106
107 memcpy(®s->regs[i], args, n * sizeof(args[0]));
108}
109
110
111
112
113
114static inline int syscall_get_arch(void)
115{
116 if (is_compat_task())
117 return AUDIT_ARCH_ARM;
118
119 return AUDIT_ARCH_AARCH64;
120}
121
122#endif
123