static int copy_mm(unsigned long clone_flags, struct task_struct *tsk) { struct mm_struct *mm, *oldmm; int retval;
tsk->min_flt = tsk->maj_flt = 0; tsk->nvcsw = tsk->nivcsw = 0; #ifdef CONFIG_DETECT_HUNG_TASK tsk->last_switch_count = tsk->nvcsw + tsk->nivcsw; #endif
tsk->mm = NULL; tsk->active_mm = NULL;
/* * Are we cloning a kernel thread? * * We need to steal a active VM for that.. */ oldmm = current->mm; if (!oldmm) return 0;
/* initialize the new vmacache entries */ vmacache_flush(tsk);
if (clone_flags & CLONE_VM) { atomic_inc(&oldmm->mm_users); mm = oldmm; goto good_mm; }
retval = -ENOMEM; mm = dup_mm(tsk); if (!mm) goto fail_nomem;
good_mm: tsk->mm = mm; tsk->active_mm = mm; return 0;
fail_nomem: return retval; }
/* * Allocate a new mm structure and copy contents from the * mm structure of the passed in task structure. */ static struct mm_struct *dup_mm(struct task_struct *tsk) { struct mm_struct *mm, *oldmm = current->mm; int err;
mm = allocate_mm(); if (!mm) goto fail_nomem;
memcpy(mm, oldmm, sizeof(*mm));
if (!mm_init(mm, tsk)) goto fail_nomem;
err = dup_mmap(mm, oldmm); if (err) goto free_pt;
mm->hiwater_rss = get_mm_rss(mm); mm->hiwater_vm = mm->total_vm;
if (mm->binfmt && !try_module_get(mm->binfmt->module)) goto free_pt;
return mm;
free_pt: /* don't put binfmt in mmput, we haven't got module yet */ mm->binfmt = NULL; mmput(mm);
fail_nomem: return NULL; }
进程创建时内存描述符处理
最新推荐文章于 2023-08-22 20:26:39 发布