Import 2.3.25pre1
[davej-history.git] / include / linux / sched.h
blob81ec83c273bbf87aca6a9738feb4d95ce74282bf
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/binfmts.h>
9 #include <linux/personality.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>
16 #include <asm/system.h>
17 #include <asm/semaphore.h>
18 #include <asm/page.h>
19 #include <asm/ptrace.h>
21 #include <linux/smp.h>
22 #include <linux/tty.h>
23 #include <linux/sem.h>
24 #include <linux/signal.h>
25 #include <linux/securebits.h>
28 * cloning flags:
30 #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
31 #define CLONE_VM 0x00000100 /* set if VM shared between processes */
32 #define CLONE_FS 0x00000200 /* set if fs info shared between processes */
33 #define CLONE_FILES 0x00000400 /* set if open files shared between processes */
34 #define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
35 #define CLONE_PID 0x00001000 /* set if pid shared */
36 #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
37 #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
38 #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
41 * These are the constant used to fake the fixed-point load-average
42 * counting. Some notes:
43 * - 11 bit fractions expand to 22 bits by the multiplies: this gives
44 * a load-average precision of 10 bits integer + 11 bits fractional
45 * - if you want to count load-averages more often, you need more
46 * precision, or rounding will get you. With 2-second counting freq,
47 * the EXP_n values would be 1981, 2034 and 2043 if still using only
48 * 11 bit fractions.
50 extern unsigned long avenrun[]; /* Load averages */
52 #define FSHIFT 11 /* nr of bits of precision */
53 #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
54 #define LOAD_FREQ (5*HZ) /* 5 sec intervals */
55 #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */
56 #define EXP_5 2014 /* 1/exp(5sec/5min) */
57 #define EXP_15 2037 /* 1/exp(5sec/15min) */
59 #define CALC_LOAD(load,exp,n) \
60 load *= exp; \
61 load += n*(FIXED_1-exp); \
62 load >>= FSHIFT;
64 #define CT_TO_SECS(x) ((x) / HZ)
65 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
67 extern int nr_running, nr_threads;
68 extern int last_pid;
70 #include <linux/fs.h>
71 #include <linux/time.h>
72 #include <linux/param.h>
73 #include <linux/resource.h>
74 #include <linux/timer.h>
76 #include <asm/processor.h>
78 #define TASK_RUNNING 0
79 #define TASK_INTERRUPTIBLE 1
80 #define TASK_UNINTERRUPTIBLE 2
81 #define TASK_ZOMBIE 4
82 #define TASK_STOPPED 8
83 #define TASK_SWAPPING 16
84 #define TASK_EXCLUSIVE 32
86 #define __set_task_state(tsk, state_value) \
87 do { tsk->state = state_value; } while (0)
88 #ifdef __SMP__
89 #define set_task_state(tsk, state_value) \
90 set_mb(tsk->state, state_value)
91 #else
92 #define set_task_state(tsk, state_value) \
93 __set_task_state(tsk, state_value)
94 #endif
96 #define __set_current_state(state_value) \
97 do { current->state = state_value; } while (0)
98 #ifdef __SMP__
99 #define set_current_state(state_value) \
100 set_mb(current->state, state_value)
101 #else
102 #define set_current_state(state_value) \
103 __set_current_state(state_value)
104 #endif
107 * Scheduling policies
109 #define SCHED_OTHER 0
110 #define SCHED_FIFO 1
111 #define SCHED_RR 2
114 * This is an additional bit set when we want to
115 * yield the CPU for one re-schedule..
117 #define SCHED_YIELD 0x10
119 struct sched_param {
120 int sched_priority;
123 #ifndef NULL
124 #define NULL ((void *) 0)
125 #endif
127 #ifdef __KERNEL__
129 #include <linux/spinlock.h>
132 * This serializes "schedule()" and also protects
133 * the run-queue from deletions/modifications (but
134 * _adding_ to the beginning of the run-queue has
135 * a separate lock).
137 extern rwlock_t tasklist_lock;
138 extern spinlock_t runqueue_lock;
140 extern void sched_init(void);
141 extern void init_idle(void);
142 extern void show_state(void);
143 extern void cpu_init (void);
144 extern void trap_init(void);
145 extern void update_one_process( struct task_struct *p,
146 unsigned long ticks, unsigned long user, 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 struct fs_struct {
190 atomic_t count;
191 int umask;
192 struct dentry * root, * pwd;
195 #define INIT_FS { \
196 ATOMIC_INIT(1), \
197 0022, \
198 NULL, NULL \
201 /* Maximum number of active map areas.. This is a random (large) number */
202 #define MAX_MAP_COUNT (65536)
204 /* Number of map areas at which the AVL tree is activated. This is arbitrary. */
205 #define AVL_MIN_MAP_COUNT 32
207 struct mm_struct {
208 struct vm_area_struct * mmap; /* list of VMAs */
209 struct vm_area_struct * mmap_avl; /* tree of VMAs */
210 struct vm_area_struct * mmap_cache; /* last find_vma result */
211 pgd_t * pgd;
212 atomic_t mm_users; /* How many users with user space? */
213 atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
214 int map_count; /* number of VMAs */
215 struct semaphore mmap_sem;
216 spinlock_t page_table_lock;
217 unsigned long context;
218 unsigned long start_code, end_code, start_data, end_data;
219 unsigned long start_brk, brk, start_stack;
220 unsigned long arg_start, arg_end, env_start, env_end;
221 unsigned long rss, total_vm, locked_vm;
222 unsigned long def_flags;
223 unsigned long cpu_vm_mask;
224 unsigned long swap_cnt; /* number of pages to swap on next pass */
225 unsigned long swap_address;
227 * This is an architecture-specific pointer: the portable
228 * part of Linux does not know about any segments.
230 void * segments;
233 #define INIT_MM(name) { \
234 &init_mmap, NULL, NULL, \
235 swapper_pg_dir, \
236 ATOMIC_INIT(2), ATOMIC_INIT(1), 1, \
237 __MUTEX_INITIALIZER(name.mmap_sem), \
238 SPIN_LOCK_UNLOCKED, \
239 0, \
240 0, 0, 0, 0, \
241 0, 0, 0, \
242 0, 0, 0, 0, \
243 0, 0, 0, \
244 0, 0, 0, 0, NULL }
246 struct signal_struct {
247 atomic_t count;
248 struct k_sigaction action[_NSIG];
249 spinlock_t siglock;
253 #define INIT_SIGNALS { \
254 ATOMIC_INIT(1), \
255 { {{0,}}, }, \
256 SPIN_LOCK_UNLOCKED }
259 * Some day this will be a full-fledged user tracking system..
260 * Right now it is only used to track how many processes a
261 * user has, but it has the potential to track memory usage etc.
263 struct user_struct;
265 struct task_struct {
266 /* these are hardcoded - don't touch */
267 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
268 unsigned long flags; /* per process flags, defined below */
269 int sigpending;
270 mm_segment_t addr_limit; /* thread address space:
271 0-0xBFFFFFFF for user-thead
272 0-0xFFFFFFFF for kernel-thread
274 struct exec_domain *exec_domain;
275 volatile long need_resched;
277 /* various fields */
278 long counter;
279 long priority;
280 cycles_t avg_slice;
281 /* SMP and runqueue state */
282 int has_cpu;
283 int processor;
284 int last_processor;
285 int lock_depth; /* Lock depth. We can context switch in and out of holding a syscall kernel lock... */
286 struct task_struct *next_task, *prev_task;
287 struct list_head run_list;
289 /* task state */
290 struct linux_binfmt *binfmt;
291 int exit_code, exit_signal;
292 int pdeath_signal; /* The signal sent when the parent dies */
293 /* ??? */
294 unsigned long personality;
295 int dumpable:1;
296 int did_exec:1;
297 pid_t pid;
298 pid_t pgrp;
299 pid_t tty_old_pgrp;
300 pid_t session;
301 /* boolean value for session group leader */
302 int leader;
304 * pointers to (original) parent process, youngest child, younger sibling,
305 * older sibling, respectively. (p->father can be replaced with
306 * p->p_pptr->pid)
308 struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
310 /* PID hash table linkage. */
311 struct task_struct *pidhash_next;
312 struct task_struct **pidhash_pprev;
314 wait_queue_head_t wait_chldexit; /* for wait4() */
315 struct semaphore *vfork_sem; /* for vfork() */
316 unsigned long policy, rt_priority;
317 unsigned long it_real_value, it_prof_value, it_virt_value;
318 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
319 struct timer_list real_timer;
320 struct tms times;
321 unsigned long start_time;
322 long per_cpu_utime[NR_CPUS], per_cpu_stime[NR_CPUS];
323 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
324 unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
325 int swappable:1;
326 /* process credentials */
327 uid_t uid,euid,suid,fsuid;
328 gid_t gid,egid,sgid,fsgid;
329 int ngroups;
330 gid_t groups[NGROUPS];
331 kernel_cap_t cap_effective, cap_inheritable, cap_permitted;
332 struct user_struct *user;
333 /* limits */
334 struct rlimit rlim[RLIM_NLIMITS];
335 unsigned short used_math;
336 char comm[16];
337 /* file system info */
338 int link_count;
339 struct tty_struct *tty; /* NULL if no tty */
340 /* ipc stuff */
341 struct sem_undo *semundo;
342 struct sem_queue *semsleeping;
343 /* CPU-specific state of this task */
344 struct thread_struct thread;
345 /* filesystem information */
346 struct fs_struct *fs;
347 /* open file information */
348 struct files_struct *files;
350 /* memory management info */
351 struct mm_struct *mm, *active_mm;
353 /* signal handlers */
354 spinlock_t sigmask_lock; /* Protects signal and blocked */
355 struct signal_struct *sig;
356 sigset_t signal, blocked;
357 struct signal_queue *sigqueue, **sigqueue_tail;
358 unsigned long sas_ss_sp;
359 size_t sas_ss_size;
361 /* Thread group tracking */
362 u32 parent_exec_id;
363 u32 self_exec_id;
367 * Per process flags
369 #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */
370 /* Not implemented yet, only for 486*/
371 #define PF_STARTING 0x00000002 /* being created */
372 #define PF_EXITING 0x00000004 /* getting shut down */
373 #define PF_PTRACED 0x00000010 /* set if ptrace (0) has been called */
374 #define PF_TRACESYS 0x00000020 /* tracing system calls */
375 #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
376 #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */
377 #define PF_DUMPCORE 0x00000200 /* dumped core */
378 #define PF_SIGNALED 0x00000400 /* killed by a signal */
379 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
380 #define PF_VFORK 0x00001000 /* Wake up parent in mm_release */
382 #define PF_USEDFPU 0x00100000 /* task used FPU this quantum (SMP) */
383 #define PF_DTRACE 0x00200000 /* delayed trace (used on m68k, i386) */
386 * Limit the stack by to some sane default: root can always
387 * increase this limit if needed.. 8MB seems reasonable.
389 #define _STK_LIM (8*1024*1024)
391 #define DEF_PRIORITY (20*HZ/100) /* 200 ms time slices */
394 * INIT_TASK is used to set up the first task table, touch at
395 * your own risk!. Base=0, limit=0x1fffff (=2MB)
397 #define INIT_TASK(name) \
398 /* state etc */ { 0,0,0,KERNEL_DS,&default_exec_domain,0, \
399 /* counter */ DEF_PRIORITY,DEF_PRIORITY,0, \
400 /* SMP */ 0,0,0,-1, \
401 /* schedlink */ &init_task,&init_task, LIST_HEAD_INIT(init_task.run_list), \
402 /* binfmt */ NULL, \
403 /* ec,brk... */ 0,0,0,0,0,0, \
404 /* pid etc.. */ 0,0,0,0,0, \
405 /* proc links*/ &init_task,&init_task,NULL,NULL,NULL, \
406 /* pidhash */ NULL, NULL, \
407 /* chld wait */ __WAIT_QUEUE_HEAD_INITIALIZER(name.wait_chldexit), NULL, \
408 /* timeout */ SCHED_OTHER,0,0,0,0,0,0,0, \
409 /* timer */ { NULL, NULL, 0, 0, it_real_fn }, \
410 /* utime */ {0,0,0,0},0, \
411 /* per CPU times */ {0, }, {0, }, \
412 /* flt */ 0,0,0,0,0,0, \
413 /* swp */ 0, \
414 /* process credentials */ \
415 /* uid etc */ 0,0,0,0,0,0,0,0, \
416 /* suppl grps*/ 0, {0,}, \
417 /* caps */ CAP_INIT_EFF_SET,CAP_INIT_INH_SET,CAP_FULL_SET, \
418 /* user */ NULL, \
419 /* rlimits */ INIT_RLIMITS, \
420 /* math */ 0, \
421 /* comm */ "swapper", \
422 /* fs info */ 0,NULL, \
423 /* ipc */ NULL, NULL, \
424 /* thread */ INIT_THREAD, \
425 /* fs */ &init_fs, \
426 /* files */ &init_files, \
427 /* mm */ NULL, &init_mm, \
428 /* signals */ SPIN_LOCK_UNLOCKED, &init_signals, {{0}}, {{0}}, NULL, &init_task.sigqueue, 0, 0, \
429 /* exec cts */ 0,0, \
432 #ifndef INIT_TASK_SIZE
433 # define INIT_TASK_SIZE 2048*sizeof(long)
434 #endif
436 union task_union {
437 struct task_struct task;
438 unsigned long stack[INIT_TASK_SIZE/sizeof(long)];
441 extern union task_union init_task_union;
443 extern struct mm_struct init_mm;
444 extern struct task_struct *init_tasks[NR_CPUS];
446 /* PID hashing. (shouldnt this be dynamic?) */
447 #define PIDHASH_SZ (4096 >> 2)
448 extern struct task_struct *pidhash[PIDHASH_SZ];
450 #define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
452 extern __inline__ void hash_pid(struct task_struct *p)
454 struct task_struct **htable = &pidhash[pid_hashfn(p->pid)];
456 if((p->pidhash_next = *htable) != NULL)
457 (*htable)->pidhash_pprev = &p->pidhash_next;
458 *htable = p;
459 p->pidhash_pprev = htable;
462 extern __inline__ void unhash_pid(struct task_struct *p)
464 if(p->pidhash_next)
465 p->pidhash_next->pidhash_pprev = p->pidhash_pprev;
466 *p->pidhash_pprev = p->pidhash_next;
469 extern __inline__ struct task_struct *find_task_by_pid(int pid)
471 struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)];
473 for(p = *htable; p && p->pid != pid; p = p->pidhash_next)
476 return p;
479 /* per-UID process charging. */
480 extern int alloc_uid(struct task_struct *);
481 void free_uid(struct task_struct *);
483 #include <asm/current.h>
485 extern unsigned long volatile jiffies;
486 extern unsigned long itimer_ticks;
487 extern unsigned long itimer_next;
488 extern struct timeval xtime;
489 extern void do_timer(struct pt_regs *);
491 extern unsigned int * prof_buffer;
492 extern unsigned long prof_len;
493 extern unsigned long prof_shift;
495 #define CURRENT_TIME (xtime.tv_sec)
497 extern void FASTCALL(__wake_up(wait_queue_head_t *q, unsigned int mode));
498 extern void FASTCALL(sleep_on(wait_queue_head_t *q));
499 extern long FASTCALL(sleep_on_timeout(wait_queue_head_t *q,
500 signed long timeout));
501 extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t *q));
502 extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t *q,
503 signed long timeout));
504 extern void FASTCALL(wake_up_process(struct task_struct * tsk));
506 #define wake_up(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE)
507 #define wake_up_interruptible(x) __wake_up((x),TASK_INTERRUPTIBLE)
509 extern int in_group_p(gid_t);
511 extern void flush_signals(struct task_struct *);
512 extern void flush_signal_handlers(struct task_struct *);
513 extern int dequeue_signal(sigset_t *, siginfo_t *);
514 extern int send_sig_info(int, struct siginfo *, struct task_struct *);
515 extern int force_sig_info(int, struct siginfo *, struct task_struct *);
516 extern int kill_pg_info(int, struct siginfo *, pid_t);
517 extern int kill_sl_info(int, struct siginfo *, pid_t);
518 extern int kill_proc_info(int, struct siginfo *, pid_t);
519 extern int kill_something_info(int, struct siginfo *, int);
520 extern void notify_parent(struct task_struct *, int);
521 extern void force_sig(int, struct task_struct *);
522 extern int send_sig(int, struct task_struct *, int);
523 extern int kill_pg(pid_t, int, int);
524 extern int kill_sl(pid_t, int, int);
525 extern int kill_proc(pid_t, int, int);
526 extern int do_sigaction(int, const struct k_sigaction *, struct k_sigaction *);
527 extern int do_sigaltstack(const stack_t *, stack_t *, unsigned long);
529 extern inline int signal_pending(struct task_struct *p)
531 return (p->sigpending != 0);
534 /* Reevaluate whether the task has signals pending delivery.
535 This is required every time the blocked sigset_t changes.
536 All callers should have t->sigmask_lock. */
538 static inline void recalc_sigpending(struct task_struct *t)
540 unsigned long ready;
541 long i;
543 switch (_NSIG_WORDS) {
544 default:
545 for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
546 ready |= t->signal.sig[i] &~ t->blocked.sig[i];
547 break;
549 case 4: ready = t->signal.sig[3] &~ t->blocked.sig[3];
550 ready |= t->signal.sig[2] &~ t->blocked.sig[2];
551 ready |= t->signal.sig[1] &~ t->blocked.sig[1];
552 ready |= t->signal.sig[0] &~ t->blocked.sig[0];
553 break;
555 case 2: ready = t->signal.sig[1] &~ t->blocked.sig[1];
556 ready |= t->signal.sig[0] &~ t->blocked.sig[0];
557 break;
559 case 1: ready = t->signal.sig[0] &~ t->blocked.sig[0];
562 t->sigpending = (ready != 0);
565 /* True if we are on the alternate signal stack. */
567 static inline int on_sig_stack(unsigned long sp)
569 return (sp - current->sas_ss_sp < current->sas_ss_size);
572 static inline int sas_ss_flags(unsigned long sp)
574 return (current->sas_ss_size == 0 ? SS_DISABLE
575 : on_sig_stack(sp) ? SS_ONSTACK : 0);
578 extern int request_irq(unsigned int,
579 void (*handler)(int, void *, struct pt_regs *),
580 unsigned long, const char *, void *);
581 extern void free_irq(unsigned int, void *);
584 * This has now become a routine instead of a macro, it sets a flag if
585 * it returns true (to do BSD-style accounting where the process is flagged
586 * if it uses root privs). The implication of this is that you should do
587 * normal permissions checks first, and check suser() last.
589 * [Dec 1997 -- Chris Evans]
590 * For correctness, the above considerations need to be extended to
591 * fsuser(). This is done, along with moving fsuser() checks to be
592 * last.
594 * These will be removed, but in the mean time, when the SECURE_NOROOT
595 * flag is set, uids don't grant privilege.
597 extern inline int suser(void)
599 if (!issecure(SECURE_NOROOT) && current->euid == 0) {
600 current->flags |= PF_SUPERPRIV;
601 return 1;
603 return 0;
606 extern inline int fsuser(void)
608 if (!issecure(SECURE_NOROOT) && current->fsuid == 0) {
609 current->flags |= PF_SUPERPRIV;
610 return 1;
612 return 0;
616 * capable() checks for a particular capability.
617 * New privilege checks should use this interface, rather than suser() or
618 * fsuser(). See include/linux/capability.h for defined capabilities.
621 extern inline int capable(int cap)
623 #if 1 /* ok now */
624 if (cap_raised(current->cap_effective, cap))
625 #else
626 if (cap_is_fs_cap(cap) ? current->fsuid == 0 : current->euid == 0)
627 #endif
629 current->flags |= PF_SUPERPRIV;
630 return 1;
632 return 0;
636 * Routines for handling mm_structs
638 extern struct mm_struct * mm_alloc(void);
640 extern struct mm_struct * start_lazy_tlb(void);
641 extern void end_lazy_tlb(struct mm_struct *mm);
643 /* mmdrop drops the mm and the page tables */
644 extern inline void FASTCALL(__mmdrop(struct mm_struct *));
645 static inline void mmdrop(struct mm_struct * mm)
647 if (atomic_dec_and_test(&mm->mm_count))
648 __mmdrop(mm);
651 /* mmput gets rid of the mappings and all user-space */
652 extern void mmput(struct mm_struct *);
653 /* Remove the current tasks stale references to the old mm_struct */
654 extern void mm_release(void);
657 * Routines for handling the fd arrays
659 extern struct file ** alloc_fd_array(int);
660 extern int expand_fd_array(struct files_struct *, int nr);
661 extern void free_fd_array(struct file **, int);
663 extern fd_set *alloc_fdset(int);
664 extern int expand_fdset(struct files_struct *, int nr);
665 extern void free_fdset(fd_set *, int);
667 /* Expand files. Return <0 on error; 0 nothing done; 1 files expanded,
668 * we may have blocked.
670 * Should be called with the files->file_lock spinlock held for write.
672 static inline int expand_files(struct files_struct *files, int nr)
674 int err, expand = 0;
675 #ifdef FDSET_DEBUG
676 printk (KERN_ERR __FUNCTION__ " %d: nr = %d\n", current->pid, nr);
677 #endif
679 if (nr >= files->max_fdset) {
680 expand = 1;
681 if ((err = expand_fdset(files, nr)))
682 goto out;
684 if (nr >= files->max_fds) {
685 expand = 1;
686 if ((err = expand_fd_array(files, nr)))
687 goto out;
689 err = expand;
690 out:
691 #ifdef FDSET_DEBUG
692 if (err)
693 printk (KERN_ERR __FUNCTION__ " %d: return %d\n", current->pid, err);
694 #endif
695 return err;
698 extern int copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
699 extern void flush_thread(void);
700 extern void exit_thread(void);
702 extern void exit_mm(struct task_struct *);
703 extern void exit_fs(struct task_struct *);
704 extern void exit_files(struct task_struct *);
705 extern void exit_sighand(struct task_struct *);
707 extern void daemonize(void);
709 extern int do_execve(char *, char **, char **, struct pt_regs *);
710 extern int do_fork(unsigned long, unsigned long, struct pt_regs *);
712 extern inline void add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait)
714 unsigned long flags;
716 wq_write_lock_irqsave(&q->lock, flags);
717 __add_wait_queue(q, wait);
718 wq_write_unlock_irqrestore(&q->lock, flags);
721 extern inline void add_wait_queue_exclusive(wait_queue_head_t *q,
722 wait_queue_t * wait)
724 unsigned long flags;
726 wq_write_lock_irqsave(&q->lock, flags);
727 __add_wait_queue_tail(q, wait);
728 wq_write_unlock_irqrestore(&q->lock, flags);
731 extern inline void remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait)
733 unsigned long flags;
735 wq_write_lock_irqsave(&q->lock, flags);
736 __remove_wait_queue(q, wait);
737 wq_write_unlock_irqrestore(&q->lock, flags);
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 ; )
818 static inline void del_from_runqueue(struct task_struct * p)
820 nr_running--;
821 list_del(&p->run_list);
822 p->run_list.next = NULL;
825 extern inline int task_on_runqueue(struct task_struct *p)
827 return (p->run_list.next != NULL);
830 extern inline void unhash_process(struct task_struct *p)
832 if (task_on_runqueue(p)) BUG();
833 write_lock_irq(&tasklist_lock);
834 nr_threads--;
835 unhash_pid(p);
836 REMOVE_LINKS(p);
837 write_unlock_irq(&tasklist_lock);
840 #endif /* __KERNEL__ */
842 #endif