- pre3:
[davej-history.git] / include / linux / sched.h
blob471a5325bde530a2a42cbe5009a73d325edc98c9
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_SIGHAND 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 */
41 #define CLONE_THREAD 0x00010000 /* Same thread group? */
43 #define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
46 * These are the constant used to fake the fixed-point load-average
47 * counting. Some notes:
48 * - 11 bit fractions expand to 22 bits by the multiplies: this gives
49 * a load-average precision of 10 bits integer + 11 bits fractional
50 * - if you want to count load-averages more often, you need more
51 * precision, or rounding will get you. With 2-second counting freq,
52 * the EXP_n values would be 1981, 2034 and 2043 if still using only
53 * 11 bit fractions.
55 extern unsigned long avenrun[]; /* Load averages */
57 #define FSHIFT 11 /* nr of bits of precision */
58 #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
59 #define LOAD_FREQ (5*HZ) /* 5 sec intervals */
60 #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */
61 #define EXP_5 2014 /* 1/exp(5sec/5min) */
62 #define EXP_15 2037 /* 1/exp(5sec/15min) */
64 #define CALC_LOAD(load,exp,n) \
65 load *= exp; \
66 load += n*(FIXED_1-exp); \
67 load >>= FSHIFT;
69 #define CT_TO_SECS(x) ((x) / HZ)
70 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
72 extern int nr_running, nr_threads;
73 extern int last_pid;
75 #include <linux/fs.h>
76 #include <linux/time.h>
77 #include <linux/param.h>
78 #include <linux/resource.h>
79 #include <linux/timer.h>
81 #include <asm/processor.h>
83 #define TASK_RUNNING 0
84 #define TASK_INTERRUPTIBLE 1
85 #define TASK_UNINTERRUPTIBLE 2
86 #define TASK_ZOMBIE 4
87 #define TASK_STOPPED 8
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 uid_t 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;
300 unsigned long sleep_time;
302 struct task_struct *next_task, *prev_task;
303 struct mm_struct *active_mm;
305 /* task state */
306 struct linux_binfmt *binfmt;
307 int exit_code, exit_signal;
308 int pdeath_signal; /* The signal sent when the parent dies */
309 /* ??? */
310 unsigned long personality;
311 int dumpable:1;
312 int did_exec:1;
313 pid_t pid;
314 pid_t pgrp;
315 pid_t tty_old_pgrp;
316 pid_t session;
317 pid_t tgid;
318 /* boolean value for session group leader */
319 int leader;
321 * pointers to (original) parent process, youngest child, younger sibling,
322 * older sibling, respectively. (p->father can be replaced with
323 * p->p_pptr->pid)
325 struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
326 struct list_head thread_group;
328 /* PID hash table linkage. */
329 struct task_struct *pidhash_next;
330 struct task_struct **pidhash_pprev;
332 wait_queue_head_t wait_chldexit; /* for wait4() */
333 struct semaphore *vfork_sem; /* for vfork() */
334 unsigned long rt_priority;
335 unsigned long it_real_value, it_prof_value, it_virt_value;
336 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
337 struct timer_list real_timer;
338 struct tms times;
339 unsigned long start_time;
340 long per_cpu_utime[NR_CPUS], per_cpu_stime[NR_CPUS];
341 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
342 unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
343 int swappable:1;
344 /* process credentials */
345 uid_t uid,euid,suid,fsuid;
346 gid_t gid,egid,sgid,fsgid;
347 int ngroups;
348 gid_t groups[NGROUPS];
349 kernel_cap_t cap_effective, cap_inheritable, cap_permitted;
350 int keep_capabilities:1;
351 struct user_struct *user;
352 /* limits */
353 struct rlimit rlim[RLIM_NLIMITS];
354 unsigned short used_math;
355 char comm[16];
356 /* file system info */
357 int link_count;
358 struct tty_struct *tty; /* NULL if no tty */
359 unsigned int locks; /* How many file locks are being held */
360 /* ipc stuff */
361 struct sem_undo *semundo;
362 struct sem_queue *semsleeping;
363 /* CPU-specific state of this task */
364 struct thread_struct thread;
365 /* filesystem information */
366 struct fs_struct *fs;
367 /* open file information */
368 struct files_struct *files;
369 /* signal handlers */
370 spinlock_t sigmask_lock; /* Protects signal and blocked */
371 struct signal_struct *sig;
373 sigset_t blocked;
374 struct sigpending pending;
376 unsigned long sas_ss_sp;
377 size_t sas_ss_size;
378 int (*notifier)(void *priv);
379 void *notifier_data;
380 sigset_t *notifier_mask;
382 /* Thread group tracking */
383 u32 parent_exec_id;
384 u32 self_exec_id;
385 /* Protection of (de-)allocation: mm, files, fs, tty */
386 spinlock_t alloc_lock;
390 * Per process flags
392 #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */
393 /* Not implemented yet, only for 486*/
394 #define PF_STARTING 0x00000002 /* being created */
395 #define PF_EXITING 0x00000004 /* getting shut down */
396 #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
397 #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */
398 #define PF_DUMPCORE 0x00000200 /* dumped core */
399 #define PF_SIGNALED 0x00000400 /* killed by a signal */
400 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
401 #define PF_VFORK 0x00001000 /* Wake up parent in mm_release */
403 #define PF_USEDFPU 0x00100000 /* task used FPU this quantum (SMP) */
406 * Ptrace flags
409 #define PT_PTRACED 0x00000001
410 #define PT_TRACESYS 0x00000002
411 #define PT_DTRACE 0x00000004 /* delayed trace (used on m68k, i386) */
412 #define PT_TRACESYSGOOD 0x00000008
415 * Limit the stack by to some sane default: root can always
416 * increase this limit if needed.. 8MB seems reasonable.
418 #define _STK_LIM (8*1024*1024)
420 #define DEF_COUNTER (10*HZ/100) /* 100 ms time slice */
421 #define MAX_COUNTER (20*HZ/100)
422 #define DEF_NICE (0)
425 * INIT_TASK is used to set up the first task table, touch at
426 * your own risk!. Base=0, limit=0x1fffff (=2MB)
428 #define INIT_TASK(tsk) \
430 state: 0, \
431 flags: 0, \
432 sigpending: 0, \
433 addr_limit: KERNEL_DS, \
434 exec_domain: &default_exec_domain, \
435 lock_depth: -1, \
436 counter: DEF_COUNTER, \
437 nice: DEF_NICE, \
438 policy: SCHED_OTHER, \
439 mm: NULL, \
440 active_mm: &init_mm, \
441 cpus_allowed: -1, \
442 run_list: LIST_HEAD_INIT(tsk.run_list), \
443 next_task: &tsk, \
444 prev_task: &tsk, \
445 p_opptr: &tsk, \
446 p_pptr: &tsk, \
447 thread_group: LIST_HEAD_INIT(tsk.thread_group), \
448 wait_chldexit: __WAIT_QUEUE_HEAD_INITIALIZER(tsk.wait_chldexit),\
449 real_timer: { \
450 function: it_real_fn \
451 }, \
452 cap_effective: CAP_INIT_EFF_SET, \
453 cap_inheritable: CAP_INIT_INH_SET, \
454 cap_permitted: CAP_FULL_SET, \
455 keep_capabilities: 0, \
456 rlim: INIT_RLIMITS, \
457 user: INIT_USER, \
458 comm: "swapper", \
459 thread: INIT_THREAD, \
460 fs: &init_fs, \
461 files: &init_files, \
462 sigmask_lock: SPIN_LOCK_UNLOCKED, \
463 sig: &init_signals, \
464 pending: { NULL, &tsk.pending.head, {{0}}}, \
465 blocked: {{0}}, \
466 alloc_lock: SPIN_LOCK_UNLOCKED \
470 #ifndef INIT_TASK_SIZE
471 # define INIT_TASK_SIZE 2048*sizeof(long)
472 #endif
474 union task_union {
475 struct task_struct task;
476 unsigned long stack[INIT_TASK_SIZE/sizeof(long)];
479 extern union task_union init_task_union;
481 extern struct mm_struct init_mm;
482 extern struct task_struct *init_tasks[NR_CPUS];
484 /* PID hashing. (shouldnt this be dynamic?) */
485 #define PIDHASH_SZ (4096 >> 2)
486 extern struct task_struct *pidhash[PIDHASH_SZ];
488 #define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
490 static inline void hash_pid(struct task_struct *p)
492 struct task_struct **htable = &pidhash[pid_hashfn(p->pid)];
494 if((p->pidhash_next = *htable) != NULL)
495 (*htable)->pidhash_pprev = &p->pidhash_next;
496 *htable = p;
497 p->pidhash_pprev = htable;
500 static inline void unhash_pid(struct task_struct *p)
502 if(p->pidhash_next)
503 p->pidhash_next->pidhash_pprev = p->pidhash_pprev;
504 *p->pidhash_pprev = p->pidhash_next;
507 static inline struct task_struct *find_task_by_pid(int pid)
509 struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)];
511 for(p = *htable; p && p->pid != pid; p = p->pidhash_next)
514 return p;
517 /* per-UID process charging. */
518 extern struct user_struct * alloc_uid(uid_t);
519 extern void free_uid(struct user_struct *);
521 #include <asm/current.h>
523 extern unsigned long volatile jiffies;
524 extern unsigned long itimer_ticks;
525 extern unsigned long itimer_next;
526 extern struct timeval xtime;
527 extern void do_timer(struct pt_regs *);
529 extern unsigned int * prof_buffer;
530 extern unsigned long prof_len;
531 extern unsigned long prof_shift;
533 #define CURRENT_TIME (xtime.tv_sec)
535 extern void FASTCALL(__wake_up(wait_queue_head_t *q, unsigned int mode, unsigned int wq_mode));
536 extern void FASTCALL(__wake_up_sync(wait_queue_head_t *q, unsigned int mode, unsigned int wq_mode));
537 extern void FASTCALL(sleep_on(wait_queue_head_t *q));
538 extern long FASTCALL(sleep_on_timeout(wait_queue_head_t *q,
539 signed long timeout));
540 extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t *q));
541 extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t *q,
542 signed long timeout));
543 extern void FASTCALL(wake_up_process(struct task_struct * tsk));
545 #define wake_up(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
546 #define wake_up_all(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,0)
547 #define wake_up_sync(x) __wake_up_sync((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
548 #define wake_up_interruptible(x) __wake_up((x),TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
549 #define wake_up_interruptible_all(x) __wake_up((x),TASK_INTERRUPTIBLE,0)
550 #define wake_up_interruptible_sync(x) __wake_up_sync((x),TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
552 extern int in_group_p(gid_t);
553 extern int in_egroup_p(gid_t);
555 extern void proc_caches_init(void);
556 extern void flush_signals(struct task_struct *);
557 extern void flush_signal_handlers(struct task_struct *);
558 extern int dequeue_signal(sigset_t *, siginfo_t *);
559 extern void block_all_signals(int (*notifier)(void *priv), void *priv,
560 sigset_t *mask);
561 extern void unblock_all_signals(void);
562 extern int send_sig_info(int, struct siginfo *, struct task_struct *);
563 extern int force_sig_info(int, struct siginfo *, struct task_struct *);
564 extern int kill_pg_info(int, struct siginfo *, pid_t);
565 extern int kill_sl_info(int, struct siginfo *, pid_t);
566 extern int kill_proc_info(int, struct siginfo *, pid_t);
567 extern void notify_parent(struct task_struct *, int);
568 extern void do_notify_parent(struct task_struct *, int);
569 extern void force_sig(int, struct task_struct *);
570 extern int send_sig(int, struct task_struct *, int);
571 extern int kill_pg(pid_t, int, int);
572 extern int kill_sl(pid_t, int, int);
573 extern int kill_proc(pid_t, int, int);
574 extern int do_sigaction(int, const struct k_sigaction *, struct k_sigaction *);
575 extern int do_sigaltstack(const stack_t *, stack_t *, unsigned long);
577 static inline int signal_pending(struct task_struct *p)
579 return (p->sigpending != 0);
583 * Re-calculate pending state from the set of locally pending
584 * signals, globally pending signals, and blocked signals.
586 static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked)
588 unsigned long ready;
589 long i;
591 switch (_NSIG_WORDS) {
592 default:
593 for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
594 ready |= signal->sig[i] &~ blocked->sig[i];
595 break;
597 case 4: ready = signal->sig[3] &~ blocked->sig[3];
598 ready |= signal->sig[2] &~ blocked->sig[2];
599 ready |= signal->sig[1] &~ blocked->sig[1];
600 ready |= signal->sig[0] &~ blocked->sig[0];
601 break;
603 case 2: ready = signal->sig[1] &~ blocked->sig[1];
604 ready |= signal->sig[0] &~ blocked->sig[0];
605 break;
607 case 1: ready = signal->sig[0] &~ blocked->sig[0];
609 return ready != 0;
612 /* Reevaluate whether the task has signals pending delivery.
613 This is required every time the blocked sigset_t changes.
614 All callers should have t->sigmask_lock. */
616 static inline void recalc_sigpending(struct task_struct *t)
618 t->sigpending = has_pending_signals(&t->pending.signal, &t->blocked);
621 /* True if we are on the alternate signal stack. */
623 static inline int on_sig_stack(unsigned long sp)
625 return (sp - current->sas_ss_sp < current->sas_ss_size);
628 static inline int sas_ss_flags(unsigned long sp)
630 return (current->sas_ss_size == 0 ? SS_DISABLE
631 : on_sig_stack(sp) ? SS_ONSTACK : 0);
634 extern int request_irq(unsigned int,
635 void (*handler)(int, void *, struct pt_regs *),
636 unsigned long, const char *, void *);
637 extern void free_irq(unsigned int, void *);
640 * This has now become a routine instead of a macro, it sets a flag if
641 * it returns true (to do BSD-style accounting where the process is flagged
642 * if it uses root privs). The implication of this is that you should do
643 * normal permissions checks first, and check suser() last.
645 * [Dec 1997 -- Chris Evans]
646 * For correctness, the above considerations need to be extended to
647 * fsuser(). This is done, along with moving fsuser() checks to be
648 * last.
650 * These will be removed, but in the mean time, when the SECURE_NOROOT
651 * flag is set, uids don't grant privilege.
653 static inline int suser(void)
655 if (!issecure(SECURE_NOROOT) && current->euid == 0) {
656 current->flags |= PF_SUPERPRIV;
657 return 1;
659 return 0;
662 static inline int fsuser(void)
664 if (!issecure(SECURE_NOROOT) && current->fsuid == 0) {
665 current->flags |= PF_SUPERPRIV;
666 return 1;
668 return 0;
672 * capable() checks for a particular capability.
673 * New privilege checks should use this interface, rather than suser() or
674 * fsuser(). See include/linux/capability.h for defined capabilities.
677 static inline int capable(int cap)
679 #if 1 /* ok now */
680 if (cap_raised(current->cap_effective, cap))
681 #else
682 if (cap_is_fs_cap(cap) ? current->fsuid == 0 : current->euid == 0)
683 #endif
685 current->flags |= PF_SUPERPRIV;
686 return 1;
688 return 0;
692 * Routines for handling mm_structs
694 extern struct mm_struct * mm_alloc(void);
696 extern struct mm_struct * start_lazy_tlb(void);
697 extern void end_lazy_tlb(struct mm_struct *mm);
699 /* mmdrop drops the mm and the page tables */
700 extern inline void FASTCALL(__mmdrop(struct mm_struct *));
701 static inline void mmdrop(struct mm_struct * mm)
703 if (atomic_dec_and_test(&mm->mm_count))
704 __mmdrop(mm);
707 /* mmput gets rid of the mappings and all user-space */
708 extern void mmput(struct mm_struct *);
709 /* Remove the current tasks stale references to the old mm_struct */
710 extern void mm_release(void);
713 * Routines for handling the fd arrays
715 extern struct file ** alloc_fd_array(int);
716 extern int expand_fd_array(struct files_struct *, int nr);
717 extern void free_fd_array(struct file **, int);
719 extern fd_set *alloc_fdset(int);
720 extern int expand_fdset(struct files_struct *, int nr);
721 extern void free_fdset(fd_set *, int);
723 extern int copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
724 extern void flush_thread(void);
725 extern void exit_thread(void);
727 extern void exit_mm(struct task_struct *);
728 extern void exit_files(struct task_struct *);
729 extern void exit_sighand(struct task_struct *);
731 extern void daemonize(void);
733 extern int do_execve(char *, char **, char **, struct pt_regs *);
734 extern int do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long);
736 extern void FASTCALL(add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
737 extern void FASTCALL(add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t * wait));
738 extern void FASTCALL(remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
740 #define __wait_event(wq, condition) \
741 do { \
742 wait_queue_t __wait; \
743 init_waitqueue_entry(&__wait, current); \
745 add_wait_queue(&wq, &__wait); \
746 for (;;) { \
747 set_current_state(TASK_UNINTERRUPTIBLE); \
748 if (condition) \
749 break; \
750 schedule(); \
752 current->state = TASK_RUNNING; \
753 remove_wait_queue(&wq, &__wait); \
754 } while (0)
756 #define wait_event(wq, condition) \
757 do { \
758 if (condition) \
759 break; \
760 __wait_event(wq, condition); \
761 } while (0)
763 #define __wait_event_interruptible(wq, condition, ret) \
764 do { \
765 wait_queue_t __wait; \
766 init_waitqueue_entry(&__wait, current); \
768 add_wait_queue(&wq, &__wait); \
769 for (;;) { \
770 set_current_state(TASK_INTERRUPTIBLE); \
771 if (condition) \
772 break; \
773 if (!signal_pending(current)) { \
774 schedule(); \
775 continue; \
777 ret = -ERESTARTSYS; \
778 break; \
780 current->state = TASK_RUNNING; \
781 remove_wait_queue(&wq, &__wait); \
782 } while (0)
784 #define wait_event_interruptible(wq, condition) \
785 ({ \
786 int __ret = 0; \
787 if (!(condition)) \
788 __wait_event_interruptible(wq, condition, __ret); \
789 __ret; \
792 #define REMOVE_LINKS(p) do { \
793 (p)->next_task->prev_task = (p)->prev_task; \
794 (p)->prev_task->next_task = (p)->next_task; \
795 if ((p)->p_osptr) \
796 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
797 if ((p)->p_ysptr) \
798 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
799 else \
800 (p)->p_pptr->p_cptr = (p)->p_osptr; \
801 } while (0)
803 #define SET_LINKS(p) do { \
804 (p)->next_task = &init_task; \
805 (p)->prev_task = init_task.prev_task; \
806 init_task.prev_task->next_task = (p); \
807 init_task.prev_task = (p); \
808 (p)->p_ysptr = NULL; \
809 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
810 (p)->p_osptr->p_ysptr = p; \
811 (p)->p_pptr->p_cptr = p; \
812 } while (0)
814 #define for_each_task(p) \
815 for (p = &init_task ; (p = p->next_task) != &init_task ; )
817 #define next_thread(p) \
818 list_entry((p)->thread_group.next, struct task_struct, thread_group)
820 static inline void del_from_runqueue(struct task_struct * p)
822 nr_running--;
823 p->sleep_time = jiffies;
824 list_del(&p->run_list);
825 p->run_list.next = NULL;
828 static inline int task_on_runqueue(struct task_struct *p)
830 return (p->run_list.next != NULL);
833 static inline void unhash_process(struct task_struct *p)
835 if (task_on_runqueue(p)) BUG();
836 write_lock_irq(&tasklist_lock);
837 nr_threads--;
838 unhash_pid(p);
839 REMOVE_LINKS(p);
840 list_del(&p->thread_group);
841 write_unlock_irq(&tasklist_lock);
844 static inline void task_lock(struct task_struct *p)
846 spin_lock(&p->alloc_lock);
849 static inline void task_unlock(struct task_struct *p)
851 spin_unlock(&p->alloc_lock);
854 /* write full pathname into buffer and return start of pathname */
855 static inline char * d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
856 char *buf, int buflen)
858 char *res;
859 struct vfsmount *rootmnt;
860 struct dentry *root;
861 read_lock(&current->fs->lock);
862 rootmnt = mntget(current->fs->rootmnt);
863 root = dget(current->fs->root);
864 read_unlock(&current->fs->lock);
865 spin_lock(&dcache_lock);
866 res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
867 spin_unlock(&dcache_lock);
868 dput(root);
869 mntput(rootmnt);
870 return res;
873 #endif /* __KERNEL__ */
875 #endif