fork.c 32 KB

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