1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef _ASM_SYSCALL_H
14#define _ASM_SYSCALL_H 1
15
16#include <uapi/linux/audit.h>
17#include <linux/sched.h>
18#include <linux/thread_info.h>
19
20
21#ifdef CONFIG_FTRACE_SYSCALLS
22extern const unsigned long sys_call_table[];
23#endif
24
25static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
26{
27
28
29
30
31
32
33 return TRAP(regs) == 0xc00 ? regs->gpr[0] : -1;
34}
35
36static inline void syscall_rollback(struct task_struct *task,
37 struct pt_regs *regs)
38{
39 regs->gpr[3] = regs->orig_gpr3;
40}
41
42static inline long syscall_get_return_value(struct task_struct *task,
43 struct pt_regs *regs)
44{
45 return regs->gpr[3];
46}
47
48static inline void syscall_set_return_value(struct task_struct *task,
49 struct pt_regs *regs,
50 int error, long val)
51{
52
53
54
55
56
57
58 if (error) {
59 regs->ccr |= 0x10000000L;
60 regs->gpr[3] = error;
61 } else {
62 regs->ccr &= ~0x10000000L;
63 regs->gpr[3] = val;
64 }
65}
66
67static inline void syscall_get_arguments(struct task_struct *task,
68 struct pt_regs *regs,
69 unsigned int i, unsigned int n,
70 unsigned long *args)
71{
72 unsigned long val, mask = -1UL;
73
74 BUG_ON(i + n > 6);
75
76#ifdef CONFIG_COMPAT
77 if (test_tsk_thread_flag(task, TIF_32BIT))
78 mask = 0xffffffff;
79#endif
80 while (n--) {
81 if (n == 0 && i == 0)
82 val = regs->orig_gpr3;
83 else
84 val = regs->gpr[3 + i + n];
85
86 args[n] = val & mask;
87 }
88}
89
90static inline void syscall_set_arguments(struct task_struct *task,
91 struct pt_regs *regs,
92 unsigned int i, unsigned int n,
93 const unsigned long *args)
94{
95 BUG_ON(i + n > 6);
96 memcpy(®s->gpr[3 + i], args, n * sizeof(args[0]));
97
98
99 if (i == 0 && n > 0)
100 regs->orig_gpr3 = args[0];
101}
102
103static inline int syscall_get_arch(struct task_struct *task)
104{
105 int arch;
106
107 if (IS_ENABLED(CONFIG_PPC64) && !test_tsk_thread_flag(task, TIF_32BIT))
108 arch = AUDIT_ARCH_PPC64;
109 else
110 arch = AUDIT_ARCH_PPC;
111
112#ifdef __LITTLE_ENDIAN__
113 arch |= __AUDIT_ARCH_LE;
114#endif
115 return arch;
116}
117#endif
118