staticstructtask_struct*dup_task_struct(structtask_struct*orig){structtask_struct*tsk;structthread_info*ti;unsignedlong*stackend;interr;prepare_to_copy(orig);tsk=alloc_task_struct();if(!tsk)returnNULL;ti=alloc_thread_info(tsk);if(!ti){free_task_struct(tsk);returnNULL;err=arch_dup_task_struct(tsk,orig);if(err)gotoout;tsk->stack=ti;err=prop_local_init_single(&tsk->dirties);if(err)gotoout;setup_thread_stack(tsk,orig);stackend=end_of_stack(tsk);*stackend=STACK_END_MAGIC;/* for overflow detection */#ifdef CONFIG_CC_STACKPROTECTOR
tsk->stack_canary=get_random_int();#endif
/* One for us, one for whoever does the "release_task()"
(usually parent) */atomic_set(&tsk->usage,2);atomic_set(&tsk->fs_excl,0);#ifdef CONFIG_BLK_DEV_IO_TRACE
tsk->btrace_seq=0;#endif
tsk->splice_pipe=NULL;account_kernel_stack(ti,1);returntsk;out:free_thread_info(ti);free_task_struct(tsk);returnNULL;}