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>
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>
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
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) \
66 load += n*(FIXED_1-exp); \
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
;
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
87 #define TASK_STOPPED 8
89 #define __set_task_state(tsk, state_value) \
90 do { (tsk)->state = (state_value); } while (0)
92 #define set_task_state(tsk, state_value) \
93 set_mb((tsk)->state, (state_value))
95 #define set_task_state(tsk, state_value) \
96 __set_task_state((tsk), (state_value))
99 #define __set_current_state(state_value) \
100 do { current->state = (state_value); } while (0)
102 #define set_current_state(state_value) \
103 set_mb(current->state, (state_value))
105 #define set_current_state(state_value) \
106 __set_current_state(state_value)
110 * Scheduling policies
112 #define SCHED_OTHER 0
117 * This is an additional bit set when we want to
118 * yield the CPU for one re-schedule..
120 #define SCHED_YIELD 0x10
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
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);
152 extern int schedule_task(struct tq_struct
*task
);
153 extern void flush_scheduled_tasks(void);
154 extern int start_context_thread(void);
155 extern int current_is_keventd(void);
158 * The default fd array needs to be at least BITS_PER_LONG,
159 * as this is the granularity returned by copy_fdset().
161 #define NR_OPEN_DEFAULT BITS_PER_LONG
164 * Open file table structure
166 struct files_struct
{
172 struct file
** fd
; /* current fd array */
173 fd_set
*close_on_exec
;
175 fd_set close_on_exec_init
;
176 fd_set open_fds_init
;
177 struct file
* fd_array
[NR_OPEN_DEFAULT
];
182 count: ATOMIC_INIT(1), \
183 file_lock: RW_LOCK_UNLOCKED, \
184 max_fds: NR_OPEN_DEFAULT, \
185 max_fdset: __FD_SETSIZE, \
187 fd: &init_files.fd_array[0], \
188 close_on_exec: &init_files.close_on_exec_init, \
189 open_fds: &init_files.open_fds_init, \
190 close_on_exec_init: { { 0, } }, \
191 open_fds_init: { { 0, } }, \
192 fd_array: { NULL, } \
195 /* Maximum number of active map areas.. This is a random (large) number */
196 #define MAX_MAP_COUNT (65536)
198 /* Number of map areas at which the AVL tree is activated. This is arbitrary. */
199 #define AVL_MIN_MAP_COUNT 32
202 struct vm_area_struct
* mmap
; /* list of VMAs */
203 struct vm_area_struct
* mmap_avl
; /* tree of VMAs */
204 struct vm_area_struct
* mmap_cache
; /* last find_vma result */
206 atomic_t mm_users
; /* How many users with user space? */
207 atomic_t mm_count
; /* How many references to "struct mm_struct" (users count as 1) */
208 int map_count
; /* number of VMAs */
209 struct semaphore mmap_sem
;
210 spinlock_t page_table_lock
;
211 unsigned long context
;
212 unsigned long start_code
, end_code
, start_data
, end_data
;
213 unsigned long start_brk
, brk
, start_stack
;
214 unsigned long arg_start
, arg_end
, env_start
, env_end
;
215 unsigned long rss
, total_vm
, locked_vm
;
216 unsigned long def_flags
;
217 unsigned long cpu_vm_mask
;
218 unsigned long swap_cnt
; /* number of pages to swap on next pass */
219 unsigned long swap_address
;
221 * This is an architecture-specific pointer: the portable
222 * part of Linux does not know about any segments.
227 #define INIT_MM(name) \
232 pgd: swapper_pg_dir, \
233 mm_users: ATOMIC_INIT(2), \
234 mm_count: ATOMIC_INIT(1), \
236 mmap_sem: __MUTEX_INITIALIZER(name.mmap_sem), \
237 page_table_lock: SPIN_LOCK_UNLOCKED, \
241 struct signal_struct
{
243 struct k_sigaction action
[_NSIG
];
248 #define INIT_SIGNALS { \
249 count: ATOMIC_INIT(1), \
250 action: { {{0,}}, }, \
251 siglock: SPIN_LOCK_UNLOCKED \
255 * Some day this will be a full-fledged user tracking system..
258 atomic_t __count
; /* reference count */
259 atomic_t processes
; /* How many processes does this user have? */
260 atomic_t files
; /* How many open files does this user have? */
262 /* Hash table maintenance information */
263 struct user_struct
*next
, **pprev
;
267 #define get_current_user() ({ \
268 struct user_struct *__user = current->user; \
269 atomic_inc(&__user->__count); \
272 extern struct user_struct root_user
;
273 #define INIT_USER (&root_user)
277 * offsets of these are hardcoded elsewhere - touch with care
279 volatile long state
; /* -1 unrunnable, 0 runnable, >0 stopped */
280 unsigned long flags
; /* per process flags, defined below */
282 mm_segment_t addr_limit
; /* thread address space:
283 0-0xBFFFFFFF for user-thead
284 0-0xFFFFFFFF for kernel-thread
286 struct exec_domain
*exec_domain
;
287 volatile long need_resched
;
288 unsigned long ptrace
;
290 int lock_depth
; /* Lock depth */
293 * offset 32 begins here on 32-bit platforms. We keep
294 * all fields in a single cacheline that are needed for
295 * the goodness() loop in schedule().
299 unsigned long policy
;
300 struct mm_struct
*mm
;
301 int has_cpu
, processor
;
302 unsigned long cpus_allowed
;
304 * (only the 'next' pointer fits into the cacheline, but
307 struct list_head run_list
;
308 unsigned long sleep_time
;
310 struct task_struct
*next_task
, *prev_task
;
311 struct mm_struct
*active_mm
;
314 struct linux_binfmt
*binfmt
;
315 int exit_code
, exit_signal
;
316 int pdeath_signal
; /* The signal sent when the parent dies */
318 unsigned long personality
;
326 /* boolean value for session group leader */
329 * pointers to (original) parent process, youngest child, younger sibling,
330 * older sibling, respectively. (p->father can be replaced with
333 struct task_struct
*p_opptr
, *p_pptr
, *p_cptr
, *p_ysptr
, *p_osptr
;
334 struct list_head thread_group
;
336 /* PID hash table linkage. */
337 struct task_struct
*pidhash_next
;
338 struct task_struct
**pidhash_pprev
;
340 wait_queue_head_t wait_chldexit
; /* for wait4() */
341 struct semaphore
*vfork_sem
; /* for vfork() */
342 unsigned long rt_priority
;
343 unsigned long it_real_value
, it_prof_value
, it_virt_value
;
344 unsigned long it_real_incr
, it_prof_incr
, it_virt_incr
;
345 struct timer_list real_timer
;
347 unsigned long start_time
;
348 long per_cpu_utime
[NR_CPUS
], per_cpu_stime
[NR_CPUS
];
349 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
350 unsigned long min_flt
, maj_flt
, nswap
, cmin_flt
, cmaj_flt
, cnswap
;
352 /* process credentials */
353 uid_t uid
,euid
,suid
,fsuid
;
354 gid_t gid
,egid
,sgid
,fsgid
;
356 gid_t groups
[NGROUPS
];
357 kernel_cap_t cap_effective
, cap_inheritable
, cap_permitted
;
358 int keep_capabilities
:1;
359 struct user_struct
*user
;
361 struct rlimit rlim
[RLIM_NLIMITS
];
362 unsigned short used_math
;
364 /* file system info */
366 struct tty_struct
*tty
; /* NULL if no tty */
367 unsigned int locks
; /* How many file locks are being held */
369 struct sem_undo
*semundo
;
370 struct sem_queue
*semsleeping
;
371 /* CPU-specific state of this task */
372 struct thread_struct thread
;
373 /* filesystem information */
374 struct fs_struct
*fs
;
375 /* open file information */
376 struct files_struct
*files
;
377 /* signal handlers */
378 spinlock_t sigmask_lock
; /* Protects signal and blocked */
379 struct signal_struct
*sig
;
382 struct sigpending pending
;
384 unsigned long sas_ss_sp
;
386 int (*notifier
)(void *priv
);
388 sigset_t
*notifier_mask
;
390 /* Thread group tracking */
393 /* Protection of (de-)allocation: mm, files, fs, tty */
394 spinlock_t alloc_lock
;
400 #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */
401 /* Not implemented yet, only for 486*/
402 #define PF_STARTING 0x00000002 /* being created */
403 #define PF_EXITING 0x00000004 /* getting shut down */
404 #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
405 #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */
406 #define PF_DUMPCORE 0x00000200 /* dumped core */
407 #define PF_SIGNALED 0x00000400 /* killed by a signal */
408 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
409 #define PF_VFORK 0x00001000 /* Wake up parent in mm_release */
411 #define PF_USEDFPU 0x00100000 /* task used FPU this quantum (SMP) */
417 #define PT_PTRACED 0x00000001
418 #define PT_TRACESYS 0x00000002
419 #define PT_DTRACE 0x00000004 /* delayed trace (used on m68k, i386) */
420 #define PT_TRACESYSGOOD 0x00000008
423 * Limit the stack by to some sane default: root can always
424 * increase this limit if needed.. 8MB seems reasonable.
426 #define _STK_LIM (8*1024*1024)
428 #define DEF_COUNTER (10*HZ/100) /* 100 ms time slice */
429 #define MAX_COUNTER (20*HZ/100)
433 * INIT_TASK is used to set up the first task table, touch at
434 * your own risk!. Base=0, limit=0x1fffff (=2MB)
436 #define INIT_TASK(tsk) \
441 addr_limit: KERNEL_DS, \
442 exec_domain: &default_exec_domain, \
444 counter: DEF_COUNTER, \
446 policy: SCHED_OTHER, \
448 active_mm: &init_mm, \
450 run_list: LIST_HEAD_INIT(tsk.run_list), \
455 thread_group: LIST_HEAD_INIT(tsk.thread_group), \
456 wait_chldexit: __WAIT_QUEUE_HEAD_INITIALIZER(tsk.wait_chldexit),\
458 function: it_real_fn \
460 cap_effective: CAP_INIT_EFF_SET, \
461 cap_inheritable: CAP_INIT_INH_SET, \
462 cap_permitted: CAP_FULL_SET, \
463 keep_capabilities: 0, \
464 rlim: INIT_RLIMITS, \
467 thread: INIT_THREAD, \
469 files: &init_files, \
470 sigmask_lock: SPIN_LOCK_UNLOCKED, \
471 sig: &init_signals, \
472 pending: { NULL, &tsk.pending.head, {{0}}}, \
474 alloc_lock: SPIN_LOCK_UNLOCKED \
478 #ifndef INIT_TASK_SIZE
479 # define INIT_TASK_SIZE 2048*sizeof(long)
483 struct task_struct task
;
484 unsigned long stack
[INIT_TASK_SIZE
/sizeof(long)];
487 extern union task_union init_task_union
;
489 extern struct mm_struct init_mm
;
490 extern struct task_struct
*init_tasks
[NR_CPUS
];
492 /* PID hashing. (shouldnt this be dynamic?) */
493 #define PIDHASH_SZ (4096 >> 2)
494 extern struct task_struct
*pidhash
[PIDHASH_SZ
];
496 #define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
498 static inline void hash_pid(struct task_struct
*p
)
500 struct task_struct
**htable
= &pidhash
[pid_hashfn(p
->pid
)];
502 if((p
->pidhash_next
= *htable
) != NULL
)
503 (*htable
)->pidhash_pprev
= &p
->pidhash_next
;
505 p
->pidhash_pprev
= htable
;
508 static inline void unhash_pid(struct task_struct
*p
)
511 p
->pidhash_next
->pidhash_pprev
= p
->pidhash_pprev
;
512 *p
->pidhash_pprev
= p
->pidhash_next
;
515 static inline struct task_struct
*find_task_by_pid(int pid
)
517 struct task_struct
*p
, **htable
= &pidhash
[pid_hashfn(pid
)];
519 for(p
= *htable
; p
&& p
->pid
!= pid
; p
= p
->pidhash_next
)
525 /* per-UID process charging. */
526 extern struct user_struct
* alloc_uid(uid_t
);
527 extern void free_uid(struct user_struct
*);
529 #include <asm/current.h>
531 extern unsigned long volatile jiffies
;
532 extern unsigned long itimer_ticks
;
533 extern unsigned long itimer_next
;
534 extern struct timeval xtime
;
535 extern void do_timer(struct pt_regs
*);
537 extern unsigned int * prof_buffer
;
538 extern unsigned long prof_len
;
539 extern unsigned long prof_shift
;
541 #define CURRENT_TIME (xtime.tv_sec)
543 extern void FASTCALL(__wake_up(wait_queue_head_t
*q
, unsigned int mode
, unsigned int wq_mode
));
544 extern void FASTCALL(__wake_up_sync(wait_queue_head_t
*q
, unsigned int mode
, unsigned int wq_mode
));
545 extern void FASTCALL(sleep_on(wait_queue_head_t
*q
));
546 extern long FASTCALL(sleep_on_timeout(wait_queue_head_t
*q
,
547 signed long timeout
));
548 extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t
*q
));
549 extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t
*q
,
550 signed long timeout
));
551 extern void FASTCALL(wake_up_process(struct task_struct
* tsk
));
553 #define wake_up(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
554 #define wake_up_all(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,0)
555 #define wake_up_sync(x) __wake_up_sync((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
556 #define wake_up_interruptible(x) __wake_up((x),TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
557 #define wake_up_interruptible_all(x) __wake_up((x),TASK_INTERRUPTIBLE,0)
558 #define wake_up_interruptible_sync(x) __wake_up_sync((x),TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
560 extern int in_group_p(gid_t
);
561 extern int in_egroup_p(gid_t
);
563 extern void proc_caches_init(void);
564 extern void flush_signals(struct task_struct
*);
565 extern void flush_signal_handlers(struct task_struct
*);
566 extern int dequeue_signal(sigset_t
*, siginfo_t
*);
567 extern void block_all_signals(int (*notifier
)(void *priv
), void *priv
,
569 extern void unblock_all_signals(void);
570 extern int send_sig_info(int, struct siginfo
*, struct task_struct
*);
571 extern int force_sig_info(int, struct siginfo
*, struct task_struct
*);
572 extern int kill_pg_info(int, struct siginfo
*, pid_t
);
573 extern int kill_sl_info(int, struct siginfo
*, pid_t
);
574 extern int kill_proc_info(int, struct siginfo
*, pid_t
);
575 extern void notify_parent(struct task_struct
*, int);
576 extern void do_notify_parent(struct task_struct
*, int);
577 extern void force_sig(int, struct task_struct
*);
578 extern int send_sig(int, struct task_struct
*, int);
579 extern int kill_pg(pid_t
, int, int);
580 extern int kill_sl(pid_t
, int, int);
581 extern int kill_proc(pid_t
, int, int);
582 extern int do_sigaction(int, const struct k_sigaction
*, struct k_sigaction
*);
583 extern int do_sigaltstack(const stack_t
*, stack_t
*, unsigned long);
585 static inline int signal_pending(struct task_struct
*p
)
587 return (p
->sigpending
!= 0);
591 * Re-calculate pending state from the set of locally pending
592 * signals, globally pending signals, and blocked signals.
594 static inline int has_pending_signals(sigset_t
*signal
, sigset_t
*blocked
)
599 switch (_NSIG_WORDS
) {
601 for (i
= _NSIG_WORDS
, ready
= 0; --i
>= 0 ;)
602 ready
|= signal
->sig
[i
] &~ blocked
->sig
[i
];
605 case 4: ready
= signal
->sig
[3] &~ blocked
->sig
[3];
606 ready
|= signal
->sig
[2] &~ blocked
->sig
[2];
607 ready
|= signal
->sig
[1] &~ blocked
->sig
[1];
608 ready
|= signal
->sig
[0] &~ blocked
->sig
[0];
611 case 2: ready
= signal
->sig
[1] &~ blocked
->sig
[1];
612 ready
|= signal
->sig
[0] &~ blocked
->sig
[0];
615 case 1: ready
= signal
->sig
[0] &~ blocked
->sig
[0];
620 /* Reevaluate whether the task has signals pending delivery.
621 This is required every time the blocked sigset_t changes.
622 All callers should have t->sigmask_lock. */
624 static inline void recalc_sigpending(struct task_struct
*t
)
626 t
->sigpending
= has_pending_signals(&t
->pending
.signal
, &t
->blocked
);
629 /* True if we are on the alternate signal stack. */
631 static inline int on_sig_stack(unsigned long sp
)
633 return (sp
- current
->sas_ss_sp
< current
->sas_ss_size
);
636 static inline int sas_ss_flags(unsigned long sp
)
638 return (current
->sas_ss_size
== 0 ? SS_DISABLE
639 : on_sig_stack(sp
) ? SS_ONSTACK
: 0);
642 extern int request_irq(unsigned int,
643 void (*handler
)(int, void *, struct pt_regs
*),
644 unsigned long, const char *, void *);
645 extern void free_irq(unsigned int, void *);
648 * This has now become a routine instead of a macro, it sets a flag if
649 * it returns true (to do BSD-style accounting where the process is flagged
650 * if it uses root privs). The implication of this is that you should do
651 * normal permissions checks first, and check suser() last.
653 * [Dec 1997 -- Chris Evans]
654 * For correctness, the above considerations need to be extended to
655 * fsuser(). This is done, along with moving fsuser() checks to be
658 * These will be removed, but in the mean time, when the SECURE_NOROOT
659 * flag is set, uids don't grant privilege.
661 static inline int suser(void)
663 if (!issecure(SECURE_NOROOT
) && current
->euid
== 0) {
664 current
->flags
|= PF_SUPERPRIV
;
670 static inline int fsuser(void)
672 if (!issecure(SECURE_NOROOT
) && current
->fsuid
== 0) {
673 current
->flags
|= PF_SUPERPRIV
;
680 * capable() checks for a particular capability.
681 * New privilege checks should use this interface, rather than suser() or
682 * fsuser(). See include/linux/capability.h for defined capabilities.
685 static inline int capable(int cap
)
688 if (cap_raised(current
->cap_effective
, cap
))
690 if (cap_is_fs_cap(cap
) ? current
->fsuid
== 0 : current
->euid
== 0)
693 current
->flags
|= PF_SUPERPRIV
;
700 * Routines for handling mm_structs
702 extern struct mm_struct
* mm_alloc(void);
704 extern struct mm_struct
* start_lazy_tlb(void);
705 extern void end_lazy_tlb(struct mm_struct
*mm
);
707 /* mmdrop drops the mm and the page tables */
708 extern inline void FASTCALL(__mmdrop(struct mm_struct
*));
709 static inline void mmdrop(struct mm_struct
* mm
)
711 if (atomic_dec_and_test(&mm
->mm_count
))
715 /* mmput gets rid of the mappings and all user-space */
716 extern void mmput(struct mm_struct
*);
717 /* Remove the current tasks stale references to the old mm_struct */
718 extern void mm_release(void);
721 * Routines for handling the fd arrays
723 extern struct file
** alloc_fd_array(int);
724 extern int expand_fd_array(struct files_struct
*, int nr
);
725 extern void free_fd_array(struct file
**, int);
727 extern fd_set
*alloc_fdset(int);
728 extern int expand_fdset(struct files_struct
*, int nr
);
729 extern void free_fdset(fd_set
*, int);
731 extern int copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct
*, struct pt_regs
*);
732 extern void flush_thread(void);
733 extern void exit_thread(void);
735 extern void exit_mm(struct task_struct
*);
736 extern void exit_files(struct task_struct
*);
737 extern void exit_sighand(struct task_struct
*);
739 extern void daemonize(void);
741 extern int do_execve(char *, char **, char **, struct pt_regs
*);
742 extern int do_fork(unsigned long, unsigned long, struct pt_regs
*, unsigned long);
744 extern void FASTCALL(add_wait_queue(wait_queue_head_t
*q
, wait_queue_t
* wait
));
745 extern void FASTCALL(add_wait_queue_exclusive(wait_queue_head_t
*q
, wait_queue_t
* wait
));
746 extern void FASTCALL(remove_wait_queue(wait_queue_head_t
*q
, wait_queue_t
* wait
));
748 #define __wait_event(wq, condition) \
750 wait_queue_t __wait; \
751 init_waitqueue_entry(&__wait, current); \
753 add_wait_queue(&wq, &__wait); \
755 set_current_state(TASK_UNINTERRUPTIBLE); \
760 current->state = TASK_RUNNING; \
761 remove_wait_queue(&wq, &__wait); \
764 #define wait_event(wq, condition) \
768 __wait_event(wq, condition); \
771 #define __wait_event_interruptible(wq, condition, ret) \
773 wait_queue_t __wait; \
774 init_waitqueue_entry(&__wait, current); \
776 add_wait_queue(&wq, &__wait); \
778 set_current_state(TASK_INTERRUPTIBLE); \
781 if (!signal_pending(current)) { \
785 ret = -ERESTARTSYS; \
788 current->state = TASK_RUNNING; \
789 remove_wait_queue(&wq, &__wait); \
792 #define wait_event_interruptible(wq, condition) \
796 __wait_event_interruptible(wq, condition, __ret); \
800 #define REMOVE_LINKS(p) do { \
801 (p)->next_task->prev_task = (p)->prev_task; \
802 (p)->prev_task->next_task = (p)->next_task; \
804 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
806 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
808 (p)->p_pptr->p_cptr = (p)->p_osptr; \
811 #define SET_LINKS(p) do { \
812 (p)->next_task = &init_task; \
813 (p)->prev_task = init_task.prev_task; \
814 init_task.prev_task->next_task = (p); \
815 init_task.prev_task = (p); \
816 (p)->p_ysptr = NULL; \
817 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
818 (p)->p_osptr->p_ysptr = p; \
819 (p)->p_pptr->p_cptr = p; \
822 #define for_each_task(p) \
823 for (p = &init_task ; (p = p->next_task) != &init_task ; )
825 #define next_thread(p) \
826 list_entry((p)->thread_group.next, struct task_struct, thread_group)
828 static inline void del_from_runqueue(struct task_struct
* p
)
831 p
->sleep_time
= jiffies
;
832 list_del(&p
->run_list
);
833 p
->run_list
.next
= NULL
;
836 static inline int task_on_runqueue(struct task_struct
*p
)
838 return (p
->run_list
.next
!= NULL
);
841 static inline void unhash_process(struct task_struct
*p
)
843 if (task_on_runqueue(p
)) BUG();
844 write_lock_irq(&tasklist_lock
);
848 list_del(&p
->thread_group
);
849 write_unlock_irq(&tasklist_lock
);
852 static inline void task_lock(struct task_struct
*p
)
854 spin_lock(&p
->alloc_lock
);
857 static inline void task_unlock(struct task_struct
*p
)
859 spin_unlock(&p
->alloc_lock
);
862 /* write full pathname into buffer and return start of pathname */
863 static inline char * d_path(struct dentry
*dentry
, struct vfsmount
*vfsmnt
,
864 char *buf
, int buflen
)
867 struct vfsmount
*rootmnt
;
869 read_lock(¤t
->fs
->lock
);
870 rootmnt
= mntget(current
->fs
->rootmnt
);
871 root
= dget(current
->fs
->root
);
872 read_unlock(¤t
->fs
->lock
);
873 spin_lock(&dcache_lock
);
874 res
= __d_path(dentry
, vfsmnt
, root
, rootmnt
, buf
, buflen
);
875 spin_unlock(&dcache_lock
);
881 #endif /* __KERNEL__ */