📄 sched.h
字号:
extern struct task_struct *task[NR_TASKS];extern struct task_struct **tarray_freelist;extern spinlock_t taskslot_lock;extern __inline__ void add_free_taskslot(struct task_struct **t){ spin_lock(&taskslot_lock); *t = (struct task_struct *) tarray_freelist; tarray_freelist = t; spin_unlock(&taskslot_lock);}extern __inline__ struct task_struct **get_free_taskslot(void){ struct task_struct **tslot; spin_lock(&taskslot_lock); if((tslot = tarray_freelist) != NULL) tarray_freelist = (struct task_struct **) *tslot; spin_unlock(&taskslot_lock); return tslot;}/* PID hashing. */#define PIDHASH_SZ (NR_TASKS >> 2)extern struct task_struct *pidhash[PIDHASH_SZ];#define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))extern __inline__ void hash_pid(struct task_struct *p){ struct task_struct **htable = &pidhash[pid_hashfn(p->pid)]; if((p->pidhash_next = *htable) != NULL) (*htable)->pidhash_pprev = &p->pidhash_next; *htable = p; p->pidhash_pprev = htable;}extern __inline__ void unhash_pid(struct task_struct *p){ if(p->pidhash_next) p->pidhash_next->pidhash_pprev = p->pidhash_pprev; *p->pidhash_pprev = p->pidhash_next;}extern __inline__ struct task_struct *find_task_by_pid(int pid){ struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)]; for(p = *htable; p && p->pid != pid; p = p->pidhash_next) ; return p;}/* per-UID process charging. */extern int alloc_uid(struct task_struct *p);void free_uid(struct task_struct *p);#include <asm/current.h>extern unsigned long volatile jiffies;extern unsigned long itimer_ticks;extern unsigned long itimer_next;extern struct timeval xtime;extern void do_timer(struct pt_regs *);extern unsigned int * prof_buffer;extern unsigned long prof_len;extern unsigned long prof_shift;#define CURRENT_TIME (xtime.tv_sec)extern void FASTCALL(__wake_up(struct wait_queue ** p, unsigned int mode));extern void FASTCALL(sleep_on(struct wait_queue ** p));extern long FASTCALL(sleep_on_timeout(struct wait_queue ** p, signed long timeout));extern void FASTCALL(interruptible_sleep_on(struct wait_queue ** p));extern long FASTCALL(interruptible_sleep_on_timeout(struct wait_queue ** p, signed long timeout));extern void FASTCALL(wake_up_process(struct task_struct * tsk));#define wake_up(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE)#define wake_up_interruptible(x) __wake_up((x),TASK_INTERRUPTIBLE)extern int in_group_p(gid_t grp);extern void flush_signals(struct task_struct *);extern void flush_signal_handlers(struct task_struct *);extern int dequeue_signal(sigset_t *block, siginfo_t *);extern int send_sig_info(int, struct siginfo *info, struct task_struct *);extern int force_sig_info(int, struct siginfo *info, struct task_struct *);extern int kill_pg_info(int, struct siginfo *info, pid_t);extern int kill_sl_info(int, struct siginfo *info, pid_t);extern int kill_proc_info(int, struct siginfo *info, pid_t);extern int kill_something_info(int, struct siginfo *info, int);extern void notify_parent(struct task_struct * tsk, int);extern void force_sig(int sig, struct task_struct * p);extern int send_sig(int sig, struct task_struct * p, int priv);extern int kill_pg(pid_t, int, int);extern int kill_sl(pid_t, int, int);extern int kill_proc(pid_t, int, int);extern int do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact);extern int do_sigaltstack(const stack_t *ss, stack_t *oss, unsigned long sp);extern inline int signal_pending(struct task_struct *p){ return (p->sigpending != 0);}/* Reevaluate whether the task has signals pending delivery. This is required every time the blocked sigset_t changes. All callers should have t->sigmask_lock. */static inline void recalc_sigpending(struct task_struct *t){ unsigned long ready; long i; switch (_NSIG_WORDS) { default: for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;) ready |= t->signal.sig[i] &~ t->blocked.sig[i]; break; case 4: ready = t->signal.sig[3] &~ t->blocked.sig[3]; ready |= t->signal.sig[2] &~ t->blocked.sig[2]; ready |= t->signal.sig[1] &~ t->blocked.sig[1]; ready |= t->signal.sig[0] &~ t->blocked.sig[0]; break; case 2: ready = t->signal.sig[1] &~ t->blocked.sig[1]; ready |= t->signal.sig[0] &~ t->blocked.sig[0]; break; case 1: ready = t->signal.sig[0] &~ t->blocked.sig[0]; } t->sigpending = (ready != 0);}/* True if we are on the alternate signal stack. */static inline int on_sig_stack(unsigned long sp){ return (sp >= current->sas_ss_sp && sp < current->sas_ss_sp + current->sas_ss_size);}static inline int sas_ss_flags(unsigned long sp){ return (current->sas_ss_size == 0 ? SS_DISABLE : on_sig_stack(sp) ? SS_ONSTACK : 0);}extern int request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *device, void *dev_id);extern void free_irq(unsigned int irq, void *dev_id);/* * This has now become a routine instead of a macro, it sets a flag if * it returns true (to do BSD-style accounting where the process is flagged * if it uses root privs). The implication of this is that you should do * normal permissions checks first, and check suser() last. * * [Dec 1997 -- Chris Evans] * For correctness, the above considerations need to be extended to * fsuser(). This is done, along with moving fsuser() checks to be * last. * * These will be removed, but in the mean time, when the SECURE_NOROOT * flag is set, uids don't grant privilege. */extern inline int suser(void){ if (!issecure(SECURE_NOROOT) && current->euid == 0) { current->flags |= PF_SUPERPRIV; return 1; } return 0;}extern inline int fsuser(void){ if (!issecure(SECURE_NOROOT) && current->fsuid == 0) { current->flags |= PF_SUPERPRIV; return 1; } return 0;}/* * capable() checks for a particular capability. * New privilege checks should use this interface, rather than suser() or * fsuser(). See include/linux/capability.h for defined capabilities. */extern inline int capable(int cap){#if 1 /* ok now */ if (cap_raised(current->cap_effective, cap))#else if (cap_is_fs_cap(cap) ? current->fsuid == 0 : current->euid == 0)#endif { current->flags |= PF_SUPERPRIV; return 1; } return 0;}/* * Routines for handling mm_structs */extern struct mm_struct * mm_alloc(void);static inline void mmget(struct mm_struct * mm){ atomic_inc(&mm->count);}extern void mmput(struct mm_struct *);/* Remove the current tasks stale references to the old mm_struct */extern void mm_release(void);/* * Routines for handling the fd arrays */extern struct file ** alloc_fd_array(int);extern int expand_fd_array(struct files_struct *, int nr);extern void free_fd_array(struct file **, int);extern fd_set *alloc_fdset(int);extern int expand_fdset(struct files_struct *, int nr);extern void free_fdset(fd_set *, int);/* Expand files. Return <0 on error; 0 nothing done; 1 files expanded, * we may have blocked. */static inline int expand_files(struct files_struct *files, int nr){ int err, expand = 0;#ifdef FDSET_DEBUG printk (KERN_ERR __FUNCTION__ " %d: nr = %d\n", current->pid, nr);#endif if (nr >= files->max_fdset) { expand = 1; if ((err = expand_fdset(files, nr + 1))) goto out; } if (nr >= files->max_fds) { expand = 1; if ((err = expand_fd_array(files, nr + 1))) goto out; } err = expand; out:#ifdef FDSET_DEBUG if (err) printk (KERN_ERR __FUNCTION__ " %d: return %d\n", current->pid, err);#endif return err;}extern int copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);extern void flush_thread(void);extern void exit_thread(void);extern void exit_mm(struct task_struct *);extern void exit_fs(struct task_struct *);extern void exit_files(struct task_struct *);extern void exit_sighand(struct task_struct *);extern int do_execve(char *, char **, char **, struct pt_regs *);extern int do_fork(unsigned long, unsigned long, struct pt_regs *);/* * The wait-queues are circular lists, and you have to be *very* sure * to keep them correct. Use only these two functions to add/remove * entries in the queues. */extern inline void __add_wait_queue(struct wait_queue ** p, struct wait_queue * wait){ wait->next = *p ? : WAIT_QUEUE_HEAD(p); *p = wait;}extern rwlock_t waitqueue_lock;extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait){ unsigned long flags; write_lock_irqsave(&waitqueue_lock, flags); __add_wait_queue(p, wait); write_unlock_irqrestore(&waitqueue_lock, flags);}extern inline void __remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait){ struct wait_queue * next = wait->next; struct wait_queue * head = next; struct wait_queue * tmp; while ((tmp = head->next) != wait) { head = tmp; } head->next = next;}extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait){ unsigned long flags; write_lock_irqsave(&waitqueue_lock, flags); __remove_wait_queue(p, wait); write_unlock_irqrestore(&waitqueue_lock, flags); }#define __wait_event(wq, condition) \do { \ struct wait_queue __wait; \ \ __wait.task = current; \ add_wait_queue(&wq, &__wait); \ for (;;) { \ current->state = TASK_UNINTERRUPTIBLE; \ mb(); \ if (condition) \ break; \ schedule(); \ } \ current->state = TASK_RUNNING; \ remove_wait_queue(&wq, &__wait); \} while (0)#define wait_event(wq, condition) \do { \ if (condition) \ break; \ __wait_event(wq, condition); \} while (0)#define __wait_event_interruptible(wq, condition, ret) \do { \ struct wait_queue __wait; \ \ __wait.task = current; \ add_wait_queue(&wq, &__wait); \ for (;;) { \ current->state = TASK_INTERRUPTIBLE; \ mb(); \ if (condition) \ break; \ if (!signal_pending(current)) { \ schedule(); \ continue; \ } \ ret = -ERESTARTSYS; \ break; \ } \ current->state = TASK_RUNNING; \ remove_wait_queue(&wq, &__wait); \} while (0) #define wait_event_interruptible(wq, condition) \({ \ int __ret = 0; \ if (!(condition)) \ __wait_event_interruptible(wq, condition, __ret); \ __ret; \})#define REMOVE_LINKS(p) do { \ (p)->next_task->prev_task = (p)->prev_task; \ (p)->prev_task->next_task = (p)->next_task; \ if ((p)->p_osptr) \ (p)->p_osptr->p_ysptr = (p)->p_ysptr; \ if ((p)->p_ysptr) \ (p)->p_ysptr->p_osptr = (p)->p_osptr; \ else \ (p)->p_pptr->p_cptr = (p)->p_osptr; \ } while (0)#define SET_LINKS(p) do { \ (p)->next_task = &init_task; \ (p)->prev_task = init_task.prev_task; \ init_task.prev_task->next_task = (p); \ init_task.prev_task = (p); \ (p)->p_ysptr = NULL; \ if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \ (p)->p_osptr->p_ysptr = p; \ (p)->p_pptr->p_cptr = p; \ } while (0)#define for_each_task(p) \ for (p = &init_task ; (p = p->next_task) != &init_task ; )#endif /* __KERNEL__ */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -