/[gentoo-x86]/sys-kernel/linux-extras/files/2.4.6-r2/sched.h
Gentoo

Contents of /sys-kernel/linux-extras/files/2.4.6-r2/sched.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download) (as text)
Fri Oct 12 03:59:48 2001 UTC (18 years, 7 months ago) by drobbins
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/x-chdr
FILE REMOVED
massive cleanup

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

  ViewVC Help
Powered by ViewVC 1.1.20