- pre3:
[davej-history.git] / include / linux / sched.h
blob1530af1ccbe3b5ad107ebddc3af21694502aeaf6
1 #ifndef _LINUX_SCHED_H
2 #define _LINUX_SCHED_H
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/personality.h>
11 #include <linux/threads.h>
12 #include <linux/kernel.h>
13 #include <linux/types.h>
14 #include <linux/times.h>
15 #include <linux/timex.h>
17 #include <asm/system.h>
18 #include <asm/semaphore.h>
19 #include <asm/page.h>
20 #include <asm/ptrace.h>
22 #include <linux/smp.h>
23 #include <linux/tty.h>
24 #include <linux/sem.h>
25 #include <linux/signal.h>
26 #include <linux/securebits.h>
27 #include <linux/fs_struct.h>
30 * cloning flags:
32 #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
33 #define CLONE_VM 0x00000100 /* set if VM shared between processes */
34 #define CLONE_FS 0x00000200 /* set if fs info shared between processes */
35 #define CLONE_FILES 0x00000400 /* set if open files shared between processes */
36 #define CLONE_SIGNAL 0x00000800 /* set if signal handlers and blocked signals shared */
37 #define CLONE_PID 0x00001000 /* set if pid shared */
38 #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
39 #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
40 #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
42 #define CLONE_SIGHAND CLONE_SIGNAL /* Old name */
45 * These are the constant used to fake the fixed-point load-average
46 * counting. Some notes:
47 * - 11 bit fractions expand to 22 bits by the multiplies: this gives
48 * a load-average precision of 10 bits integer + 11 bits fractional
49 * - if you want to count load-averages more often, you need more
50 * precision, or rounding will get you. With 2-second counting freq,
51 * the EXP_n values would be 1981, 2034 and 2043 if still using only
52 * 11 bit fractions.
54 extern unsigned long avenrun[]; /* Load averages */
56 #define FSHIFT 11 /* nr of bits of precision */
57 #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
58 #define LOAD_FREQ (5*HZ) /* 5 sec intervals */
59 #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */
60 #define EXP_5 2014 /* 1/exp(5sec/5min) */
61 #define EXP_15 2037 /* 1/exp(5sec/15min) */
63 #define CALC_LOAD(load,exp,n) \
64 load *= exp; \
65 load += n*(FIXED_1-exp); \
66 load >>= FSHIFT;
68 #define CT_TO_SECS(x) ((x) / HZ)
69 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
71 extern int nr_running, nr_threads;
72 extern int last_pid;
74 #include <linux/fs.h>
75 #include <linux/time.h>
76 #include <linux/param.h>
77 #include <linux/resource.h>
78 #include <linux/timer.h>
80 #include <asm/processor.h>
82 #define TASK_RUNNING 0
83 #define TASK_INTERRUPTIBLE 1
84 #define TASK_UNINTERRUPTIBLE 2
85 #define TASK_ZOMBIE 4
86 #define TASK_STOPPED 8
87 #define TASK_EXCLUSIVE 32
89 #define __set_task_state(tsk, state_value) \
90 do { (tsk)->state = (state_value); } while (0)
91 #ifdef CONFIG_SMP
92 #define set_task_state(tsk, state_value) \
93 set_mb((tsk)->state, (state_value))
94 #else
95 #define set_task_state(tsk, state_value) \
96 __set_task_state((tsk), (state_value))
97 #endif
99 #define __set_current_state(state_value) \
100 do { current->state = (state_value); } while (0)
101 #ifdef CONFIG_SMP
102 #define set_current_state(state_value) \
103 set_mb(current->state, (state_value))
104 #else
105 #define set_current_state(state_value) \
106 __set_current_state(state_value)
107 #endif
110 * Scheduling policies
112 #define SCHED_OTHER 0
113 #define SCHED_FIFO 1
114 #define SCHED_RR 2
117 * This is an additional bit set when we want to
118 * yield the CPU for one re-schedule..
120 #define SCHED_YIELD 0x10
122 struct sched_param {
123 int sched_priority;
126 #ifdef __KERNEL__
128 #include <linux/spinlock.h>
131 * This serializes "schedule()" and also protects
132 * the run-queue from deletions/modifications (but
133 * _adding_ to the beginning of the run-queue has
134 * a separate lock).
136 extern rwlock_t tasklist_lock;
137 extern spinlock_t runqueue_lock;
139 extern void sched_init(void);
140 extern void init_idle(void);
141 extern void show_state(void);
142 extern void cpu_init (void);
143 extern void trap_init(void);
144 extern void update_process_times(int user);
145 extern void update_one_process(struct task_struct *p, unsigned long user,
146 unsigned long system, int cpu);
148 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
149 extern signed long FASTCALL(schedule_timeout(signed long timeout));
150 asmlinkage void schedule(void);
153 * The default fd array needs to be at least BITS_PER_LONG,
154 * as this is the granularity returned by copy_fdset().
156 #define NR_OPEN_DEFAULT BITS_PER_LONG
159 * Open file table structure
161 struct files_struct {
162 atomic_t count;
163 rwlock_t file_lock;
164 int max_fds;
165 int max_fdset;
166 int next_fd;
167 struct file ** fd; /* current fd array */
168 fd_set *close_on_exec;
169 fd_set *open_fds;
170 fd_set close_on_exec_init;
171 fd_set open_fds_init;
172 struct file * fd_array[NR_OPEN_DEFAULT];
175 #define INIT_FILES { \
176 ATOMIC_INIT(1), \
177 RW_LOCK_UNLOCKED, \
178 NR_OPEN_DEFAULT, \
179 __FD_SETSIZE, \
180 0, \
181 &init_files.fd_array[0], \
182 &init_files.close_on_exec_init, \
183 &init_files.open_fds_init, \
184 { { 0, } }, \
185 { { 0, } }, \
186 { NULL, } \
189 /* Maximum number of active map areas.. This is a random (large) number */
190 #define MAX_MAP_COUNT (65536)
192 /* Number of map areas at which the AVL tree is activated. This is arbitrary. */
193 #define AVL_MIN_MAP_COUNT 32
195 struct mm_struct {
196 struct vm_area_struct * mmap; /* list of VMAs */
197 struct vm_area_struct * mmap_avl; /* tree of VMAs */
198 struct vm_area_struct * mmap_cache; /* last find_vma result */
199 pgd_t * pgd;
200 atomic_t mm_users; /* How many users with user space? */
201 atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
202 int map_count; /* number of VMAs */
203 struct semaphore mmap_sem;
204 spinlock_t page_table_lock;
205 unsigned long context;
206 unsigned long start_code, end_code, start_data, end_data;
207 unsigned long start_brk, brk, start_stack;
208 unsigned long arg_start, arg_end, env_start, env_end;
209 unsigned long rss, total_vm, locked_vm;
210 unsigned long def_flags;
211 unsigned long cpu_vm_mask;
212 unsigned long swap_cnt; /* number of pages to swap on next pass */
213 unsigned long swap_address;
215 * This is an architecture-specific pointer: the portable
216 * part of Linux does not know about any segments.
218 void * segments;
221 #define INIT_MM(name) { \
222 &init_mmap, NULL, NULL, \
223 swapper_pg_dir, \
224 ATOMIC_INIT(2), ATOMIC_INIT(1), 1, \
225 __MUTEX_INITIALIZER(name.mmap_sem), \
226 SPIN_LOCK_UNLOCKED, \
227 0, \
228 0, 0, 0, 0, \
229 0, 0, 0, \
230 0, 0, 0, 0, \
231 0, 0, 0, \
232 0, 0, 0, 0, NULL }
234 struct signal_struct {
235 atomic_t count;
236 struct k_sigaction action[_NSIG];
237 spinlock_t siglock;
241 #define INIT_SIGNALS { \
242 ATOMIC_INIT(1), \
243 { {{0,}}, }, \
244 SPIN_LOCK_UNLOCKED }
247 * Some day this will be a full-fledged user tracking system..
249 struct user_struct {
250 atomic_t __count; /* reference count */
251 atomic_t processes; /* How many processes does this user have? */
252 atomic_t files; /* How many open files does this user have? */
254 /* Hash table maintenance information */
255 struct user_struct *next, **pprev;
256 unsigned int uid;
259 #define get_current_user() ({ \
260 struct user_struct *__user = current->user; \
261 atomic_inc(&__user->__count); \
262 __user; })
264 extern struct user_struct root_user;
265 #define INIT_USER (&root_user)
267 struct task_struct {
269 * offsets of these are hardcoded elsewhere - touch with care
271 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
272 unsigned long flags; /* per process flags, defined below */
273 int sigpending;
274 mm_segment_t addr_limit; /* thread address space:
275 0-0xBFFFFFFF for user-thead
276 0-0xFFFFFFFF for kernel-thread
278 struct exec_domain *exec_domain;
279 volatile long need_resched;
280 unsigned long ptrace;
282 int lock_depth; /* Lock depth */
285 * offset 32 begins here on 32-bit platforms. We keep
286 * all fields in a single cacheline that are needed for
287 * the goodness() loop in schedule().
289 long counter;
290 long nice;
291 unsigned long policy;
292 struct mm_struct *mm;
293 int has_cpu, processor;
294 unsigned long cpus_allowed;
296 * (only the 'next' pointer fits into the cacheline, but
297 * that's just fine.)
299 struct list_head run_list;
301 struct task_struct *next_task, *prev_task;
302 struct mm_struct *active_mm;
304 /* task state */
305 struct linux_binfmt *binfmt;
306 int exit_code, exit_signal;
307 int pdeath_signal; /* The signal sent when the parent dies */
308 /* ??? */
309 unsigned long personality;
310 int dumpable:1;
311 int did_exec:1;
312 pid_t pid;
313 pid_t pgrp;
314 pid_t tty_old_pgrp;
315 pid_t session;
316 pid_t tgid;
317 /* boolean value for session group leader */
318 int leader;
320 * pointers to (original) parent process, youngest child, younger sibling,
321 * older sibling, respectively. (p->father can be replaced with
322 * p->p_pptr->pid)
324 struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
325 struct list_head thread_group;
327 /* PID hash table linkage. */
328 struct task_struct *pidhash_next;
329 struct task_struct **pidhash_pprev;
331 wait_queue_head_t wait_chldexit; /* for wait4() */
332 struct semaphore *vfork_sem; /* for vfork() */
333 unsigned long rt_priority;
334 unsigned long it_real_value, it_prof_value, it_virt_value;
335 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
336 struct timer_list real_timer;
337 struct tms times;
338 unsigned long start_time;
339 long per_cpu_utime[NR_CPUS], per_cpu_stime[NR_CPUS];
340 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
341 unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
342 int swappable:1;
343 /* process credentials */
344 uid_t uid,euid,suid,fsuid;
345 gid_t gid,egid,sgid,fsgid;
346 int ngroups;
347 gid_t groups[NGROUPS];
348 kernel_cap_t cap_effective, cap_inheritable, cap_permitted;
349 int keep_capabilities:1;
350 struct user_struct *user;
351 /* limits */
352 struct rlimit rlim[RLIM_NLIMITS];
353 unsigned short used_math;
354 char comm[16];
355 /* file system info */
356 int link_count;
357 struct tty_struct *tty; /* NULL if no tty */
358 /* ipc stuff */
359 struct sem_undo *semundo;
360 struct sem_queue *semsleeping;
361 /* CPU-specific state of this task */
362 struct thread_struct thread;
363 /* filesystem information */
364 struct fs_struct *fs;
365 /* open file information */
366 struct files_struct *files;
367 /* signal handlers */
368 spinlock_t sigmask_lock; /* Protects signal and blocked */
369 struct signal_struct *sig;
371 sigset_t blocked;
372 struct sigpending pending;
374 unsigned long sas_ss_sp;
375 size_t sas_ss_size;
376 int (*notifier)(void *priv);
377 void *notifier_data;
378 sigset_t *notifier_mask;
380 /* Thread group tracking */
381 u32 parent_exec_id;
382 u32 self_exec_id;
383 /* Protection of (de-)allocation: mm, files, fs, tty */
384 spinlock_t alloc_lock;
388 * Per process flags
390 #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */
391 /* Not implemented yet, only for 486*/
392 #define PF_STARTING 0x00000002 /* being created */
393 #define PF_EXITING 0x00000004 /* getting shut down */
394 #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
395 #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */
396 #define PF_DUMPCORE 0x00000200 /* dumped core */
397 #define PF_SIGNALED 0x00000400 /* killed by a signal */
398 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
399 #define PF_VFORK 0x00001000 /* Wake up parent in mm_release */
401 #define PF_USEDFPU 0x00100000 /* task used FPU this quantum (SMP) */
404 * Ptrace flags
407 #define PT_PTRACED 0x00000001
408 #define PT_TRACESYS 0x00000002
409 #define PT_DTRACE 0x00000004 /* delayed trace (used on m68k, i386) */
412 * Limit the stack by to some sane default: root can always
413 * increase this limit if needed.. 8MB seems reasonable.
415 #define _STK_LIM (8*1024*1024)
417 #define DEF_COUNTER (10*HZ/100) /* 100 ms time slice */
418 #define MAX_COUNTER (20*HZ/100)
419 #define DEF_NICE (0)
422 * INIT_TASK is used to set up the first task table, touch at
423 * your own risk!. Base=0, limit=0x1fffff (=2MB)
425 #define INIT_TASK(tsk) \
427 state: 0, \
428 flags: 0, \
429 sigpending: 0, \
430 addr_limit: KERNEL_DS, \
431 exec_domain: &default_exec_domain, \
432 lock_depth: -1, \
433 counter: DEF_COUNTER, \
434 nice: DEF_NICE, \
435 policy: SCHED_OTHER, \
436 mm: NULL, \
437 active_mm: &init_mm, \
438 cpus_allowed: -1, \
439 run_list: LIST_HEAD_INIT(tsk.run_list), \
440 next_task: &tsk, \
441 prev_task: &tsk, \
442 p_opptr: &tsk, \
443 p_pptr: &tsk, \
444 thread_group: LIST_HEAD_INIT(tsk.thread_group), \
445 wait_chldexit: __WAIT_QUEUE_HEAD_INITIALIZER(tsk.wait_chldexit),\
446 real_timer: { \
447 function: it_real_fn \
448 }, \
449 cap_effective: CAP_INIT_EFF_SET, \
450 cap_inheritable: CAP_INIT_INH_SET, \
451 cap_permitted: CAP_FULL_SET, \
452 keep_capabilities: 0, \
453 rlim: INIT_RLIMITS, \
454 user: INIT_USER, \
455 comm: "swapper", \
456 thread: INIT_THREAD, \
457 fs: &init_fs, \
458 files: &init_files, \
459 sigmask_lock: SPIN_LOCK_UNLOCKED, \
460 sig: &init_signals, \
461 pending: { NULL, &tsk.pending.head, {{0}}}, \
462 blocked: {{0}}, \
463 alloc_lock: SPIN_LOCK_UNLOCKED \
467 #ifndef INIT_TASK_SIZE
468 # define INIT_TASK_SIZE 2048*sizeof(long)
469 #endif
471 union task_union {
472 struct task_struct task;
473 unsigned long stack[INIT_TASK_SIZE/sizeof(long)];
476 extern union task_union init_task_union;
478 extern struct mm_struct init_mm;
479 extern struct task_struct *init_tasks[NR_CPUS];
481 /* PID hashing. (shouldnt this be dynamic?) */
482 #define PIDHASH_SZ (4096 >> 2)
483 extern struct task_struct *pidhash[PIDHASH_SZ];
485 #define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
487 static inline void hash_pid(struct task_struct *p)
489 struct task_struct **htable = &pidhash[pid_hashfn(p->pid)];
491 if((p->pidhash_next = *htable) != NULL)
492 (*htable)->pidhash_pprev = &p->pidhash_next;
493 *htable = p;
494 p->pidhash_pprev = htable;
497 static inline void unhash_pid(struct task_struct *p)
499 if(p->pidhash_next)
500 p->pidhash_next->pidhash_pprev = p->pidhash_pprev;
501 *p->pidhash_pprev = p->pidhash_next;
504 static inline struct task_struct *find_task_by_pid(int pid)
506 struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)];
508 for(p = *htable; p && p->pid != pid; p = p->pidhash_next)
511 return p;
514 /* per-UID process charging. */
515 extern struct user_struct * alloc_uid(uid_t);
516 extern void free_uid(struct user_struct *);
518 #include <asm/current.h>
520 extern unsigned long volatile jiffies;
521 extern unsigned long itimer_ticks;
522 extern unsigned long itimer_next;
523 extern struct timeval xtime;
524 extern void do_timer(struct pt_regs *);
526 extern unsigned int * prof_buffer;
527 extern unsigned long prof_len;
528 extern unsigned long prof_shift;
530 #define CURRENT_TIME (xtime.tv_sec)
532 extern void FASTCALL(__wake_up(wait_queue_head_t *q, unsigned int mode));
533 extern void FASTCALL(__wake_up_sync(wait_queue_head_t *q, unsigned int mode));
534 extern void FASTCALL(sleep_on(wait_queue_head_t *q));
535 extern long FASTCALL(sleep_on_timeout(wait_queue_head_t *q,
536 signed long timeout));
537 extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t *q));
538 extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t *q,
539 signed long timeout));
540 extern void FASTCALL(wake_up_process(struct task_struct * tsk));
542 #define wake_up(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE | TASK_EXCLUSIVE)
543 #define wake_up_all(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE)
544 #define wake_up_sync(x) __wake_up_sync((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE | TASK_EXCLUSIVE)
545 #define wake_up_interruptible(x) __wake_up((x),TASK_INTERRUPTIBLE | TASK_EXCLUSIVE)
546 #define wake_up_interruptible_all(x) __wake_up((x),TASK_INTERRUPTIBLE)
547 #define wake_up_interruptible_sync(x) __wake_up_sync((x),TASK_INTERRUPTIBLE | TASK_EXCLUSIVE)
549 extern int in_group_p(gid_t);
550 extern int in_egroup_p(gid_t);
552 extern void proc_caches_init(void);
553 extern void flush_signals(struct task_struct *);
554 extern void flush_signal_handlers(struct task_struct *);
555 extern int dequeue_signal(sigset_t *, siginfo_t *);
556 extern void block_all_signals(int (*notifier)(void *priv), void *priv,
557 sigset_t *mask);
558 extern void unblock_all_signals(void);
559 extern int send_sig_info(int, struct siginfo *, struct task_struct *);
560 extern int force_sig_info(int, struct siginfo *, struct task_struct *);
561 extern int kill_pg_info(int, struct siginfo *, pid_t);
562 extern int kill_sl_info(int, struct siginfo *, pid_t);
563 extern int kill_proc_info(int, struct siginfo *, pid_t);
564 extern void notify_parent(struct task_struct *, int);
565 extern void do_notify_parent(struct task_struct *, int);
566 extern void force_sig(int, struct task_struct *);
567 extern int send_sig(int, struct task_struct *, int);
568 extern int kill_pg(pid_t, int, int);
569 extern int kill_sl(pid_t, int, int);
570 extern int kill_proc(pid_t, int, int);
571 extern int do_sigaction(int, const struct k_sigaction *, struct k_sigaction *);
572 extern int do_sigaltstack(const stack_t *, stack_t *, unsigned long);
574 static inline int signal_pending(struct task_struct *p)
576 return (p->sigpending != 0);
580 * Re-calculate pending state from the set of locally pending
581 * signals, globally pending signals, and blocked signals.
583 static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked)
585 unsigned long ready;
586 long i;
588 switch (_NSIG_WORDS) {
589 default:
590 for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
591 ready |= signal->sig[i] &~ blocked->sig[i];
592 break;
594 case 4: ready = signal->sig[3] &~ blocked->sig[3];
595 ready |= signal->sig[2] &~ blocked->sig[2];
596 ready |= signal->sig[1] &~ blocked->sig[1];
597 ready |= signal->sig[0] &~ blocked->sig[0];
598 break;
600 case 2: ready = signal->sig[1] &~ blocked->sig[1];
601 ready |= signal->sig[0] &~ blocked->sig[0];
602 break;
604 case 1: ready = signal->sig[0] &~ blocked->sig[0];
606 return ready != 0;
609 /* Reevaluate whether the task has signals pending delivery.
610 This is required every time the blocked sigset_t changes.
611 All callers should have t->sigmask_lock. */
613 static inline void recalc_sigpending(struct task_struct *t)
615 t->sigpending = has_pending_signals(&t->pending.signal, &t->blocked);
618 /* True if we are on the alternate signal stack. */
620 static inline int on_sig_stack(unsigned long sp)
622 return (sp - current->sas_ss_sp < current->sas_ss_size);
625 static inline int sas_ss_flags(unsigned long sp)
627 return (current->sas_ss_size == 0 ? SS_DISABLE
628 : on_sig_stack(sp) ? SS_ONSTACK : 0);
631 extern int request_irq(unsigned int,
632 void (*handler)(int, void *, struct pt_regs *),
633 unsigned long, const char *, void *);
634 extern void free_irq(unsigned int, void *);
637 * This has now become a routine instead of a macro, it sets a flag if
638 * it returns true (to do BSD-style accounting where the process is flagged
639 * if it uses root privs). The implication of this is that you should do
640 * normal permissions checks first, and check suser() last.
642 * [Dec 1997 -- Chris Evans]
643 * For correctness, the above considerations need to be extended to
644 * fsuser(). This is done, along with moving fsuser() checks to be
645 * last.
647 * These will be removed, but in the mean time, when the SECURE_NOROOT
648 * flag is set, uids don't grant privilege.
650 static inline int suser(void)
652 if (!issecure(SECURE_NOROOT) && current->euid == 0) {
653 current->flags |= PF_SUPERPRIV;
654 return 1;
656 return 0;
659 static inline int fsuser(void)
661 if (!issecure(SECURE_NOROOT) && current->fsuid == 0) {
662 current->flags |= PF_SUPERPRIV;
663 return 1;
665 return 0;
669 * capable() checks for a particular capability.
670 * New privilege checks should use this interface, rather than suser() or
671 * fsuser(). See include/linux/capability.h for defined capabilities.
674 static inline int capable(int cap)
676 #if 1 /* ok now */
677 if (cap_raised(current->cap_effective, cap))
678 #else
679 if (cap_is_fs_cap(cap) ? current->fsuid == 0 : current->euid == 0)
680 #endif
682 current->flags |= PF_SUPERPRIV;
683 return 1;
685 return 0;
689 * Routines for handling mm_structs
691 extern struct mm_struct * mm_alloc(void);
693 extern struct mm_struct * start_lazy_tlb(void);
694 extern void end_lazy_tlb(struct mm_struct *mm);
696 /* mmdrop drops the mm and the page tables */
697 extern inline void FASTCALL(__mmdrop(struct mm_struct *));
698 static inline void mmdrop(struct mm_struct * mm)
700 if (atomic_dec_and_test(&mm->mm_count))
701 __mmdrop(mm);
704 /* mmput gets rid of the mappings and all user-space */
705 extern void mmput(struct mm_struct *);
706 /* Remove the current tasks stale references to the old mm_struct */
707 extern void mm_release(void);
710 * Routines for handling the fd arrays
712 extern struct file ** alloc_fd_array(int);
713 extern int expand_fd_array(struct files_struct *, int nr);
714 extern void free_fd_array(struct file **, int);
716 extern fd_set *alloc_fdset(int);
717 extern int expand_fdset(struct files_struct *, int nr);
718 extern void free_fdset(fd_set *, int);
720 extern int copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
721 extern void flush_thread(void);
722 extern void exit_thread(void);
724 extern void exit_mm(struct task_struct *);
725 extern void exit_files(struct task_struct *);
726 extern void exit_sighand(struct task_struct *);
728 extern void daemonize(void);
730 extern int do_execve(char *, char **, char **, struct pt_regs *);
731 extern int do_fork(unsigned long, unsigned long, struct pt_regs *);
733 extern void FASTCALL(add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
734 extern void FASTCALL(add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t * wait));
735 extern void FASTCALL(remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
737 #define __wait_event(wq, condition) \
738 do { \
739 wait_queue_t __wait; \
740 init_waitqueue_entry(&__wait, current); \
742 add_wait_queue(&wq, &__wait); \
743 for (;;) { \
744 set_current_state(TASK_UNINTERRUPTIBLE); \
745 if (condition) \
746 break; \
747 schedule(); \
749 current->state = TASK_RUNNING; \
750 remove_wait_queue(&wq, &__wait); \
751 } while (0)
753 #define wait_event(wq, condition) \
754 do { \
755 if (condition) \
756 break; \
757 __wait_event(wq, condition); \
758 } while (0)
760 #define __wait_event_interruptible(wq, condition, ret) \
761 do { \
762 wait_queue_t __wait; \
763 init_waitqueue_entry(&__wait, current); \
765 add_wait_queue(&wq, &__wait); \
766 for (;;) { \
767 set_current_state(TASK_INTERRUPTIBLE); \
768 if (condition) \
769 break; \
770 if (!signal_pending(current)) { \
771 schedule(); \
772 continue; \
774 ret = -ERESTARTSYS; \
775 break; \
777 current->state = TASK_RUNNING; \
778 remove_wait_queue(&wq, &__wait); \
779 } while (0)
781 #define wait_event_interruptible(wq, condition) \
782 ({ \
783 int __ret = 0; \
784 if (!(condition)) \
785 __wait_event_interruptible(wq, condition, __ret); \
786 __ret; \
789 #define REMOVE_LINKS(p) do { \
790 (p)->next_task->prev_task = (p)->prev_task; \
791 (p)->prev_task->next_task = (p)->next_task; \
792 if ((p)->p_osptr) \
793 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
794 if ((p)->p_ysptr) \
795 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
796 else \
797 (p)->p_pptr->p_cptr = (p)->p_osptr; \
798 } while (0)
800 #define SET_LINKS(p) do { \
801 (p)->next_task = &init_task; \
802 (p)->prev_task = init_task.prev_task; \
803 init_task.prev_task->next_task = (p); \
804 init_task.prev_task = (p); \
805 (p)->p_ysptr = NULL; \
806 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
807 (p)->p_osptr->p_ysptr = p; \
808 (p)->p_pptr->p_cptr = p; \
809 } while (0)
811 #define for_each_task(p) \
812 for (p = &init_task ; (p = p->next_task) != &init_task ; )
814 #define next_thread(p) \
815 list_entry((p)->thread_group.next, struct task_struct, thread_group)
817 static inline void del_from_runqueue(struct task_struct * p)
819 nr_running--;
820 list_del(&p->run_list);
821 p->run_list.next = NULL;
824 static inline int task_on_runqueue(struct task_struct *p)
826 return (p->run_list.next != NULL);
829 static inline void unhash_process(struct task_struct *p)
831 if (task_on_runqueue(p)) BUG();
832 write_lock_irq(&tasklist_lock);
833 nr_threads--;
834 unhash_pid(p);
835 REMOVE_LINKS(p);
836 list_del(&p->thread_group);
837 write_unlock_irq(&tasklist_lock);
840 static inline void task_lock(struct task_struct *p)
842 spin_lock(&p->alloc_lock);
845 static inline void task_unlock(struct task_struct *p)
847 spin_unlock(&p->alloc_lock);
850 /* write full pathname into buffer and return start of pathname */
851 static inline char * d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
852 char *buf, int buflen)
854 char *res;
855 struct vfsmount *rootmnt;
856 struct dentry *root;
857 read_lock(&current->fs->lock);
858 rootmnt = mntget(current->fs->rootmnt);
859 root = dget(current->fs->root);
860 read_unlock(&current->fs->lock);
861 spin_lock(&dcache_lock);
862 res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
863 spin_unlock(&dcache_lock);
864 dput(root);
865 mntput(rootmnt);
866 return res;
869 #endif /* __KERNEL__ */
871 #endif