进程创建时内存描述符处理

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; }

 

 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值