summaryrefslogtreecommitdiff
path: root/arch/sparc/kernel/process.c
blob: d72fa066594303c8a964dc77b4d8a337efad29b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// SPDX-License-Identifier: GPL-2.0

/*
 * This file handles the architecture independent parts of process handling..
 */

#include <linux/compat.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/ptrace.h>
#include <linux/sched.h>
#include <linux/sched/task.h>
#include <linux/sched/task_stack.h>
#include <linux/signal.h>
#include <linux/syscalls.h>

#include "kernel.h"

asmlinkage long sparc_fork(struct pt_regs *regs)
{
	unsigned long orig_i1;
	long ret;
	struct kernel_clone_args args = {
		.exit_signal	= SIGCHLD,
	};

	synchronize_user_stack();

	orig_i1 = regs->u_regs[UREG_I1];
	/* Reuse the parent's stack for the child. */
	args.stack = regs->u_regs[UREG_FP];

	ret = kernel_clone(&args);

	/* If we get an error and potentially restart the system
	 * call, we're screwed because copy_thread() clobbered
	 * the parent's %o1.  So detect that case and restore it
	 * here.
	 */
	if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
		regs->u_regs[UREG_I1] = orig_i1;

	return ret;
}

asmlinkage long sparc_vfork(struct pt_regs *regs)
{
	unsigned long orig_i1;
	long ret;
	struct kernel_clone_args args = {
		.flags		= CLONE_VFORK | CLONE_VM,
		.exit_signal	= SIGCHLD,
	};

	synchronize_user_stack();

	orig_i1 = regs->u_regs[UREG_I1];
	/* Reuse the parent's stack for the child. */
	args.stack = regs->u_regs[UREG_FP];

	ret = kernel_clone(&args);

	/* If we get an error and potentially restart the system
	 * call, we're screwed because copy_thread() clobbered
	 * the parent's %o1.  So detect that case and restore it
	 * here.
	 */
	if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
		regs->u_regs[UREG_I1] = orig_i1;

	return ret;
}

asmlinkage long sparc_clone(struct pt_regs *regs)
{
	unsigned long orig_i1;
	unsigned int flags;
	long ret;
	struct kernel_clone_args args = {0};

	synchronize_user_stack();

	orig_i1 = regs->u_regs[UREG_I1];
	flags = lower_32_bits(regs->u_regs[UREG_I0]);
	args.flags		= (flags & ~CSIGNAL);
	args.exit_signal	= (flags & CSIGNAL);
	args.tls		= regs->u_regs[UREG_I3];

#ifdef CONFIG_COMPAT
	if (test_thread_flag(TIF_32BIT)) {
		args.pidfd	= compat_ptr(regs->u_regs[UREG_I2]);
		args.child_tid	= compat_ptr(regs->u_regs[UREG_I4]);
		args.parent_tid	= compat_ptr(regs->u_regs[UREG_I2]);
	} else
#endif
	{
		args.pidfd	= (int __user *)regs->u_regs[UREG_I2];
		args.child_tid	= (int __user *)regs->u_regs[UREG_I4];
		args.parent_tid	= (int __user *)regs->u_regs[UREG_I2];
	}

	/* Did userspace give setup a separate stack for the child or are we
	 * reusing the parent's?
	 */
	if (regs->u_regs[UREG_I1])
		args.stack = regs->u_regs[UREG_I1];
	else
		args.stack = regs->u_regs[UREG_FP];

	ret = kernel_clone(&args);

	/* If we get an error and potentially restart the system
	 * call, we're screwed because copy_thread() clobbered
	 * the parent's %o1.  So detect that case and restore it
	 * here.
	 */
	if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
		regs->u_regs[UREG_I1] = orig_i1;

	return ret;
}

asmlinkage long sparc_clone3(struct pt_regs *regs)
{
	unsigned long sz;
	struct clone_args __user *cl_args;

	synchronize_user_stack();

	cl_args = (struct clone_args __user *)regs->u_regs[UREG_I0];
	sz = regs->u_regs[UREG_I1];

	return sys_clone3(cl_args, sz);
}