fork.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. /*
  2. * linux/kernel/fork.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. /*
  7. * 'fork.c' contains the help-routines for the 'fork' system call
  8. * (see also entry.S and others).
  9. * Fork is rather simple, once you get the hang of it, but the memory
  10. * management can be a bitch. See 'mm/memory.c': 'copy_page_range()'
  11. */
  12. #include <linux/config.h>
  13. #include <linux/slab.h>
  14. #include <linux/init.h>
  15. #include <linux/unistd.h>
  16. #include <linux/smp_lock.h>
  17. #include <linux/module.h>
  18. #include <linux/vmalloc.h>
  19. #include <linux/completion.h>
  20. #include <linux/namespace.h>
  21. #include <linux/personality.h>
  22. #include <linux/mempolicy.h>
  23. #include <linux/sem.h>
  24. #include <linux/file.h>
  25. #include <linux/key.h>
  26. #include <linux/binfmts.h>
  27. #include <linux/mman.h>
  28. #include <linux/fs.h>
  29. #include <linux/cpu.h>
  30. #include <linux/cpuset.h>
  31. #include <linux/security.h>
  32. #include <linux/swap.h>
  33. #include <linux/syscalls.h>
  34. #include <linux/jiffies.h>
  35. #include <linux/futex.h>
  36. #include <linux/ptrace.h>
  37. #include <linux/mount.h>
  38. #include <linux/audit.h>
  39. #include <linux/profile.h>
  40. #include <linux/rmap.h>
  41. #include <linux/acct.h>
  42. #include <asm/pgtable.h>
  43. #include <asm/pgalloc.h>
  44. #include <asm/uaccess.h>
  45. #include <asm/mmu_context.h>
  46. #include <asm/cacheflush.h>
  47. #include <asm/tlbflush.h>
  48. /*
  49. * Protected counters by write_lock_irq(&tasklist_lock)
  50. */
  51. unsigned long total_forks; /* Handle normal Linux uptimes. */
  52. int nr_threads; /* The idle threads do not count.. */
  53. int max_threads; /* tunable limit on nr_threads */
  54. DEFINE_PER_CPU(unsigned long, process_counts) = 0;
  55. __cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */
  56. EXPORT_SYMBOL(tasklist_lock);
  57. int nr_processes(void)
  58. {
  59. int cpu;
  60. int total = 0;
  61. for_each_online_cpu(cpu)
  62. total += per_cpu(process_counts, cpu);
  63. return total;
  64. }
  65. #ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
  66. # define alloc_task_struct() kmem_cache_alloc(task_struct_cachep, GFP_KERNEL)
  67. # define free_task_struct(tsk) kmem_cache_free(task_struct_cachep, (tsk))
  68. static kmem_cache_t *task_struct_cachep;
  69. #endif
  70. /* SLAB cache for signal_struct structures (tsk->signal) */
  71. kmem_cache_t *signal_cachep;
  72. /* SLAB cache for sighand_struct structures (tsk->sighand) */
  73. kmem_cache_t *sighand_cachep;
  74. /* SLAB cache for files_struct structures (tsk->files) */
  75. kmem_cache_t *files_cachep;
  76. /* SLAB cache for fs_struct structures (tsk->fs) */
  77. kmem_cache_t *fs_cachep;
  78. /* SLAB cache for vm_area_struct structures */
  79. kmem_cache_t *vm_area_cachep;
  80. /* SLAB cache for mm_struct structures (tsk->mm) */
  81. static kmem_cache_t *mm_cachep;
  82. void free_task(struct task_struct *tsk)
  83. {
  84. free_thread_info(tsk->thread_info);
  85. free_task_struct(tsk);
  86. }
  87. EXPORT_SYMBOL(free_task);
  88. void __put_task_struct(struct task_struct *tsk)
  89. {
  90. WARN_ON(!(tsk->exit_state & (EXIT_DEAD | EXIT_ZOMBIE)));
  91. WARN_ON(atomic_read(&tsk->usage));
  92. WARN_ON(tsk == current);
  93. if (unlikely(tsk->audit_context))
  94. audit_free(tsk);
  95. security_task_free(tsk);
  96. free_uid(tsk->user);
  97. put_group_info(tsk->group_info);
  98. if (!profile_handoff_task(tsk))
  99. free_task(tsk);
  100. }
  101. void __init fork_init(unsigned long mempages)
  102. {
  103. #ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
  104. #ifndef ARCH_MIN_TASKALIGN
  105. #define ARCH_MIN_TASKALIGN L1_CACHE_BYTES
  106. #endif
  107. /* create a slab on which task_structs can be allocated */
  108. task_struct_cachep =
  109. kmem_cache_create("task_struct", sizeof(struct task_struct),
  110. ARCH_MIN_TASKALIGN, SLAB_PANIC, NULL, NULL);
  111. #endif
  112. /*
  113. * The default maximum number of threads is set to a safe
  114. * value: the thread structures can take up at most half
  115. * of memory.
  116. */
  117. max_threads = mempages / (8 * THREAD_SIZE / PAGE_SIZE);
  118. /*
  119. * we need to allow at least 20 threads to boot a system
  120. */
  121. if(max_threads < 20)
  122. max_threads = 20;
  123. init_task.signal->rlim[RLIMIT_NPROC].rlim_cur = max_threads/2;
  124. init_task.signal->rlim[RLIMIT_NPROC].rlim_max = max_threads/2;
  125. init_task.signal->rlim[RLIMIT_SIGPENDING] =
  126. init_task.signal->rlim[RLIMIT_NPROC];
  127. }
  128. static struct task_struct *dup_task_struct(struct task_struct *orig)
  129. {
  130. struct task_struct *tsk;
  131. struct thread_info *ti;
  132. prepare_to_copy(orig);
  133. tsk = alloc_task_struct();
  134. if (!tsk)
  135. return NULL;
  136. ti = alloc_thread_info(tsk);
  137. if (!ti) {
  138. free_task_struct(tsk);
  139. return NULL;
  140. }
  141. *ti = *orig->thread_info;
  142. *tsk = *orig;
  143. tsk->thread_info = ti;
  144. ti->task = tsk;
  145. /* One for us, one for whoever does the "release_task()" (usually parent) */
  146. atomic_set(&tsk->usage,2);
  147. return tsk;
  148. }
  149. #ifdef CONFIG_MMU
  150. static inline int dup_mmap(struct mm_struct * mm, struct mm_struct * oldmm)
  151. {
  152. struct vm_area_struct * mpnt, *tmp, **pprev;
  153. struct rb_node **rb_link, *rb_parent;
  154. int retval;
  155. unsigned long charge;
  156. struct mempolicy *pol;
  157. down_write(&oldmm->mmap_sem);
  158. flush_cache_mm(current->mm);
  159. mm->locked_vm = 0;
  160. mm->mmap = NULL;
  161. mm->mmap_cache = NULL;
  162. mm->free_area_cache = oldmm->mmap_base;
  163. mm->cached_hole_size = ~0UL;
  164. mm->map_count = 0;
  165. set_mm_counter(mm, rss, 0);
  166. set_mm_counter(mm, anon_rss, 0);
  167. cpus_clear(mm->cpu_vm_mask);
  168. mm->mm_rb = RB_ROOT;
  169. rb_link = &mm->mm_rb.rb_node;
  170. rb_parent = NULL;
  171. pprev = &mm->mmap;
  172. for (mpnt = current->mm->mmap ; mpnt ; mpnt = mpnt->vm_next) {
  173. struct file *file;
  174. if (mpnt->vm_flags & VM_DONTCOPY) {
  175. __vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
  176. -vma_pages(mpnt));
  177. continue;
  178. }
  179. charge = 0;
  180. if (mpnt->vm_flags & VM_ACCOUNT) {
  181. unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
  182. if (security_vm_enough_memory(len))
  183. goto fail_nomem;
  184. charge = len;
  185. }
  186. tmp = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
  187. if (!tmp)
  188. goto fail_nomem;
  189. *tmp = *mpnt;
  190. pol = mpol_copy(vma_policy(mpnt));
  191. retval = PTR_ERR(pol);
  192. if (IS_ERR(pol))
  193. goto fail_nomem_policy;
  194. vma_set_policy(tmp, pol);
  195. tmp->vm_flags &= ~VM_LOCKED;
  196. tmp->vm_mm = mm;
  197. tmp->vm_next = NULL;
  198. anon_vma_link(tmp);
  199. file = tmp->vm_file;
  200. if (file) {
  201. struct inode *inode = file->f_dentry->d_inode;
  202. get_file(file);
  203. if (tmp->vm_flags & VM_DENYWRITE)
  204. atomic_dec(&inode->i_writecount);
  205. /* insert tmp into the share list, just after mpnt */
  206. spin_lock(&file->f_mapping->i_mmap_lock);
  207. tmp->vm_truncate_count = mpnt->vm_truncate_count;
  208. flush_dcache_mmap_lock(file->f_mapping);
  209. vma_prio_tree_add(tmp, mpnt);
  210. flush_dcache_mmap_unlock(file->f_mapping);
  211. spin_unlock(&file->f_mapping->i_mmap_lock);
  212. }
  213. /*
  214. * Link in the new vma and copy the page table entries:
  215. * link in first so that swapoff can see swap entries.
  216. * Note that, exceptionally, here the vma is inserted
  217. * without holding mm->mmap_sem.
  218. */
  219. spin_lock(&mm->page_table_lock);
  220. *pprev = tmp;
  221. pprev = &tmp->vm_next;
  222. __vma_link_rb(mm, tmp, rb_link, rb_parent);
  223. rb_link = &tmp->vm_rb.rb_right;
  224. rb_parent = &tmp->vm_rb;
  225. mm->map_count++;
  226. retval = copy_page_range(mm, current->mm, tmp);
  227. spin_unlock(&mm->page_table_lock);
  228. if (tmp->vm_ops && tmp->vm_ops->open)
  229. tmp->vm_ops->open(tmp);
  230. if (retval)
  231. goto out;
  232. }
  233. retval = 0;
  234. out:
  235. flush_tlb_mm(current->mm);
  236. up_write(&oldmm->mmap_sem);
  237. return retval;
  238. fail_nomem_policy:
  239. kmem_cache_free(vm_area_cachep, tmp);
  240. fail_nomem:
  241. retval = -ENOMEM;
  242. vm_unacct_memory(charge);
  243. goto out;
  244. }
  245. static inline int mm_alloc_pgd(struct mm_struct * mm)
  246. {
  247. mm->pgd = pgd_alloc(mm);
  248. if (unlikely(!mm->pgd))
  249. return -ENOMEM;
  250. return 0;
  251. }
  252. static inline void mm_free_pgd(struct mm_struct * mm)
  253. {
  254. pgd_free(mm->pgd);
  255. }
  256. #else
  257. #define dup_mmap(mm, oldmm) (0)
  258. #define mm_alloc_pgd(mm) (0)
  259. #define mm_free_pgd(mm)
  260. #endif /* CONFIG_MMU */
  261. __cacheline_aligned_in_smp DEFINE_SPINLOCK(mmlist_lock);
  262. #define allocate_mm() (kmem_cache_alloc(mm_cachep, SLAB_KERNEL))
  263. #define free_mm(mm) (kmem_cache_free(mm_cachep, (mm)))
  264. #include <linux/init_task.h>
  265. static struct mm_struct * mm_init(struct mm_struct * mm)
  266. {
  267. atomic_set(&mm->mm_users, 1);
  268. atomic_set(&mm->mm_count, 1);
  269. init_rwsem(&mm->mmap_sem);
  270. INIT_LIST_HEAD(&mm->mmlist);
  271. mm->core_waiters = 0;
  272. mm->nr_ptes = 0;
  273. spin_lock_init(&mm->page_table_lock);
  274. rwlock_init(&mm->ioctx_list_lock);
  275. mm->ioctx_list = NULL;
  276. mm->default_kioctx = (struct kioctx)INIT_KIOCTX(mm->default_kioctx, *mm);
  277. mm->free_area_cache = TASK_UNMAPPED_BASE;
  278. mm->cached_hole_size = ~0UL;
  279. if (likely(!mm_alloc_pgd(mm))) {
  280. mm->def_flags = 0;
  281. return mm;
  282. }
  283. free_mm(mm);
  284. return NULL;
  285. }
  286. /*
  287. * Allocate and initialize an mm_struct.
  288. */
  289. struct mm_struct * mm_alloc(void)
  290. {
  291. struct mm_struct * mm;
  292. mm = allocate_mm();
  293. if (mm) {
  294. memset(mm, 0, sizeof(*mm));
  295. mm = mm_init(mm);
  296. }
  297. return mm;
  298. }
  299. /*
  300. * Called when the last reference to the mm
  301. * is dropped: either by a lazy thread or by
  302. * mmput. Free the page directory and the mm.
  303. */
  304. void fastcall __mmdrop(struct mm_struct *mm)
  305. {
  306. BUG_ON(mm == &init_mm);
  307. mm_free_pgd(mm);
  308. destroy_context(mm);
  309. free_mm(mm);
  310. }
  311. /*
  312. * Decrement the use count and release all resources for an mm.
  313. */
  314. void mmput(struct mm_struct *mm)
  315. {
  316. if (atomic_dec_and_test(&mm->mm_users)) {
  317. exit_aio(mm);
  318. exit_mmap(mm);
  319. if (!list_empty(&mm->mmlist)) {
  320. spin_lock(&mmlist_lock);
  321. list_del(&mm->mmlist);
  322. spin_unlock(&mmlist_lock);
  323. }
  324. put_swap_token(mm);
  325. mmdrop(mm);
  326. }
  327. }
  328. EXPORT_SYMBOL_GPL(mmput);
  329. /**
  330. * get_task_mm - acquire a reference to the task's mm
  331. *
  332. * Returns %NULL if the task has no mm. Checks PF_BORROWED_MM (meaning
  333. * this kernel workthread has transiently adopted a user mm with use_mm,
  334. * to do its AIO) is not set and if so returns a reference to it, after
  335. * bumping up the use count. User must release the mm via mmput()
  336. * after use. Typically used by /proc and ptrace.
  337. */
  338. struct mm_struct *get_task_mm(struct task_struct *task)
  339. {
  340. struct mm_struct *mm;
  341. task_lock(task);
  342. mm = task->mm;
  343. if (mm) {
  344. if (task->flags & PF_BORROWED_MM)
  345. mm = NULL;
  346. else
  347. atomic_inc(&mm->mm_users);
  348. }
  349. task_unlock(task);
  350. return mm;
  351. }
  352. EXPORT_SYMBOL_GPL(get_task_mm);
  353. /* Please note the differences between mmput and mm_release.
  354. * mmput is called whenever we stop holding onto a mm_struct,
  355. * error success whatever.
  356. *
  357. * mm_release is called after a mm_struct has been removed
  358. * from the current process.
  359. *
  360. * This difference is important for error handling, when we
  361. * only half set up a mm_struct for a new process and need to restore
  362. * the old one. Because we mmput the new mm_struct before
  363. * restoring the old one. . .
  364. * Eric Biederman 10 January 1998
  365. */
  366. void mm_release(struct task_struct *tsk, struct mm_struct *mm)
  367. {
  368. struct completion *vfork_done = tsk->vfork_done;
  369. /* Get rid of any cached register state */
  370. deactivate_mm(tsk, mm);
  371. /* notify parent sleeping on vfork() */
  372. if (vfork_done) {
  373. tsk->vfork_done = NULL;
  374. complete(vfork_done);
  375. }
  376. if (tsk->clear_child_tid && atomic_read(&mm->mm_users) > 1) {
  377. u32 __user * tidptr = tsk->clear_child_tid;
  378. tsk->clear_child_tid = NULL;
  379. /*
  380. * We don't check the error code - if userspace has
  381. * not set up a proper pointer then tough luck.
  382. */
  383. put_user(0, tidptr);
  384. sys_futex(tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
  385. }
  386. }
  387. static int copy_mm(unsigned long clone_flags, struct task_struct * tsk)
  388. {
  389. struct mm_struct * mm, *oldmm;
  390. int retval;
  391. tsk->min_flt = tsk->maj_flt = 0;
  392. tsk->nvcsw = tsk->nivcsw = 0;
  393. tsk->mm = NULL;
  394. tsk->active_mm = NULL;
  395. /*
  396. * Are we cloning a kernel thread?
  397. *
  398. * We need to steal a active VM for that..
  399. */
  400. oldmm = current->mm;
  401. if (!oldmm)
  402. return 0;
  403. if (clone_flags & CLONE_VM) {
  404. atomic_inc(&oldmm->mm_users);
  405. mm = oldmm;
  406. /*
  407. * There are cases where the PTL is held to ensure no
  408. * new threads start up in user mode using an mm, which
  409. * allows optimizing out ipis; the tlb_gather_mmu code
  410. * is an example.
  411. */
  412. spin_unlock_wait(&oldmm->page_table_lock);
  413. goto good_mm;
  414. }
  415. retval = -ENOMEM;
  416. mm = allocate_mm();
  417. if (!mm)
  418. goto fail_nomem;
  419. /* Copy the current MM stuff.. */
  420. memcpy(mm, oldmm, sizeof(*mm));
  421. if (!mm_init(mm))
  422. goto fail_nomem;
  423. if (init_new_context(tsk,mm))
  424. goto fail_nocontext;
  425. retval = dup_mmap(mm, oldmm);
  426. if (retval)
  427. goto free_pt;
  428. mm->hiwater_rss = get_mm_counter(mm,rss);
  429. mm->hiwater_vm = mm->total_vm;
  430. good_mm:
  431. tsk->mm = mm;
  432. tsk->active_mm = mm;
  433. return 0;
  434. free_pt:
  435. mmput(mm);
  436. fail_nomem:
  437. return retval;
  438. fail_nocontext:
  439. /*
  440. * If init_new_context() failed, we cannot use mmput() to free the mm
  441. * because it calls destroy_context()
  442. */
  443. mm_free_pgd(mm);
  444. free_mm(mm);
  445. return retval;
  446. }
  447. static inline struct fs_struct *__copy_fs_struct(struct fs_struct *old)
  448. {
  449. struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
  450. /* We don't need to lock fs - think why ;-) */
  451. if (fs) {
  452. atomic_set(&fs->count, 1);
  453. rwlock_init(&fs->lock);
  454. fs->umask = old->umask;
  455. read_lock(&old->lock);
  456. fs->rootmnt = mntget(old->rootmnt);
  457. fs->root = dget(old->root);
  458. fs->pwdmnt = mntget(old->pwdmnt);
  459. fs->pwd = dget(old->pwd);
  460. if (old->altroot) {
  461. fs->altrootmnt = mntget(old->altrootmnt);
  462. fs->altroot = dget(old->altroot);
  463. } else {
  464. fs->altrootmnt = NULL;
  465. fs->altroot = NULL;
  466. }
  467. read_unlock(&old->lock);
  468. }
  469. return fs;
  470. }
  471. struct fs_struct *copy_fs_struct(struct fs_struct *old)
  472. {
  473. return __copy_fs_struct(old);
  474. }
  475. EXPORT_SYMBOL_GPL(copy_fs_struct);
  476. static inline int copy_fs(unsigned long clone_flags, struct task_struct * tsk)
  477. {
  478. if (clone_flags & CLONE_FS) {
  479. atomic_inc(&current->fs->count);
  480. return 0;
  481. }
  482. tsk->fs = __copy_fs_struct(current->fs);
  483. if (!tsk->fs)
  484. return -ENOMEM;
  485. return 0;
  486. }
  487. static int count_open_files(struct files_struct *files, int size)
  488. {
  489. int i;
  490. /* Find the last open fd */
  491. for (i = size/(8*sizeof(long)); i > 0; ) {
  492. if (files->open_fds->fds_bits[--i])
  493. break;
  494. }
  495. i = (i+1) * 8 * sizeof(long);
  496. return i;
  497. }
  498. static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
  499. {
  500. struct files_struct *oldf, *newf;
  501. struct file **old_fds, **new_fds;
  502. int open_files, size, i, error = 0, expand;
  503. /*
  504. * A background process may not have any files ...
  505. */
  506. oldf = current->files;
  507. if (!oldf)
  508. goto out;
  509. if (clone_flags & CLONE_FILES) {
  510. atomic_inc(&oldf->count);
  511. goto out;
  512. }
  513. /*
  514. * Note: we may be using current for both targets (See exec.c)
  515. * This works because we cache current->files (old) as oldf. Don't
  516. * break this.
  517. */
  518. tsk->files = NULL;
  519. error = -ENOMEM;
  520. newf = kmem_cache_alloc(files_cachep, SLAB_KERNEL);
  521. if (!newf)
  522. goto out;
  523. atomic_set(&newf->count, 1);
  524. spin_lock_init(&newf->file_lock);
  525. newf->next_fd = 0;
  526. newf->max_fds = NR_OPEN_DEFAULT;
  527. newf->max_fdset = __FD_SETSIZE;
  528. newf->close_on_exec = &newf->close_on_exec_init;
  529. newf->open_fds = &newf->open_fds_init;
  530. newf->fd = &newf->fd_array[0];
  531. spin_lock(&oldf->file_lock);
  532. open_files = count_open_files(oldf, oldf->max_fdset);
  533. expand = 0;
  534. /*
  535. * Check whether we need to allocate a larger fd array or fd set.
  536. * Note: we're not a clone task, so the open count won't change.
  537. */
  538. if (open_files > newf->max_fdset) {
  539. newf->max_fdset = 0;
  540. expand = 1;
  541. }
  542. if (open_files > newf->max_fds) {
  543. newf->max_fds = 0;
  544. expand = 1;
  545. }
  546. /* if the old fdset gets grown now, we'll only copy up to "size" fds */
  547. if (expand) {
  548. spin_unlock(&oldf->file_lock);
  549. spin_lock(&newf->file_lock);
  550. error = expand_files(newf, open_files-1);
  551. spin_unlock(&newf->file_lock);
  552. if (error < 0)
  553. goto out_release;
  554. spin_lock(&oldf->file_lock);
  555. }
  556. old_fds = oldf->fd;
  557. new_fds = newf->fd;
  558. memcpy(newf->open_fds->fds_bits, oldf->open_fds->fds_bits, open_files/8);
  559. memcpy(newf->close_on_exec->fds_bits, oldf->close_on_exec->fds_bits, open_files/8);
  560. for (i = open_files; i != 0; i--) {
  561. struct file *f = *old_fds++;
  562. if (f) {
  563. get_file(f);
  564. } else {
  565. /*
  566. * The fd may be claimed in the fd bitmap but not yet
  567. * instantiated in the files array if a sibling thread
  568. * is partway through open(). So make sure that this
  569. * fd is available to the new process.
  570. */
  571. FD_CLR(open_files - i, newf->open_fds);
  572. }
  573. *new_fds++ = f;
  574. }
  575. spin_unlock(&oldf->file_lock);
  576. /* compute the remainder to be cleared */
  577. size = (newf->max_fds - open_files) * sizeof(struct file *);
  578. /* This is long word aligned thus could use a optimized version */
  579. memset(new_fds, 0, size);
  580. if (newf->max_fdset > open_files) {
  581. int left = (newf->max_fdset-open_files)/8;
  582. int start = open_files / (8 * sizeof(unsigned long));
  583. memset(&newf->open_fds->fds_bits[start], 0, left);
  584. memset(&newf->close_on_exec->fds_bits[start], 0, left);
  585. }
  586. tsk->files = newf;
  587. error = 0;
  588. out:
  589. return error;
  590. out_release:
  591. free_fdset (newf->close_on_exec, newf->max_fdset);
  592. free_fdset (newf->open_fds, newf->max_fdset);
  593. free_fd_array(newf->fd, newf->max_fds);
  594. kmem_cache_free(files_cachep, newf);
  595. goto out;
  596. }
  597. /*
  598. * Helper to unshare the files of the current task.
  599. * We don't want to expose copy_files internals to
  600. * the exec layer of the kernel.
  601. */
  602. int unshare_files(void)
  603. {
  604. struct files_struct *files = current->files;
  605. int rc;
  606. if(!files)
  607. BUG();
  608. /* This can race but the race causes us to copy when we don't
  609. need to and drop the copy */
  610. if(atomic_read(&files->count) == 1)
  611. {
  612. atomic_inc(&files->count);
  613. return 0;
  614. }
  615. rc = copy_files(0, current);
  616. if(rc)
  617. current->files = files;
  618. return rc;
  619. }
  620. EXPORT_SYMBOL(unshare_files);
  621. static inline int copy_sighand(unsigned long clone_flags, struct task_struct * tsk)
  622. {
  623. struct sighand_struct *sig;
  624. if (clone_flags & (CLONE_SIGHAND | CLONE_THREAD)) {
  625. atomic_inc(&current->sighand->count);
  626. return 0;
  627. }
  628. sig = kmem_cache_alloc(sighand_cachep, GFP_KERNEL);
  629. tsk->sighand = sig;
  630. if (!sig)
  631. return -ENOMEM;
  632. spin_lock_init(&sig->siglock);
  633. atomic_set(&sig->count, 1);
  634. memcpy(sig->action, current->sighand->action, sizeof(sig->action));
  635. return 0;
  636. }
  637. static inline int copy_signal(unsigned long clone_flags, struct task_struct * tsk)
  638. {
  639. struct signal_struct *sig;
  640. int ret;
  641. if (clone_flags & CLONE_THREAD) {
  642. atomic_inc(&current->signal->count);
  643. atomic_inc(&current->signal->live);
  644. return 0;
  645. }
  646. sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
  647. tsk->signal = sig;
  648. if (!sig)
  649. return -ENOMEM;
  650. ret = copy_thread_group_keys(tsk);
  651. if (ret < 0) {
  652. kmem_cache_free(signal_cachep, sig);
  653. return ret;
  654. }
  655. atomic_set(&sig->count, 1);
  656. atomic_set(&sig->live, 1);
  657. init_waitqueue_head(&sig->wait_chldexit);
  658. sig->flags = 0;
  659. sig->group_exit_code = 0;
  660. sig->group_exit_task = NULL;
  661. sig->group_stop_count = 0;
  662. sig->curr_target = NULL;
  663. init_sigpending(&sig->shared_pending);
  664. INIT_LIST_HEAD(&sig->posix_timers);
  665. sig->it_real_value = sig->it_real_incr = 0;
  666. sig->real_timer.function = it_real_fn;
  667. sig->real_timer.data = (unsigned long) tsk;
  668. init_timer(&sig->real_timer);
  669. sig->it_virt_expires = cputime_zero;
  670. sig->it_virt_incr = cputime_zero;
  671. sig->it_prof_expires = cputime_zero;
  672. sig->it_prof_incr = cputime_zero;
  673. sig->tty = current->signal->tty;
  674. sig->pgrp = process_group(current);
  675. sig->session = current->signal->session;
  676. sig->leader = 0; /* session leadership doesn't inherit */
  677. sig->tty_old_pgrp = 0;
  678. sig->utime = sig->stime = sig->cutime = sig->cstime = cputime_zero;
  679. sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0;
  680. sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0;
  681. sig->sched_time = 0;
  682. INIT_LIST_HEAD(&sig->cpu_timers[0]);
  683. INIT_LIST_HEAD(&sig->cpu_timers[1]);
  684. INIT_LIST_HEAD(&sig->cpu_timers[2]);
  685. task_lock(current->group_leader);
  686. memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim);
  687. task_unlock(current->group_leader);
  688. if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) {
  689. /*
  690. * New sole thread in the process gets an expiry time
  691. * of the whole CPU time limit.
  692. */
  693. tsk->it_prof_expires =
  694. secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur);
  695. }
  696. return 0;
  697. }
  698. static inline void copy_flags(unsigned long clone_flags, struct task_struct *p)
  699. {
  700. unsigned long new_flags = p->flags;
  701. new_flags &= ~PF_SUPERPRIV;
  702. new_flags |= PF_FORKNOEXEC;
  703. if (!(clone_flags & CLONE_PTRACE))
  704. p->ptrace = 0;
  705. p->flags = new_flags;
  706. }
  707. asmlinkage long sys_set_tid_address(int __user *tidptr)
  708. {
  709. current->clear_child_tid = tidptr;
  710. return current->pid;
  711. }
  712. /*
  713. * This creates a new process as a copy of the old one,
  714. * but does not actually start it yet.
  715. *
  716. * It copies the registers, and all the appropriate
  717. * parts of the process environment (as per the clone
  718. * flags). The actual kick-off is left to the caller.
  719. */
  720. static task_t *copy_process(unsigned long clone_flags,
  721. unsigned long stack_start,
  722. struct pt_regs *regs,
  723. unsigned long stack_size,
  724. int __user *parent_tidptr,
  725. int __user *child_tidptr,
  726. int pid)
  727. {
  728. int retval;
  729. struct task_struct *p = NULL;
  730. if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
  731. return ERR_PTR(-EINVAL);
  732. /*
  733. * Thread groups must share signals as well, and detached threads
  734. * can only be started up within the thread group.
  735. */
  736. if ((clone_flags & CLONE_THREAD) && !(clone_flags & CLONE_SIGHAND))
  737. return ERR_PTR(-EINVAL);
  738. /*
  739. * Shared signal handlers imply shared VM. By way of the above,
  740. * thread groups also imply shared VM. Blocking this case allows
  741. * for various simplifications in other code.
  742. */
  743. if ((clone_flags & CLONE_SIGHAND) && !(clone_flags & CLONE_VM))
  744. return ERR_PTR(-EINVAL);
  745. retval = security_task_create(clone_flags);
  746. if (retval)
  747. goto fork_out;
  748. retval = -ENOMEM;
  749. p = dup_task_struct(current);
  750. if (!p)
  751. goto fork_out;
  752. retval = -EAGAIN;
  753. if (atomic_read(&p->user->processes) >=
  754. p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
  755. if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
  756. p->user != &root_user)
  757. goto bad_fork_free;
  758. }
  759. atomic_inc(&p->user->__count);
  760. atomic_inc(&p->user->processes);
  761. get_group_info(p->group_info);
  762. /*
  763. * If multiple threads are within copy_process(), then this check
  764. * triggers too late. This doesn't hurt, the check is only there
  765. * to stop root fork bombs.
  766. */
  767. if (nr_threads >= max_threads)
  768. goto bad_fork_cleanup_count;
  769. if (!try_module_get(p->thread_info->exec_domain->module))
  770. goto bad_fork_cleanup_count;
  771. if (p->binfmt && !try_module_get(p->binfmt->module))
  772. goto bad_fork_cleanup_put_domain;
  773. p->did_exec = 0;
  774. copy_flags(clone_flags, p);
  775. p->pid = pid;
  776. retval = -EFAULT;
  777. if (clone_flags & CLONE_PARENT_SETTID)
  778. if (put_user(p->pid, parent_tidptr))
  779. goto bad_fork_cleanup;
  780. p->proc_dentry = NULL;
  781. INIT_LIST_HEAD(&p->children);
  782. INIT_LIST_HEAD(&p->sibling);
  783. p->vfork_done = NULL;
  784. spin_lock_init(&p->alloc_lock);
  785. spin_lock_init(&p->proc_lock);
  786. clear_tsk_thread_flag(p, TIF_SIGPENDING);
  787. init_sigpending(&p->pending);
  788. p->utime = cputime_zero;
  789. p->stime = cputime_zero;
  790. p->sched_time = 0;
  791. p->rchar = 0; /* I/O counter: bytes read */
  792. p->wchar = 0; /* I/O counter: bytes written */
  793. p->syscr = 0; /* I/O counter: read syscalls */
  794. p->syscw = 0; /* I/O counter: write syscalls */
  795. acct_clear_integrals(p);
  796. p->it_virt_expires = cputime_zero;
  797. p->it_prof_expires = cputime_zero;
  798. p->it_sched_expires = 0;
  799. INIT_LIST_HEAD(&p->cpu_timers[0]);
  800. INIT_LIST_HEAD(&p->cpu_timers[1]);
  801. INIT_LIST_HEAD(&p->cpu_timers[2]);
  802. p->lock_depth = -1; /* -1 = no lock */
  803. do_posix_clock_monotonic_gettime(&p->start_time);
  804. p->security = NULL;
  805. p->io_context = NULL;
  806. p->io_wait = NULL;
  807. p->audit_context = NULL;
  808. #ifdef CONFIG_NUMA
  809. p->mempolicy = mpol_copy(p->mempolicy);
  810. if (IS_ERR(p->mempolicy)) {
  811. retval = PTR_ERR(p->mempolicy);
  812. p->mempolicy = NULL;
  813. goto bad_fork_cleanup;
  814. }
  815. #endif
  816. p->tgid = p->pid;
  817. if (clone_flags & CLONE_THREAD)
  818. p->tgid = current->tgid;
  819. if ((retval = security_task_alloc(p)))
  820. goto bad_fork_cleanup_policy;
  821. if ((retval = audit_alloc(p)))
  822. goto bad_fork_cleanup_security;
  823. /* copy all the process information */
  824. if ((retval = copy_semundo(clone_flags, p)))
  825. goto bad_fork_cleanup_audit;
  826. if ((retval = copy_files(clone_flags, p)))
  827. goto bad_fork_cleanup_semundo;
  828. if ((retval = copy_fs(clone_flags, p)))
  829. goto bad_fork_cleanup_files;
  830. if ((retval = copy_sighand(clone_flags, p)))
  831. goto bad_fork_cleanup_fs;
  832. if ((retval = copy_signal(clone_flags, p)))
  833. goto bad_fork_cleanup_sighand;
  834. if ((retval = copy_mm(clone_flags, p)))
  835. goto bad_fork_cleanup_signal;
  836. if ((retval = copy_keys(clone_flags, p)))
  837. goto bad_fork_cleanup_mm;
  838. if ((retval = copy_namespace(clone_flags, p)))
  839. goto bad_fork_cleanup_keys;
  840. retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs);
  841. if (retval)
  842. goto bad_fork_cleanup_namespace;
  843. p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
  844. /*
  845. * Clear TID on mm_release()?
  846. */
  847. p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? child_tidptr: NULL;
  848. /*
  849. * Syscall tracing should be turned off in the child regardless
  850. * of CLONE_PTRACE.
  851. */
  852. clear_tsk_thread_flag(p, TIF_SYSCALL_TRACE);
  853. /* Our parent execution domain becomes current domain
  854. These must match for thread signalling to apply */
  855. p->parent_exec_id = p->self_exec_id;
  856. /* ok, now we should be set up.. */
  857. p->exit_signal = (clone_flags & CLONE_THREAD) ? -1 : (clone_flags & CSIGNAL);
  858. p->pdeath_signal = 0;
  859. p->exit_state = 0;
  860. /* Perform scheduler related setup */
  861. sched_fork(p);
  862. /*
  863. * Ok, make it visible to the rest of the system.
  864. * We dont wake it up yet.
  865. */
  866. p->group_leader = p;
  867. INIT_LIST_HEAD(&p->ptrace_children);
  868. INIT_LIST_HEAD(&p->ptrace_list);
  869. /* Need tasklist lock for parent etc handling! */
  870. write_lock_irq(&tasklist_lock);
  871. /*
  872. * The task hasn't been attached yet, so cpus_allowed mask cannot
  873. * have changed. The cpus_allowed mask of the parent may have
  874. * changed after it was copied first time, and it may then move to
  875. * another CPU - so we re-copy it here and set the child's CPU to
  876. * the parent's CPU. This avoids alot of nasty races.
  877. */
  878. p->cpus_allowed = current->cpus_allowed;
  879. set_task_cpu(p, smp_processor_id());
  880. /*
  881. * Check for pending SIGKILL! The new thread should not be allowed
  882. * to slip out of an OOM kill. (or normal SIGKILL.)
  883. */
  884. if (sigismember(&current->pending.signal, SIGKILL)) {
  885. write_unlock_irq(&tasklist_lock);
  886. retval = -EINTR;
  887. goto bad_fork_cleanup_namespace;
  888. }
  889. /* CLONE_PARENT re-uses the old parent */
  890. if (clone_flags & (CLONE_PARENT|CLONE_THREAD))
  891. p->real_parent = current->real_parent;
  892. else
  893. p->real_parent = current;
  894. p->parent = p->real_parent;
  895. if (clone_flags & CLONE_THREAD) {
  896. spin_lock(&current->sighand->siglock);
  897. /*
  898. * Important: if an exit-all has been started then
  899. * do not create this new thread - the whole thread
  900. * group is supposed to exit anyway.
  901. */
  902. if (current->signal->flags & SIGNAL_GROUP_EXIT) {
  903. spin_unlock(&current->sighand->siglock);
  904. write_unlock_irq(&tasklist_lock);
  905. retval = -EAGAIN;
  906. goto bad_fork_cleanup_namespace;
  907. }
  908. p->group_leader = current->group_leader;
  909. if (current->signal->group_stop_count > 0) {
  910. /*
  911. * There is an all-stop in progress for the group.
  912. * We ourselves will stop as soon as we check signals.
  913. * Make the new thread part of that group stop too.
  914. */
  915. current->signal->group_stop_count++;
  916. set_tsk_thread_flag(p, TIF_SIGPENDING);
  917. }
  918. if (!cputime_eq(current->signal->it_virt_expires,
  919. cputime_zero) ||
  920. !cputime_eq(current->signal->it_prof_expires,
  921. cputime_zero) ||
  922. current->signal->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY ||
  923. !list_empty(&current->signal->cpu_timers[0]) ||
  924. !list_empty(&current->signal->cpu_timers[1]) ||
  925. !list_empty(&current->signal->cpu_timers[2])) {
  926. /*
  927. * Have child wake up on its first tick to check
  928. * for process CPU timers.
  929. */
  930. p->it_prof_expires = jiffies_to_cputime(1);
  931. }
  932. spin_unlock(&current->sighand->siglock);
  933. }
  934. SET_LINKS(p);
  935. if (unlikely(p->ptrace & PT_PTRACED))
  936. __ptrace_link(p, current->parent);
  937. cpuset_fork(p);
  938. attach_pid(p, PIDTYPE_PID, p->pid);
  939. attach_pid(p, PIDTYPE_TGID, p->tgid);
  940. if (thread_group_leader(p)) {
  941. attach_pid(p, PIDTYPE_PGID, process_group(p));
  942. attach_pid(p, PIDTYPE_SID, p->signal->session);
  943. if (p->pid)
  944. __get_cpu_var(process_counts)++;
  945. }
  946. nr_threads++;
  947. total_forks++;
  948. write_unlock_irq(&tasklist_lock);
  949. retval = 0;
  950. fork_out:
  951. if (retval)
  952. return ERR_PTR(retval);
  953. return p;
  954. bad_fork_cleanup_namespace:
  955. exit_namespace(p);
  956. bad_fork_cleanup_keys:
  957. exit_keys(p);
  958. bad_fork_cleanup_mm:
  959. if (p->mm)
  960. mmput(p->mm);
  961. bad_fork_cleanup_signal:
  962. exit_signal(p);
  963. bad_fork_cleanup_sighand:
  964. exit_sighand(p);
  965. bad_fork_cleanup_fs:
  966. exit_fs(p); /* blocking */
  967. bad_fork_cleanup_files:
  968. exit_files(p); /* blocking */
  969. bad_fork_cleanup_semundo:
  970. exit_sem(p);
  971. bad_fork_cleanup_audit:
  972. audit_free(p);
  973. bad_fork_cleanup_security:
  974. security_task_free(p);
  975. bad_fork_cleanup_policy:
  976. #ifdef CONFIG_NUMA
  977. mpol_free(p->mempolicy);
  978. #endif
  979. bad_fork_cleanup:
  980. if (p->binfmt)
  981. module_put(p->binfmt->module);
  982. bad_fork_cleanup_put_domain:
  983. module_put(p->thread_info->exec_domain->module);
  984. bad_fork_cleanup_count:
  985. put_group_info(p->group_info);
  986. atomic_dec(&p->user->processes);
  987. free_uid(p->user);
  988. bad_fork_free:
  989. free_task(p);
  990. goto fork_out;
  991. }
  992. struct pt_regs * __devinit __attribute__((weak)) idle_regs(struct pt_regs *regs)
  993. {
  994. memset(regs, 0, sizeof(struct pt_regs));
  995. return regs;
  996. }
  997. task_t * __devinit fork_idle(int cpu)
  998. {
  999. task_t *task;
  1000. struct pt_regs regs;
  1001. task = copy_process(CLONE_VM, 0, idle_regs(&regs), 0, NULL, NULL, 0);
  1002. if (!task)
  1003. return ERR_PTR(-ENOMEM);
  1004. init_idle(task, cpu);
  1005. unhash_process(task);
  1006. return task;
  1007. }
  1008. static inline int fork_traceflag (unsigned clone_flags)
  1009. {
  1010. if (clone_flags & CLONE_UNTRACED)
  1011. return 0;
  1012. else if (clone_flags & CLONE_VFORK) {
  1013. if (current->ptrace & PT_TRACE_VFORK)
  1014. return PTRACE_EVENT_VFORK;
  1015. } else if ((clone_flags & CSIGNAL) != SIGCHLD) {
  1016. if (current->ptrace & PT_TRACE_CLONE)
  1017. return PTRACE_EVENT_CLONE;
  1018. } else if (current->ptrace & PT_TRACE_FORK)
  1019. return PTRACE_EVENT_FORK;
  1020. return 0;
  1021. }
  1022. /*
  1023. * Ok, this is the main fork-routine.
  1024. *
  1025. * It copies the process, and if successful kick-starts
  1026. * it and waits for it to finish using the VM if required.
  1027. */
  1028. long do_fork(unsigned long clone_flags,
  1029. unsigned long stack_start,
  1030. struct pt_regs *regs,
  1031. unsigned long stack_size,
  1032. int __user *parent_tidptr,
  1033. int __user *child_tidptr)
  1034. {
  1035. struct task_struct *p;
  1036. int trace = 0;
  1037. long pid = alloc_pidmap();
  1038. if (pid < 0)
  1039. return -EAGAIN;
  1040. if (unlikely(current->ptrace)) {
  1041. trace = fork_traceflag (clone_flags);
  1042. if (trace)
  1043. clone_flags |= CLONE_PTRACE;
  1044. }
  1045. p = copy_process(clone_flags, stack_start, regs, stack_size, parent_tidptr, child_tidptr, pid);
  1046. /*
  1047. * Do this prior waking up the new thread - the thread pointer
  1048. * might get invalid after that point, if the thread exits quickly.
  1049. */
  1050. if (!IS_ERR(p)) {
  1051. struct completion vfork;
  1052. if (clone_flags & CLONE_VFORK) {
  1053. p->vfork_done = &vfork;
  1054. init_completion(&vfork);
  1055. }
  1056. if ((p->ptrace & PT_PTRACED) || (clone_flags & CLONE_STOPPED)) {
  1057. /*
  1058. * We'll start up with an immediate SIGSTOP.
  1059. */
  1060. sigaddset(&p->pending.signal, SIGSTOP);
  1061. set_tsk_thread_flag(p, TIF_SIGPENDING);
  1062. }
  1063. if (!(clone_flags & CLONE_STOPPED))
  1064. wake_up_new_task(p, clone_flags);
  1065. else
  1066. p->state = TASK_STOPPED;
  1067. if (unlikely (trace)) {
  1068. current->ptrace_message = pid;
  1069. ptrace_notify ((trace << 8) | SIGTRAP);
  1070. }
  1071. if (clone_flags & CLONE_VFORK) {
  1072. wait_for_completion(&vfork);
  1073. if (unlikely (current->ptrace & PT_TRACE_VFORK_DONE))
  1074. ptrace_notify ((PTRACE_EVENT_VFORK_DONE << 8) | SIGTRAP);
  1075. }
  1076. } else {
  1077. free_pidmap(pid);
  1078. pid = PTR_ERR(p);
  1079. }
  1080. return pid;
  1081. }
  1082. void __init proc_caches_init(void)
  1083. {
  1084. sighand_cachep = kmem_cache_create("sighand_cache",
  1085. sizeof(struct sighand_struct), 0,
  1086. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
  1087. signal_cachep = kmem_cache_create("signal_cache",
  1088. sizeof(struct signal_struct), 0,
  1089. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
  1090. files_cachep = kmem_cache_create("files_cache",
  1091. sizeof(struct files_struct), 0,
  1092. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
  1093. fs_cachep = kmem_cache_create("fs_cache",
  1094. sizeof(struct fs_struct), 0,
  1095. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
  1096. vm_area_cachep = kmem_cache_create("vm_area_struct",
  1097. sizeof(struct vm_area_struct), 0,
  1098. SLAB_PANIC, NULL, NULL);
  1099. mm_cachep = kmem_cache_create("mm_struct",
  1100. sizeof(struct mm_struct), 0,
  1101. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
  1102. }