signal.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_SCHED_SIGNAL_H
  3. #define _LINUX_SCHED_SIGNAL_H
  4. #include <linux/rculist.h>
  5. #include <linux/signal.h>
  6. #include <linux/sched.h>
  7. #include <linux/sched/jobctl.h>
  8. #include <linux/sched/task.h>
  9. #include <linux/cred.h>
  10. /*
  11. * Types defining task->signal and task->sighand and APIs using them:
  12. */
  13. struct sighand_struct {
  14. atomic_t count;
  15. struct k_sigaction action[_NSIG];
  16. spinlock_t siglock;
  17. wait_queue_head_t signalfd_wqh;
  18. };
  19. /*
  20. * Per-process accounting stats:
  21. */
  22. struct pacct_struct {
  23. int ac_flag;
  24. long ac_exitcode;
  25. unsigned long ac_mem;
  26. u64 ac_utime, ac_stime;
  27. unsigned long ac_minflt, ac_majflt;
  28. };
  29. struct cpu_itimer {
  30. u64 expires;
  31. u64 incr;
  32. };
  33. /*
  34. * This is the atomic variant of task_cputime, which can be used for
  35. * storing and updating task_cputime statistics without locking.
  36. */
  37. struct task_cputime_atomic {
  38. atomic64_t utime;
  39. atomic64_t stime;
  40. atomic64_t sum_exec_runtime;
  41. };
  42. #define INIT_CPUTIME_ATOMIC \
  43. (struct task_cputime_atomic) { \
  44. .utime = ATOMIC64_INIT(0), \
  45. .stime = ATOMIC64_INIT(0), \
  46. .sum_exec_runtime = ATOMIC64_INIT(0), \
  47. }
  48. /**
  49. * struct thread_group_cputimer - thread group interval timer counts
  50. * @cputime_atomic: atomic thread group interval timers.
  51. * @running: true when there are timers running and
  52. * @cputime_atomic receives updates.
  53. * @checking_timer: true when a thread in the group is in the
  54. * process of checking for thread group timers.
  55. *
  56. * This structure contains the version of task_cputime, above, that is
  57. * used for thread group CPU timer calculations.
  58. */
  59. struct thread_group_cputimer {
  60. struct task_cputime_atomic cputime_atomic;
  61. bool running;
  62. bool checking_timer;
  63. };
  64. struct multiprocess_signals {
  65. sigset_t signal;
  66. struct hlist_node node;
  67. };
  68. /*
  69. * NOTE! "signal_struct" does not have its own
  70. * locking, because a shared signal_struct always
  71. * implies a shared sighand_struct, so locking
  72. * sighand_struct is always a proper superset of
  73. * the locking of signal_struct.
  74. */
  75. struct signal_struct {
  76. atomic_t sigcnt;
  77. atomic_t live;
  78. int nr_threads;
  79. struct list_head thread_head;
  80. wait_queue_head_t wait_chldexit; /* for wait4() */
  81. /* current thread group signal load-balancing target: */
  82. struct task_struct *curr_target;
  83. /* shared signal handling: */
  84. struct sigpending shared_pending;
  85. /* For collecting multiprocess signals during fork */
  86. struct hlist_head multiprocess;
  87. /* thread group exit support */
  88. int group_exit_code;
  89. /* overloaded:
  90. * - notify group_exit_task when ->count is equal to notify_count
  91. * - everyone except group_exit_task is stopped during signal delivery
  92. * of fatal signals, group_exit_task processes the signal.
  93. */
  94. int notify_count;
  95. struct task_struct *group_exit_task;
  96. /* thread group stop support, overloads group_exit_code too */
  97. int group_stop_count;
  98. unsigned int flags; /* see SIGNAL_* flags below */
  99. /*
  100. * PR_SET_CHILD_SUBREAPER marks a process, like a service
  101. * manager, to re-parent orphan (double-forking) child processes
  102. * to this process instead of 'init'. The service manager is
  103. * able to receive SIGCHLD signals and is able to investigate
  104. * the process until it calls wait(). All children of this
  105. * process will inherit a flag if they should look for a
  106. * child_subreaper process at exit.
  107. */
  108. unsigned int is_child_subreaper:1;
  109. unsigned int has_child_subreaper:1;
  110. #ifdef CONFIG_POSIX_TIMERS
  111. /* POSIX.1b Interval Timers */
  112. int posix_timer_id;
  113. struct list_head posix_timers;
  114. /* ITIMER_REAL timer for the process */
  115. struct hrtimer real_timer;
  116. ktime_t it_real_incr;
  117. /*
  118. * ITIMER_PROF and ITIMER_VIRTUAL timers for the process, we use
  119. * CPUCLOCK_PROF and CPUCLOCK_VIRT for indexing array as these
  120. * values are defined to 0 and 1 respectively
  121. */
  122. struct cpu_itimer it[2];
  123. /*
  124. * Thread group totals for process CPU timers.
  125. * See thread_group_cputimer(), et al, for details.
  126. */
  127. struct thread_group_cputimer cputimer;
  128. /* Earliest-expiration cache. */
  129. struct task_cputime cputime_expires;
  130. struct list_head cpu_timers[3];
  131. #endif
  132. /* PID/PID hash table linkage. */
  133. struct pid *pids[PIDTYPE_MAX];
  134. #ifdef CONFIG_NO_HZ_FULL
  135. atomic_t tick_dep_mask;
  136. #endif
  137. struct pid *tty_old_pgrp;
  138. /* boolean value for session group leader */
  139. int leader;
  140. struct tty_struct *tty; /* NULL if no tty */
  141. #ifdef CONFIG_SCHED_AUTOGROUP
  142. struct autogroup *autogroup;
  143. #endif
  144. /*
  145. * Cumulative resource counters for dead threads in the group,
  146. * and for reaped dead child processes forked by this group.
  147. * Live threads maintain their own counters and add to these
  148. * in __exit_signal, except for the group leader.
  149. */
  150. seqlock_t stats_lock;
  151. u64 utime, stime, cutime, cstime;
  152. u64 gtime;
  153. u64 cgtime;
  154. struct prev_cputime prev_cputime;
  155. unsigned long nvcsw, nivcsw, cnvcsw, cnivcsw;
  156. unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
  157. unsigned long inblock, oublock, cinblock, coublock;
  158. unsigned long maxrss, cmaxrss;
  159. struct task_io_accounting ioac;
  160. /*
  161. * Cumulative ns of schedule CPU time fo dead threads in the
  162. * group, not including a zombie group leader, (This only differs
  163. * from jiffies_to_ns(utime + stime) if sched_clock uses something
  164. * other than jiffies.)
  165. */
  166. unsigned long long sum_sched_runtime;
  167. /*
  168. * We don't bother to synchronize most readers of this at all,
  169. * because there is no reader checking a limit that actually needs
  170. * to get both rlim_cur and rlim_max atomically, and either one
  171. * alone is a single word that can safely be read normally.
  172. * getrlimit/setrlimit use task_lock(current->group_leader) to
  173. * protect this instead of the siglock, because they really
  174. * have no need to disable irqs.
  175. */
  176. struct rlimit rlim[RLIM_NLIMITS];
  177. #ifdef CONFIG_BSD_PROCESS_ACCT
  178. struct pacct_struct pacct; /* per-process accounting information */
  179. #endif
  180. #ifdef CONFIG_TASKSTATS
  181. struct taskstats *stats;
  182. #endif
  183. #ifdef CONFIG_AUDIT
  184. unsigned audit_tty;
  185. struct tty_audit_buf *tty_audit_buf;
  186. #endif
  187. /*
  188. * Thread is the potential origin of an oom condition; kill first on
  189. * oom
  190. */
  191. bool oom_flag_origin;
  192. short oom_score_adj; /* OOM kill score adjustment */
  193. short oom_score_adj_min; /* OOM kill score adjustment min value.
  194. * Only settable by CAP_SYS_RESOURCE. */
  195. struct mm_struct *oom_mm; /* recorded mm when the thread group got
  196. * killed by the oom killer */
  197. struct mutex cred_guard_mutex; /* guard against foreign influences on
  198. * credential calculations
  199. * (notably. ptrace) */
  200. } __randomize_layout;
  201. /*
  202. * Bits in flags field of signal_struct.
  203. */
  204. #define SIGNAL_STOP_STOPPED 0x00000001 /* job control stop in effect */
  205. #define SIGNAL_STOP_CONTINUED 0x00000002 /* SIGCONT since WCONTINUED reap */
  206. #define SIGNAL_GROUP_EXIT 0x00000004 /* group exit in progress */
  207. #define SIGNAL_GROUP_COREDUMP 0x00000008 /* coredump in progress */
  208. /*
  209. * Pending notifications to parent.
  210. */
  211. #define SIGNAL_CLD_STOPPED 0x00000010
  212. #define SIGNAL_CLD_CONTINUED 0x00000020
  213. #define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED)
  214. #define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */
  215. #define SIGNAL_STOP_MASK (SIGNAL_CLD_MASK | SIGNAL_STOP_STOPPED | \
  216. SIGNAL_STOP_CONTINUED)
  217. static inline void signal_set_stop_flags(struct signal_struct *sig,
  218. unsigned int flags)
  219. {
  220. WARN_ON(sig->flags & (SIGNAL_GROUP_EXIT|SIGNAL_GROUP_COREDUMP));
  221. sig->flags = (sig->flags & ~SIGNAL_STOP_MASK) | flags;
  222. }
  223. /* If true, all threads except ->group_exit_task have pending SIGKILL */
  224. static inline int signal_group_exit(const struct signal_struct *sig)
  225. {
  226. return (sig->flags & SIGNAL_GROUP_EXIT) ||
  227. (sig->group_exit_task != NULL);
  228. }
  229. extern void flush_signals(struct task_struct *);
  230. extern void ignore_signals(struct task_struct *);
  231. extern void flush_signal_handlers(struct task_struct *, int force_default);
  232. extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
  233. static inline int kernel_dequeue_signal(siginfo_t *info)
  234. {
  235. struct task_struct *tsk = current;
  236. siginfo_t __info;
  237. int ret;
  238. spin_lock_irq(&tsk->sighand->siglock);
  239. ret = dequeue_signal(tsk, &tsk->blocked, info ?: &__info);
  240. spin_unlock_irq(&tsk->sighand->siglock);
  241. return ret;
  242. }
  243. static inline void kernel_signal_stop(void)
  244. {
  245. spin_lock_irq(&current->sighand->siglock);
  246. if (current->jobctl & JOBCTL_STOP_DEQUEUED)
  247. set_special_state(TASK_STOPPED);
  248. spin_unlock_irq(&current->sighand->siglock);
  249. schedule();
  250. }
  251. #ifdef __ARCH_SI_TRAPNO
  252. # define ___ARCH_SI_TRAPNO(_a1) , _a1
  253. #else
  254. # define ___ARCH_SI_TRAPNO(_a1)
  255. #endif
  256. #ifdef __ia64__
  257. # define ___ARCH_SI_IA64(_a1, _a2, _a3) , _a1, _a2, _a3
  258. #else
  259. # define ___ARCH_SI_IA64(_a1, _a2, _a3)
  260. #endif
  261. int force_sig_fault(int sig, int code, void __user *addr
  262. ___ARCH_SI_TRAPNO(int trapno)
  263. ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
  264. , struct task_struct *t);
  265. int send_sig_fault(int sig, int code, void __user *addr
  266. ___ARCH_SI_TRAPNO(int trapno)
  267. ___ARCH_SI_IA64(int imm, unsigned int flags, unsigned long isr)
  268. , struct task_struct *t);
  269. int force_sig_mceerr(int code, void __user *, short, struct task_struct *);
  270. int send_sig_mceerr(int code, void __user *, short, struct task_struct *);
  271. int force_sig_bnderr(void __user *addr, void __user *lower, void __user *upper);
  272. int force_sig_pkuerr(void __user *addr, u32 pkey);
  273. int force_sig_ptrace_errno_trap(int errno, void __user *addr);
  274. extern int send_sig_info(int, struct siginfo *, struct task_struct *);
  275. extern int force_sigsegv(int, struct task_struct *);
  276. extern int force_sig_info(int, struct siginfo *, struct task_struct *);
  277. extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
  278. extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
  279. extern int kill_pid_info_as_cred(int, struct siginfo *, struct pid *,
  280. const struct cred *);
  281. extern int kill_pgrp(struct pid *pid, int sig, int priv);
  282. extern int kill_pid(struct pid *pid, int sig, int priv);
  283. extern __must_check bool do_notify_parent(struct task_struct *, int);
  284. extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent);
  285. extern void force_sig(int, struct task_struct *);
  286. extern int send_sig(int, struct task_struct *, int);
  287. extern int zap_other_threads(struct task_struct *p);
  288. extern struct sigqueue *sigqueue_alloc(void);
  289. extern void sigqueue_free(struct sigqueue *);
  290. extern int send_sigqueue(struct sigqueue *, struct pid *, enum pid_type);
  291. extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
  292. static inline int restart_syscall(void)
  293. {
  294. set_tsk_thread_flag(current, TIF_SIGPENDING);
  295. return -ERESTARTNOINTR;
  296. }
  297. static inline int signal_pending(struct task_struct *p)
  298. {
  299. return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
  300. }
  301. static inline int __fatal_signal_pending(struct task_struct *p)
  302. {
  303. return unlikely(sigismember(&p->pending.signal, SIGKILL));
  304. }
  305. static inline int fatal_signal_pending(struct task_struct *p)
  306. {
  307. return signal_pending(p) && __fatal_signal_pending(p);
  308. }
  309. static inline int signal_pending_state(long state, struct task_struct *p)
  310. {
  311. if (!(state & (TASK_INTERRUPTIBLE | TASK_WAKEKILL)))
  312. return 0;
  313. if (!signal_pending(p))
  314. return 0;
  315. return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
  316. }
  317. /*
  318. * Reevaluate whether the task has signals pending delivery.
  319. * Wake the task if so.
  320. * This is required every time the blocked sigset_t changes.
  321. * callers must hold sighand->siglock.
  322. */
  323. extern void recalc_sigpending_and_wake(struct task_struct *t);
  324. extern void recalc_sigpending(void);
  325. extern void calculate_sigpending(void);
  326. extern void signal_wake_up_state(struct task_struct *t, unsigned int state);
  327. static inline void signal_wake_up(struct task_struct *t, bool resume)
  328. {
  329. signal_wake_up_state(t, resume ? TASK_WAKEKILL : 0);
  330. }
  331. static inline void ptrace_signal_wake_up(struct task_struct *t, bool resume)
  332. {
  333. signal_wake_up_state(t, resume ? __TASK_TRACED : 0);
  334. }
  335. void task_join_group_stop(struct task_struct *task);
  336. #ifdef TIF_RESTORE_SIGMASK
  337. /*
  338. * Legacy restore_sigmask accessors. These are inefficient on
  339. * SMP architectures because they require atomic operations.
  340. */
  341. /**
  342. * set_restore_sigmask() - make sure saved_sigmask processing gets done
  343. *
  344. * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code
  345. * will run before returning to user mode, to process the flag. For
  346. * all callers, TIF_SIGPENDING is already set or it's no harm to set
  347. * it. TIF_RESTORE_SIGMASK need not be in the set of bits that the
  348. * arch code will notice on return to user mode, in case those bits
  349. * are scarce. We set TIF_SIGPENDING here to ensure that the arch
  350. * signal code always gets run when TIF_RESTORE_SIGMASK is set.
  351. */
  352. static inline void set_restore_sigmask(void)
  353. {
  354. set_thread_flag(TIF_RESTORE_SIGMASK);
  355. WARN_ON(!test_thread_flag(TIF_SIGPENDING));
  356. }
  357. static inline void clear_restore_sigmask(void)
  358. {
  359. clear_thread_flag(TIF_RESTORE_SIGMASK);
  360. }
  361. static inline bool test_restore_sigmask(void)
  362. {
  363. return test_thread_flag(TIF_RESTORE_SIGMASK);
  364. }
  365. static inline bool test_and_clear_restore_sigmask(void)
  366. {
  367. return test_and_clear_thread_flag(TIF_RESTORE_SIGMASK);
  368. }
  369. #else /* TIF_RESTORE_SIGMASK */
  370. /* Higher-quality implementation, used if TIF_RESTORE_SIGMASK doesn't exist. */
  371. static inline void set_restore_sigmask(void)
  372. {
  373. current->restore_sigmask = true;
  374. WARN_ON(!test_thread_flag(TIF_SIGPENDING));
  375. }
  376. static inline void clear_restore_sigmask(void)
  377. {
  378. current->restore_sigmask = false;
  379. }
  380. static inline bool test_restore_sigmask(void)
  381. {
  382. return current->restore_sigmask;
  383. }
  384. static inline bool test_and_clear_restore_sigmask(void)
  385. {
  386. if (!current->restore_sigmask)
  387. return false;
  388. current->restore_sigmask = false;
  389. return true;
  390. }
  391. #endif
  392. static inline void restore_saved_sigmask(void)
  393. {
  394. if (test_and_clear_restore_sigmask())
  395. __set_current_blocked(&current->saved_sigmask);
  396. }
  397. static inline sigset_t *sigmask_to_save(void)
  398. {
  399. sigset_t *res = &current->blocked;
  400. if (unlikely(test_restore_sigmask()))
  401. res = &current->saved_sigmask;
  402. return res;
  403. }
  404. static inline int kill_cad_pid(int sig, int priv)
  405. {
  406. return kill_pid(cad_pid, sig, priv);
  407. }
  408. /* These can be the second arg to send_sig_info/send_group_sig_info. */
  409. #define SEND_SIG_NOINFO ((struct siginfo *) 0)
  410. #define SEND_SIG_PRIV ((struct siginfo *) 1)
  411. #define SEND_SIG_FORCED ((struct siginfo *) 2)
  412. /*
  413. * True if we are on the alternate signal stack.
  414. */
  415. static inline int on_sig_stack(unsigned long sp)
  416. {
  417. /*
  418. * If the signal stack is SS_AUTODISARM then, by construction, we
  419. * can't be on the signal stack unless user code deliberately set
  420. * SS_AUTODISARM when we were already on it.
  421. *
  422. * This improves reliability: if user state gets corrupted such that
  423. * the stack pointer points very close to the end of the signal stack,
  424. * then this check will enable the signal to be handled anyway.
  425. */
  426. if (current->sas_ss_flags & SS_AUTODISARM)
  427. return 0;
  428. #ifdef CONFIG_STACK_GROWSUP
  429. return sp >= current->sas_ss_sp &&
  430. sp - current->sas_ss_sp < current->sas_ss_size;
  431. #else
  432. return sp > current->sas_ss_sp &&
  433. sp - current->sas_ss_sp <= current->sas_ss_size;
  434. #endif
  435. }
  436. static inline int sas_ss_flags(unsigned long sp)
  437. {
  438. if (!current->sas_ss_size)
  439. return SS_DISABLE;
  440. return on_sig_stack(sp) ? SS_ONSTACK : 0;
  441. }
  442. static inline void sas_ss_reset(struct task_struct *p)
  443. {
  444. p->sas_ss_sp = 0;
  445. p->sas_ss_size = 0;
  446. p->sas_ss_flags = SS_DISABLE;
  447. }
  448. static inline unsigned long sigsp(unsigned long sp, struct ksignal *ksig)
  449. {
  450. if (unlikely((ksig->ka.sa.sa_flags & SA_ONSTACK)) && ! sas_ss_flags(sp))
  451. #ifdef CONFIG_STACK_GROWSUP
  452. return current->sas_ss_sp;
  453. #else
  454. return current->sas_ss_sp + current->sas_ss_size;
  455. #endif
  456. return sp;
  457. }
  458. extern void __cleanup_sighand(struct sighand_struct *);
  459. extern void flush_itimer_signals(void);
  460. #define tasklist_empty() \
  461. list_empty(&init_task.tasks)
  462. #define next_task(p) \
  463. list_entry_rcu((p)->tasks.next, struct task_struct, tasks)
  464. #define for_each_process(p) \
  465. for (p = &init_task ; (p = next_task(p)) != &init_task ; )
  466. extern bool current_is_single_threaded(void);
  467. /*
  468. * Careful: do_each_thread/while_each_thread is a double loop so
  469. * 'break' will not work as expected - use goto instead.
  470. */
  471. #define do_each_thread(g, t) \
  472. for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
  473. #define while_each_thread(g, t) \
  474. while ((t = next_thread(t)) != g)
  475. #define __for_each_thread(signal, t) \
  476. list_for_each_entry_rcu(t, &(signal)->thread_head, thread_node)
  477. #define for_each_thread(p, t) \
  478. __for_each_thread((p)->signal, t)
  479. /* Careful: this is a double loop, 'break' won't work as expected. */
  480. #define for_each_process_thread(p, t) \
  481. for_each_process(p) for_each_thread(p, t)
  482. typedef int (*proc_visitor)(struct task_struct *p, void *data);
  483. void walk_process_tree(struct task_struct *top, proc_visitor, void *);
  484. static inline
  485. struct pid *task_pid_type(struct task_struct *task, enum pid_type type)
  486. {
  487. struct pid *pid;
  488. if (type == PIDTYPE_PID)
  489. pid = task_pid(task);
  490. else
  491. pid = task->signal->pids[type];
  492. return pid;
  493. }
  494. static inline struct pid *task_tgid(struct task_struct *task)
  495. {
  496. return task->signal->pids[PIDTYPE_TGID];
  497. }
  498. /*
  499. * Without tasklist or RCU lock it is not safe to dereference
  500. * the result of task_pgrp/task_session even if task == current,
  501. * we can race with another thread doing sys_setsid/sys_setpgid.
  502. */
  503. static inline struct pid *task_pgrp(struct task_struct *task)
  504. {
  505. return task->signal->pids[PIDTYPE_PGID];
  506. }
  507. static inline struct pid *task_session(struct task_struct *task)
  508. {
  509. return task->signal->pids[PIDTYPE_SID];
  510. }
  511. static inline int get_nr_threads(struct task_struct *tsk)
  512. {
  513. return tsk->signal->nr_threads;
  514. }
  515. static inline bool thread_group_leader(struct task_struct *p)
  516. {
  517. return p->exit_signal >= 0;
  518. }
  519. /* Do to the insanities of de_thread it is possible for a process
  520. * to have the pid of the thread group leader without actually being
  521. * the thread group leader. For iteration through the pids in proc
  522. * all we care about is that we have a task with the appropriate
  523. * pid, we don't actually care if we have the right task.
  524. */
  525. static inline bool has_group_leader_pid(struct task_struct *p)
  526. {
  527. return task_pid(p) == task_tgid(p);
  528. }
  529. static inline
  530. bool same_thread_group(struct task_struct *p1, struct task_struct *p2)
  531. {
  532. return p1->signal == p2->signal;
  533. }
  534. static inline struct task_struct *next_thread(const struct task_struct *p)
  535. {
  536. return list_entry_rcu(p->thread_group.next,
  537. struct task_struct, thread_group);
  538. }
  539. static inline int thread_group_empty(struct task_struct *p)
  540. {
  541. return list_empty(&p->thread_group);
  542. }
  543. #define delay_group_leader(p) \
  544. (thread_group_leader(p) && !thread_group_empty(p))
  545. extern struct sighand_struct *__lock_task_sighand(struct task_struct *tsk,
  546. unsigned long *flags);
  547. static inline struct sighand_struct *lock_task_sighand(struct task_struct *tsk,
  548. unsigned long *flags)
  549. {
  550. struct sighand_struct *ret;
  551. ret = __lock_task_sighand(tsk, flags);
  552. (void)__cond_lock(&tsk->sighand->siglock, ret);
  553. return ret;
  554. }
  555. static inline void unlock_task_sighand(struct task_struct *tsk,
  556. unsigned long *flags)
  557. {
  558. spin_unlock_irqrestore(&tsk->sighand->siglock, *flags);
  559. }
  560. static inline unsigned long task_rlimit(const struct task_struct *tsk,
  561. unsigned int limit)
  562. {
  563. return READ_ONCE(tsk->signal->rlim[limit].rlim_cur);
  564. }
  565. static inline unsigned long task_rlimit_max(const struct task_struct *tsk,
  566. unsigned int limit)
  567. {
  568. return READ_ONCE(tsk->signal->rlim[limit].rlim_max);
  569. }
  570. static inline unsigned long rlimit(unsigned int limit)
  571. {
  572. return task_rlimit(current, limit);
  573. }
  574. static inline unsigned long rlimit_max(unsigned int limit)
  575. {
  576. return task_rlimit_max(current, limit);
  577. }
  578. #endif /* _LINUX_SCHED_SIGNAL_H */