fork.c 32 KB

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