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