xref: /linux/arch/alpha/include/asm/syscall.h (revision e2683c8868d03382da7e1ce8453b543a043066d1)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_ALPHA_SYSCALL_H
3 #define _ASM_ALPHA_SYSCALL_H
4 
5 #include <uapi/linux/audit.h>
6 #include <linux/audit.h>
7 #include <linux/sched.h>
8 #include <linux/types.h>
9 #include <asm/ptrace.h>
10 
11 static inline int syscall_get_arch(struct task_struct *task)
12 {
13 	return AUDIT_ARCH_ALPHA;
14 }
15 
16 static inline long syscall_get_return_value(struct task_struct *task,
17 					    struct pt_regs *regs)
18 {
19 	return regs->r19 ? -(long)regs->r0 : (long)regs->r0;
20 }
21 
22 /*
23  * Alpha syscall ABI / kernel conventions:
24  *  - PAL provides syscall number in r0 on entry.
25  *  - The kernel tracks the active syscall number in regs->r1 (mutable) and
26  *    preserves the original syscall number in regs->r2 for rollback/restart.
27  *  - Return value is in regs->r0, with regs->r19 ("a3") as the error flag
28  *    (0=success, 1=error; on error regs->r0 holds positive errno).
29  */
30 
31 static inline long syscall_get_nr(struct task_struct *task,
32 				struct pt_regs *regs)
33 {
34 	return (long)regs->r1;
35 }
36 
37 static inline void syscall_set_nr(struct task_struct *task,
38 				struct pt_regs *regs,
39 				long nr)
40 {
41 	regs->r1 = (unsigned long)nr;
42 }
43 
44 /*
45  * Syscall arguments:
46  *   regs->r16..regs->r21 carry up to 6 syscall arguments on entry.
47  *   Note: regs->r19 is also used as "a3" (error flag) on syscall return.
48  */
49 
50 static inline void syscall_get_arguments(struct task_struct *task,
51 					struct pt_regs *regs,
52 					unsigned long *args)
53 {
54 	args[0] = regs->r16;
55 	args[1] = regs->r17;
56 	args[2] = regs->r18;
57 	args[3] = regs->r19;
58 	args[4] = regs->r20;
59 	args[5] = regs->r21;
60 }
61 
62 static inline void syscall_set_arguments(struct task_struct *task,
63 					struct pt_regs *regs,
64 					const unsigned long *args)
65 {
66 	regs->r16 = args[0];
67 	regs->r17 = args[1];
68 	regs->r18 = args[2];
69 	regs->r19 = args[3];
70 	regs->r20 = args[4];
71 	regs->r21 = args[5];
72 }
73 /*
74  * Set return value for a syscall.
75  * Alpha uses r0 for return value and r19 ("a3") as the error indicator:
76  *   a3 = 0 => success
77  *   a3 = 1 => error, and userspace interprets r0 as errno (positive).
78  *
79  * The kernel reports errors to userspace by setting a3=1 and placing a
80  * positive errno value in r0. Some syscall paths do this in entry.S,
81  * while others (e.g. seccomp/ptrace helpers) use syscall_set_return_value().
82  */
83 
84 static inline void syscall_set_return_value(struct task_struct *task,
85 					struct pt_regs *regs,
86 					int error, long val)
87 {
88 
89 	if (error) {
90 		/* error is negative errno in this tree */
91 		regs->r0  = (unsigned long)(-error);  /* positive errno */
92 		regs->r19 = 1;                        /* a3 = error */
93 	} else {
94 		regs->r0  = (unsigned long)val;
95 		regs->r19 = 0;                        /* a3 = success */
96 	}
97 }
98 
99 /* Restore the original syscall nr after seccomp/ptrace modified regs->r1. */
100 static inline void syscall_rollback(struct task_struct *task,
101 					struct pt_regs *regs)
102 {
103 	regs->r1 = regs->r2;
104 }
105 
106 #endif	/* _ASM_ALPHA_SYSCALL_H */
107