fork.c (a77aea92010acf54ad785047234418d5d68772e2) fork.c (3864601387cf4196371e3c1897fdffa5228296f9)
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

--- 45 unchanged lines hidden (view full) ---

54#include <linux/acct.h>
55#include <linux/tsacct_kern.h>
56#include <linux/cn_proc.h>
57#include <linux/freezer.h>
58#include <linux/delayacct.h>
59#include <linux/taskstats_kern.h>
60#include <linux/random.h>
61#include <linux/tty.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

--- 45 unchanged lines hidden (view full) ---

54#include <linux/acct.h>
55#include <linux/tsacct_kern.h>
56#include <linux/cn_proc.h>
57#include <linux/freezer.h>
58#include <linux/delayacct.h>
59#include <linux/taskstats_kern.h>
60#include <linux/random.h>
61#include <linux/tty.h>
62#include <linux/proc_fs.h>
63#include <linux/blkdev.h>
64#include <linux/fs_struct.h>
65#include <linux/magic.h>
66#include <linux/perf_event.h>
67#include <linux/posix-timers.h>
68#include <linux/user-return-notifier.h>
69#include <linux/oom.h>
70#include <linux/khugepaged.h>

--- 521 unchanged lines hidden (view full) ---

592 put_swap_token(mm);
593 if (mm->binfmt)
594 module_put(mm->binfmt->module);
595 mmdrop(mm);
596 }
597}
598EXPORT_SYMBOL_GPL(mmput);
599
62#include <linux/blkdev.h>
63#include <linux/fs_struct.h>
64#include <linux/magic.h>
65#include <linux/perf_event.h>
66#include <linux/posix-timers.h>
67#include <linux/user-return-notifier.h>
68#include <linux/oom.h>
69#include <linux/khugepaged.h>

--- 521 unchanged lines hidden (view full) ---

591 put_swap_token(mm);
592 if (mm->binfmt)
593 module_put(mm->binfmt->module);
594 mmdrop(mm);
595 }
596}
597EXPORT_SYMBOL_GPL(mmput);
598
599/*
600 * We added or removed a vma mapping the executable. The vmas are only mapped
601 * during exec and are not mapped with the mmap system call.
602 * Callers must hold down_write() on the mm's mmap_sem for these
603 */
604void added_exe_file_vma(struct mm_struct *mm)
605{
606 mm->num_exe_file_vmas++;
607}
608
609void removed_exe_file_vma(struct mm_struct *mm)
610{
611 mm->num_exe_file_vmas--;
612 if ((mm->num_exe_file_vmas == 0) && mm->exe_file){
613 fput(mm->exe_file);
614 mm->exe_file = NULL;
615 }
616
617}
618
619void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file)
620{
621 if (new_exe_file)
622 get_file(new_exe_file);
623 if (mm->exe_file)
624 fput(mm->exe_file);
625 mm->exe_file = new_exe_file;
626 mm->num_exe_file_vmas = 0;
627}
628
629struct file *get_mm_exe_file(struct mm_struct *mm)
630{
631 struct file *exe_file;
632
633 /* We need mmap_sem to protect against races with removal of
634 * VM_EXECUTABLE vmas */
635 down_read(&mm->mmap_sem);
636 exe_file = mm->exe_file;
637 if (exe_file)
638 get_file(exe_file);
639 up_read(&mm->mmap_sem);
640 return exe_file;
641}
642
643static void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm)
644{
645 /* It's safe to write the exe_file pointer without exe_file_lock because
646 * this is called during fork when the task is not yet in /proc */
647 newmm->exe_file = get_mm_exe_file(oldmm);
648}
649
600/**
601 * get_task_mm - acquire a reference to the task's mm
602 *
603 * Returns %NULL if the task has no mm. Checks PF_KTHREAD (meaning
604 * this kernel workthread has transiently adopted a user mm with use_mm,
605 * to do its AIO) is not set and if so returns a reference to it, after
606 * bumping up the use count. User must release the mm via mmput()
607 * after use. Typically used by /proc and ptrace.

--- 1118 unchanged lines hidden ---
650/**
651 * get_task_mm - acquire a reference to the task's mm
652 *
653 * Returns %NULL if the task has no mm. Checks PF_KTHREAD (meaning
654 * this kernel workthread has transiently adopted a user mm with use_mm,
655 * to do its AIO) is not set and if so returns a reference to it, after
656 * bumping up the use count. User must release the mm via mmput()
657 * after use. Typically used by /proc and ptrace.

--- 1118 unchanged lines hidden ---