fork.c (51cc50685a4275c6a02653670af9f108a64e01cf) | fork.c (09a05394fe2448a4139b014936330af23fa7ec83) |
---|---|
1/* 2 * linux/kernel/fork.c 3 * 4 * Copyright (C) 1991, 1992 Linus Torvalds 5 */ 6 7/* 8 * 'fork.c' contains the help-routines for the 'fork' system call --- 23 unchanged lines hidden (view full) --- 32#include <linux/capability.h> 33#include <linux/cpu.h> 34#include <linux/cgroup.h> 35#include <linux/security.h> 36#include <linux/hugetlb.h> 37#include <linux/swap.h> 38#include <linux/syscalls.h> 39#include <linux/jiffies.h> | 1/* 2 * linux/kernel/fork.c 3 * 4 * Copyright (C) 1991, 1992 Linus Torvalds 5 */ 6 7/* 8 * 'fork.c' contains the help-routines for the 'fork' system call --- 23 unchanged lines hidden (view full) --- 32#include <linux/capability.h> 33#include <linux/cpu.h> 34#include <linux/cgroup.h> 35#include <linux/security.h> 36#include <linux/hugetlb.h> 37#include <linux/swap.h> 38#include <linux/syscalls.h> 39#include <linux/jiffies.h> |
40#include <linux/tracehook.h> |
|
40#include <linux/futex.h> 41#include <linux/task_io_accounting_ops.h> 42#include <linux/rcupdate.h> 43#include <linux/ptrace.h> 44#include <linux/mount.h> 45#include <linux/audit.h> 46#include <linux/memcontrol.h> 47#include <linux/profile.h> --- 812 unchanged lines hidden (view full) --- 860} 861 862static void copy_flags(unsigned long clone_flags, struct task_struct *p) 863{ 864 unsigned long new_flags = p->flags; 865 866 new_flags &= ~PF_SUPERPRIV; 867 new_flags |= PF_FORKNOEXEC; | 41#include <linux/futex.h> 42#include <linux/task_io_accounting_ops.h> 43#include <linux/rcupdate.h> 44#include <linux/ptrace.h> 45#include <linux/mount.h> 46#include <linux/audit.h> 47#include <linux/memcontrol.h> 48#include <linux/profile.h> --- 812 unchanged lines hidden (view full) --- 861} 862 863static void copy_flags(unsigned long clone_flags, struct task_struct *p) 864{ 865 unsigned long new_flags = p->flags; 866 867 new_flags &= ~PF_SUPERPRIV; 868 new_flags |= PF_FORKNOEXEC; |
868 if (!(clone_flags & CLONE_PTRACE)) 869 p->ptrace = 0; | 869 new_flags |= PF_STARTING; |
870 p->flags = new_flags; 871 clear_freeze_flag(p); 872} 873 874asmlinkage long sys_set_tid_address(int __user *tidptr) 875{ 876 current->clear_child_tid = tidptr; 877 --- 24 unchanged lines hidden (view full) --- 902 * parts of the process environment (as per the clone 903 * flags). The actual kick-off is left to the caller. 904 */ 905static struct task_struct *copy_process(unsigned long clone_flags, 906 unsigned long stack_start, 907 struct pt_regs *regs, 908 unsigned long stack_size, 909 int __user *child_tidptr, | 870 p->flags = new_flags; 871 clear_freeze_flag(p); 872} 873 874asmlinkage long sys_set_tid_address(int __user *tidptr) 875{ 876 current->clear_child_tid = tidptr; 877 --- 24 unchanged lines hidden (view full) --- 902 * parts of the process environment (as per the clone 903 * flags). The actual kick-off is left to the caller. 904 */ 905static struct task_struct *copy_process(unsigned long clone_flags, 906 unsigned long stack_start, 907 struct pt_regs *regs, 908 unsigned long stack_size, 909 int __user *child_tidptr, |
910 struct pid *pid) | 910 struct pid *pid, 911 int trace) |
911{ 912 int retval; 913 struct task_struct *p; 914 int cgroup_callbacks_done = 0; 915 916 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS)) 917 return ERR_PTR(-EINVAL); 918 --- 239 unchanged lines hidden (view full) --- 1158 p->exit_state = 0; 1159 1160 /* 1161 * Ok, make it visible to the rest of the system. 1162 * We dont wake it up yet. 1163 */ 1164 p->group_leader = p; 1165 INIT_LIST_HEAD(&p->thread_group); | 912{ 913 int retval; 914 struct task_struct *p; 915 int cgroup_callbacks_done = 0; 916 917 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS)) 918 return ERR_PTR(-EINVAL); 919 --- 239 unchanged lines hidden (view full) --- 1159 p->exit_state = 0; 1160 1161 /* 1162 * Ok, make it visible to the rest of the system. 1163 * We dont wake it up yet. 1164 */ 1165 p->group_leader = p; 1166 INIT_LIST_HEAD(&p->thread_group); |
1166 INIT_LIST_HEAD(&p->ptrace_entry); 1167 INIT_LIST_HEAD(&p->ptraced); | |
1168 1169 /* Now that the task is set up, run cgroup callbacks if 1170 * necessary. We need to run them before the task is visible 1171 * on the tasklist. */ 1172 cgroup_fork_callbacks(p); 1173 cgroup_callbacks_done = 1; 1174 1175 /* Need tasklist lock for parent etc handling! */ --- 14 unchanged lines hidden (view full) --- 1190 !cpu_online(task_cpu(p)))) 1191 set_task_cpu(p, smp_processor_id()); 1192 1193 /* CLONE_PARENT re-uses the old parent */ 1194 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) 1195 p->real_parent = current->real_parent; 1196 else 1197 p->real_parent = current; | 1167 1168 /* Now that the task is set up, run cgroup callbacks if 1169 * necessary. We need to run them before the task is visible 1170 * on the tasklist. */ 1171 cgroup_fork_callbacks(p); 1172 cgroup_callbacks_done = 1; 1173 1174 /* Need tasklist lock for parent etc handling! */ --- 14 unchanged lines hidden (view full) --- 1189 !cpu_online(task_cpu(p)))) 1190 set_task_cpu(p, smp_processor_id()); 1191 1192 /* CLONE_PARENT re-uses the old parent */ 1193 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) 1194 p->real_parent = current->real_parent; 1195 else 1196 p->real_parent = current; |
1198 p->parent = p->real_parent; | |
1199 1200 spin_lock(¤t->sighand->siglock); 1201 1202 /* 1203 * Process group and session signals need to be delivered to just the 1204 * parent before the fork or both the parent and the child after the 1205 * fork. Restart if a signal comes in before we add the new process to 1206 * it's process group. --- 25 unchanged lines hidden (view full) --- 1232 * for process CPU timers. 1233 */ 1234 p->it_prof_expires = jiffies_to_cputime(1); 1235 } 1236 } 1237 1238 if (likely(p->pid)) { 1239 list_add_tail(&p->sibling, &p->real_parent->children); | 1197 1198 spin_lock(¤t->sighand->siglock); 1199 1200 /* 1201 * Process group and session signals need to be delivered to just the 1202 * parent before the fork or both the parent and the child after the 1203 * fork. Restart if a signal comes in before we add the new process to 1204 * it's process group. --- 25 unchanged lines hidden (view full) --- 1230 * for process CPU timers. 1231 */ 1232 p->it_prof_expires = jiffies_to_cputime(1); 1233 } 1234 } 1235 1236 if (likely(p->pid)) { 1237 list_add_tail(&p->sibling, &p->real_parent->children); |
1240 if (unlikely(p->ptrace & PT_PTRACED)) 1241 __ptrace_link(p, current->parent); | 1238 tracehook_finish_clone(p, clone_flags, trace); |
1242 1243 if (thread_group_leader(p)) { 1244 if (clone_flags & CLONE_NEWPID) 1245 p->nsproxy->pid_ns->child_reaper = p; 1246 1247 p->signal->leader_pid = pid; 1248 p->signal->tty = current->signal->tty; 1249 set_task_pgrp(p, task_pgrp_nr(current)); --- 68 unchanged lines hidden (view full) --- 1318} 1319 1320struct task_struct * __cpuinit fork_idle(int cpu) 1321{ 1322 struct task_struct *task; 1323 struct pt_regs regs; 1324 1325 task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, | 1239 1240 if (thread_group_leader(p)) { 1241 if (clone_flags & CLONE_NEWPID) 1242 p->nsproxy->pid_ns->child_reaper = p; 1243 1244 p->signal->leader_pid = pid; 1245 p->signal->tty = current->signal->tty; 1246 set_task_pgrp(p, task_pgrp_nr(current)); --- 68 unchanged lines hidden (view full) --- 1315} 1316 1317struct task_struct * __cpuinit fork_idle(int cpu) 1318{ 1319 struct task_struct *task; 1320 struct pt_regs regs; 1321 1322 task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, |
1326 &init_struct_pid); | 1323 &init_struct_pid, 0); |
1327 if (!IS_ERR(task)) 1328 init_idle(task, cpu); 1329 1330 return task; 1331} 1332 | 1324 if (!IS_ERR(task)) 1325 init_idle(task, cpu); 1326 1327 return task; 1328} 1329 |
1333static int fork_traceflag(unsigned clone_flags) 1334{ 1335 if (clone_flags & CLONE_UNTRACED) 1336 return 0; 1337 else if (clone_flags & CLONE_VFORK) { 1338 if (current->ptrace & PT_TRACE_VFORK) 1339 return PTRACE_EVENT_VFORK; 1340 } else if ((clone_flags & CSIGNAL) != SIGCHLD) { 1341 if (current->ptrace & PT_TRACE_CLONE) 1342 return PTRACE_EVENT_CLONE; 1343 } else if (current->ptrace & PT_TRACE_FORK) 1344 return PTRACE_EVENT_FORK; 1345 1346 return 0; 1347} 1348 | |
1349/* 1350 * Ok, this is the main fork-routine. 1351 * 1352 * It copies the process, and if successful kick-starts 1353 * it and waits for it to finish using the VM if required. 1354 */ 1355long do_fork(unsigned long clone_flags, 1356 unsigned long stack_start, --- 18 unchanged lines hidden (view full) --- 1375 count--; 1376 printk(KERN_INFO "fork(): process `%s' used deprecated " 1377 "clone flags 0x%lx\n", 1378 get_task_comm(comm, current), 1379 clone_flags & CLONE_STOPPED); 1380 } 1381 } 1382 | 1330/* 1331 * Ok, this is the main fork-routine. 1332 * 1333 * It copies the process, and if successful kick-starts 1334 * it and waits for it to finish using the VM if required. 1335 */ 1336long do_fork(unsigned long clone_flags, 1337 unsigned long stack_start, --- 18 unchanged lines hidden (view full) --- 1356 count--; 1357 printk(KERN_INFO "fork(): process `%s' used deprecated " 1358 "clone flags 0x%lx\n", 1359 get_task_comm(comm, current), 1360 clone_flags & CLONE_STOPPED); 1361 } 1362 } 1363 |
1383 if (unlikely(current->ptrace)) { 1384 trace = fork_traceflag (clone_flags); 1385 if (trace) 1386 clone_flags |= CLONE_PTRACE; 1387 } | 1364 /* 1365 * When called from kernel_thread, don't do user tracing stuff. 1366 */ 1367 if (likely(user_mode(regs))) 1368 trace = tracehook_prepare_clone(clone_flags); |
1388 1389 p = copy_process(clone_flags, stack_start, regs, stack_size, | 1369 1370 p = copy_process(clone_flags, stack_start, regs, stack_size, |
1390 child_tidptr, NULL); | 1371 child_tidptr, NULL, trace); |
1391 /* 1392 * Do this prior waking up the new thread - the thread pointer 1393 * might get invalid after that point, if the thread exits quickly. 1394 */ 1395 if (!IS_ERR(p)) { 1396 struct completion vfork; 1397 1398 nr = task_pid_vnr(p); 1399 1400 if (clone_flags & CLONE_PARENT_SETTID) 1401 put_user(nr, parent_tidptr); 1402 1403 if (clone_flags & CLONE_VFORK) { 1404 p->vfork_done = &vfork; 1405 init_completion(&vfork); 1406 } 1407 | 1372 /* 1373 * Do this prior waking up the new thread - the thread pointer 1374 * might get invalid after that point, if the thread exits quickly. 1375 */ 1376 if (!IS_ERR(p)) { 1377 struct completion vfork; 1378 1379 nr = task_pid_vnr(p); 1380 1381 if (clone_flags & CLONE_PARENT_SETTID) 1382 put_user(nr, parent_tidptr); 1383 1384 if (clone_flags & CLONE_VFORK) { 1385 p->vfork_done = &vfork; 1386 init_completion(&vfork); 1387 } 1388 |
1408 if ((p->ptrace & PT_PTRACED) || (clone_flags & CLONE_STOPPED)) { | 1389 tracehook_report_clone(trace, regs, clone_flags, nr, p); 1390 1391 /* 1392 * We set PF_STARTING at creation in case tracing wants to 1393 * use this to distinguish a fully live task from one that 1394 * hasn't gotten to tracehook_report_clone() yet. Now we 1395 * clear it and set the child going. 1396 */ 1397 p->flags &= ~PF_STARTING; 1398 1399 if (unlikely(clone_flags & CLONE_STOPPED)) { |
1409 /* 1410 * We'll start up with an immediate SIGSTOP. 1411 */ 1412 sigaddset(&p->pending.signal, SIGSTOP); 1413 set_tsk_thread_flag(p, TIF_SIGPENDING); | 1400 /* 1401 * We'll start up with an immediate SIGSTOP. 1402 */ 1403 sigaddset(&p->pending.signal, SIGSTOP); 1404 set_tsk_thread_flag(p, TIF_SIGPENDING); |
1414 } 1415 1416 if (!(clone_flags & CLONE_STOPPED)) 1417 wake_up_new_task(p, clone_flags); 1418 else | |
1419 __set_task_state(p, TASK_STOPPED); | 1405 __set_task_state(p, TASK_STOPPED); |
1420 1421 if (unlikely (trace)) { 1422 current->ptrace_message = nr; 1423 ptrace_notify ((trace << 8) | SIGTRAP); | 1406 } else { 1407 wake_up_new_task(p, clone_flags); |
1424 } 1425 | 1408 } 1409 |
1410 tracehook_report_clone_complete(trace, regs, 1411 clone_flags, nr, p); 1412 |
|
1426 if (clone_flags & CLONE_VFORK) { 1427 freezer_do_not_count(); 1428 wait_for_completion(&vfork); 1429 freezer_count(); 1430 if (unlikely (current->ptrace & PT_TRACE_VFORK_DONE)) { 1431 current->ptrace_message = nr; 1432 ptrace_notify ((PTRACE_EVENT_VFORK_DONE << 8) | SIGTRAP); 1433 } --- 286 unchanged lines hidden --- | 1413 if (clone_flags & CLONE_VFORK) { 1414 freezer_do_not_count(); 1415 wait_for_completion(&vfork); 1416 freezer_count(); 1417 if (unlikely (current->ptrace & PT_TRACE_VFORK_DONE)) { 1418 current->ptrace_message = nr; 1419 ptrace_notify ((PTRACE_EVENT_VFORK_DONE << 8) | SIGTRAP); 1420 } --- 286 unchanged lines hidden --- |