Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) // Copyright (C) 2008-2009 Red Hat, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) // Copyright (C) 2005-2017 Andes Technology Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #ifndef _ASM_NDS32_SYSCALL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #define _ASM_NDS32_SYSCALL_H	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <uapi/linux/audit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) struct task_struct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) struct pt_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * syscall_get_nr - find what system call a task is executing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * @task:	task of interest, must be blocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * @regs:	task_pt_regs() of @task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * If @task is executing a system call or is at system call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * tracing about to attempt one, returns the system call number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * If @task is not executing a system call, i.e. it's blocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * inside the kernel for a fault or signal, returns -1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * Note this returns int even on 64-bit machines.  Only 32 bits of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * system call number can be meaningful.  If the actual arch value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * is 64 bits, this truncates to 32 bits so 0xffffffff means -1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * It's only valid to call this when @task is known to be blocked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	return regs->syscallno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * syscall_rollback - roll back registers after an aborted system call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * @task:	task of interest, must be in system call exit tracing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * @regs:	task_pt_regs() of @task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * It's only valid to call this when @task is stopped for system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * call exit tracing (due to TIF_SYSCALL_TRACE or TIF_SYSCALL_AUDIT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * after tracehook_report_syscall_entry() returned nonzero to prevent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * the system call from taking place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * This rolls back the register state in @regs so it's as if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * system call instruction was a no-op.  The registers containing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * the system call number and arguments are as they were before the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * system call instruction.  This may not be the same as what the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * register state looked like at system call entry tracing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) syscall_rollback(struct task_struct *task, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	regs->uregs[0] = regs->orig_r0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * syscall_get_error - check result of traced system call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @task:	task of interest, must be blocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * @regs:	task_pt_regs() of @task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * Returns 0 if the system call succeeded, or -ERRORCODE if it failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * It's only valid to call this when @task is stopped for tracing on exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static inline long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) syscall_get_error(struct task_struct *task, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	unsigned long error = regs->uregs[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return IS_ERR_VALUE(error) ? error : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * syscall_get_return_value - get the return value of a traced system call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * @task:	task of interest, must be blocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * @regs:	task_pt_regs() of @task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * Returns the return value of the successful system call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * This value is meaningless if syscall_get_error() returned nonzero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * It's only valid to call this when @task is stopped for tracing on exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static inline long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return regs->uregs[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  * syscall_set_return_value - change the return value of a traced system call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * @task:	task of interest, must be blocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * @regs:	task_pt_regs() of @task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * @error:	negative error code, or zero to indicate success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * @val:	user return value if @error is zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * This changes the results of the system call that user mode will see.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * If @error is zero, the user sees a successful system call with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * return value of @val.  If @error is nonzero, it's a negated errno
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * code; the user sees a failed system call with this errno code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * It's only valid to call this when @task is stopped for tracing on exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			 int error, long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	regs->uregs[0] = (long)error ? error : val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  * syscall_get_arguments - extract system call parameter values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * @task:	task of interest, must be blocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * @regs:	task_pt_regs() of @task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * @args:	array filled with argument values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * Fetches 6 arguments to the system call (from 0 through 5). The first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * argument is stored in @args[0], and so on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * It's only valid to call this when @task is stopped for tracing on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define SYSCALL_MAX_ARGS 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		      unsigned long *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	args[0] = regs->orig_r0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	memcpy(args, &regs->uregs[0] + 1, 5 * sizeof(args[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * syscall_set_arguments - change system call parameter value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * @task:	task of interest, must be in system call entry tracing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * @regs:	task_pt_regs() of @task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * @args:	array of argument values to store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * Changes 6 arguments to the system call. The first argument gets value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * @args[0], and so on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * It's only valid to call this when @task is stopped for tracing on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		      const unsigned long *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	regs->orig_r0 = args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	memcpy(&regs->uregs[0] + 1, args, 5 * sizeof(args[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) syscall_get_arch(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		? AUDIT_ARCH_NDS32BE : AUDIT_ARCH_NDS32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #endif /* _ASM_NDS32_SYSCALL_H */