ia64/xen-unstable

view linux-2.4-xen-sparse/include/linux/sched.h @ 6046:e0146a206ea2

- include linux/vmalloc.h for vmalloc
- include grant table includes from common.h rather than blkback.c,
since both C files use grant tables
- include linux/version.h from block.h (a macro there uses it)
- include asm-xen/hypervisor.h from block.h (virt_to_machine)

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