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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * This file handles the architecture independent parts of process handling..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "kernel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) asmlinkage long sparc_fork(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	unsigned long orig_i1 = regs->u_regs[UREG_I1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct kernel_clone_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		.exit_signal	= SIGCHLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		/* Reuse the parent's stack for the child. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		.stack		= regs->u_regs[UREG_FP],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	ret = kernel_clone(&args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	/* If we get an error and potentially restart the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	 * call, we're screwed because copy_thread() clobbered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	 * the parent's %o1.  So detect that case and restore it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	 * here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		regs->u_regs[UREG_I1] = orig_i1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) asmlinkage long sparc_vfork(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	unsigned long orig_i1 = regs->u_regs[UREG_I1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct kernel_clone_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		.flags		= CLONE_VFORK | CLONE_VM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		.exit_signal	= SIGCHLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		/* Reuse the parent's stack for the child. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		.stack		= regs->u_regs[UREG_FP],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	ret = kernel_clone(&args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	/* If we get an error and potentially restart the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 * call, we're screwed because copy_thread() clobbered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 * the parent's %o1.  So detect that case and restore it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 * here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		regs->u_regs[UREG_I1] = orig_i1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) asmlinkage long sparc_clone(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned long orig_i1 = regs->u_regs[UREG_I1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned int flags = lower_32_bits(regs->u_regs[UREG_I0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	struct kernel_clone_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		.flags		= (flags & ~CSIGNAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		.exit_signal	= (flags & CSIGNAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		.tls		= regs->u_regs[UREG_I3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (test_thread_flag(TIF_32BIT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		args.pidfd	= compat_ptr(regs->u_regs[UREG_I2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		args.child_tid	= compat_ptr(regs->u_regs[UREG_I4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		args.parent_tid	= compat_ptr(regs->u_regs[UREG_I2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		args.pidfd	= (int __user *)regs->u_regs[UREG_I2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		args.child_tid	= (int __user *)regs->u_regs[UREG_I4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		args.parent_tid	= (int __user *)regs->u_regs[UREG_I2];
^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) 	/* Did userspace give setup a separate stack for the child or are we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 * reusing the parent's?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (regs->u_regs[UREG_I1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		args.stack = regs->u_regs[UREG_I1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		args.stack = regs->u_regs[UREG_FP];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	ret = kernel_clone(&args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/* If we get an error and potentially restart the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	 * call, we're screwed because copy_thread() clobbered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	 * the parent's %o1.  So detect that case and restore it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	 * here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		regs->u_regs[UREG_I1] = orig_i1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }