~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/kernel/fork.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  linux/kernel/fork.c
  3  *
  4  *  Copyright (C) 1991, 1992  Linus Torvalds
  5  */
  6 
  7 /*
  8  *  'fork.c' contains the help-routines for the 'fork' system call
  9  * (see also entry.S and others).
 10  * Fork is rather simple, once you get the hang of it, but the memory
 11  * management can be a bitch. See 'mm/memory.c': 'copy_page_tables()'
 12  */
 13 
 14 #include <linux/config.h>
 15 #include <linux/malloc.h>
 16 #include <linux/init.h>
 17 #include <linux/unistd.h>
 18 #include <linux/smp_lock.h>
 19 #include <linux/module.h>
 20 #include <linux/vmalloc.h>
 21 
 22 #include <asm/pgtable.h>
 23 #include <asm/pgalloc.h>
 24 #include <asm/uaccess.h>
 25 #include <asm/mmu_context.h>
 26 
 27 /* The idle threads do not count.. */
 28 int nr_threads;
 29 int nr_running;
 30 
 31 int max_threads;
 32 unsigned long total_forks;      /* Handle normal Linux uptimes. */
 33 int last_pid;
 34 
 35 struct task_struct *pidhash[PIDHASH_SZ];
 36 
 37 void add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait)
 38 {
 39         unsigned long flags;
 40 
 41         wq_write_lock_irqsave(&q->lock, flags);
 42         wait->flags = 0;
 43         __add_wait_queue(q, wait);
 44         wq_write_unlock_irqrestore(&q->lock, flags);
 45 }
 46 
 47 void add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t * wait)
 48 {
 49         unsigned long flags;
 50 
 51         wq_write_lock_irqsave(&q->lock, flags);
 52         wait->flags = WQ_FLAG_EXCLUSIVE;
 53         __add_wait_queue_tail(q, wait);
 54         wq_write_unlock_irqrestore(&q->lock, flags);
 55 }
 56 
 57 void remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait)
 58 {
 59         unsigned long flags;
 60 
 61         wq_write_lock_irqsave(&q->lock, flags);
 62         __remove_wait_queue(q, wait);
 63         wq_write_unlock_irqrestore(&q->lock, flags);
 64 }
 65 
 66 void __init fork_init(unsigned long mempages)
 67 {
 68         /*
 69          * The default maximum number of threads is set to a safe
 70          * value: the thread structures can take up at most half
 71          * of memory.
 72          */
 73         max_threads = mempages / (THREAD_SIZE/PAGE_SIZE) / 2;
 74 
 75         init_task.rlim[RLIMIT_NPROC].rlim_cur = max_threads/2;
 76         init_task.rlim[RLIMIT_NPROC].rlim_max = max_threads/2;
 77 }
 78 
 79 /* Protects next_safe and last_pid. */
 80 spinlock_t lastpid_lock = SPIN_LOCK_UNLOCKED;
 81 
 82 static int get_pid(unsigned long flags)
 83 {
 84         static int next_safe = PID_MAX;
 85         struct task_struct *p;
 86 
 87         if (flags & CLONE_PID)
 88                 return current->pid;
 89 
 90         spin_lock(&lastpid_lock);
 91         if((++last_pid) & 0xffff8000) {
 92                 last_pid = 300;         /* Skip daemons etc. */
 93                 goto inside;
 94         }
 95         if(last_pid >= next_safe) {
 96 inside:
 97                 next_safe = PID_MAX;
 98                 read_lock(&tasklist_lock);
 99         repeat:
100                 for_each_task(p) {
101                         if(p->pid == last_pid   ||
102                            p->pgrp == last_pid  ||
103                            p->session == last_pid) {
104                                 if(++last_pid >= next_safe) {
105                                         if(last_pid & 0xffff8000)
106                                                 last_pid = 300;
107                                         next_safe = PID_MAX;
108                                 }
109                                 goto repeat;
110                         }
111                         if(p->pid > last_pid && next_safe > p->pid)
112                                 next_safe = p->pid;
113                         if(p->pgrp > last_pid && next_safe > p->pgrp)
114                                 next_safe = p->pgrp;
115                         if(p->session > last_pid && next_safe > p->session)
116                                 next_safe = p->session;
117                 }
118                 read_unlock(&tasklist_lock);
119         }
120         spin_unlock(&lastpid_lock);
121 
122         return last_pid;
123 }
124 
125 static inline int dup_mmap(struct mm_struct * mm)
126 {
127         struct vm_area_struct * mpnt, *tmp, **pprev;
128         int retval;
129 
130         flush_cache_mm(current->mm);
131         mm->locked_vm = 0;
132         mm->mmap = NULL;
133         mm->mmap_avl = NULL;
134         mm->mmap_cache = NULL;
135         mm->map_count = 0;
136         mm->cpu_vm_mask = 0;
137         mm->swap_cnt = 0;
138         mm->swap_address = 0;
139         pprev = &mm->mmap;
140         for (mpnt = current->mm->mmap ; mpnt ; mpnt = mpnt->vm_next) {
141                 struct file *file;
142 
143                 retval = -ENOMEM;
144                 if(mpnt->vm_flags & VM_DONTCOPY)
145                         continue;
146                 tmp = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
147                 if (!tmp)
148                         goto fail_nomem;
149                 *tmp = *mpnt;
150                 tmp->vm_flags &= ~VM_LOCKED;
151                 tmp->vm_mm = mm;
152                 mm->map_count++;
153                 tmp->vm_next = NULL;
154                 file = tmp->vm_file;
155                 if (file) {
156                         struct inode *inode = file->f_dentry->d_inode;
157                         get_file(file);
158                         if (tmp->vm_flags & VM_DENYWRITE)
159                                 atomic_dec(&inode->i_writecount);
160       
161                         /* insert tmp into the share list, just after mpnt */
162                         spin_lock(&inode->i_mapping->i_shared_lock);
163                         if((tmp->vm_next_share = mpnt->vm_next_share) != NULL)
164                                 mpnt->vm_next_share->vm_pprev_share =
165                                         &tmp->vm_next_share;
166                         mpnt->vm_next_share = tmp;
167                         tmp->vm_pprev_share = &mpnt->vm_next_share;
168                         spin_unlock(&inode->i_mapping->i_shared_lock);
169                 }
170 
171                 /* Copy the pages, but defer checking for errors */
172                 retval = copy_page_range(mm, current->mm, tmp);
173                 if (!retval && tmp->vm_ops && tmp->vm_ops->open)
174                         tmp->vm_ops->open(tmp);
175 
176                 /*
177                  * Link in the new vma even if an error occurred,
178                  * so that exit_mmap() can clean up the mess.
179                  */
180                 *pprev = tmp;
181                 pprev = &tmp->vm_next;
182 
183                 if (retval)
184                         goto fail_nomem;
185         }
186         retval = 0;
187         if (mm->map_count >= AVL_MIN_MAP_COUNT)
188                 build_mmap_avl(mm);
189 
190 fail_nomem:
191         flush_tlb_mm(current->mm);
192         return retval;
193 }
194 
195 spinlock_t mmlist_lock __cacheline_aligned = SPIN_LOCK_UNLOCKED;
196 
197 #define allocate_mm()   (kmem_cache_alloc(mm_cachep, SLAB_KERNEL))
198 #define free_mm(mm)     (kmem_cache_free(mm_cachep, (mm)))
199 
200 static struct mm_struct * mm_init(struct mm_struct * mm)
201 {
202         atomic_set(&mm->mm_users, 1);
203         atomic_set(&mm->mm_count, 1);
204         init_MUTEX(&mm->mmap_sem);
205         mm->page_table_lock = SPIN_LOCK_UNLOCKED;
206         mm->pgd = pgd_alloc();
207         if (mm->pgd)
208                 return mm;
209         free_mm(mm);
210         return NULL;
211 }
212         
213 
214 /*
215  * Allocate and initialize an mm_struct.
216  */
217 struct mm_struct * mm_alloc(void)
218 {
219         struct mm_struct * mm;
220 
221         mm = allocate_mm();
222         if (mm) {
223                 memset(mm, 0, sizeof(*mm));
224                 return mm_init(mm);
225         }
226         return NULL;
227 }
228 
229 /*
230  * Called when the last reference to the mm
231  * is dropped: either by a lazy thread or by
232  * mmput. Free the page directory and the mm.
233  */
234 inline void __mmdrop(struct mm_struct *mm)
235 {
236         if (mm == &init_mm) BUG();
237         pgd_free(mm->pgd);
238         destroy_context(mm);
239         free_mm(mm);
240 }
241 
242 /*
243  * Decrement the use count and release all resources for an mm.
244  */
245 void mmput(struct mm_struct *mm)
246 {
247         if (atomic_dec_and_lock(&mm->mm_users, &mmlist_lock)) {
248                 list_del(&mm->mmlist);
249                 spin_unlock(&mmlist_lock);
250                 exit_mmap(mm);
251                 mmdrop(mm);
252         }
253 }
254 
255 /* Please note the differences between mmput and mm_release.
256  * mmput is called whenever we stop holding onto a mm_struct,
257  * error success whatever.
258  *
259  * mm_release is called after a mm_struct has been removed
260  * from the current process.
261  *
262  * This difference is important for error handling, when we
263  * only half set up a mm_struct for a new process and need to restore
264  * the old one.  Because we mmput the new mm_struct before
265  * restoring the old one. . .
266  * Eric Biederman 10 January 1998
267  */
268 void mm_release(void)
269 {
270         struct task_struct *tsk = current;
271 
272         /* notify parent sleeping on vfork() */
273         if (tsk->flags & PF_VFORK) {
274                 tsk->flags &= ~PF_VFORK;
275                 up(tsk->p_opptr->vfork_sem);
276         }
277 }
278 
279 static int copy_mm(unsigned long clone_flags, struct task_struct * tsk)
280 {
281         struct mm_struct * mm, *oldmm;
282         int retval;
283 
284         tsk->min_flt = tsk->maj_flt = 0;
285         tsk->cmin_flt = tsk->cmaj_flt = 0;
286         tsk->nswap = tsk->cnswap = 0;
287 
288         tsk->mm = NULL;
289         tsk->active_mm = NULL;
290 
291         /*
292          * Are we cloning a kernel thread?
293          *
294          * We need to steal a active VM for that..
295          */
296         oldmm = current->mm;
297         if (!oldmm)
298                 return 0;
299 
300         if (clone_flags & CLONE_VM) {
301                 atomic_inc(&oldmm->mm_users);
302                 mm = oldmm;
303                 goto good_mm;
304         }
305 
306         retval = -ENOMEM;
307         mm = allocate_mm();
308         if (!mm)
309                 goto fail_nomem;
310 
311         /* Copy the current MM stuff.. */
312         memcpy(mm, oldmm, sizeof(*mm));
313         if (!mm_init(mm))
314                 goto fail_nomem;
315 
316         down(&oldmm->mmap_sem);
317         retval = dup_mmap(mm);
318         up(&oldmm->mmap_sem);
319 
320         /*
321          * Add it to the mmlist after the parent.
322          *
323          * Doing it this way means that we can order
324          * the list, and fork() won't mess up the
325          * ordering significantly.
326          */
327         spin_lock(&mmlist_lock);
328         list_add(&mm->mmlist, &oldmm->mmlist);
329         spin_unlock(&mmlist_lock);
330 
331         if (retval)
332                 goto free_pt;
333 
334         /*
335          * child gets a private LDT (if there was an LDT in the parent)
336          */
337         copy_segments(tsk, mm);
338 
339         if (init_new_context(tsk,mm))
340                 goto free_pt;
341 
342 good_mm:
343         tsk->mm = mm;
344         tsk->active_mm = mm;
345         return 0;
346 
347 free_pt:
348         mmput(mm);
349 fail_nomem:
350         return retval;
351 }
352 
353 static inline struct fs_struct *__copy_fs_struct(struct fs_struct *old)
354 {
355         struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
356         /* We don't need to lock fs - think why ;-) */
357         if (fs) {
358                 atomic_set(&fs->count, 1);
359                 fs->lock = RW_LOCK_UNLOCKED;
360                 fs->umask = old->umask;
361                 read_lock(&old->lock);
362                 fs->rootmnt = mntget(old->rootmnt);
363                 fs->root = dget(old->root);
364                 fs->pwdmnt = mntget(old->pwdmnt);
365                 fs->pwd = dget(old->pwd);
366                 if (old->altroot) {
367                         fs->altrootmnt = mntget(old->altrootmnt);
368                         fs->altroot = dget(old->altroot);
369                 } else {
370                         fs->altrootmnt = NULL;
371                         fs->altroot = NULL;
372                 }       
373                 read_unlock(&old->lock);
374         }
375         return fs;
376 }
377 
378 struct fs_struct *copy_fs_struct(struct fs_struct *old)
379 {
380         return __copy_fs_struct(old);
381 }
382 
383 static inline int copy_fs(unsigned long clone_flags, struct task_struct * tsk)
384 {
385         if (clone_flags & CLONE_FS) {
386                 atomic_inc(&current->fs->count);
387                 return 0;
388         }
389         tsk->fs = __copy_fs_struct(current->fs);
390         if (!tsk->fs)
391                 return -1;
392         return 0;
393 }
394 
395 static int count_open_files(struct files_struct *files, int size)
396 {
397         int i;
398         
399         /* Find the last open fd */
400         for (i = size/(8*sizeof(long)); i > 0; ) {
401                 if (files->open_fds->fds_bits[--i])
402                         break;
403         }
404         i = (i+1) * 8 * sizeof(long);
405         return i;
406 }
407 
408 static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
409 {
410         struct files_struct *oldf, *newf;
411         struct file **old_fds, **new_fds;
412         int open_files, nfds, size, i, error = 0;
413 
414         /*
415          * A background process may not have any files ...
416          */
417         oldf = current->files;
418         if (!oldf)
419                 goto out;
420 
421         if (clone_flags & CLONE_FILES) {
422                 atomic_inc(&oldf->count);
423                 goto out;
424         }
425 
426         tsk->files = NULL;
427         error = -ENOMEM;
428         newf = kmem_cache_alloc(files_cachep, SLAB_KERNEL);
429         if (!newf) 
430                 goto out;
431 
432         atomic_set(&newf->count, 1);
433 
434         newf->file_lock     = RW_LOCK_UNLOCKED;
435         newf->next_fd       = 0;
436         newf->max_fds       = NR_OPEN_DEFAULT;
437         newf->max_fdset     = __FD_SETSIZE;
438         newf->close_on_exec = &newf->close_on_exec_init;
439         newf->open_fds      = &newf->open_fds_init;
440         newf->fd            = &newf->fd_array[0];
441 
442         /* We don't yet have the oldf readlock, but even if the old
443            fdset gets grown now, we'll only copy up to "size" fds */
444         size = oldf->max_fdset;
445         if (size > __FD_SETSIZE) {
446                 newf->max_fdset = 0;
447                 write_lock(&newf->file_lock);
448                 error = expand_fdset(newf, size);
449                 write_unlock(&newf->file_lock);
450                 if (error)
451                         goto out_release;
452         }
453         read_lock(&oldf->file_lock);
454 
455         open_files = count_open_files(oldf, size);
456 
457         /*
458          * Check whether we need to allocate a larger fd array.
459          * Note: we're not a clone task, so the open count won't
460          * change.
461          */
462         nfds = NR_OPEN_DEFAULT;
463         if (open_files > nfds) {
464                 read_unlock(&oldf->file_lock);
465                 newf->max_fds = 0;
466                 write_lock(&newf->file_lock);
467                 error = expand_fd_array(newf, open_files);
468                 write_unlock(&newf->file_lock);
469                 if (error) 
470                         goto out_release;
471                 nfds = newf->max_fds;
472                 read_lock(&oldf->file_lock);
473         }
474 
475         old_fds = oldf->fd;
476         new_fds = newf->fd;
477 
478         memcpy(newf->open_fds->fds_bits, oldf->open_fds->fds_bits, open_files/8);
479         memcpy(newf->close_on_exec->fds_bits, oldf->close_on_exec->fds_bits, open_files/8);
480 
481         for (i = open_files; i != 0; i--) {
482                 struct file *f = *old_fds++;
483                 if (f)
484                         get_file(f);
485                 *new_fds++ = f;
486         }
487         read_unlock(&oldf->file_lock);
488 
489         /* compute the remainder to be cleared */
490         size = (newf->max_fds - open_files) * sizeof(struct file *);
491 
492         /* This is long word aligned thus could use a optimized version */ 
493         memset(new_fds, 0, size); 
494 
495         if (newf->max_fdset > open_files) {
496                 int left = (newf->max_fdset-open_files)/8;
497                 int start = open_files / (8 * sizeof(unsigned long));
498                 
499                 memset(&newf->open_fds->fds_bits[start], 0, left);
500                 memset(&newf->close_on_exec->fds_bits[start], 0, left);
501         }
502 
503         tsk->files = newf;
504         error = 0;
505 out:
506         return error;
507 
508 out_release:
509         free_fdset (newf->close_on_exec, newf->max_fdset);
510         free_fdset (newf->open_fds, newf->max_fdset);
511         kmem_cache_free(files_cachep, newf);
512         goto out;
513 }
514 
515 static inline int copy_sighand(unsigned long clone_flags, struct task_struct * tsk)
516 {
517         struct signal_struct *sig;
518 
519         if (clone_flags & CLONE_SIGHAND) {
520                 atomic_inc(&current->sig->count);
521                 return 0;
522         }
523         sig = kmem_cache_alloc(sigact_cachep, GFP_KERNEL);
524         tsk->sig = sig;
525         if (!sig)
526                 return -1;
527         spin_lock_init(&sig->siglock);
528         atomic_set(&sig->count, 1);
529         memcpy(tsk->sig->action, current->sig->action, sizeof(tsk->sig->action));
530         return 0;
531 }
532 
533 static inline void copy_flags(unsigned long clone_flags, struct task_struct *p)
534 {
535         unsigned long new_flags = p->flags;
536 
537         new_flags &= ~(PF_SUPERPRIV | PF_USEDFPU | PF_VFORK);
538         new_flags |= PF_FORKNOEXEC;
539         if (!(clone_flags & CLONE_PTRACE))
540                 p->ptrace = 0;
541         if (clone_flags & CLONE_VFORK)
542                 new_flags |= PF_VFORK;
543         p->flags = new_flags;
544 }
545 
546 /*
547  *  Ok, this is the main fork-routine. It copies the system process
548  * information (task[nr]) and sets up the necessary registers. It also
549  * copies the data segment in its entirety.  The "stack_start" and
550  * "stack_top" arguments are simply passed along to the platform
551  * specific copy_thread() routine.  Most platforms ignore stack_top.
552  * For an example that's using stack_top, see
553  * arch/ia64/kernel/process.c.
554  */
555 int do_fork(unsigned long clone_flags, unsigned long stack_start,
556             struct pt_regs *regs, unsigned long stack_size)
557 {
558         int retval = -ENOMEM;
559         struct task_struct *p;
560         DECLARE_MUTEX_LOCKED(sem);
561 
562         if (clone_flags & CLONE_PID) {
563                 /* This is only allowed from the boot up thread */
564                 if (current->pid)
565                         return -EPERM;
566         }
567         
568         current->vfork_sem = &sem;
569 
570         p = alloc_task_struct();
571         if (!p)
572                 goto fork_out;
573 
574         *p = *current;
575 
576         retval = -EAGAIN;
577         if (atomic_read(&p->user->processes) >= p->rlim[RLIMIT_NPROC].rlim_cur)
578                 goto bad_fork_free;
579         atomic_inc(&p->user->__count);
580         atomic_inc(&p->user->processes);
581 
582         /*
583          * Counter increases are protected by
584          * the kernel lock so nr_threads can't
585          * increase under us (but it may decrease).
586          */
587         if (nr_threads >= max_threads)
588                 goto bad_fork_cleanup_count;
589         
590         get_exec_domain(p->exec_domain);
591 
592         if (p->binfmt && p->binfmt->module)
593                 __MOD_INC_USE_COUNT(p->binfmt->module);
594 
595         p->did_exec = 0;
596         p->swappable = 0;
597         p->state = TASK_UNINTERRUPTIBLE;
598 
599         copy_flags(clone_flags, p);
600         p->pid = get_pid(clone_flags);
601 
602         p->run_list.next = NULL;
603         p->run_list.prev = NULL;
604 
605         if ((clone_flags & CLONE_VFORK) || !(clone_flags & CLONE_PARENT)) {
606                 p->p_opptr = current;
607                 if (!(p->ptrace & PT_PTRACED))
608                         p->p_pptr = current;
609         }
610         p->p_cptr = NULL;
611         init_waitqueue_head(&p->wait_chldexit);
612         p->vfork_sem = NULL;
613         spin_lock_init(&p->alloc_lock);
614 
615         p->sigpending = 0;
616         init_sigpending(&p->pending);
617 
618         p->it_real_value = p->it_virt_value = p->it_prof_value = 0;
619         p->it_real_incr = p->it_virt_incr = p->it_prof_incr = 0;
620         init_timer(&p->real_timer);
621         p->real_timer.data = (unsigned long) p;
622 
623         p->leader = 0;          /* session leadership doesn't inherit */
624         p->tty_old_pgrp = 0;
625         p->times.tms_utime = p->times.tms_stime = 0;
626         p->times.tms_cutime = p->times.tms_cstime = 0;
627 #ifdef CONFIG_SMP
628         {
629                 int i;
630                 p->has_cpu = 0;
631                 p->processor = current->processor;
632                 /* ?? should we just memset this ?? */
633                 for(i = 0; i < smp_num_cpus; i++)
634                         p->per_cpu_utime[i] = p->per_cpu_stime[i] = 0;
635                 spin_lock_init(&p->sigmask_lock);
636         }
637 #endif
638         p->lock_depth = -1;             /* -1 = no lock */
639         p->start_time = jiffies;
640 
641         retval = -ENOMEM;
642         /* copy all the process information */
643         if (copy_files(clone_flags, p))
644                 goto bad_fork_cleanup;
645         if (copy_fs(clone_flags, p))
646                 goto bad_fork_cleanup_files;
647         if (copy_sighand(clone_flags, p))
648                 goto bad_fork_cleanup_fs;
649         if (copy_mm(clone_flags, p))
650                 goto bad_fork_cleanup_sighand;
651         retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs);
652         if (retval)
653                 goto bad_fork_cleanup_sighand;
654         p->semundo = NULL;
655         
656         /* Our parent execution domain becomes current domain
657            These must match for thread signalling to apply */
658            
659         p->parent_exec_id = p->self_exec_id;
660 
661         /* ok, now we should be set up.. */
662         p->swappable = 1;
663         p->exit_signal = clone_flags & CSIGNAL;
664         p->pdeath_signal = 0;
665 
666         /*
667          * "share" dynamic priority between parent and child, thus the
668          * total amount of dynamic priorities in the system doesnt change,
669          * more scheduling fairness. This is only important in the first
670          * timeslice, on the long run the scheduling behaviour is unchanged.
671          */
672         p->counter = (current->counter + 1) >> 1;
673         current->counter >>= 1;
674         if (!current->counter)
675                 current->need_resched = 1;
676 
677         /*
678          * Ok, add it to the run-queues and make it
679          * visible to the rest of the system.
680          *
681          * Let it rip!
682          */
683         retval = p->pid;
684         p->tgid = retval;
685         INIT_LIST_HEAD(&p->thread_group);
686         write_lock_irq(&tasklist_lock);
687         if (clone_flags & CLONE_THREAD) {
688                 p->tgid = current->tgid;
689                 list_add(&p->thread_group, &current->thread_group);
690         }
691         SET_LINKS(p);
692         hash_pid(p);
693         nr_threads++;
694         write_unlock_irq(&tasklist_lock);
695 
696         if (p->ptrace & PT_PTRACED)
697                 send_sig(SIGSTOP, p, 1);
698 
699         wake_up_process(p);             /* do this last */
700         ++total_forks;
701 
702 fork_out:
703         if ((clone_flags & CLONE_VFORK) && (retval > 0)) 
704                 down(&sem);
705         return retval;
706 
707 bad_fork_cleanup_sighand:
708         exit_sighand(p);
709 bad_fork_cleanup_fs:
710         exit_fs(p); /* blocking */
711 bad_fork_cleanup_files:
712         exit_files(p); /* blocking */
713 bad_fork_cleanup:
714         put_exec_domain(p->exec_domain);
715         if (p->binfmt && p->binfmt->module)
716                 __MOD_DEC_USE_COUNT(p->binfmt->module);
717 bad_fork_cleanup_count:
718         atomic_dec(&p->user->processes);
719         free_uid(p->user);
720 bad_fork_free:
721         free_task_struct(p);
722         goto fork_out;
723 }
724 
725 /* SLAB cache for signal_struct structures (tsk->sig) */
726 kmem_cache_t *sigact_cachep;
727 
728 /* SLAB cache for files_struct structures (tsk->files) */
729 kmem_cache_t *files_cachep;
730 
731 /* SLAB cache for fs_struct structures (tsk->fs) */
732 kmem_cache_t *fs_cachep;
733 
734 /* SLAB cache for vm_area_struct structures */
735 kmem_cache_t *vm_area_cachep;
736 
737 /* SLAB cache for mm_struct structures (tsk->mm) */
738 kmem_cache_t *mm_cachep;
739 
740 void __init proc_caches_init(void)
741 {
742         sigact_cachep = kmem_cache_create("signal_act",
743                         sizeof(struct signal_struct), 0,
744                         SLAB_HWCACHE_ALIGN, NULL, NULL);
745         if (!sigact_cachep)
746                 panic("Cannot create signal action SLAB cache");
747 
748         files_cachep = kmem_cache_create("files_cache", 
749                          sizeof(struct files_struct), 0, 
750                          SLAB_HWCACHE_ALIGN, NULL, NULL);
751         if (!files_cachep) 
752                 panic("Cannot create files SLAB cache");
753 
754         fs_cachep = kmem_cache_create("fs_cache", 
755                          sizeof(struct fs_struct), 0, 
756                          SLAB_HWCACHE_ALIGN, NULL, NULL);
757         if (!fs_cachep) 
758                 panic("Cannot create fs_struct SLAB cache");
759  
760         vm_area_cachep = kmem_cache_create("vm_area_struct",
761                         sizeof(struct vm_area_struct), 0,
762                         SLAB_HWCACHE_ALIGN, NULL, NULL);
763         if(!vm_area_cachep)
764                 panic("vma_init: Cannot alloc vm_area_struct SLAB cache");
765 
766         mm_cachep = kmem_cache_create("mm_struct",
767                         sizeof(struct mm_struct), 0,
768                         SLAB_HWCACHE_ALIGN, NULL, NULL);
769         if(!mm_cachep)
770                 panic("vma_init: Cannot alloc mm_struct SLAB cache");
771 }
772 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.