File: /usr/src/linux/include/linux/sched.h

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