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-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Access to user system call parameters and results
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2008-2009 Red Hat, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * See asm-generic/syscall.h for descriptions of what we must do here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #ifndef _ASM_X86_SYSCALL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define _ASM_X86_SYSCALL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <uapi/linux/audit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/thread_info.h>	/* for TS_COMPAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) typedef long (*sys_call_ptr_t)(const struct pt_regs *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) extern const sys_call_ptr_t sys_call_table[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #if defined(CONFIG_X86_32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define ia32_sys_call_table sys_call_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #if defined(CONFIG_IA32_EMULATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) extern const sys_call_ptr_t ia32_sys_call_table[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #ifdef CONFIG_X86_X32_ABI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) extern const sys_call_ptr_t x32_sys_call_table[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #endif
^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)  * Only the low 32 bits of orig_ax are meaningful, so we return int.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * This importantly ignores the high bits on 64-bit, so comparisons
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * sign-extend the low 32 bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return regs->orig_ax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static inline void syscall_rollback(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 				    struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	regs->ax = regs->orig_ax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static inline long syscall_get_error(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				     struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	unsigned long error = regs->ax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #ifdef CONFIG_IA32_EMULATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 * TS_COMPAT is set for 32-bit syscall entries and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 * remains set until we return to user mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		 * and will match correctly in comparisons.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		error = (long) (int) error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return IS_ERR_VALUE(error) ? error : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static inline long syscall_get_return_value(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 					    struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return regs->ax;
^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) static inline void syscall_set_return_value(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 					    struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 					    int error, long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	regs->ax = (long) error ?: val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static inline void syscall_get_arguments(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 					 struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 					 unsigned long *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	memcpy(args, &regs->bx, 6 * sizeof(args[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) static inline void syscall_set_arguments(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 					 struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 					 unsigned int i, unsigned int n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 					 const unsigned long *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	BUG_ON(i + n > 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	memcpy(&regs->bx + i, args, n * sizeof(args[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static inline int syscall_get_arch(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return AUDIT_ARCH_I386;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #else	 /* CONFIG_X86_64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static inline void syscall_get_arguments(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 					 struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 					 unsigned long *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) # ifdef CONFIG_IA32_EMULATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (task->thread_info.status & TS_COMPAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		*args++ = regs->bx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		*args++ = regs->cx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		*args++ = regs->dx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		*args++ = regs->si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		*args++ = regs->di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		*args   = regs->bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		*args++ = regs->di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		*args++ = regs->si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		*args++ = regs->dx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		*args++ = regs->r10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		*args++ = regs->r8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		*args   = regs->r9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static inline void syscall_set_arguments(struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 					 struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 					 const unsigned long *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) # ifdef CONFIG_IA32_EMULATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (task->thread_info.status & TS_COMPAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		regs->bx = *args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		regs->cx = *args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		regs->dx = *args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		regs->si = *args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		regs->di = *args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		regs->bp = *args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		regs->di = *args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		regs->si = *args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		regs->dx = *args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		regs->r10 = *args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		regs->r8 = *args++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		regs->r9 = *args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static inline int syscall_get_arch(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* x32 tasks should be considered AUDIT_ARCH_X86_64. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return (IS_ENABLED(CONFIG_IA32_EMULATION) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		task->thread_info.status & TS_COMPAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) void do_syscall_64(unsigned long nr, struct pt_regs *regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) void do_int80_syscall_32(struct pt_regs *regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) long do_fast_syscall_32(struct pt_regs *regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #endif	/* CONFIG_X86_32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #endif	/* _ASM_X86_SYSCALL_H */