hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/arch/powerpc/include/asm/syscall.h
....@@ -1,11 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Access to user system call parameters and results
34 *
45 * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
5
- *
6
- * This copyrighted material is made available to anyone wishing to use,
7
- * modify, copy, or redistribute it subject to the terms and conditions
8
- * of the GNU General Public License v.2.
96 *
107 * See asm-generic/syscall.h for descriptions of what we must do here.
118 */
....@@ -18,9 +15,8 @@
1815 #include <linux/thread_info.h>
1916
2017 /* ftrace syscalls requires exporting the sys_call_table */
21
-#ifdef CONFIG_FTRACE_SYSCALLS
2218 extern const unsigned long sys_call_table[];
23
-#endif /* CONFIG_FTRACE_SYSCALLS */
19
+extern const unsigned long compat_sys_call_table[];
2420
2521 static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
2622 {
....@@ -30,13 +26,32 @@
3026 * This is important for seccomp so that compat tasks can set r0 = -1
3127 * to reject the syscall.
3228 */
33
- return TRAP(regs) == 0xc00 ? regs->gpr[0] : -1;
29
+ if (trap_is_syscall(regs))
30
+ return regs->gpr[0];
31
+ else
32
+ return -1;
3433 }
3534
3635 static inline void syscall_rollback(struct task_struct *task,
3736 struct pt_regs *regs)
3837 {
3938 regs->gpr[3] = regs->orig_gpr3;
39
+}
40
+
41
+static inline long syscall_get_error(struct task_struct *task,
42
+ struct pt_regs *regs)
43
+{
44
+ if (trap_is_scv(regs)) {
45
+ unsigned long error = regs->gpr[3];
46
+
47
+ return IS_ERR_VALUE(error) ? error : 0;
48
+ } else {
49
+ /*
50
+ * If the system call failed,
51
+ * regs->gpr[3] contains a positive ERRORCODE.
52
+ */
53
+ return (regs->ccr & 0x10000000UL) ? -regs->gpr[3] : 0;
54
+ }
4055 }
4156
4257 static inline long syscall_get_return_value(struct task_struct *task,
....@@ -49,39 +64,41 @@
4964 struct pt_regs *regs,
5065 int error, long val)
5166 {
52
- /*
53
- * In the general case it's not obvious that we must deal with CCR
54
- * here, as the syscall exit path will also do that for us. However
55
- * there are some places, eg. the signal code, which check ccr to
56
- * decide if the value in r3 is actually an error.
57
- */
58
- if (error) {
59
- regs->ccr |= 0x10000000L;
60
- regs->gpr[3] = error;
67
+ if (trap_is_scv(regs)) {
68
+ regs->gpr[3] = (long) error ?: val;
6169 } else {
62
- regs->ccr &= ~0x10000000L;
63
- regs->gpr[3] = val;
70
+ /*
71
+ * In the general case it's not obvious that we must deal with
72
+ * CCR here, as the syscall exit path will also do that for us.
73
+ * However there are some places, eg. the signal code, which
74
+ * check ccr to decide if the value in r3 is actually an error.
75
+ */
76
+ if (error) {
77
+ regs->ccr |= 0x10000000L;
78
+ regs->gpr[3] = error;
79
+ } else {
80
+ regs->ccr &= ~0x10000000L;
81
+ regs->gpr[3] = val;
82
+ }
6483 }
6584 }
6685
6786 static inline void syscall_get_arguments(struct task_struct *task,
6887 struct pt_regs *regs,
69
- unsigned int i, unsigned int n,
7088 unsigned long *args)
7189 {
7290 unsigned long val, mask = -1UL;
73
-
74
- BUG_ON(i + n > 6);
91
+ unsigned int n = 6;
7592
7693 #ifdef CONFIG_COMPAT
7794 if (test_tsk_thread_flag(task, TIF_32BIT))
7895 mask = 0xffffffff;
7996 #endif
8097 while (n--) {
81
- if (n == 0 && i == 0)
98
+ if (n == 0)
8299 val = regs->orig_gpr3;
83100 else
84
- val = regs->gpr[3 + i + n];
101
+ val = regs->gpr[3 + n];
85102
86103 args[n] = val & mask;
87104 }
....@@ -89,20 +106,23 @@
89106
90107 static inline void syscall_set_arguments(struct task_struct *task,
91108 struct pt_regs *regs,
92
- unsigned int i, unsigned int n,
93109 const unsigned long *args)
94110 {
95
- BUG_ON(i + n > 6);
96
- memcpy(&regs->gpr[3 + i], args, n * sizeof(args[0]));
111
+ memcpy(&regs->gpr[3], args, 6 * sizeof(args[0]));
97112
98113 /* Also copy the first argument into orig_gpr3 */
99
- if (i == 0 && n > 0)
100
- regs->orig_gpr3 = args[0];
114
+ regs->orig_gpr3 = args[0];
101115 }
102116
103
-static inline int syscall_get_arch(void)
117
+static inline int syscall_get_arch(struct task_struct *task)
104118 {
105
- int arch = is_32bit_task() ? AUDIT_ARCH_PPC : AUDIT_ARCH_PPC64;
119
+ int arch;
120
+
121
+ if (IS_ENABLED(CONFIG_PPC64) && !test_tsk_thread_flag(task, TIF_32BIT))
122
+ arch = AUDIT_ARCH_PPC64;
123
+ else
124
+ arch = AUDIT_ARCH_PPC;
125
+
106126 #ifdef __LITTLE_ENDIAN__
107127 arch |= __AUDIT_ARCH_LE;
108128 #endif