4 #include <asm/param.h> /* for HZ */
6 extern unsigned long event;
8 #include <linux/config.h>
9 #include <linux/binfmts.h>
10 #include <linux/threads.h>
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/times.h>
14 #include <linux/timex.h>
15 #include <linux/rbtree.h>
17 #include <asm/system.h>
18 #include <asm/semaphore.h>
20 #include <asm/ptrace.h>
23 #include <linux/smp.h>
24 #include <linux/tty.h>
25 #include <linux/sem.h>
26 #include <linux/signal.h>
27 #include <linux/securebits.h>
28 #include <linux/fs_struct.h>
35 #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
36 #define CLONE_VM 0x00000100 /* set if VM shared between processes */
37 #define CLONE_FS 0x00000200 /* set if fs info shared between processes */
38 #define CLONE_FILES 0x00000400 /* set if open files shared between processes */
39 #define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */
40 #define CLONE_PID 0x00001000 /* set if pid shared */
41 #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
42 #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
43 #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
44 #define CLONE_THREAD 0x00010000 /* Same thread group? */
45 #define CLONE_NEWNS 0x00020000 /* New namespace group? */
47 #define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
50 * These are the constant used to fake the fixed-point load-average
51 * counting. Some notes:
52 * - 11 bit fractions expand to 22 bits by the multiplies: this gives
53 * a load-average precision of 10 bits integer + 11 bits fractional
54 * - if you want to count load-averages more often, you need more
55 * precision, or rounding will get you. With 2-second counting freq,
56 * the EXP_n values would be 1981, 2034 and 2043 if still using only
59 extern unsigned long avenrun[]; /* Load averages */
61 #define FSHIFT 11 /* nr of bits of precision */
62 #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
63 #define LOAD_FREQ (5*HZ) /* 5 sec intervals */
64 #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */
65 #define EXP_5 2014 /* 1/exp(5sec/5min) */
66 #define EXP_15 2037 /* 1/exp(5sec/15min) */
68 #define CALC_LOAD(load,exp,n) \
70 load += n*(FIXED_1-exp); \
73 #define CT_TO_SECS(x) ((x) / HZ)
74 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
76 extern int nr_running, nr_threads;
80 #include <linux/time.h>
81 #include <linux/param.h>
82 #include <linux/resource.h>
84 #include <linux/timer.h>
87 #include <asm/processor.h>
89 #define TASK_RUNNING 0
90 #define TASK_INTERRUPTIBLE 1
91 #define TASK_UNINTERRUPTIBLE 2
93 #define TASK_STOPPED 8
95 #define __set_task_state(tsk, state_value) \
96 do { (tsk)->state = (state_value); } while (0)
97 #define set_task_state(tsk, state_value) \
98 set_mb((tsk)->state, (state_value))
100 #define __set_current_state(state_value) \
101 do { current->state = (state_value); } while (0)
102 #define set_current_state(state_value) \
103 set_mb(current->state, (state_value))
106 * Scheduling policies
108 #define SCHED_OTHER 0
113 * This is an additional bit set when we want to
114 * yield the CPU for one re-schedule..
116 #define SCHED_YIELD 0x10
126 #include <linux/spinlock.h>
129 * This serializes "schedule()" and also protects
130 * the run-queue from deletions/modifications (but
131 * _adding_ to the beginning of the run-queue has
134 extern rwlock_t tasklist_lock;
135 extern spinlock_t runqueue_lock;
136 extern spinlock_t mmlist_lock;
138 extern void sched_init(void);
139 extern void init_idle(void);
140 extern void show_state(void);
141 extern void cpu_init (void);
142 extern void trap_init(void);
143 extern void update_process_times(int user);
144 extern void update_one_process(struct task_struct *p, unsigned long user,
145 unsigned long system, int cpu);
147 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
148 extern signed long FASTCALL(schedule_timeout(signed long timeout));
149 asmlinkage void schedule(void);
151 extern int schedule_task(struct tq_struct *task);
152 extern void flush_scheduled_tasks(void);
153 extern int start_context_thread(void);
154 extern int current_is_keventd(void);
157 extern void set_cpus_allowed(struct task_struct *p, unsigned long new_mask);
159 # define set_cpus_allowed(p, new_mask) do { } while (0)
163 * The default fd array needs to be at least BITS_PER_LONG,
164 * as this is the granularity returned by copy_fdset().
166 #define NR_OPEN_DEFAULT BITS_PER_LONG
170 * Open file table structure
172 struct files_struct {
174 rwlock_t file_lock; /* Protects all the below members. Nests inside tsk->alloc_lock */
178 struct file ** fd; /* current fd array */
179 fd_set *close_on_exec;
181 fd_set close_on_exec_init;
182 fd_set open_fds_init;
183 struct file * fd_array[NR_OPEN_DEFAULT];
188 count: ATOMIC_INIT(1), \
189 file_lock: RW_LOCK_UNLOCKED, \
190 max_fds: NR_OPEN_DEFAULT, \
191 max_fdset: __FD_SETSIZE, \
193 fd: &init_files.fd_array[0], \
194 close_on_exec: &init_files.close_on_exec_init, \
195 open_fds: &init_files.open_fds_init, \
196 close_on_exec_init: { { 0, } }, \
197 open_fds_init: { { 0, } }, \
198 fd_array: { NULL, } \
201 /* Maximum number of active map areas.. This is a random (large) number */
202 #define DEFAULT_MAX_MAP_COUNT (65536)
204 extern int max_map_count;
207 struct vm_area_struct * mmap; /* list of VMAs */
209 struct vm_area_struct * mmap_cache; /* last find_vma result */
211 atomic_t mm_users; /* How many users with user space? */
212 atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
213 int map_count; /* number of VMAs */
214 struct rw_semaphore mmap_sem;
215 spinlock_t page_table_lock; /* Protects task page tables and mm->rss */
217 struct list_head mmlist; /* List of all active mm's. These are globally strung
218 * together off init_mm.mmlist, and are protected
222 unsigned long start_code, end_code, start_data, end_data;
223 unsigned long start_brk, brk, start_stack;
224 unsigned long arg_start, arg_end, env_start, env_end;
225 unsigned long rss, total_vm, locked_vm;
226 unsigned long def_flags;
227 unsigned long cpu_vm_mask;
228 unsigned long swap_address;
232 /* Architecture-specific MM context */
233 mm_context_t context;
236 extern int mmlist_nr;
238 #define INIT_MM(name) \
241 pgd: swapper_pg_dir, \
242 mm_users: ATOMIC_INIT(2), \
243 mm_count: ATOMIC_INIT(1), \
244 mmap_sem: __RWSEM_INITIALIZER(name.mmap_sem), \
245 page_table_lock: SPIN_LOCK_UNLOCKED, \
246 mmlist: LIST_HEAD_INIT(name.mmlist), \
249 struct signal_struct {
251 struct k_sigaction action[_NSIG];
256 #define INIT_SIGNALS { \
257 count: ATOMIC_INIT(1), \
258 action: { {{0,}}, }, \
259 siglock: SPIN_LOCK_UNLOCKED \
263 * Some day this will be a full-fledged user tracking system..
266 atomic_t __count; /* reference count */
267 atomic_t processes; /* How many processes does this user have? */
268 atomic_t files; /* How many open files does this user have? */
270 /* Hash table maintenance information */
271 struct user_struct *next, **pprev;
275 #define get_current_user() ({ \
276 struct user_struct *__tmp_user = current->user; \
277 atomic_inc(&__tmp_user->__count); \
280 extern struct user_struct root_user;
281 #define INIT_USER (&root_user)
285 * offsets of these are hardcoded elsewhere - touch with care
287 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
288 unsigned long flags; /* per process flags, defined below */
290 mm_segment_t addr_limit; /* thread address space:
291 0-0xBFFFFFFF for user-thead
292 0-0xFFFFFFFF for kernel-thread
294 struct exec_domain *exec_domain;
295 volatile long need_resched;
296 unsigned long ptrace;
298 int lock_depth; /* Lock depth */
301 * offset 32 begins here on 32-bit platforms. We keep
302 * all fields in a single cacheline that are needed for
303 * the goodness() loop in schedule().
307 unsigned long policy;
308 struct mm_struct *mm;
311 * cpus_runnable is ~0 if the process is not running on any
312 * CPU. It's (1 << cpu) if it's running on a CPU. This mask
313 * is updated under the runqueue lock.
315 * To determine whether a process might run on a CPU, this
316 * mask is AND-ed with cpus_allowed.
318 unsigned long cpus_runnable, cpus_allowed;
320 * (only the 'next' pointer fits into the cacheline, but
323 struct list_head run_list;
324 unsigned long sleep_time;
326 struct task_struct *next_task, *prev_task;
327 struct mm_struct *active_mm;
328 struct list_head local_pages;
329 unsigned int allocation_order, nr_local_pages;
332 struct linux_binfmt *binfmt;
333 int exit_code, exit_signal;
334 int pdeath_signal; /* The signal sent when the parent dies */
336 unsigned long personality;
338 unsigned task_dumpable:1;
344 /* boolean value for session group leader */
347 * pointers to (original) parent process, youngest child, younger sibling,
348 * older sibling, respectively. (p->father can be replaced with
351 struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
352 struct list_head thread_group;
354 /* PID hash table linkage. */
355 struct task_struct *pidhash_next;
356 struct task_struct **pidhash_pprev;
358 wait_queue_head_t wait_chldexit; /* for wait4() */
359 struct completion *vfork_done; /* for vfork() */
360 unsigned long rt_priority;
361 unsigned long it_real_value, it_prof_value, it_virt_value;
362 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
363 struct timer_list real_timer;
365 unsigned long start_time;
366 long per_cpu_utime[NR_CPUS], per_cpu_stime[NR_CPUS];
367 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
368 unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
370 /* process credentials */
371 uid_t uid,euid,suid,fsuid;
372 gid_t gid,egid,sgid,fsgid;
374 gid_t groups[NGROUPS];
375 kernel_cap_t cap_effective, cap_inheritable, cap_permitted;
376 int keep_capabilities:1;
377 struct user_struct *user;
379 struct rlimit rlim[RLIM_NLIMITS];
380 unsigned short used_math;
382 /* file system info */
383 int link_count, total_link_count;
384 struct tty_struct *tty; /* NULL if no tty */
385 unsigned int locks; /* How many file locks are being held */
387 struct sem_undo *semundo;
388 struct sem_queue *semsleeping;
389 /* CPU-specific state of this task */
390 struct thread_struct thread;
391 /* filesystem information */
392 struct fs_struct *fs;
393 /* open file information */
394 struct files_struct *files;
396 struct namespace *namespace;
397 /* signal handlers */
398 spinlock_t sigmask_lock; /* Protects signal and blocked */
399 struct signal_struct *sig;
402 struct sigpending pending;
404 unsigned long sas_ss_sp;
406 int (*notifier)(void *priv);
408 sigset_t *notifier_mask;
410 /* Thread group tracking */
413 /* Protection of (de-)allocation: mm, files, fs, tty */
414 spinlock_t alloc_lock;
416 /* journalling filesystem info */
419 struct list_head *scm_work_list;
425 #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */
426 /* Not implemented yet, only for 486*/
427 #define PF_STARTING 0x00000002 /* being created */
428 #define PF_EXITING 0x00000004 /* getting shut down */
429 #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
430 #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */
431 #define PF_DUMPCORE 0x00000200 /* dumped core */
432 #define PF_SIGNALED 0x00000400 /* killed by a signal */
433 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
434 #define PF_MEMDIE 0x00001000 /* Killed for out-of-memory */
435 #define PF_FREE_PAGES 0x00002000 /* per process page freeing */
436 #define PF_NOIO 0x00004000 /* avoid generating further I/O */
437 #define PF_FSTRANS 0x00008000 /* inside a filesystem transaction */
439 #define PF_USEDFPU 0x00100000 /* task used FPU this quantum (SMP) */
445 #define PT_PTRACED 0x00000001
446 #define PT_TRACESYS 0x00000002
447 #define PT_DTRACE 0x00000004 /* delayed trace (used on m68k, i386) */
448 #define PT_TRACESYSGOOD 0x00000008
449 #define PT_PTRACE_CAP 0x00000010 /* ptracer can follow suid-exec */
451 #define is_dumpable(tsk) ((tsk)->task_dumpable && (tsk)->mm && (tsk)->mm->dumpable)
454 * Limit the stack by to some sane default: root can always
455 * increase this limit if needed.. 8MB seems reasonable.
457 #define _STK_LIM (8*1024*1024)
459 #define DEF_COUNTER (10*HZ/100) /* 100 ms time slice */
460 #define MAX_COUNTER (20*HZ/100)
463 extern void yield(void);
466 * The default (Linux) execution domain.
468 extern struct exec_domain default_exec_domain;
471 * INIT_TASK is used to set up the first task table, touch at
472 * your own risk!. Base=0, limit=0x1fffff (=2MB)
474 #define INIT_TASK(tsk) \
479 addr_limit: KERNEL_DS, \
480 exec_domain: &default_exec_domain, \
482 counter: DEF_COUNTER, \
484 policy: SCHED_OTHER, \
486 active_mm: &init_mm, \
487 cpus_runnable: ~0UL, \
488 cpus_allowed: ~0UL, \
489 run_list: LIST_HEAD_INIT(tsk.run_list), \
494 thread_group: LIST_HEAD_INIT(tsk.thread_group), \
495 wait_chldexit: __WAIT_QUEUE_HEAD_INITIALIZER(tsk.wait_chldexit),\
497 function: it_real_fn \
499 cap_effective: CAP_INIT_EFF_SET, \
500 cap_inheritable: CAP_INIT_INH_SET, \
501 cap_permitted: CAP_FULL_SET, \
502 keep_capabilities: 0, \
503 rlim: INIT_RLIMITS, \
506 thread: INIT_THREAD, \
508 files: &init_files, \
509 sigmask_lock: SPIN_LOCK_UNLOCKED, \
510 sig: &init_signals, \
511 pending: { NULL, &tsk.pending.head, {{0}}}, \
513 alloc_lock: SPIN_LOCK_UNLOCKED, \
514 journal_info: NULL, \
518 #ifndef INIT_TASK_SIZE
519 # define INIT_TASK_SIZE 2048*sizeof(long)
523 struct task_struct task;
524 unsigned long stack[INIT_TASK_SIZE/sizeof(long)];
527 extern union task_union init_task_union;
529 extern struct mm_struct init_mm;
530 extern struct task_struct *init_tasks[NR_CPUS];
532 /* PID hashing. (shouldnt this be dynamic?) */
533 #define PIDHASH_SZ (4096 >> 2)
534 extern struct task_struct *pidhash[PIDHASH_SZ];
536 #define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
538 static inline void hash_pid(struct task_struct *p)
540 struct task_struct **htable = &pidhash[pid_hashfn(p->pid)];
542 if((p->pidhash_next = *htable) != NULL)
543 (*htable)->pidhash_pprev = &p->pidhash_next;
545 p->pidhash_pprev = htable;
548 static inline void unhash_pid(struct task_struct *p)
551 p->pidhash_next->pidhash_pprev = p->pidhash_pprev;
552 *p->pidhash_pprev = p->pidhash_next;
555 static inline struct task_struct *find_task_by_pid(int pid)
557 struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)];
559 for(p = *htable; p && p->pid != pid; p = p->pidhash_next)
565 #define task_has_cpu(tsk) ((tsk)->cpus_runnable != ~0UL)
567 static inline void task_set_cpu(struct task_struct *tsk, unsigned int cpu)
569 tsk->processor = cpu;
570 tsk->cpus_runnable = 1UL << cpu;
573 static inline void task_release_cpu(struct task_struct *tsk)
575 tsk->cpus_runnable = ~0UL;
578 /* per-UID process charging. */
579 extern struct user_struct * alloc_uid(uid_t);
580 extern void free_uid(struct user_struct *);
581 extern void switch_uid(struct user_struct *);
583 #include <asm/current.h>
585 extern unsigned long volatile jiffies;
586 extern unsigned long itimer_ticks;
587 extern unsigned long itimer_next;
588 extern struct timeval xtime;
589 extern void do_timer(struct pt_regs *);
591 extern unsigned int * prof_buffer;
592 extern unsigned long prof_len;
593 extern unsigned long prof_shift;
595 #define CURRENT_TIME (xtime.tv_sec)
597 extern void FASTCALL(__wake_up(wait_queue_head_t *q, unsigned int mode, int nr));
598 extern void FASTCALL(__wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr));
599 extern void FASTCALL(sleep_on(wait_queue_head_t *q));
600 extern long FASTCALL(sleep_on_timeout(wait_queue_head_t *q,
601 signed long timeout));
602 extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t *q));
603 extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t *q,
604 signed long timeout));
605 extern int FASTCALL(wake_up_process(struct task_struct * tsk));
607 #define wake_up(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 1)
608 #define wake_up_nr(x, nr) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, nr)
609 #define wake_up_all(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 0)
610 #define wake_up_sync(x) __wake_up_sync((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 1)
611 #define wake_up_sync_nr(x, nr) __wake_up_sync((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, nr)
612 #define wake_up_interruptible(x) __wake_up((x),TASK_INTERRUPTIBLE, 1)
613 #define wake_up_interruptible_nr(x, nr) __wake_up((x),TASK_INTERRUPTIBLE, nr)
614 #define wake_up_interruptible_all(x) __wake_up((x),TASK_INTERRUPTIBLE, 0)
615 #define wake_up_interruptible_sync(x) __wake_up_sync((x),TASK_INTERRUPTIBLE, 1)
616 #define wake_up_interruptible_sync_nr(x, nr) __wake_up_sync((x),TASK_INTERRUPTIBLE, nr)
617 asmlinkage long sys_wait4(pid_t pid,unsigned int * stat_addr, int options, struct rusage * ru);
619 extern int in_group_p(gid_t);
620 extern int in_egroup_p(gid_t);
622 extern void proc_caches_init(void);
623 extern void flush_signals(struct task_struct *);
624 extern void flush_signal_handlers(struct task_struct *);
625 extern void sig_exit(int, int, struct siginfo *);
626 extern int dequeue_signal(sigset_t *, siginfo_t *);
627 extern void block_all_signals(int (*notifier)(void *priv), void *priv,
629 extern void unblock_all_signals(void);
630 extern int send_sig_info(int, struct siginfo *, struct task_struct *);
631 extern int force_sig_info(int, struct siginfo *, struct task_struct *);
632 extern int kill_pg_info(int, struct siginfo *, pid_t);
633 extern int kill_sl_info(int, struct siginfo *, pid_t);
634 extern int kill_proc_info(int, struct siginfo *, pid_t);
635 extern void notify_parent(struct task_struct *, int);
636 extern void do_notify_parent(struct task_struct *, int);
637 extern void force_sig(int, struct task_struct *);
638 extern int send_sig(int, struct task_struct *, int);
639 extern int kill_pg(pid_t, int, int);
640 extern int kill_sl(pid_t, int, int);
641 extern int kill_proc(pid_t, int, int);
642 extern int do_sigaction(int, const struct k_sigaction *, struct k_sigaction *);
643 extern int do_sigaltstack(const stack_t *, stack_t *, unsigned long);
645 static inline int signal_pending(struct task_struct *p)
647 return (p->sigpending != 0);
651 * Re-calculate pending state from the set of locally pending
652 * signals, globally pending signals, and blocked signals.
654 static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked)
659 switch (_NSIG_WORDS) {
661 for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
662 ready |= signal->sig[i] &~ blocked->sig[i];
665 case 4: ready = signal->sig[3] &~ blocked->sig[3];
666 ready |= signal->sig[2] &~ blocked->sig[2];
667 ready |= signal->sig[1] &~ blocked->sig[1];
668 ready |= signal->sig[0] &~ blocked->sig[0];
671 case 2: ready = signal->sig[1] &~ blocked->sig[1];
672 ready |= signal->sig[0] &~ blocked->sig[0];
675 case 1: ready = signal->sig[0] &~ blocked->sig[0];
680 /* Reevaluate whether the task has signals pending delivery.
681 This is required every time the blocked sigset_t changes.
682 All callers should have t->sigmask_lock. */
684 static inline void recalc_sigpending(struct task_struct *t)
686 t->sigpending = has_pending_signals(&t->pending.signal, &t->blocked);
689 /* True if we are on the alternate signal stack. */
691 static inline int on_sig_stack(unsigned long sp)
693 return (sp - current->sas_ss_sp < current->sas_ss_size);
696 static inline int sas_ss_flags(unsigned long sp)
698 return (current->sas_ss_size == 0 ? SS_DISABLE
699 : on_sig_stack(sp) ? SS_ONSTACK : 0);
702 extern int request_irq(unsigned int,
703 void (*handler)(int, void *, struct pt_regs *),
704 unsigned long, const char *, void *);
705 extern void free_irq(unsigned int, void *);
708 * This has now become a routine instead of a macro, it sets a flag if
709 * it returns true (to do BSD-style accounting where the process is flagged
710 * if it uses root privs). The implication of this is that you should do
711 * normal permissions checks first, and check suser() last.
713 * [Dec 1997 -- Chris Evans]
714 * For correctness, the above considerations need to be extended to
715 * fsuser(). This is done, along with moving fsuser() checks to be
718 * These will be removed, but in the mean time, when the SECURE_NOROOT
719 * flag is set, uids don't grant privilege.
721 static inline int suser(void)
723 if (!issecure(SECURE_NOROOT) && current->euid == 0) {
724 current->flags |= PF_SUPERPRIV;
730 static inline int fsuser(void)
732 if (!issecure(SECURE_NOROOT) && current->fsuid == 0) {
733 current->flags |= PF_SUPERPRIV;
740 * capable() checks for a particular capability.
741 * New privilege checks should use this interface, rather than suser() or
742 * fsuser(). See include/linux/capability.h for defined capabilities.
745 static inline int capable(int cap)
748 if (cap_raised(current->cap_effective, cap))
750 if (cap_is_fs_cap(cap) ? current->fsuid == 0 : current->euid == 0)
753 current->flags |= PF_SUPERPRIV;
760 * Routines for handling mm_structs
762 extern struct mm_struct * mm_alloc(void);
764 extern struct mm_struct * start_lazy_tlb(void);
765 extern void end_lazy_tlb(struct mm_struct *mm);
767 /* mmdrop drops the mm and the page tables */
768 extern void FASTCALL(__mmdrop(struct mm_struct *));
769 static inline void mmdrop(struct mm_struct * mm)
771 if (atomic_dec_and_test(&mm->mm_count))
775 /* mmput gets rid of the mappings and all user-space */
776 extern void mmput(struct mm_struct *);
777 /* Remove the current tasks stale references to the old mm_struct */
778 extern void mm_release(void);
781 * Routines for handling the fd arrays
783 extern struct file ** alloc_fd_array(int);
784 extern int expand_fd_array(struct files_struct *, int nr);
785 extern void free_fd_array(struct file **, int);
787 extern fd_set *alloc_fdset(int);
788 extern int expand_fdset(struct files_struct *, int nr);
789 extern void free_fdset(fd_set *, int);
791 extern int copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
792 extern void flush_thread(void);
793 extern void exit_thread(void);
795 extern void exit_mm(struct task_struct *);
796 extern void exit_files(struct task_struct *);
797 extern void exit_sighand(struct task_struct *);
799 extern void reparent_to_init(void);
800 extern void daemonize(void);
802 extern int do_execve(char *, char **, char **, struct pt_regs *);
803 extern int do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long);
805 extern void set_task_comm(struct task_struct *tsk, char *from);
806 extern void get_task_comm(char *to, struct task_struct *tsk);
808 extern void FASTCALL(add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
809 extern void FASTCALL(add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t * wait));
810 extern void FASTCALL(remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
812 extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
814 #define __wait_event(wq, condition) \
816 wait_queue_t __wait; \
817 init_waitqueue_entry(&__wait, current); \
819 add_wait_queue(&wq, &__wait); \
821 set_current_state(TASK_UNINTERRUPTIBLE); \
826 current->state = TASK_RUNNING; \
827 remove_wait_queue(&wq, &__wait); \
830 #define wait_event(wq, condition) \
834 __wait_event(wq, condition); \
837 #define __wait_event_interruptible(wq, condition, ret) \
839 wait_queue_t __wait; \
840 init_waitqueue_entry(&__wait, current); \
842 add_wait_queue(&wq, &__wait); \
844 set_current_state(TASK_INTERRUPTIBLE); \
847 if (!signal_pending(current)) { \
851 ret = -ERESTARTSYS; \
854 current->state = TASK_RUNNING; \
855 remove_wait_queue(&wq, &__wait); \
858 #define wait_event_interruptible(wq, condition) \
862 __wait_event_interruptible(wq, condition, __ret); \
866 #define REMOVE_LINKS(p) do { \
867 (p)->next_task->prev_task = (p)->prev_task; \
868 (p)->prev_task->next_task = (p)->next_task; \
870 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
872 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
874 (p)->p_pptr->p_cptr = (p)->p_osptr; \
877 #define SET_LINKS(p) do { \
878 (p)->next_task = &init_task; \
879 (p)->prev_task = init_task.prev_task; \
880 init_task.prev_task->next_task = (p); \
881 init_task.prev_task = (p); \
882 (p)->p_ysptr = NULL; \
883 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
884 (p)->p_osptr->p_ysptr = p; \
885 (p)->p_pptr->p_cptr = p; \
888 #define for_each_task(p) \
889 for (p = &init_task ; (p = p->next_task) != &init_task ; )
891 #define for_each_thread(task) \
892 for (task = next_thread(current) ; task != current ; task = next_thread(task))
894 #define next_thread(p) \
895 list_entry((p)->thread_group.next, struct task_struct, thread_group)
897 #define thread_group_leader(p) (p->pid == p->tgid)
899 static inline void del_from_runqueue(struct task_struct * p)
902 p->sleep_time = jiffies;
903 list_del(&p->run_list);
904 p->run_list.next = NULL;
907 static inline int task_on_runqueue(struct task_struct *p)
909 return (p->run_list.next != NULL);
912 static inline void unhash_process(struct task_struct *p)
914 if (task_on_runqueue(p))
916 write_lock_irq(&tasklist_lock);
920 list_del(&p->thread_group);
921 write_unlock_irq(&tasklist_lock);
924 /* Protects ->fs, ->files, ->mm, and synchronises with wait4(). Nests inside tasklist_lock */
925 static inline void task_lock(struct task_struct *p)
927 spin_lock(&p->alloc_lock);
930 static inline void task_unlock(struct task_struct *p)
932 spin_unlock(&p->alloc_lock);
935 /* write full pathname into buffer and return start of pathname */
936 static inline char * d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
937 char *buf, int buflen)
940 struct vfsmount *rootmnt;
942 read_lock(¤t->fs->lock);
943 rootmnt = mntget(current->fs->rootmnt);
944 root = dget(current->fs->root);
945 read_unlock(¤t->fs->lock);
946 spin_lock(&dcache_lock);
947 res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
948 spin_unlock(&dcache_lock);
954 static inline int need_resched(void)
956 return (unlikely(current->need_resched));
959 extern void __cond_resched(void);
960 static inline void cond_resched(void)
966 #endif /* __KERNEL__ */