History

fork: Provide a function for copying init_mm

Provide a function for copying init_mm. This function will be later used for setting a temporary mm.

Nadav Amit committed 7 years ago

Commit 13585fa1 parent aad42dd2 files · +19 −6Browse files

Unified · Split

2 files
  1. include/linux/sched/task.h +1 −0
  2. kernel/fork.c +18 −6
include/linux/sched/task.h+1−0
@@ -76,6 +76,7 @@ extern void exit_itimers(struct signal_struct *); · 75 unmodified lines
76extern long _do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *, unsigned long);76extern long _do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *, unsigned long);
77extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *);77extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *);
78struct task_struct *fork_idle(int);78struct task_struct *fork_idle(int);
79struct mm_struct *copy_init_mm(void);
79extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);80extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
80extern long kernel_wait4(pid_t, int __user *, int, struct rusage *);81extern long kernel_wait4(pid_t, int __user *, int, struct rusage *);
81 82
kernel/fork.c+18−6
@@ -1299,13 +1299,20 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm) · 1298 unmodified lines
1299 complete_vfork_done(tsk);1299 complete_vfork_done(tsk);
1300}1300}
1301 1301
1302/*1302/**
1303 * Allocate a new mm structure and copy contents from the1303 * dup_mm() - duplicates an existing mm structure
1304 * mm structure of the passed in task structure.1304 * @tsk: the task_struct with which the new mm will be associated.
1305 * @oldmm: the mm to duplicate.
1306 *
1307 * Allocates a new mm structure and duplicates the provided @oldmm structure
1308 * content into it.
1309 *
1310 * Return: the duplicated mm or NULL on failure.
1305 */1311 */
1306static struct mm_struct *dup_mm(struct task_struct *tsk)1312static struct mm_struct *dup_mm(struct task_struct *tsk,
1313 struct mm_struct *oldmm)
1307{1314{
1308 struct mm_struct *mm, *oldmm = current->mm;1315 struct mm_struct *mm;
1309 int err;1316 int err;
1310 1317
1311 mm = allocate_mm();1318 mm = allocate_mm();
@@ -1372,7 +1379,7 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk) · 60 unmodified lines
1372 }1379 }
1373 1380
1374 retval = -ENOMEM;1381 retval = -ENOMEM;
1375 mm = dup_mm(tsk);1382 mm = dup_mm(tsk, current->mm);
1376 if (!mm)1383 if (!mm)
1377 goto fail_nomem;1384 goto fail_nomem;
1378 1385
@@ -2187,6 +2194,11 @@ struct task_struct *fork_idle(int cpu) · 808 unmodified lines
2187 return task;2194 return task;
2188}2195}
2189 2196
2197struct mm_struct *copy_init_mm(void)
2198{
2199 return dup_mm(NULL, &init_mm);
2200}
2201
2190/*2202/*
2191 * Ok, this is the main fork-routine.2203 * Ok, this is the main fork-routine.
2192 *2204 *

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t