- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / include / linux / sched.h
blob403a93e900401a9f7489a53b1b0f5d09fb4f001d
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/personality.h>
11 #include <linux/threads.h>
12 #include <linux/kernel.h>
13 #include <linux/types.h>
14 #include <linux/times.h>
15 #include <linux/timex.h>
17 #include <asm/system.h>
18 #include <asm/semaphore.h>
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>
31 * cloning flags:
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? */
44 #define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
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.
56 extern unsigned long avenrun[]; /* Load averages */
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) */
65 #define CALC_LOAD(load,exp,n) \
66 load *= exp; \
67 load += n*(FIXED_1-exp); \
68 load >>= FSHIFT;
70 #define CT_TO_SECS(x) ((x) / HZ)
71 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
73 extern int nr_running, nr_threads;
74 extern int last_pid;
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>
82 #include <asm/processor.h>
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
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
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
111 * Scheduling policies
113 #define SCHED_OTHER 0
114 #define SCHED_FIFO 1
115 #define SCHED_RR 2
118 * This is an additional bit set when we want to
119 * yield the CPU for one re-schedule..
121 #define SCHED_YIELD 0x10
123 struct sched_param {
124 int sched_priority;
127 #ifdef __KERNEL__
129 #include <linux/spinlock.h>
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).
137 extern rwlock_t tasklist_lock;
138 extern spinlock_t runqueue_lock;
140 extern void sched_init(void);
141 extern void init_idle(void);
142 extern void show_state(void);
143 extern void cpu_init (void);
144 extern void trap_init(void);
145 extern void update_process_times(int user);
146 extern void update_one_process(struct task_struct *p, unsigned long user,
147 unsigned long system, int cpu);
149 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
150 extern signed long FASTCALL(schedule_timeout(signed long timeout));
151 asmlinkage void schedule(void);
153 extern int schedule_task(struct tq_struct *task);
154 extern void flush_scheduled_tasks(void);
155 extern int start_context_thread(void);
156 extern int current_is_keventd(void);
159 * The default fd array needs to be at least BITS_PER_LONG,
160 * as this is the granularity returned by copy_fdset().
162 #define NR_OPEN_DEFAULT BITS_PER_LONG
165 * Open file table structure
167 struct files_struct {
168 atomic_t count;
169 rwlock_t file_lock;
170 int max_fds;
171 int max_fdset;
172 int next_fd;
173 struct file ** fd; /* current fd array */
174 fd_set *close_on_exec;
175 fd_set *open_fds;
176 fd_set close_on_exec_init;
177 fd_set open_fds_init;
178 struct file * fd_array[NR_OPEN_DEFAULT];
181 #define INIT_FILES \
183 count: ATOMIC_INIT(1), \
184 file_lock: RW_LOCK_UNLOCKED, \
185 max_fds: NR_OPEN_DEFAULT, \
186 max_fdset: __FD_SETSIZE, \
187 next_fd: 0, \
188 fd: &init_files.fd_array[0], \
189 close_on_exec: &init_files.close_on_exec_init, \
190 open_fds: &init_files.open_fds_init, \
191 close_on_exec_init: { { 0, } }, \
192 open_fds_init: { { 0, } }, \
193 fd_array: { NULL, } \
196 /* Maximum number of active map areas.. This is a random (large) number */
197 #define MAX_MAP_COUNT (65536)
199 /* Number of map areas at which the AVL tree is activated. This is arbitrary. */
200 #define AVL_MIN_MAP_COUNT 32
202 struct mm_struct {
203 struct vm_area_struct * mmap; /* list of VMAs */
204 struct vm_area_struct * mmap_avl; /* tree of VMAs */
205 struct vm_area_struct * mmap_cache; /* last find_vma result */
206 pgd_t * pgd;
207 atomic_t mm_users; /* How many users with user space? */
208 atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
209 int map_count; /* number of VMAs */
210 struct semaphore mmap_sem;
211 spinlock_t page_table_lock;
212 unsigned long start_code, end_code, start_data, end_data;
213 unsigned long start_brk, brk, start_stack;
214 unsigned long arg_start, arg_end, env_start, env_end;
215 unsigned long rss, total_vm, locked_vm;
216 unsigned long def_flags;
217 unsigned long cpu_vm_mask;
218 unsigned long swap_cnt; /* number of pages to swap on next pass */
219 unsigned long swap_address;
221 /* Architecture-specific MM context */
222 mm_context_t context;
225 #define INIT_MM(name) \
227 mmap: &init_mmap, \
228 mmap_avl: NULL, \
229 mmap_cache: NULL, \
230 pgd: swapper_pg_dir, \
231 mm_users: ATOMIC_INIT(2), \
232 mm_count: ATOMIC_INIT(1), \
233 map_count: 1, \
234 mmap_sem: __MUTEX_INITIALIZER(name.mmap_sem), \
235 page_table_lock: SPIN_LOCK_UNLOCKED, \
238 struct signal_struct {
239 atomic_t count;
240 struct k_sigaction action[_NSIG];
241 spinlock_t siglock;
245 #define INIT_SIGNALS { \
246 count: ATOMIC_INIT(1), \
247 action: { {{0,}}, }, \
248 siglock: SPIN_LOCK_UNLOCKED \
252 * Some day this will be a full-fledged user tracking system..
254 struct user_struct {
255 atomic_t __count; /* reference count */
256 atomic_t processes; /* How many processes does this user have? */
257 atomic_t files; /* How many open files does this user have? */
259 /* Hash table maintenance information */
260 struct user_struct *next, **pprev;
261 uid_t uid;
264 #define get_current_user() ({ \
265 struct user_struct *__user = current->user; \
266 atomic_inc(&__user->__count); \
267 __user; })
269 extern struct user_struct root_user;
270 #define INIT_USER (&root_user)
272 struct task_struct {
274 * offsets of these are hardcoded elsewhere - touch with care
276 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
277 unsigned long flags; /* per process flags, defined below */
278 int sigpending;
279 mm_segment_t addr_limit; /* thread address space:
280 0-0xBFFFFFFF for user-thead
281 0-0xFFFFFFFF for kernel-thread
283 struct exec_domain *exec_domain;
284 volatile long need_resched;
285 unsigned long ptrace;
287 int lock_depth; /* Lock depth */
290 * offset 32 begins here on 32-bit platforms. We keep
291 * all fields in a single cacheline that are needed for
292 * the goodness() loop in schedule().
294 long counter;
295 long nice;
296 unsigned long policy;
297 struct mm_struct *mm;
298 int has_cpu, processor;
299 unsigned long cpus_allowed;
301 * (only the 'next' pointer fits into the cacheline, but
302 * that's just fine.)
304 struct list_head run_list;
305 unsigned long sleep_time;
307 struct task_struct *next_task, *prev_task;
308 struct mm_struct *active_mm;
310 /* task state */
311 struct linux_binfmt *binfmt;
312 int exit_code, exit_signal;
313 int pdeath_signal; /* The signal sent when the parent dies */
314 /* ??? */
315 unsigned long personality;
316 int dumpable:1;
317 int did_exec:1;
318 pid_t pid;
319 pid_t pgrp;
320 pid_t tty_old_pgrp;
321 pid_t session;
322 pid_t tgid;
323 /* boolean value for session group leader */
324 int leader;
326 * pointers to (original) parent process, youngest child, younger sibling,
327 * older sibling, respectively. (p->father can be replaced with
328 * p->p_pptr->pid)
330 struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
331 struct list_head thread_group;
333 /* PID hash table linkage. */
334 struct task_struct *pidhash_next;
335 struct task_struct **pidhash_pprev;
337 wait_queue_head_t wait_chldexit; /* for wait4() */
338 struct semaphore *vfork_sem; /* for vfork() */
339 unsigned long rt_priority;
340 unsigned long it_real_value, it_prof_value, it_virt_value;
341 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
342 struct timer_list real_timer;
343 struct tms times;
344 unsigned long start_time;
345 long per_cpu_utime[NR_CPUS], per_cpu_stime[NR_CPUS];
346 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
347 unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
348 int swappable:1;
349 /* process credentials */
350 uid_t uid,euid,suid,fsuid;
351 gid_t gid,egid,sgid,fsgid;
352 int ngroups;
353 gid_t groups[NGROUPS];
354 kernel_cap_t cap_effective, cap_inheritable, cap_permitted;
355 int keep_capabilities:1;
356 struct user_struct *user;
357 /* limits */
358 struct rlimit rlim[RLIM_NLIMITS];
359 unsigned short used_math;
360 char comm[16];
361 /* file system info */
362 int link_count;
363 struct tty_struct *tty; /* NULL if no tty */
364 unsigned int locks; /* How many file locks are being held */
365 /* ipc stuff */
366 struct sem_undo *semundo;
367 struct sem_queue *semsleeping;
368 /* CPU-specific state of this task */
369 struct thread_struct thread;
370 /* filesystem information */
371 struct fs_struct *fs;
372 /* open file information */
373 struct files_struct *files;
374 /* signal handlers */
375 spinlock_t sigmask_lock; /* Protects signal and blocked */
376 struct signal_struct *sig;
378 sigset_t blocked;
379 struct sigpending pending;
381 unsigned long sas_ss_sp;
382 size_t sas_ss_size;
383 int (*notifier)(void *priv);
384 void *notifier_data;
385 sigset_t *notifier_mask;
387 /* Thread group tracking */
388 u32 parent_exec_id;
389 u32 self_exec_id;
390 /* Protection of (de-)allocation: mm, files, fs, tty */
391 spinlock_t alloc_lock;
395 * Per process flags
397 #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */
398 /* Not implemented yet, only for 486*/
399 #define PF_STARTING 0x00000002 /* being created */
400 #define PF_EXITING 0x00000004 /* getting shut down */
401 #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
402 #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */
403 #define PF_DUMPCORE 0x00000200 /* dumped core */
404 #define PF_SIGNALED 0x00000400 /* killed by a signal */
405 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
406 #define PF_VFORK 0x00001000 /* Wake up parent in mm_release */
408 #define PF_USEDFPU 0x00100000 /* task used FPU this quantum (SMP) */
411 * Ptrace flags
414 #define PT_PTRACED 0x00000001
415 #define PT_TRACESYS 0x00000002
416 #define PT_DTRACE 0x00000004 /* delayed trace (used on m68k, i386) */
417 #define PT_TRACESYSGOOD 0x00000008
420 * Limit the stack by to some sane default: root can always
421 * increase this limit if needed.. 8MB seems reasonable.
423 #define _STK_LIM (8*1024*1024)
425 #define DEF_COUNTER (10*HZ/100) /* 100 ms time slice */
426 #define MAX_COUNTER (20*HZ/100)
427 #define DEF_NICE (0)
430 * INIT_TASK is used to set up the first task table, touch at
431 * your own risk!. Base=0, limit=0x1fffff (=2MB)
433 #define INIT_TASK(tsk) \
435 state: 0, \
436 flags: 0, \
437 sigpending: 0, \
438 addr_limit: KERNEL_DS, \
439 exec_domain: &default_exec_domain, \
440 lock_depth: -1, \
441 counter: DEF_COUNTER, \
442 nice: DEF_NICE, \
443 policy: SCHED_OTHER, \
444 mm: NULL, \
445 active_mm: &init_mm, \
446 cpus_allowed: -1, \
447 run_list: LIST_HEAD_INIT(tsk.run_list), \
448 next_task: &tsk, \
449 prev_task: &tsk, \
450 p_opptr: &tsk, \
451 p_pptr: &tsk, \
452 thread_group: LIST_HEAD_INIT(tsk.thread_group), \
453 wait_chldexit: __WAIT_QUEUE_HEAD_INITIALIZER(tsk.wait_chldexit),\
454 real_timer: { \
455 function: it_real_fn \
456 }, \
457 cap_effective: CAP_INIT_EFF_SET, \
458 cap_inheritable: CAP_INIT_INH_SET, \
459 cap_permitted: CAP_FULL_SET, \
460 keep_capabilities: 0, \
461 rlim: INIT_RLIMITS, \
462 user: INIT_USER, \
463 comm: "swapper", \
464 thread: INIT_THREAD, \
465 fs: &init_fs, \
466 files: &init_files, \
467 sigmask_lock: SPIN_LOCK_UNLOCKED, \
468 sig: &init_signals, \
469 pending: { NULL, &tsk.pending.head, {{0}}}, \
470 blocked: {{0}}, \
471 alloc_lock: SPIN_LOCK_UNLOCKED \
475 #ifndef INIT_TASK_SIZE
476 # define INIT_TASK_SIZE 2048*sizeof(long)
477 #endif
479 union task_union {
480 struct task_struct task;
481 unsigned long stack[INIT_TASK_SIZE/sizeof(long)];
484 extern union task_union init_task_union;
486 extern struct mm_struct init_mm;
487 extern struct task_struct *init_tasks[NR_CPUS];
489 /* PID hashing. (shouldnt this be dynamic?) */
490 #define PIDHASH_SZ (4096 >> 2)
491 extern struct task_struct *pidhash[PIDHASH_SZ];
493 #define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
495 static inline void hash_pid(struct task_struct *p)
497 struct task_struct **htable = &pidhash[pid_hashfn(p->pid)];
499 if((p->pidhash_next = *htable) != NULL)
500 (*htable)->pidhash_pprev = &p->pidhash_next;
501 *htable = p;
502 p->pidhash_pprev = htable;
505 static inline void unhash_pid(struct task_struct *p)
507 if(p->pidhash_next)
508 p->pidhash_next->pidhash_pprev = p->pidhash_pprev;
509 *p->pidhash_pprev = p->pidhash_next;
512 static inline struct task_struct *find_task_by_pid(int pid)
514 struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)];
516 for(p = *htable; p && p->pid != pid; p = p->pidhash_next)
519 return p;
522 /* per-UID process charging. */
523 extern struct user_struct * alloc_uid(uid_t);
524 extern void free_uid(struct user_struct *);
526 #include <asm/current.h>
528 extern unsigned long volatile jiffies;
529 extern unsigned long itimer_ticks;
530 extern unsigned long itimer_next;
531 extern struct timeval xtime;
532 extern void do_timer(struct pt_regs *);
534 extern unsigned int * prof_buffer;
535 extern unsigned long prof_len;
536 extern unsigned long prof_shift;
538 #define CURRENT_TIME (xtime.tv_sec)
540 extern void FASTCALL(__wake_up(wait_queue_head_t *q, unsigned int mode, unsigned int wq_mode));
541 extern void FASTCALL(__wake_up_sync(wait_queue_head_t *q, unsigned int mode, unsigned int wq_mode));
542 extern void FASTCALL(sleep_on(wait_queue_head_t *q));
543 extern long FASTCALL(sleep_on_timeout(wait_queue_head_t *q,
544 signed long timeout));
545 extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t *q));
546 extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t *q,
547 signed long timeout));
548 extern void FASTCALL(wake_up_process(struct task_struct * tsk));
550 #define wake_up(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
551 #define wake_up_all(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,0)
552 #define wake_up_sync(x) __wake_up_sync((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
553 #define wake_up_interruptible(x) __wake_up((x),TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
554 #define wake_up_interruptible_all(x) __wake_up((x),TASK_INTERRUPTIBLE,0)
555 #define wake_up_interruptible_sync(x) __wake_up_sync((x),TASK_INTERRUPTIBLE,WQ_FLAG_EXCLUSIVE)
557 extern int in_group_p(gid_t);
558 extern int in_egroup_p(gid_t);
560 extern void proc_caches_init(void);
561 extern void flush_signals(struct task_struct *);
562 extern void flush_signal_handlers(struct task_struct *);
563 extern int dequeue_signal(sigset_t *, siginfo_t *);
564 extern void block_all_signals(int (*notifier)(void *priv), void *priv,
565 sigset_t *mask);
566 extern void unblock_all_signals(void);
567 extern int send_sig_info(int, struct siginfo *, struct task_struct *);
568 extern int force_sig_info(int, struct siginfo *, struct task_struct *);
569 extern int kill_pg_info(int, struct siginfo *, pid_t);
570 extern int kill_sl_info(int, struct siginfo *, pid_t);
571 extern int kill_proc_info(int, struct siginfo *, pid_t);
572 extern void notify_parent(struct task_struct *, int);
573 extern void do_notify_parent(struct task_struct *, int);
574 extern void force_sig(int, struct task_struct *);
575 extern int send_sig(int, struct task_struct *, int);
576 extern int kill_pg(pid_t, int, int);
577 extern int kill_sl(pid_t, int, int);
578 extern int kill_proc(pid_t, int, int);
579 extern int do_sigaction(int, const struct k_sigaction *, struct k_sigaction *);
580 extern int do_sigaltstack(const stack_t *, stack_t *, unsigned long);
582 static inline int signal_pending(struct task_struct *p)
584 return (p->sigpending != 0);
588 * Re-calculate pending state from the set of locally pending
589 * signals, globally pending signals, and blocked signals.
591 static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked)
593 unsigned long ready;
594 long i;
596 switch (_NSIG_WORDS) {
597 default:
598 for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
599 ready |= signal->sig[i] &~ blocked->sig[i];
600 break;
602 case 4: ready = signal->sig[3] &~ blocked->sig[3];
603 ready |= signal->sig[2] &~ blocked->sig[2];
604 ready |= signal->sig[1] &~ blocked->sig[1];
605 ready |= signal->sig[0] &~ blocked->sig[0];
606 break;
608 case 2: ready = signal->sig[1] &~ blocked->sig[1];
609 ready |= signal->sig[0] &~ blocked->sig[0];
610 break;
612 case 1: ready = signal->sig[0] &~ blocked->sig[0];
614 return ready != 0;
617 /* Reevaluate whether the task has signals pending delivery.
618 This is required every time the blocked sigset_t changes.
619 All callers should have t->sigmask_lock. */
621 static inline void recalc_sigpending(struct task_struct *t)
623 t->sigpending = has_pending_signals(&t->pending.signal, &t->blocked);
626 /* True if we are on the alternate signal stack. */
628 static inline int on_sig_stack(unsigned long sp)
630 return (sp - current->sas_ss_sp < current->sas_ss_size);
633 static inline int sas_ss_flags(unsigned long sp)
635 return (current->sas_ss_size == 0 ? SS_DISABLE
636 : on_sig_stack(sp) ? SS_ONSTACK : 0);
639 extern int request_irq(unsigned int,
640 void (*handler)(int, void *, struct pt_regs *),
641 unsigned long, const char *, void *);
642 extern void free_irq(unsigned int, void *);
645 * This has now become a routine instead of a macro, it sets a flag if
646 * it returns true (to do BSD-style accounting where the process is flagged
647 * if it uses root privs). The implication of this is that you should do
648 * normal permissions checks first, and check suser() last.
650 * [Dec 1997 -- Chris Evans]
651 * For correctness, the above considerations need to be extended to
652 * fsuser(). This is done, along with moving fsuser() checks to be
653 * last.
655 * These will be removed, but in the mean time, when the SECURE_NOROOT
656 * flag is set, uids don't grant privilege.
658 static inline int suser(void)
660 if (!issecure(SECURE_NOROOT) && current->euid == 0) {
661 current->flags |= PF_SUPERPRIV;
662 return 1;
664 return 0;
667 static inline int fsuser(void)
669 if (!issecure(SECURE_NOROOT) && current->fsuid == 0) {
670 current->flags |= PF_SUPERPRIV;
671 return 1;
673 return 0;
677 * capable() checks for a particular capability.
678 * New privilege checks should use this interface, rather than suser() or
679 * fsuser(). See include/linux/capability.h for defined capabilities.
682 static inline int capable(int cap)
684 #if 1 /* ok now */
685 if (cap_raised(current->cap_effective, cap))
686 #else
687 if (cap_is_fs_cap(cap) ? current->fsuid == 0 : current->euid == 0)
688 #endif
690 current->flags |= PF_SUPERPRIV;
691 return 1;
693 return 0;
697 * Routines for handling mm_structs
699 extern struct mm_struct * mm_alloc(void);
701 extern struct mm_struct * start_lazy_tlb(void);
702 extern void end_lazy_tlb(struct mm_struct *mm);
704 /* mmdrop drops the mm and the page tables */
705 extern inline void FASTCALL(__mmdrop(struct mm_struct *));
706 static inline void mmdrop(struct mm_struct * mm)
708 if (atomic_dec_and_test(&mm->mm_count))
709 __mmdrop(mm);
712 /* mmput gets rid of the mappings and all user-space */
713 extern void mmput(struct mm_struct *);
714 /* Remove the current tasks stale references to the old mm_struct */
715 extern void mm_release(void);
718 * Routines for handling the fd arrays
720 extern struct file ** alloc_fd_array(int);
721 extern int expand_fd_array(struct files_struct *, int nr);
722 extern void free_fd_array(struct file **, int);
724 extern fd_set *alloc_fdset(int);
725 extern int expand_fdset(struct files_struct *, int nr);
726 extern void free_fdset(fd_set *, int);
728 extern int copy_thread(int, unsigned long, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
729 extern void flush_thread(void);
730 extern void exit_thread(void);
732 extern void exit_mm(struct task_struct *);
733 extern void exit_files(struct task_struct *);
734 extern void exit_sighand(struct task_struct *);
736 extern void daemonize(void);
738 extern int do_execve(char *, char **, char **, struct pt_regs *);
739 extern int do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long);
741 extern void FASTCALL(add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
742 extern void FASTCALL(add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t * wait));
743 extern void FASTCALL(remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
745 #define __wait_event(wq, condition) \
746 do { \
747 wait_queue_t __wait; \
748 init_waitqueue_entry(&__wait, current); \
750 add_wait_queue(&wq, &__wait); \
751 for (;;) { \
752 set_current_state(TASK_UNINTERRUPTIBLE); \
753 if (condition) \
754 break; \
755 schedule(); \
757 current->state = TASK_RUNNING; \
758 remove_wait_queue(&wq, &__wait); \
759 } while (0)
761 #define wait_event(wq, condition) \
762 do { \
763 if (condition) \
764 break; \
765 __wait_event(wq, condition); \
766 } while (0)
768 #define __wait_event_interruptible(wq, condition, ret) \
769 do { \
770 wait_queue_t __wait; \
771 init_waitqueue_entry(&__wait, current); \
773 add_wait_queue(&wq, &__wait); \
774 for (;;) { \
775 set_current_state(TASK_INTERRUPTIBLE); \
776 if (condition) \
777 break; \
778 if (!signal_pending(current)) { \
779 schedule(); \
780 continue; \
782 ret = -ERESTARTSYS; \
783 break; \
785 current->state = TASK_RUNNING; \
786 remove_wait_queue(&wq, &__wait); \
787 } while (0)
789 #define wait_event_interruptible(wq, condition) \
790 ({ \
791 int __ret = 0; \
792 if (!(condition)) \
793 __wait_event_interruptible(wq, condition, __ret); \
794 __ret; \
797 #define REMOVE_LINKS(p) do { \
798 (p)->next_task->prev_task = (p)->prev_task; \
799 (p)->prev_task->next_task = (p)->next_task; \
800 if ((p)->p_osptr) \
801 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
802 if ((p)->p_ysptr) \
803 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
804 else \
805 (p)->p_pptr->p_cptr = (p)->p_osptr; \
806 } while (0)
808 #define SET_LINKS(p) do { \
809 (p)->next_task = &init_task; \
810 (p)->prev_task = init_task.prev_task; \
811 init_task.prev_task->next_task = (p); \
812 init_task.prev_task = (p); \
813 (p)->p_ysptr = NULL; \
814 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
815 (p)->p_osptr->p_ysptr = p; \
816 (p)->p_pptr->p_cptr = p; \
817 } while (0)
819 #define for_each_task(p) \
820 for (p = &init_task ; (p = p->next_task) != &init_task ; )
822 #define next_thread(p) \
823 list_entry((p)->thread_group.next, struct task_struct, thread_group)
825 static inline void del_from_runqueue(struct task_struct * p)
827 nr_running--;
828 p->sleep_time = jiffies;
829 list_del(&p->run_list);
830 p->run_list.next = NULL;
833 static inline int task_on_runqueue(struct task_struct *p)
835 return (p->run_list.next != NULL);
838 static inline void unhash_process(struct task_struct *p)
840 if (task_on_runqueue(p)) BUG();
841 write_lock_irq(&tasklist_lock);
842 nr_threads--;
843 unhash_pid(p);
844 REMOVE_LINKS(p);
845 list_del(&p->thread_group);
846 write_unlock_irq(&tasklist_lock);
849 static inline void task_lock(struct task_struct *p)
851 spin_lock(&p->alloc_lock);
854 static inline void task_unlock(struct task_struct *p)
856 spin_unlock(&p->alloc_lock);
859 /* write full pathname into buffer and return start of pathname */
860 static inline char * d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
861 char *buf, int buflen)
863 char *res;
864 struct vfsmount *rootmnt;
865 struct dentry *root;
866 read_lock(&current->fs->lock);
867 rootmnt = mntget(current->fs->rootmnt);
868 root = dget(current->fs->root);
869 read_unlock(&current->fs->lock);
870 spin_lock(&dcache_lock);
871 res = __d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
872 spin_unlock(&dcache_lock);
873 dput(root);
874 mntput(rootmnt);
875 return res;
878 #endif /* __KERNEL__ */
880 #endif