Provide a function for copying init_mm. This function will be later used for setting a temporary mm.
Unified · Split
| @@ -76,6 +76,7 @@ extern void exit_itimers(struct signal_struct *); · 75 unmodified lines | ||
| 76 | 76 | extern long _do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *, unsigned long); |
| 77 | 77 | extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *); |
| 78 | 78 | struct task_struct *fork_idle(int); |
| 79 | +struct mm_struct *copy_init_mm(void); | |
| 79 | 80 | extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags); |
| 80 | 81 | extern long kernel_wait4(pid_t, int __user *, int, struct rusage *); |
| 81 | 82 | |
| @@ -1299,13 +1299,20 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm) · 1298 unmodified lines | ||
| 1299 | 1299 | complete_vfork_done(tsk); |
| 1300 | 1300 | } |
| 1301 | 1301 | |
| 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. | |
| 1305 | 1311 | */ |
| 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) | |
| 1307 | 1314 | { |
| 1308 | − struct mm_struct *mm, *oldmm = current->mm; | |
| 1315 | + struct mm_struct *mm; | |
| 1309 | 1316 | int err; |
| 1310 | 1317 | |
| 1311 | 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 | 1381 | retval = -ENOMEM; |
| 1375 | − mm = dup_mm(tsk); | |
| 1382 | + mm = dup_mm(tsk, current->mm); | |
| 1376 | 1383 | if (!mm) |
| 1377 | 1384 | goto fail_nomem; |
| 1378 | 1385 | |
| @@ -2187,6 +2194,11 @@ struct task_struct *fork_idle(int cpu) · 808 unmodified lines | ||
| 2187 | 2194 | return task; |
| 2188 | 2195 | } |
| 2189 | 2196 | |
| 2197 | +struct mm_struct *copy_init_mm(void) | |
| 2198 | +{ | |
| 2199 | + return dup_mm(NULL, &init_mm); | |
| 2200 | +} | |
| 2201 | + | |
| 2190 | 2202 | /* |
| 2191 | 2203 | * Ok, this is the main fork-routine. |
| 2192 | 2204 | * |