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