Skip to content

Commit d2ce4e9

Browse files
Al Virorichardweinberger
authored andcommitted
um: kill thread->forking
we only use that to tell copy_thread() done by syscall from that done by kernel_thread(). However, it's easier to do simply by checking PF_KTHREAD in thread flags. Merge sys_clone() guts for 32bit and 64bit, while we are at it... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent f9a38ea commit d2ce4e9

7 files changed

Lines changed: 29 additions & 66 deletions

File tree

‎arch/um/include/asm/processor-generic.h‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ struct mm_struct;
2020

2121
struct thread_struct {
2222
struct task_struct *saved_task;
23-
/*
24-
* This flag is set to 1 before calling do_fork (and analyzed in
25-
* copy_thread) to mark that we are begin called from userspace (fork /
26-
* vfork / clone), and reset to 0 after. It is left to 0 when called
27-
* from kernelspace (i.e. kernel_thread() or fork_idle(),
28-
* as of 2.6.11).
29-
*/
30-
int forking;
3123
struct pt_regs regs;
3224
int singlestep_syscall;
3325
void *fault_addr;
@@ -58,7 +50,6 @@ struct thread_struct {
5850

5951
#define INIT_THREAD \
6052
{ \
61-
.forking = 0, \
6253
.regs = EMPTY_REGS, \
6354
.fault_addr = NULL, \
6455
.prev_sched = NULL, \

‎arch/um/kernel/process.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,12 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
181181
struct pt_regs *regs)
182182
{
183183
void (*handler)(void);
184+
int kthread = current->flags & PF_KTHREAD;
184185
int ret = 0;
185186

186187
p->thread = (struct thread_struct) INIT_THREAD;
187188

188-
if (current->thread.forking) {
189+
if (!kthread) {
189190
memcpy(&p->thread.regs.regs, &regs->regs,
190191
sizeof(p->thread.regs.regs));
191192
PT_REGS_SET_SYSCALL_RETURN(&p->thread.regs, 0);
@@ -195,16 +196,15 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
195196
handler = fork_handler;
196197

197198
arch_copy_thread(&current->thread.arch, &p->thread.arch);
198-
}
199-
else {
199+
} else {
200200
get_safe_registers(p->thread.regs.regs.gp, p->thread.regs.regs.fp);
201201
p->thread.request.u.thread = current->thread.request.u.thread;
202202
handler = new_thread_handler;
203203
}
204204

205205
new_thread(task_stack_page(p), &p->thread.switch_buf, handler);
206206

207-
if (current->thread.forking) {
207+
if (!kthread) {
208208
clear_flushed_tls(p);
209209

210210
/*

‎arch/um/kernel/syscall.c‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@
1717

1818
long sys_fork(void)
1919
{
20-
long ret;
21-
22-
current->thread.forking = 1;
23-
ret = do_fork(SIGCHLD, UPT_SP(&current->thread.regs.regs),
20+
return do_fork(SIGCHLD, UPT_SP(&current->thread.regs.regs),
2421
&current->thread.regs, 0, NULL, NULL);
25-
current->thread.forking = 0;
26-
return ret;
2722
}
2823

2924
long sys_vfork(void)
3025
{
31-
long ret;
32-
33-
current->thread.forking = 1;
34-
ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
26+
return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD,
3527
UPT_SP(&current->thread.regs.regs),
3628
&current->thread.regs, 0, NULL, NULL);
37-
current->thread.forking = 0;
38-
return ret;
29+
}
30+
31+
long sys_clone(unsigned long clone_flags, unsigned long newsp,
32+
void __user *parent_tid, void __user *child_tid)
33+
{
34+
if (!newsp)
35+
newsp = UPT_SP(&current->thread.regs.regs);
36+
37+
return do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
38+
child_tid);
3939
}
4040

4141
long old_mmap(unsigned long addr, unsigned long len,

‎arch/x86/um/shared/sysdep/syscalls.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern long sys_clone(unsigned long clone_flags, unsigned long newsp,
2+
void __user *parent_tid, void __user *child_tid);
13
#ifdef __i386__
24
#include "syscalls_32.h"
35
#else

‎arch/x86/um/sys_call_table_32.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define ptregs_execve sys_execve
2929
#define ptregs_iopl sys_iopl
3030
#define ptregs_vm86old sys_vm86old
31-
#define ptregs_clone sys_clone
31+
#define ptregs_clone i386_clone
3232
#define ptregs_vm86 sys_vm86
3333
#define ptregs_sigaltstack sys_sigaltstack
3434
#define ptregs_vfork sys_vfork

‎arch/x86/um/syscalls_32.c‎

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,24 @@
33
* Licensed under the GPL
44
*/
55

6-
#include "linux/sched.h"
7-
#include "linux/shm.h"
8-
#include "linux/ipc.h"
9-
#include "linux/syscalls.h"
10-
#include "asm/mman.h"
11-
#include "asm/uaccess.h"
12-
#include "asm/unistd.h"
6+
#include <linux/syscalls.h>
7+
#include <sysdep/syscalls.h>
138

149
/*
1510
* The prototype on i386 is:
1611
*
17-
* int clone(int flags, void * child_stack, int * parent_tidptr, struct user_desc * newtls, int * child_tidptr)
12+
* int clone(int flags, void * child_stack, int * parent_tidptr, struct user_desc * newtls
1813
*
1914
* and the "newtls" arg. on i386 is read by copy_thread directly from the
2015
* register saved on the stack.
2116
*/
22-
long sys_clone(unsigned long clone_flags, unsigned long newsp,
23-
int __user *parent_tid, void *newtls, int __user *child_tid)
17+
long i386_clone(unsigned long clone_flags, unsigned long newsp,
18+
int __user *parent_tid, void *newtls, int __user *child_tid)
2419
{
25-
long ret;
26-
27-
if (!newsp)
28-
newsp = UPT_SP(&current->thread.regs.regs);
29-
30-
current->thread.forking = 1;
31-
ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
32-
child_tid);
33-
current->thread.forking = 0;
34-
return ret;
20+
return sys_clone(clone_flags, newsp, parent_tid, child_tid);
3521
}
3622

23+
3724
long sys_sigaction(int sig, const struct old_sigaction __user *act,
3825
struct old_sigaction __user *oact)
3926
{

‎arch/x86/um/syscalls_64.c‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
* Licensed under the GPL
66
*/
77

8-
#include "linux/linkage.h"
9-
#include "linux/personality.h"
10-
#include "linux/utsname.h"
11-
#include "asm/prctl.h" /* XXX This should get the constants from libc */
12-
#include "asm/uaccess.h"
13-
#include "os.h"
8+
#include <linux/sched.h>
9+
#include <asm/prctl.h> /* XXX This should get the constants from libc */
10+
#include <os.h>
1411

1512
long arch_prctl(struct task_struct *task, int code, unsigned long __user *addr)
1613
{
@@ -79,20 +76,6 @@ long sys_arch_prctl(int code, unsigned long addr)
7976
return arch_prctl(current, code, (unsigned long __user *) addr);
8077
}
8178

82-
long sys_clone(unsigned long clone_flags, unsigned long newsp,
83-
void __user *parent_tid, void __user *child_tid)
84-
{
85-
long ret;
86-
87-
if (!newsp)
88-
newsp = UPT_SP(&current->thread.regs.regs);
89-
current->thread.forking = 1;
90-
ret = do_fork(clone_flags, newsp, &current->thread.regs, 0, parent_tid,
91-
child_tid);
92-
current->thread.forking = 0;
93-
return ret;
94-
}
95-
9679
void arch_switch_to(struct task_struct *to)
9780
{
9881
if ((to->thread.arch.fs == 0) || (to->mm == NULL))

0 commit comments

Comments
 (0)