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 void schedule_task(struct tq_struct
*task
);
155 * The default fd array needs to be at least BITS_PER_LONG,
156 * as this is the granularity returned by copy_fdset().
158 #define NR_OPEN_DEFAULT BITS_PER_LONG
161 * Open file table structure
163 struct files_struct
{
169 struct file
** fd
; /* current fd array */
170 fd_set
*close_on_exec
;
172 fd_set close_on_exec_init
;
173 fd_set open_fds_init
;
174 struct file
* fd_array
[NR_OPEN_DEFAULT
];
179 count: ATOMIC_INIT(1), \
180 file_lock: RW_LOCK_UNLOCKED, \
181 max_fds: NR_OPEN_DEFAULT, \
182 max_fdset: __FD_SETSIZE, \
184 fd: &init_files.fd_array[0], \
185 close_on_exec: &init_files.close_on_exec_init, \
186 open_fds: &init_files.open_fds_init, \
187 close_on_exec_init: { { 0, } }, \
188 open_fds_init: { { 0, } }, \
189 fd_array: { NULL, } \
192 /* Maximum number of active map areas.. This is a random (large) number */
193 #define MAX_MAP_COUNT (65536)
195 /* Number of map areas at which the AVL tree is activated. This is arbitrary. */
196 #define AVL_MIN_MAP_COUNT 32
199 struct vm_area_struct
* mmap
; /* list of VMAs */
200 struct vm_area_struct
* mmap_avl
; /* tree of VMAs */
201 struct vm_area_struct
* mmap_cache
; /* last find_vma result */
203 atomic_t mm_users
; /* How many users with user space? */
204 atomic_t mm_count
; /* How many references to "struct mm_struct" (users count as 1) */
205 int map_count
; /* number of VMAs */
206 struct semaphore mmap_sem
;
207 spinlock_t page_table_lock
;
208 unsigned long context
;
209 unsigned long start_code
, end_code
, start_data
, end_data
;
210 unsigned long start_brk
, brk
, start_stack
;
211 unsigned long arg_start
, arg_end
, env_start
, env_end
;
212 unsigned long rss
, total_vm
, locked_vm
;
213 unsigned long def_flags
;
214 unsigned long cpu_vm_mask
;
215 unsigned long swap_cnt
; /* number of pages to swap on next pass */
216 unsigned long swap_address
;
218 * This is an architecture-specific pointer: the portable
219 * part of Linux does not know about any segments.
224 #define INIT_MM(name) \
229 pgd: swapper_pg_dir, \
230 mm_users: ATOMIC_INIT(2), \
231 mm_count: ATOMIC_INIT(1), \
233 mmap_sem: __MUTEX_INITIALIZER(name.mmap_sem), \
234 page_table_lock: SPIN_LOCK_UNLOCKED, \
238 struct signal_struct
{
240 struct k_sigaction action
[_NSIG
];
245 #define INIT_SIGNALS { \
246 count: ATOMIC_INIT(1), \
247 action: { {{0,}}, }, \
248 siglock: SPIN_LOCK_UNLOCKED \
252 * Some day this will be a full-fledged user tracking system..
255 atomic_t __count
; /* reference count */
256 atomic_t processes
; /* How many processes does this user have? */
257 atomic_t files
; /* How many open files does this user have? */
259 /* Hash table maintenance information */
260 struct user_struct
*next
, **pprev
;
264 #define get_current_user() ({ \
265 struct user_struct *__user = current->user; \
266 atomic_inc(&__user->__count); \
269 extern struct user_struct root_user
;
270 #define INIT_USER (&root_user)
274 * offsets of these are hardcoded elsewhere - touch with care
276 volatile long state
; /* -1 unrunnable, 0 runnable, >0 stopped */
277 unsigned long flags
; /* per process flags, defined below */
279 mm_segment_t addr_limit
; /* thread address space:
280 0-0xBFFFFFFF for user-thead
281 0-0xFFFFFFFF for kernel-thread
283 struct exec_domain
*exec_domain
;
284 volatile long need_resched
;
285 unsigned long ptrace
;
287 int lock_depth
; /* Lock depth */
290 * offset 32 begins here on 32-bit platforms. We keep
291 * all fields in a single cacheline that are needed for
292 * the goodness() loop in schedule().
296 unsigned long policy
;
297 struct mm_struct
*mm
;
298 int has_cpu
, processor
;
299 unsigned long cpus_allowed
;
301 * (only the 'next' pointer fits into the cacheline, but
304 struct list_head run_list
;
305 unsigned long sleep_time
;
307 struct task_struct
*next_task
, *prev_task
;
308 struct mm_struct
*active_mm
;
311 struct linux_binfmt
*binfmt
;
312 int exit_code
, exit_signal
;
313 int pdeath_signal
; /* The signal sent when the parent dies */
315 unsigned long personality
;
323 /* boolean value for session group leader */
326 * pointers to (original) parent process, youngest child, younger sibling,
327 * older sibling, respectively. (p->father can be replaced with
330 struct task_struct
*p_opptr
, *p_pptr
, *p_cptr
, *p_ysptr
, *p_osptr
;
331 struct list_head thread_group
;
333 /* PID hash table linkage. */
334 struct task_struct
*pidhash_next
;
335 struct task_struct
**pidhash_pprev
;
337 wait_queue_head_t wait_chldexit
; /* for wait4() */
338 struct semaphore
*vfork_sem
; /* for vfork() */
339 unsigned long rt_priority
;
340 unsigned long it_real_value
, it_prof_value
, it_virt_value
;
341 unsigned long it_real_incr
, it_prof_incr
, it_virt_incr
;
342 struct timer_list real_timer
;
344 unsigned long start_time
;
345 long per_cpu_utime
[NR_CPUS
], per_cpu_stime
[NR_CPUS
];
346 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
347 unsigned long min_flt
, maj_flt
, nswap
, cmin_flt
, cmaj_flt
, cnswap
;
349 /* process credentials */
350 uid_t uid
,euid
,suid
,fsuid
;
351 gid_t gid
,egid
,sgid
,fsgid
;
353 gid_t groups
[NGROUPS
];
354 kernel_cap_t cap_effective
, cap_inheritable
, cap_permitted
;
355 int keep_capabilities
:1;
356 struct user_struct
*user
;
358 struct rlimit rlim
[RLIM_NLIMITS
];
359 unsigned short used_math
;
361 /* file system info */
363 struct tty_struct
*tty
; /* NULL if no tty */
364 unsigned int locks
; /* How many file locks are being held */
366 struct sem_undo
*semundo
;
367 struct sem_queue
*semsleeping
;
368 /* CPU-specific state of this task */
369 struct thread_struct thread
;
370 /* filesystem information */
371 struct fs_struct
*fs
;
372 /* open file information */
373 struct files_struct
*files
;
374 /* signal handlers */
375 spinlock_t sigmask_lock
; /* Protects signal and blocked */
376 struct signal_struct
*sig
;
379 struct sigpending pending
;
381 unsigned long sas_ss_sp
;
383 int (*notifier
)(void *priv
);
385 sigset_t
*notifier_mask
;
387 /* Thread group tracking */
390 /* Protection of (de-)allocation: mm, files, fs, tty */
391 spinlock_t alloc_lock
;
397 #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */
398 /* Not implemented yet, only for 486*/
399 #define PF_STARTING 0x00000002 /* being created */
400 #define PF_EXITING 0x00000004 /* getting shut down */
401 #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
402 #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */
403 #define PF_DUMPCORE 0x00000200 /* dumped core */
404 #define PF_SIGNALED 0x00000400 /* killed by a signal */
405 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
406 #define PF_VFORK 0x00001000 /* Wake up parent in mm_release */
408 #define PF_USEDFPU 0x00100000 /* task used FPU this quantum (SMP) */
414 #define PT_PTRACED 0x00000001
415 #define PT_TRACESYS 0x00000002
416 #define PT_DTRACE 0x00000004 /* delayed trace (used on m68k, i386) */
417 #define PT_TRACESYSGOOD 0x00000008
420 * Limit the stack by to some sane default: root can always
421 * increase this limit if needed.. 8MB seems reasonable.
423 #define _STK_LIM (8*1024*1024)
425 #define DEF_COUNTER (10*HZ/100) /* 100 ms time slice */
426 #define MAX_COUNTER (20*HZ/100)
430 * INIT_TASK is used to set up the first task table, touch at
431 * your own risk!. Base=0, limit=0x1fffff (=2MB)
433 #define INIT_TASK(tsk) \
438 addr_limit: KERNEL_DS, \
439 exec_domain: &default_exec_domain, \
441 counter: DEF_COUNTER, \
443 policy: SCHED_OTHER, \
445 active_mm: &init_mm, \
447 run_list: LIST_HEAD_INIT(tsk.run_list), \
452 thread_group: LIST_HEAD_INIT(tsk.thread_group), \
453 wait_chldexit: __WAIT_QUEUE_HEAD_INITIALIZER(tsk.wait_chldexit),\
455 function: it_real_fn \
457 cap_effective: CAP_INIT_EFF_SET, \
458 cap_inheritable: CAP_INIT_INH_SET, \
459 cap_permitted: CAP_FULL_SET, \
460 keep_capabilities: 0, \
461 rlim: INIT_RLIMITS, \
464 thread: INIT_THREAD, \
466 files: &init_files, \
467 sigmask_lock: SPIN_LOCK_UNLOCKED, \
468 sig: &init_signals, \
469 pending: { NULL, &tsk.pending.head, {{0}}}, \
471 alloc_lock: SPIN_LOCK_UNLOCKED \
475 #ifndef INIT_TASK_SIZE
476 # define INIT_TASK_SIZE 2048*sizeof(long)
480 struct task_struct task
;
481 unsigned long stack
[INIT_TASK_SIZE
/sizeof(long)];
484 extern union task_union init_task_union
;
486 extern struct mm_struct init_mm
;
487 extern struct task_struct
*init_tasks
[NR_CPUS
];
489 /* PID hashing. (shouldnt this be dynamic?) */
490 #define PIDHASH_SZ (4096 >> 2)
491 extern struct task_struct
*pidhash
[PIDHASH_SZ
];
493 #define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
495 static inline void hash_pid(struct task_struct
*p
)
497 struct task_struct
**htable
= &pidhash
[pid_hashfn(p
->pid
)];
499 if((p
->pidhash_next
= *htable
) != NULL
)
500 (*htable
)->pidhash_pprev
= &p
->pidhash_next
;
502 p
->pidhash_pprev
= htable
;
505 static inline void unhash_pid(struct task_struct
*p
)
508 p
->pidhash_next
->pidhash_pprev
= p
->pidhash_pprev
;
509 *p
->pidhash_pprev
= p
->pidhash_next
;
512 static inline struct task_struct
*find_task_by_pid(int pid
)
514 struct task_struct
*p
, **htable
= &pidhash
[pid_hashfn(pid
)];
516 for(p
= *htable
; p
&& p
->pid
!= pid
; p
= p
->pidhash_next
)
522 /* per-UID process charging. */
523 extern struct user_struct
* alloc_uid(uid_t
);
524 extern void free_uid(struct user_struct
*);
526 #include <asm/current.h>
528 extern unsigned long volatile jiffies
;
529 extern unsigned long itimer_ticks
;
530 extern unsigned long itimer_next
;
531 extern struct timeval xtime
;
532 extern void do_timer(struct pt_regs
*);
534 extern unsigned int * prof_buffer
;
535 extern unsigned long prof_len
;
536 extern unsigned long prof_shift
;
538 #define CURRENT_TIME (xtime.tv_sec)
540 extern void FASTCALL(__wake_up(wait_queue_head_t
*q
, unsigned int mode
, unsigned int wq_mode
));
541 extern void FASTCALL(__wake_up_sync(wait_queue_head_t
*q
, unsigned int mode
, unsigned int wq_mode
));
542 extern void FASTCALL(sleep_on(wait_queue_head_t
*q
));
543 extern long FASTCALL(sleep_on_timeout(wait_queue_head_t
*q
,
544 signed long timeout
));
545 extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t
*q
));
546 extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t
*q
,
547 signed long timeout
));
548 extern void FASTCALL(wake_up_process(struct task_struct
* tsk
));
550 #define wake_up(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
551 #define wake_up_all(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,0)
552 #define wake_up_sync(x) __wake_up_sync((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
553 #define wake_up_interruptible(x) __wake_up((x),TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
554 #define wake_up_interruptible_all(x) __wake_up((x),TASK_INTERRUPTIBLE,0)
555 #define wake_up_interruptible_sync(x) __wake_up_sync((x),TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
557 extern int in_group_p(gid_t
);
558 extern int in_egroup_p(gid_t
);
560 extern void proc_caches_init(void);
561 extern void flush_signals(struct task_struct
*);
562 extern void flush_signal_handlers(struct task_struct
*);
563 extern int dequeue_signal(sigset_t
*, siginfo_t
*);
564 extern void block_all_signals(int (*notifier
)(void *priv
), void *priv
,
566 extern void unblock_all_signals(void);
567 extern int send_sig_info(int, struct siginfo
*, struct task_struct
*);
568 extern int force_sig_info(int, struct siginfo
*, struct task_struct
*);
569 extern int kill_pg_info(int, struct siginfo
*, pid_t
);
570 extern int kill_sl_info(int, struct siginfo
*, pid_t
);
571 extern int kill_proc_info(int, struct siginfo
*, pid_t
);
572 extern void notify_parent(struct task_struct
*, int);
573 extern void do_notify_parent(struct task_struct
*, int);
574 extern void force_sig(int, struct task_struct
*);
575 extern int send_sig(int, struct task_struct
*, int);
576 extern int kill_pg(pid_t
, int, int);
577 extern int kill_sl(pid_t
, int, int);
578 extern int kill_proc(pid_t
, int, int);
579 extern int do_sigaction(int, const struct k_sigaction
*, struct k_sigaction
*);
580 extern int do_sigaltstack(const stack_t
*, stack_t
*, unsigned long);
582 static inline int signal_pending(struct task_struct
*p
)
584 return (p
->sigpending
!= 0);
588 * Re-calculate pending state from the set of locally pending
589 * signals, globally pending signals, and blocked signals.
591 static inline int has_pending_signals(sigset_t
*signal
, sigset_t
*blocked
)
596 switch (_NSIG_WORDS
) {
598 for (i
= _NSIG_WORDS
, ready
= 0; --i
>= 0 ;)
599 ready
|= signal
->sig
[i
] &~ blocked
->sig
[i
];
602 case 4: ready
= signal
->sig
[3] &~ blocked
->sig
[3];
603 ready
|= signal
->sig
[2] &~ blocked
->sig
[2];
604 ready
|= signal
->sig
[1] &~ blocked
->sig
[1];
605 ready
|= signal
->sig
[0] &~ blocked
->sig
[0];
608 case 2: ready
= signal
->sig
[1] &~ blocked
->sig
[1];
609 ready
|= signal
->sig
[0] &~ blocked
->sig
[0];
612 case 1: ready
= signal
->sig
[0] &~ blocked
->sig
[0];
617 /* Reevaluate whether the task has signals pending delivery.
618 This is required every time the blocked sigset_t changes.
619 All callers should have t->sigmask_lock. */
621 static inline void recalc_sigpending(struct task_struct
*t
)
623 t
->sigpending
= has_pending_signals(&t
->pending
.signal
, &t
->blocked
);
626 /* True if we are on the alternate signal stack. */
628 static inline int on_sig_stack(unsigned long sp
)
630 return (sp
- current
->sas_ss_sp
< current
->sas_ss_size
);
633 static inline int sas_ss_flags(unsigned long sp
)
635 return (current
->sas_ss_size
== 0 ? SS_DISABLE
636 : on_sig_stack(sp
) ? SS_ONSTACK
: 0);
639 extern int request_irq(unsigned int,
640 void (*handler
)(int, void *, struct pt_regs
*),
641 unsigned long, const char *, void *);
642 extern void free_irq(unsigned int, void *);
645 * This has now become a routine instead of a macro, it sets a flag if
646 * it returns true (to do BSD-style accounting where the process is flagged
647 * if it uses root privs). The implication of this is that you should do
648 * normal permissions checks first, and check suser() last.
650 * [Dec 1997 -- Chris Evans]
651 * For correctness, the above considerations need to be extended to
652 * fsuser(). This is done, along with moving fsuser() checks to be
655 * These will be removed, but in the mean time, when the SECURE_NOROOT
656 * flag is set, uids don't grant privilege.
658 static inline int suser(void)
660 if (!issecure(SECURE_NOROOT
) && current
->euid
== 0) {
661 current
->flags
|= PF_SUPERPRIV
;
667 static inline int fsuser(void)
669 if (!issecure(SECURE_NOROOT
) && current
->fsuid
== 0) {
670 current
->flags
|= PF_SUPERPRIV
;
677 * capable() checks for a particular capability.
678 * New privilege checks should use this interface, rather than suser() or
679 * fsuser(). See include/linux/capability.h for defined capabilities.
682 static inline int capable(int cap
)
685 if (cap_raised(current
->cap_effective
, cap
))
687 if (cap_is_fs_cap(cap
) ? current
->fsuid
== 0 : current
->euid
== 0)
690 current
->flags
|= PF_SUPERPRIV
;
697 * Routines for handling mm_structs
699 extern struct mm_struct
* mm_alloc(void);
701 extern struct mm_struct
* start_lazy_tlb(void);
702 extern void end_lazy_tlb(struct mm_struct
*mm
);
704 /* mmdrop drops the mm and the page tables */
705 extern inline void FASTCALL(__mmdrop(struct mm_struct
*));
706 static inline void mmdrop(struct mm_struct
* mm
)
708 if (atomic_dec_and_test(&mm
->mm_count
))
712 /* mmput gets rid of the mappings and all user-space */
713 extern void mmput(struct mm_struct
*);
714 /* Remove the current tasks stale references to the old mm_struct */
715 extern void mm_release(void);
718 * Routines for handling the fd arrays
720 extern struct file
** alloc_fd_array(int);
721 extern int expand_fd_array(struct files_struct
*, int nr
);
722 extern void free_fd_array(struct file
**, int);
724 extern fd_set
*alloc_fdset(int);
725 extern int expand_fdset(struct files_struct
*, int nr
);
726 extern void free_fdset(fd_set
*, int);
728 extern int copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct
*, struct pt_regs
*);
729 extern void flush_thread(void);
730 extern void exit_thread(void);
732 extern void exit_mm(struct task_struct
*);
733 extern void exit_files(struct task_struct
*);
734 extern void exit_sighand(struct task_struct
*);
736 extern void daemonize(void);
738 extern int do_execve(char *, char **, char **, struct pt_regs
*);
739 extern int do_fork(unsigned long, unsigned long, struct pt_regs
*, unsigned long);
741 extern void FASTCALL(add_wait_queue(wait_queue_head_t
*q
, wait_queue_t
* wait
));
742 extern void FASTCALL(add_wait_queue_exclusive(wait_queue_head_t
*q
, wait_queue_t
* wait
));
743 extern void FASTCALL(remove_wait_queue(wait_queue_head_t
*q
, wait_queue_t
* wait
));
745 #define __wait_event(wq, condition) \
747 wait_queue_t __wait; \
748 init_waitqueue_entry(&__wait, current); \
750 add_wait_queue(&wq, &__wait); \
752 set_current_state(TASK_UNINTERRUPTIBLE); \
757 current->state = TASK_RUNNING; \
758 remove_wait_queue(&wq, &__wait); \
761 #define wait_event(wq, condition) \
765 __wait_event(wq, condition); \
768 #define __wait_event_interruptible(wq, condition, ret) \
770 wait_queue_t __wait; \
771 init_waitqueue_entry(&__wait, current); \
773 add_wait_queue(&wq, &__wait); \
775 set_current_state(TASK_INTERRUPTIBLE); \
778 if (!signal_pending(current)) { \
782 ret = -ERESTARTSYS; \
785 current->state = TASK_RUNNING; \
786 remove_wait_queue(&wq, &__wait); \
789 #define wait_event_interruptible(wq, condition) \
793 __wait_event_interruptible(wq, condition, __ret); \
797 #define REMOVE_LINKS(p) do { \
798 (p)->next_task->prev_task = (p)->prev_task; \
799 (p)->prev_task->next_task = (p)->next_task; \
801 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
803 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
805 (p)->p_pptr->p_cptr = (p)->p_osptr; \
808 #define SET_LINKS(p) do { \
809 (p)->next_task = &init_task; \
810 (p)->prev_task = init_task.prev_task; \
811 init_task.prev_task->next_task = (p); \
812 init_task.prev_task = (p); \
813 (p)->p_ysptr = NULL; \
814 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
815 (p)->p_osptr->p_ysptr = p; \
816 (p)->p_pptr->p_cptr = p; \
819 #define for_each_task(p) \
820 for (p = &init_task ; (p = p->next_task) != &init_task ; )
822 #define next_thread(p) \
823 list_entry((p)->thread_group.next, struct task_struct, thread_group)
825 static inline void del_from_runqueue(struct task_struct
* p
)
828 p
->sleep_time
= jiffies
;
829 list_del(&p
->run_list
);
830 p
->run_list
.next
= NULL
;
833 static inline int task_on_runqueue(struct task_struct
*p
)
835 return (p
->run_list
.next
!= NULL
);
838 static inline void unhash_process(struct task_struct
*p
)
840 if (task_on_runqueue(p
)) BUG();
841 write_lock_irq(&tasklist_lock
);
845 list_del(&p
->thread_group
);
846 write_unlock_irq(&tasklist_lock
);
849 static inline void task_lock(struct task_struct
*p
)
851 spin_lock(&p
->alloc_lock
);
854 static inline void task_unlock(struct task_struct
*p
)
856 spin_unlock(&p
->alloc_lock
);
859 /* write full pathname into buffer and return start of pathname */
860 static inline char * d_path(struct dentry
*dentry
, struct vfsmount
*vfsmnt
,
861 char *buf
, int buflen
)
864 struct vfsmount
*rootmnt
;
866 read_lock(¤t
->fs
->lock
);
867 rootmnt
= mntget(current
->fs
->rootmnt
);
868 root
= dget(current
->fs
->root
);
869 read_unlock(¤t
->fs
->lock
);
870 spin_lock(&dcache_lock
);
871 res
= __d_path(dentry
, vfsmnt
, root
, rootmnt
, buf
, buflen
);
872 spin_unlock(&dcache_lock
);
878 #endif /* __KERNEL__ */