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