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
7676 extern long _do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *, unsigned long);
7777 extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *);
7878 struct task_struct *fork_idle(int);
79+struct mm_struct *copy_init_mm(void);
7980 extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
8081 extern long kernel_wait4(pid_t, int __user *, int, struct rusage *);
8182
kernel/fork.c+18−6
@@ -1299,13 +1299,20 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm) · 1298 unmodified lines
12991299 complete_vfork_done(tsk);
13001300 }
13011301
1302−/*
1303− * Allocate a new mm structure and copy contents from the
1304− * mm structure of the passed in task structure.
1302+/**
1303+ * dup_mm() - duplicates an existing mm 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.
13051311 */
1306−static struct mm_struct *dup_mm(struct task_struct *tsk)
1312+static struct mm_struct *dup_mm(struct task_struct *tsk,
1313+ struct mm_struct *oldmm)
13071314 {
1308− struct mm_struct *mm, *oldmm = current->mm;
1315+ struct mm_struct *mm;
13091316 int err;
13101317
13111318 mm = allocate_mm();
@@ -1372,7 +1379,7 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk) · 60 unmodified lines
13721379 }
13731380
13741381 retval = -ENOMEM;
1375− mm = dup_mm(tsk);
1382+ mm = dup_mm(tsk, current->mm);
13761383 if (!mm)
13771384 goto fail_nomem;
13781385
@@ -2187,6 +2194,11 @@ struct task_struct *fork_idle(int cpu) · 808 unmodified lines
21872194 return task;
21882195 }
21892196
2197+struct mm_struct *copy_init_mm(void)
2198+{
2199+ return dup_mm(NULL, &init_mm);
2200+}
2201+
21902202 /*
21912203 * Ok, this is the main fork-routine.
21922204 *

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