signal.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612
  1. /*
  2. * linux/kernel/signal.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. *
  6. * 1997-11-02 Modified for POSIX.1b signals by Richard Henderson
  7. *
  8. * 2003-06-02 Jim Houston - Concurrent Computer Corp.
  9. * Changes to use preallocated sigqueue structures
  10. * to allow signals to be sent reliably.
  11. */
  12. #include <linux/config.h>
  13. #include <linux/slab.h>
  14. #include <linux/module.h>
  15. #include <linux/smp_lock.h>
  16. #include <linux/init.h>
  17. #include <linux/sched.h>
  18. #include <linux/fs.h>
  19. #include <linux/tty.h>
  20. #include <linux/binfmts.h>
  21. #include <linux/security.h>
  22. #include <linux/syscalls.h>
  23. #include <linux/ptrace.h>
  24. #include <linux/signal.h>
  25. #include <linux/audit.h>
  26. #include <linux/capability.h>
  27. #include <asm/param.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/unistd.h>
  30. #include <asm/siginfo.h>
  31. /*
  32. * SLAB caches for signal bits.
  33. */
  34. static kmem_cache_t *sigqueue_cachep;
  35. /*
  36. * In POSIX a signal is sent either to a specific thread (Linux task)
  37. * or to the process as a whole (Linux thread group). How the signal
  38. * is sent determines whether it's to one thread or the whole group,
  39. * which determines which signal mask(s) are involved in blocking it
  40. * from being delivered until later. When the signal is delivered,
  41. * either it's caught or ignored by a user handler or it has a default
  42. * effect that applies to the whole thread group (POSIX process).
  43. *
  44. * The possible effects an unblocked signal set to SIG_DFL can have are:
  45. * ignore - Nothing Happens
  46. * terminate - kill the process, i.e. all threads in the group,
  47. * similar to exit_group. The group leader (only) reports
  48. * WIFSIGNALED status to its parent.
  49. * coredump - write a core dump file describing all threads using
  50. * the same mm and then kill all those threads
  51. * stop - stop all the threads in the group, i.e. TASK_STOPPED state
  52. *
  53. * SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
  54. * Other signals when not blocked and set to SIG_DFL behaves as follows.
  55. * The job control signals also have other special effects.
  56. *
  57. * +--------------------+------------------+
  58. * | POSIX signal | default action |
  59. * +--------------------+------------------+
  60. * | SIGHUP | terminate |
  61. * | SIGINT | terminate |
  62. * | SIGQUIT | coredump |
  63. * | SIGILL | coredump |
  64. * | SIGTRAP | coredump |
  65. * | SIGABRT/SIGIOT | coredump |
  66. * | SIGBUS | coredump |
  67. * | SIGFPE | coredump |
  68. * | SIGKILL | terminate(+) |
  69. * | SIGUSR1 | terminate |
  70. * | SIGSEGV | coredump |
  71. * | SIGUSR2 | terminate |
  72. * | SIGPIPE | terminate |
  73. * | SIGALRM | terminate |
  74. * | SIGTERM | terminate |
  75. * | SIGCHLD | ignore |
  76. * | SIGCONT | ignore(*) |
  77. * | SIGSTOP | stop(*)(+) |
  78. * | SIGTSTP | stop(*) |
  79. * | SIGTTIN | stop(*) |
  80. * | SIGTTOU | stop(*) |
  81. * | SIGURG | ignore |
  82. * | SIGXCPU | coredump |
  83. * | SIGXFSZ | coredump |
  84. * | SIGVTALRM | terminate |
  85. * | SIGPROF | terminate |
  86. * | SIGPOLL/SIGIO | terminate |
  87. * | SIGSYS/SIGUNUSED | coredump |
  88. * | SIGSTKFLT | terminate |
  89. * | SIGWINCH | ignore |
  90. * | SIGPWR | terminate |
  91. * | SIGRTMIN-SIGRTMAX | terminate |
  92. * +--------------------+------------------+
  93. * | non-POSIX signal | default action |
  94. * +--------------------+------------------+
  95. * | SIGEMT | coredump |
  96. * +--------------------+------------------+
  97. *
  98. * (+) For SIGKILL and SIGSTOP the action is "always", not just "default".
  99. * (*) Special job control effects:
  100. * When SIGCONT is sent, it resumes the process (all threads in the group)
  101. * from TASK_STOPPED state and also clears any pending/queued stop signals
  102. * (any of those marked with "stop(*)"). This happens regardless of blocking,
  103. * catching, or ignoring SIGCONT. When any stop signal is sent, it clears
  104. * any pending/queued SIGCONT signals; this happens regardless of blocking,
  105. * catching, or ignored the stop signal, though (except for SIGSTOP) the
  106. * default action of stopping the process may happen later or never.
  107. */
  108. #ifdef SIGEMT
  109. #define M_SIGEMT M(SIGEMT)
  110. #else
  111. #define M_SIGEMT 0
  112. #endif
  113. #if SIGRTMIN > BITS_PER_LONG
  114. #define M(sig) (1ULL << ((sig)-1))
  115. #else
  116. #define M(sig) (1UL << ((sig)-1))
  117. #endif
  118. #define T(sig, mask) (M(sig) & (mask))
  119. #define SIG_KERNEL_ONLY_MASK (\
  120. M(SIGKILL) | M(SIGSTOP) )
  121. #define SIG_KERNEL_STOP_MASK (\
  122. M(SIGSTOP) | M(SIGTSTP) | M(SIGTTIN) | M(SIGTTOU) )
  123. #define SIG_KERNEL_COREDUMP_MASK (\
  124. M(SIGQUIT) | M(SIGILL) | M(SIGTRAP) | M(SIGABRT) | \
  125. M(SIGFPE) | M(SIGSEGV) | M(SIGBUS) | M(SIGSYS) | \
  126. M(SIGXCPU) | M(SIGXFSZ) | M_SIGEMT )
  127. #define SIG_KERNEL_IGNORE_MASK (\
  128. M(SIGCONT) | M(SIGCHLD) | M(SIGWINCH) | M(SIGURG) )
  129. #define sig_kernel_only(sig) \
  130. (((sig) < SIGRTMIN) && T(sig, SIG_KERNEL_ONLY_MASK))
  131. #define sig_kernel_coredump(sig) \
  132. (((sig) < SIGRTMIN) && T(sig, SIG_KERNEL_COREDUMP_MASK))
  133. #define sig_kernel_ignore(sig) \
  134. (((sig) < SIGRTMIN) && T(sig, SIG_KERNEL_IGNORE_MASK))
  135. #define sig_kernel_stop(sig) \
  136. (((sig) < SIGRTMIN) && T(sig, SIG_KERNEL_STOP_MASK))
  137. #define sig_needs_tasklist(sig) ((sig) == SIGCONT)
  138. #define sig_user_defined(t, signr) \
  139. (((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_DFL) && \
  140. ((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_IGN))
  141. #define sig_fatal(t, signr) \
  142. (!T(signr, SIG_KERNEL_IGNORE_MASK|SIG_KERNEL_STOP_MASK) && \
  143. (t)->sighand->action[(signr)-1].sa.sa_handler == SIG_DFL)
  144. static int sig_ignored(struct task_struct *t, int sig)
  145. {
  146. void __user * handler;
  147. /*
  148. * Tracers always want to know about signals..
  149. */
  150. if (t->ptrace & PT_PTRACED)
  151. return 0;
  152. /*
  153. * Blocked signals are never ignored, since the
  154. * signal handler may change by the time it is
  155. * unblocked.
  156. */
  157. if (sigismember(&t->blocked, sig))
  158. return 0;
  159. /* Is it explicitly or implicitly ignored? */
  160. handler = t->sighand->action[sig-1].sa.sa_handler;
  161. return handler == SIG_IGN ||
  162. (handler == SIG_DFL && sig_kernel_ignore(sig));
  163. }
  164. /*
  165. * Re-calculate pending state from the set of locally pending
  166. * signals, globally pending signals, and blocked signals.
  167. */
  168. static inline int has_pending_signals(sigset_t *signal, sigset_t *blocked)
  169. {
  170. unsigned long ready;
  171. long i;
  172. switch (_NSIG_WORDS) {
  173. default:
  174. for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
  175. ready |= signal->sig[i] &~ blocked->sig[i];
  176. break;
  177. case 4: ready = signal->sig[3] &~ blocked->sig[3];
  178. ready |= signal->sig[2] &~ blocked->sig[2];
  179. ready |= signal->sig[1] &~ blocked->sig[1];
  180. ready |= signal->sig[0] &~ blocked->sig[0];
  181. break;
  182. case 2: ready = signal->sig[1] &~ blocked->sig[1];
  183. ready |= signal->sig[0] &~ blocked->sig[0];
  184. break;
  185. case 1: ready = signal->sig[0] &~ blocked->sig[0];
  186. }
  187. return ready != 0;
  188. }
  189. #define PENDING(p,b) has_pending_signals(&(p)->signal, (b))
  190. fastcall void recalc_sigpending_tsk(struct task_struct *t)
  191. {
  192. if (t->signal->group_stop_count > 0 ||
  193. (freezing(t)) ||
  194. PENDING(&t->pending, &t->blocked) ||
  195. PENDING(&t->signal->shared_pending, &t->blocked))
  196. set_tsk_thread_flag(t, TIF_SIGPENDING);
  197. else
  198. clear_tsk_thread_flag(t, TIF_SIGPENDING);
  199. }
  200. void recalc_sigpending(void)
  201. {
  202. recalc_sigpending_tsk(current);
  203. }
  204. /* Given the mask, find the first available signal that should be serviced. */
  205. static int
  206. next_signal(struct sigpending *pending, sigset_t *mask)
  207. {
  208. unsigned long i, *s, *m, x;
  209. int sig = 0;
  210. s = pending->signal.sig;
  211. m = mask->sig;
  212. switch (_NSIG_WORDS) {
  213. default:
  214. for (i = 0; i < _NSIG_WORDS; ++i, ++s, ++m)
  215. if ((x = *s &~ *m) != 0) {
  216. sig = ffz(~x) + i*_NSIG_BPW + 1;
  217. break;
  218. }
  219. break;
  220. case 2: if ((x = s[0] &~ m[0]) != 0)
  221. sig = 1;
  222. else if ((x = s[1] &~ m[1]) != 0)
  223. sig = _NSIG_BPW + 1;
  224. else
  225. break;
  226. sig += ffz(~x);
  227. break;
  228. case 1: if ((x = *s &~ *m) != 0)
  229. sig = ffz(~x) + 1;
  230. break;
  231. }
  232. return sig;
  233. }
  234. static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags,
  235. int override_rlimit)
  236. {
  237. struct sigqueue *q = NULL;
  238. atomic_inc(&t->user->sigpending);
  239. if (override_rlimit ||
  240. atomic_read(&t->user->sigpending) <=
  241. t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
  242. q = kmem_cache_alloc(sigqueue_cachep, flags);
  243. if (unlikely(q == NULL)) {
  244. atomic_dec(&t->user->sigpending);
  245. } else {
  246. INIT_LIST_HEAD(&q->list);
  247. q->flags = 0;
  248. q->user = get_uid(t->user);
  249. }
  250. return(q);
  251. }
  252. static void __sigqueue_free(struct sigqueue *q)
  253. {
  254. if (q->flags & SIGQUEUE_PREALLOC)
  255. return;
  256. atomic_dec(&q->user->sigpending);
  257. free_uid(q->user);
  258. kmem_cache_free(sigqueue_cachep, q);
  259. }
  260. void flush_sigqueue(struct sigpending *queue)
  261. {
  262. struct sigqueue *q;
  263. sigemptyset(&queue->signal);
  264. while (!list_empty(&queue->list)) {
  265. q = list_entry(queue->list.next, struct sigqueue , list);
  266. list_del_init(&q->list);
  267. __sigqueue_free(q);
  268. }
  269. }
  270. /*
  271. * Flush all pending signals for a task.
  272. */
  273. void flush_signals(struct task_struct *t)
  274. {
  275. unsigned long flags;
  276. spin_lock_irqsave(&t->sighand->siglock, flags);
  277. clear_tsk_thread_flag(t,TIF_SIGPENDING);
  278. flush_sigqueue(&t->pending);
  279. flush_sigqueue(&t->signal->shared_pending);
  280. spin_unlock_irqrestore(&t->sighand->siglock, flags);
  281. }
  282. /*
  283. * Flush all handlers for a task.
  284. */
  285. void
  286. flush_signal_handlers(struct task_struct *t, int force_default)
  287. {
  288. int i;
  289. struct k_sigaction *ka = &t->sighand->action[0];
  290. for (i = _NSIG ; i != 0 ; i--) {
  291. if (force_default || ka->sa.sa_handler != SIG_IGN)
  292. ka->sa.sa_handler = SIG_DFL;
  293. ka->sa.sa_flags = 0;
  294. sigemptyset(&ka->sa.sa_mask);
  295. ka++;
  296. }
  297. }
  298. /* Notify the system that a driver wants to block all signals for this
  299. * process, and wants to be notified if any signals at all were to be
  300. * sent/acted upon. If the notifier routine returns non-zero, then the
  301. * signal will be acted upon after all. If the notifier routine returns 0,
  302. * then then signal will be blocked. Only one block per process is
  303. * allowed. priv is a pointer to private data that the notifier routine
  304. * can use to determine if the signal should be blocked or not. */
  305. void
  306. block_all_signals(int (*notifier)(void *priv), void *priv, sigset_t *mask)
  307. {
  308. unsigned long flags;
  309. spin_lock_irqsave(&current->sighand->siglock, flags);
  310. current->notifier_mask = mask;
  311. current->notifier_data = priv;
  312. current->notifier = notifier;
  313. spin_unlock_irqrestore(&current->sighand->siglock, flags);
  314. }
  315. /* Notify the system that blocking has ended. */
  316. void
  317. unblock_all_signals(void)
  318. {
  319. unsigned long flags;
  320. spin_lock_irqsave(&current->sighand->siglock, flags);
  321. current->notifier = NULL;
  322. current->notifier_data = NULL;
  323. recalc_sigpending();
  324. spin_unlock_irqrestore(&current->sighand->siglock, flags);
  325. }
  326. static int collect_signal(int sig, struct sigpending *list, siginfo_t *info)
  327. {
  328. struct sigqueue *q, *first = NULL;
  329. int still_pending = 0;
  330. if (unlikely(!sigismember(&list->signal, sig)))
  331. return 0;
  332. /*
  333. * Collect the siginfo appropriate to this signal. Check if
  334. * there is another siginfo for the same signal.
  335. */
  336. list_for_each_entry(q, &list->list, list) {
  337. if (q->info.si_signo == sig) {
  338. if (first) {
  339. still_pending = 1;
  340. break;
  341. }
  342. first = q;
  343. }
  344. }
  345. if (first) {
  346. list_del_init(&first->list);
  347. copy_siginfo(info, &first->info);
  348. __sigqueue_free(first);
  349. if (!still_pending)
  350. sigdelset(&list->signal, sig);
  351. } else {
  352. /* Ok, it wasn't in the queue. This must be
  353. a fast-pathed signal or we must have been
  354. out of queue space. So zero out the info.
  355. */
  356. sigdelset(&list->signal, sig);
  357. info->si_signo = sig;
  358. info->si_errno = 0;
  359. info->si_code = 0;
  360. info->si_pid = 0;
  361. info->si_uid = 0;
  362. }
  363. return 1;
  364. }
  365. static int __dequeue_signal(struct sigpending *pending, sigset_t *mask,
  366. siginfo_t *info)
  367. {
  368. int sig = 0;
  369. sig = next_signal(pending, mask);
  370. if (sig) {
  371. if (current->notifier) {
  372. if (sigismember(current->notifier_mask, sig)) {
  373. if (!(current->notifier)(current->notifier_data)) {
  374. clear_thread_flag(TIF_SIGPENDING);
  375. return 0;
  376. }
  377. }
  378. }
  379. if (!collect_signal(sig, pending, info))
  380. sig = 0;
  381. }
  382. recalc_sigpending();
  383. return sig;
  384. }
  385. /*
  386. * Dequeue a signal and return the element to the caller, which is
  387. * expected to free it.
  388. *
  389. * All callers have to hold the siglock.
  390. */
  391. int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
  392. {
  393. int signr = __dequeue_signal(&tsk->pending, mask, info);
  394. if (!signr)
  395. signr = __dequeue_signal(&tsk->signal->shared_pending,
  396. mask, info);
  397. if (signr && unlikely(sig_kernel_stop(signr))) {
  398. /*
  399. * Set a marker that we have dequeued a stop signal. Our
  400. * caller might release the siglock and then the pending
  401. * stop signal it is about to process is no longer in the
  402. * pending bitmasks, but must still be cleared by a SIGCONT
  403. * (and overruled by a SIGKILL). So those cases clear this
  404. * shared flag after we've set it. Note that this flag may
  405. * remain set after the signal we return is ignored or
  406. * handled. That doesn't matter because its only purpose
  407. * is to alert stop-signal processing code when another
  408. * processor has come along and cleared the flag.
  409. */
  410. if (!(tsk->signal->flags & SIGNAL_GROUP_EXIT))
  411. tsk->signal->flags |= SIGNAL_STOP_DEQUEUED;
  412. }
  413. if ( signr &&
  414. ((info->si_code & __SI_MASK) == __SI_TIMER) &&
  415. info->si_sys_private){
  416. /*
  417. * Release the siglock to ensure proper locking order
  418. * of timer locks outside of siglocks. Note, we leave
  419. * irqs disabled here, since the posix-timers code is
  420. * about to disable them again anyway.
  421. */
  422. spin_unlock(&tsk->sighand->siglock);
  423. do_schedule_next_timer(info);
  424. spin_lock(&tsk->sighand->siglock);
  425. }
  426. return signr;
  427. }
  428. /*
  429. * Tell a process that it has a new active signal..
  430. *
  431. * NOTE! we rely on the previous spin_lock to
  432. * lock interrupts for us! We can only be called with
  433. * "siglock" held, and the local interrupt must
  434. * have been disabled when that got acquired!
  435. *
  436. * No need to set need_resched since signal event passing
  437. * goes through ->blocked
  438. */
  439. void signal_wake_up(struct task_struct *t, int resume)
  440. {
  441. unsigned int mask;
  442. set_tsk_thread_flag(t, TIF_SIGPENDING);
  443. /*
  444. * For SIGKILL, we want to wake it up in the stopped/traced case.
  445. * We don't check t->state here because there is a race with it
  446. * executing another processor and just now entering stopped state.
  447. * By using wake_up_state, we ensure the process will wake up and
  448. * handle its death signal.
  449. */
  450. mask = TASK_INTERRUPTIBLE;
  451. if (resume)
  452. mask |= TASK_STOPPED | TASK_TRACED;
  453. if (!wake_up_state(t, mask))
  454. kick_process(t);
  455. }
  456. /*
  457. * Remove signals in mask from the pending set and queue.
  458. * Returns 1 if any signals were found.
  459. *
  460. * All callers must be holding the siglock.
  461. *
  462. * This version takes a sigset mask and looks at all signals,
  463. * not just those in the first mask word.
  464. */
  465. static int rm_from_queue_full(sigset_t *mask, struct sigpending *s)
  466. {
  467. struct sigqueue *q, *n;
  468. sigset_t m;
  469. sigandsets(&m, mask, &s->signal);
  470. if (sigisemptyset(&m))
  471. return 0;
  472. signandsets(&s->signal, &s->signal, mask);
  473. list_for_each_entry_safe(q, n, &s->list, list) {
  474. if (sigismember(mask, q->info.si_signo)) {
  475. list_del_init(&q->list);
  476. __sigqueue_free(q);
  477. }
  478. }
  479. return 1;
  480. }
  481. /*
  482. * Remove signals in mask from the pending set and queue.
  483. * Returns 1 if any signals were found.
  484. *
  485. * All callers must be holding the siglock.
  486. */
  487. static int rm_from_queue(unsigned long mask, struct sigpending *s)
  488. {
  489. struct sigqueue *q, *n;
  490. if (!sigtestsetmask(&s->signal, mask))
  491. return 0;
  492. sigdelsetmask(&s->signal, mask);
  493. list_for_each_entry_safe(q, n, &s->list, list) {
  494. if (q->info.si_signo < SIGRTMIN &&
  495. (mask & sigmask(q->info.si_signo))) {
  496. list_del_init(&q->list);
  497. __sigqueue_free(q);
  498. }
  499. }
  500. return 1;
  501. }
  502. /*
  503. * Bad permissions for sending the signal
  504. */
  505. static int check_kill_permission(int sig, struct siginfo *info,
  506. struct task_struct *t)
  507. {
  508. int error = -EINVAL;
  509. if (!valid_signal(sig))
  510. return error;
  511. error = -EPERM;
  512. if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info)))
  513. && ((sig != SIGCONT) ||
  514. (current->signal->session != t->signal->session))
  515. && (current->euid ^ t->suid) && (current->euid ^ t->uid)
  516. && (current->uid ^ t->suid) && (current->uid ^ t->uid)
  517. && !capable(CAP_KILL))
  518. return error;
  519. error = security_task_kill(t, info, sig);
  520. if (!error)
  521. audit_signal_info(sig, t); /* Let audit system see the signal */
  522. return error;
  523. }
  524. /* forward decl */
  525. static void do_notify_parent_cldstop(struct task_struct *tsk,
  526. int to_self,
  527. int why);
  528. /*
  529. * Handle magic process-wide effects of stop/continue signals.
  530. * Unlike the signal actions, these happen immediately at signal-generation
  531. * time regardless of blocking, ignoring, or handling. This does the
  532. * actual continuing for SIGCONT, but not the actual stopping for stop
  533. * signals. The process stop is done as a signal action for SIG_DFL.
  534. */
  535. static void handle_stop_signal(int sig, struct task_struct *p)
  536. {
  537. struct task_struct *t;
  538. if (p->signal->flags & SIGNAL_GROUP_EXIT)
  539. /*
  540. * The process is in the middle of dying already.
  541. */
  542. return;
  543. if (sig_kernel_stop(sig)) {
  544. /*
  545. * This is a stop signal. Remove SIGCONT from all queues.
  546. */
  547. rm_from_queue(sigmask(SIGCONT), &p->signal->shared_pending);
  548. t = p;
  549. do {
  550. rm_from_queue(sigmask(SIGCONT), &t->pending);
  551. t = next_thread(t);
  552. } while (t != p);
  553. } else if (sig == SIGCONT) {
  554. /*
  555. * Remove all stop signals from all queues,
  556. * and wake all threads.
  557. */
  558. if (unlikely(p->signal->group_stop_count > 0)) {
  559. /*
  560. * There was a group stop in progress. We'll
  561. * pretend it finished before we got here. We are
  562. * obliged to report it to the parent: if the
  563. * SIGSTOP happened "after" this SIGCONT, then it
  564. * would have cleared this pending SIGCONT. If it
  565. * happened "before" this SIGCONT, then the parent
  566. * got the SIGCHLD about the stop finishing before
  567. * the continue happened. We do the notification
  568. * now, and it's as if the stop had finished and
  569. * the SIGCHLD was pending on entry to this kill.
  570. */
  571. p->signal->group_stop_count = 0;
  572. p->signal->flags = SIGNAL_STOP_CONTINUED;
  573. spin_unlock(&p->sighand->siglock);
  574. do_notify_parent_cldstop(p, (p->ptrace & PT_PTRACED), CLD_STOPPED);
  575. spin_lock(&p->sighand->siglock);
  576. }
  577. rm_from_queue(SIG_KERNEL_STOP_MASK, &p->signal->shared_pending);
  578. t = p;
  579. do {
  580. unsigned int state;
  581. rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending);
  582. /*
  583. * If there is a handler for SIGCONT, we must make
  584. * sure that no thread returns to user mode before
  585. * we post the signal, in case it was the only
  586. * thread eligible to run the signal handler--then
  587. * it must not do anything between resuming and
  588. * running the handler. With the TIF_SIGPENDING
  589. * flag set, the thread will pause and acquire the
  590. * siglock that we hold now and until we've queued
  591. * the pending signal.
  592. *
  593. * Wake up the stopped thread _after_ setting
  594. * TIF_SIGPENDING
  595. */
  596. state = TASK_STOPPED;
  597. if (sig_user_defined(t, SIGCONT) && !sigismember(&t->blocked, SIGCONT)) {
  598. set_tsk_thread_flag(t, TIF_SIGPENDING);
  599. state |= TASK_INTERRUPTIBLE;
  600. }
  601. wake_up_state(t, state);
  602. t = next_thread(t);
  603. } while (t != p);
  604. if (p->signal->flags & SIGNAL_STOP_STOPPED) {
  605. /*
  606. * We were in fact stopped, and are now continued.
  607. * Notify the parent with CLD_CONTINUED.
  608. */
  609. p->signal->flags = SIGNAL_STOP_CONTINUED;
  610. p->signal->group_exit_code = 0;
  611. spin_unlock(&p->sighand->siglock);
  612. do_notify_parent_cldstop(p, (p->ptrace & PT_PTRACED), CLD_CONTINUED);
  613. spin_lock(&p->sighand->siglock);
  614. } else {
  615. /*
  616. * We are not stopped, but there could be a stop
  617. * signal in the middle of being processed after
  618. * being removed from the queue. Clear that too.
  619. */
  620. p->signal->flags = 0;
  621. }
  622. } else if (sig == SIGKILL) {
  623. /*
  624. * Make sure that any pending stop signal already dequeued
  625. * is undone by the wakeup for SIGKILL.
  626. */
  627. p->signal->flags = 0;
  628. }
  629. }
  630. static int send_signal(int sig, struct siginfo *info, struct task_struct *t,
  631. struct sigpending *signals)
  632. {
  633. struct sigqueue * q = NULL;
  634. int ret = 0;
  635. /*
  636. * fast-pathed signals for kernel-internal things like SIGSTOP
  637. * or SIGKILL.
  638. */
  639. if (info == SEND_SIG_FORCED)
  640. goto out_set;
  641. /* Real-time signals must be queued if sent by sigqueue, or
  642. some other real-time mechanism. It is implementation
  643. defined whether kill() does so. We attempt to do so, on
  644. the principle of least surprise, but since kill is not
  645. allowed to fail with EAGAIN when low on memory we just
  646. make sure at least one signal gets delivered and don't
  647. pass on the info struct. */
  648. q = __sigqueue_alloc(t, GFP_ATOMIC, (sig < SIGRTMIN &&
  649. (is_si_special(info) ||
  650. info->si_code >= 0)));
  651. if (q) {
  652. list_add_tail(&q->list, &signals->list);
  653. switch ((unsigned long) info) {
  654. case (unsigned long) SEND_SIG_NOINFO:
  655. q->info.si_signo = sig;
  656. q->info.si_errno = 0;
  657. q->info.si_code = SI_USER;
  658. q->info.si_pid = current->pid;
  659. q->info.si_uid = current->uid;
  660. break;
  661. case (unsigned long) SEND_SIG_PRIV:
  662. q->info.si_signo = sig;
  663. q->info.si_errno = 0;
  664. q->info.si_code = SI_KERNEL;
  665. q->info.si_pid = 0;
  666. q->info.si_uid = 0;
  667. break;
  668. default:
  669. copy_siginfo(&q->info, info);
  670. break;
  671. }
  672. } else if (!is_si_special(info)) {
  673. if (sig >= SIGRTMIN && info->si_code != SI_USER)
  674. /*
  675. * Queue overflow, abort. We may abort if the signal was rt
  676. * and sent by user using something other than kill().
  677. */
  678. return -EAGAIN;
  679. }
  680. out_set:
  681. sigaddset(&signals->signal, sig);
  682. return ret;
  683. }
  684. #define LEGACY_QUEUE(sigptr, sig) \
  685. (((sig) < SIGRTMIN) && sigismember(&(sigptr)->signal, (sig)))
  686. static int
  687. specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  688. {
  689. int ret = 0;
  690. if (!irqs_disabled())
  691. BUG();
  692. assert_spin_locked(&t->sighand->siglock);
  693. /* Short-circuit ignored signals. */
  694. if (sig_ignored(t, sig))
  695. goto out;
  696. /* Support queueing exactly one non-rt signal, so that we
  697. can get more detailed information about the cause of
  698. the signal. */
  699. if (LEGACY_QUEUE(&t->pending, sig))
  700. goto out;
  701. ret = send_signal(sig, info, t, &t->pending);
  702. if (!ret && !sigismember(&t->blocked, sig))
  703. signal_wake_up(t, sig == SIGKILL);
  704. out:
  705. return ret;
  706. }
  707. /*
  708. * Force a signal that the process can't ignore: if necessary
  709. * we unblock the signal and change any SIG_IGN to SIG_DFL.
  710. */
  711. int
  712. force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  713. {
  714. unsigned long int flags;
  715. int ret;
  716. spin_lock_irqsave(&t->sighand->siglock, flags);
  717. if (t->sighand->action[sig-1].sa.sa_handler == SIG_IGN) {
  718. t->sighand->action[sig-1].sa.sa_handler = SIG_DFL;
  719. }
  720. if (sigismember(&t->blocked, sig)) {
  721. sigdelset(&t->blocked, sig);
  722. }
  723. recalc_sigpending_tsk(t);
  724. ret = specific_send_sig_info(sig, info, t);
  725. spin_unlock_irqrestore(&t->sighand->siglock, flags);
  726. return ret;
  727. }
  728. void
  729. force_sig_specific(int sig, struct task_struct *t)
  730. {
  731. force_sig_info(sig, SEND_SIG_FORCED, t);
  732. }
  733. /*
  734. * Test if P wants to take SIG. After we've checked all threads with this,
  735. * it's equivalent to finding no threads not blocking SIG. Any threads not
  736. * blocking SIG were ruled out because they are not running and already
  737. * have pending signals. Such threads will dequeue from the shared queue
  738. * as soon as they're available, so putting the signal on the shared queue
  739. * will be equivalent to sending it to one such thread.
  740. */
  741. static inline int wants_signal(int sig, struct task_struct *p)
  742. {
  743. if (sigismember(&p->blocked, sig))
  744. return 0;
  745. if (p->flags & PF_EXITING)
  746. return 0;
  747. if (sig == SIGKILL)
  748. return 1;
  749. if (p->state & (TASK_STOPPED | TASK_TRACED))
  750. return 0;
  751. return task_curr(p) || !signal_pending(p);
  752. }
  753. static void
  754. __group_complete_signal(int sig, struct task_struct *p)
  755. {
  756. struct task_struct *t;
  757. /*
  758. * Now find a thread we can wake up to take the signal off the queue.
  759. *
  760. * If the main thread wants the signal, it gets first crack.
  761. * Probably the least surprising to the average bear.
  762. */
  763. if (wants_signal(sig, p))
  764. t = p;
  765. else if (thread_group_empty(p))
  766. /*
  767. * There is just one thread and it does not need to be woken.
  768. * It will dequeue unblocked signals before it runs again.
  769. */
  770. return;
  771. else {
  772. /*
  773. * Otherwise try to find a suitable thread.
  774. */
  775. t = p->signal->curr_target;
  776. if (t == NULL)
  777. /* restart balancing at this thread */
  778. t = p->signal->curr_target = p;
  779. BUG_ON(t->tgid != p->tgid);
  780. while (!wants_signal(sig, t)) {
  781. t = next_thread(t);
  782. if (t == p->signal->curr_target)
  783. /*
  784. * No thread needs to be woken.
  785. * Any eligible threads will see
  786. * the signal in the queue soon.
  787. */
  788. return;
  789. }
  790. p->signal->curr_target = t;
  791. }
  792. /*
  793. * Found a killable thread. If the signal will be fatal,
  794. * then start taking the whole group down immediately.
  795. */
  796. if (sig_fatal(p, sig) && !(p->signal->flags & SIGNAL_GROUP_EXIT) &&
  797. !sigismember(&t->real_blocked, sig) &&
  798. (sig == SIGKILL || !(t->ptrace & PT_PTRACED))) {
  799. /*
  800. * This signal will be fatal to the whole group.
  801. */
  802. if (!sig_kernel_coredump(sig)) {
  803. /*
  804. * Start a group exit and wake everybody up.
  805. * This way we don't have other threads
  806. * running and doing things after a slower
  807. * thread has the fatal signal pending.
  808. */
  809. p->signal->flags = SIGNAL_GROUP_EXIT;
  810. p->signal->group_exit_code = sig;
  811. p->signal->group_stop_count = 0;
  812. t = p;
  813. do {
  814. sigaddset(&t->pending.signal, SIGKILL);
  815. signal_wake_up(t, 1);
  816. t = next_thread(t);
  817. } while (t != p);
  818. return;
  819. }
  820. /*
  821. * There will be a core dump. We make all threads other
  822. * than the chosen one go into a group stop so that nothing
  823. * happens until it gets scheduled, takes the signal off
  824. * the shared queue, and does the core dump. This is a
  825. * little more complicated than strictly necessary, but it
  826. * keeps the signal state that winds up in the core dump
  827. * unchanged from the death state, e.g. which thread had
  828. * the core-dump signal unblocked.
  829. */
  830. rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending);
  831. rm_from_queue(SIG_KERNEL_STOP_MASK, &p->signal->shared_pending);
  832. p->signal->group_stop_count = 0;
  833. p->signal->group_exit_task = t;
  834. t = p;
  835. do {
  836. p->signal->group_stop_count++;
  837. signal_wake_up(t, 0);
  838. t = next_thread(t);
  839. } while (t != p);
  840. wake_up_process(p->signal->group_exit_task);
  841. return;
  842. }
  843. /*
  844. * The signal is already in the shared-pending queue.
  845. * Tell the chosen thread to wake up and dequeue it.
  846. */
  847. signal_wake_up(t, sig == SIGKILL);
  848. return;
  849. }
  850. int
  851. __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
  852. {
  853. int ret = 0;
  854. assert_spin_locked(&p->sighand->siglock);
  855. handle_stop_signal(sig, p);
  856. /* Short-circuit ignored signals. */
  857. if (sig_ignored(p, sig))
  858. return ret;
  859. if (LEGACY_QUEUE(&p->signal->shared_pending, sig))
  860. /* This is a non-RT signal and we already have one queued. */
  861. return ret;
  862. /*
  863. * Put this signal on the shared-pending queue, or fail with EAGAIN.
  864. * We always use the shared queue for process-wide signals,
  865. * to avoid several races.
  866. */
  867. ret = send_signal(sig, info, p, &p->signal->shared_pending);
  868. if (unlikely(ret))
  869. return ret;
  870. __group_complete_signal(sig, p);
  871. return 0;
  872. }
  873. /*
  874. * Nuke all other threads in the group.
  875. */
  876. void zap_other_threads(struct task_struct *p)
  877. {
  878. struct task_struct *t;
  879. p->signal->flags = SIGNAL_GROUP_EXIT;
  880. p->signal->group_stop_count = 0;
  881. if (thread_group_empty(p))
  882. return;
  883. for (t = next_thread(p); t != p; t = next_thread(t)) {
  884. /*
  885. * Don't bother with already dead threads
  886. */
  887. if (t->exit_state)
  888. continue;
  889. /*
  890. * We don't want to notify the parent, since we are
  891. * killed as part of a thread group due to another
  892. * thread doing an execve() or similar. So set the
  893. * exit signal to -1 to allow immediate reaping of
  894. * the process. But don't detach the thread group
  895. * leader.
  896. */
  897. if (t != p->group_leader)
  898. t->exit_signal = -1;
  899. /* SIGKILL will be handled before any pending SIGSTOP */
  900. sigaddset(&t->pending.signal, SIGKILL);
  901. signal_wake_up(t, 1);
  902. }
  903. }
  904. /*
  905. * Must be called under rcu_read_lock() or with tasklist_lock read-held.
  906. */
  907. struct sighand_struct *lock_task_sighand(struct task_struct *tsk, unsigned long *flags)
  908. {
  909. struct sighand_struct *sighand;
  910. for (;;) {
  911. sighand = rcu_dereference(tsk->sighand);
  912. if (unlikely(sighand == NULL))
  913. break;
  914. spin_lock_irqsave(&sighand->siglock, *flags);
  915. if (likely(sighand == tsk->sighand))
  916. break;
  917. spin_unlock_irqrestore(&sighand->siglock, *flags);
  918. }
  919. return sighand;
  920. }
  921. int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
  922. {
  923. unsigned long flags;
  924. int ret;
  925. ret = check_kill_permission(sig, info, p);
  926. if (!ret && sig) {
  927. ret = -ESRCH;
  928. if (lock_task_sighand(p, &flags)) {
  929. ret = __group_send_sig_info(sig, info, p);
  930. unlock_task_sighand(p, &flags);
  931. }
  932. }
  933. return ret;
  934. }
  935. /*
  936. * kill_pg_info() sends a signal to a process group: this is what the tty
  937. * control characters do (^C, ^Z etc)
  938. */
  939. int __kill_pg_info(int sig, struct siginfo *info, pid_t pgrp)
  940. {
  941. struct task_struct *p = NULL;
  942. int retval, success;
  943. if (pgrp <= 0)
  944. return -EINVAL;
  945. success = 0;
  946. retval = -ESRCH;
  947. do_each_task_pid(pgrp, PIDTYPE_PGID, p) {
  948. int err = group_send_sig_info(sig, info, p);
  949. success |= !err;
  950. retval = err;
  951. } while_each_task_pid(pgrp, PIDTYPE_PGID, p);
  952. return success ? 0 : retval;
  953. }
  954. int
  955. kill_pg_info(int sig, struct siginfo *info, pid_t pgrp)
  956. {
  957. int retval;
  958. read_lock(&tasklist_lock);
  959. retval = __kill_pg_info(sig, info, pgrp);
  960. read_unlock(&tasklist_lock);
  961. return retval;
  962. }
  963. int
  964. kill_proc_info(int sig, struct siginfo *info, pid_t pid)
  965. {
  966. int error;
  967. int acquired_tasklist_lock = 0;
  968. struct task_struct *p;
  969. rcu_read_lock();
  970. if (unlikely(sig_needs_tasklist(sig))) {
  971. read_lock(&tasklist_lock);
  972. acquired_tasklist_lock = 1;
  973. }
  974. p = find_task_by_pid(pid);
  975. error = -ESRCH;
  976. if (p)
  977. error = group_send_sig_info(sig, info, p);
  978. if (unlikely(acquired_tasklist_lock))
  979. read_unlock(&tasklist_lock);
  980. rcu_read_unlock();
  981. return error;
  982. }
  983. /* like kill_proc_info(), but doesn't use uid/euid of "current" */
  984. int kill_proc_info_as_uid(int sig, struct siginfo *info, pid_t pid,
  985. uid_t uid, uid_t euid)
  986. {
  987. int ret = -EINVAL;
  988. struct task_struct *p;
  989. if (!valid_signal(sig))
  990. return ret;
  991. read_lock(&tasklist_lock);
  992. p = find_task_by_pid(pid);
  993. if (!p) {
  994. ret = -ESRCH;
  995. goto out_unlock;
  996. }
  997. if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info)))
  998. && (euid != p->suid) && (euid != p->uid)
  999. && (uid != p->suid) && (uid != p->uid)) {
  1000. ret = -EPERM;
  1001. goto out_unlock;
  1002. }
  1003. if (sig && p->sighand) {
  1004. unsigned long flags;
  1005. spin_lock_irqsave(&p->sighand->siglock, flags);
  1006. ret = __group_send_sig_info(sig, info, p);
  1007. spin_unlock_irqrestore(&p->sighand->siglock, flags);
  1008. }
  1009. out_unlock:
  1010. read_unlock(&tasklist_lock);
  1011. return ret;
  1012. }
  1013. EXPORT_SYMBOL_GPL(kill_proc_info_as_uid);
  1014. /*
  1015. * kill_something_info() interprets pid in interesting ways just like kill(2).
  1016. *
  1017. * POSIX specifies that kill(-1,sig) is unspecified, but what we have
  1018. * is probably wrong. Should make it like BSD or SYSV.
  1019. */
  1020. static int kill_something_info(int sig, struct siginfo *info, int pid)
  1021. {
  1022. if (!pid) {
  1023. return kill_pg_info(sig, info, process_group(current));
  1024. } else if (pid == -1) {
  1025. int retval = 0, count = 0;
  1026. struct task_struct * p;
  1027. read_lock(&tasklist_lock);
  1028. for_each_process(p) {
  1029. if (p->pid > 1 && p->tgid != current->tgid) {
  1030. int err = group_send_sig_info(sig, info, p);
  1031. ++count;
  1032. if (err != -EPERM)
  1033. retval = err;
  1034. }
  1035. }
  1036. read_unlock(&tasklist_lock);
  1037. return count ? retval : -ESRCH;
  1038. } else if (pid < 0) {
  1039. return kill_pg_info(sig, info, -pid);
  1040. } else {
  1041. return kill_proc_info(sig, info, pid);
  1042. }
  1043. }
  1044. /*
  1045. * These are for backward compatibility with the rest of the kernel source.
  1046. */
  1047. /*
  1048. * These two are the most common entry points. They send a signal
  1049. * just to the specific thread.
  1050. */
  1051. int
  1052. send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
  1053. {
  1054. int ret;
  1055. unsigned long flags;
  1056. /*
  1057. * Make sure legacy kernel users don't send in bad values
  1058. * (normal paths check this in check_kill_permission).
  1059. */
  1060. if (!valid_signal(sig))
  1061. return -EINVAL;
  1062. /*
  1063. * We need the tasklist lock even for the specific
  1064. * thread case (when we don't need to follow the group
  1065. * lists) in order to avoid races with "p->sighand"
  1066. * going away or changing from under us.
  1067. */
  1068. read_lock(&tasklist_lock);
  1069. spin_lock_irqsave(&p->sighand->siglock, flags);
  1070. ret = specific_send_sig_info(sig, info, p);
  1071. spin_unlock_irqrestore(&p->sighand->siglock, flags);
  1072. read_unlock(&tasklist_lock);
  1073. return ret;
  1074. }
  1075. #define __si_special(priv) \
  1076. ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO)
  1077. int
  1078. send_sig(int sig, struct task_struct *p, int priv)
  1079. {
  1080. return send_sig_info(sig, __si_special(priv), p);
  1081. }
  1082. /*
  1083. * This is the entry point for "process-wide" signals.
  1084. * They will go to an appropriate thread in the thread group.
  1085. */
  1086. int
  1087. send_group_sig_info(int sig, struct siginfo *info, struct task_struct *p)
  1088. {
  1089. int ret;
  1090. read_lock(&tasklist_lock);
  1091. ret = group_send_sig_info(sig, info, p);
  1092. read_unlock(&tasklist_lock);
  1093. return ret;
  1094. }
  1095. void
  1096. force_sig(int sig, struct task_struct *p)
  1097. {
  1098. force_sig_info(sig, SEND_SIG_PRIV, p);
  1099. }
  1100. /*
  1101. * When things go south during signal handling, we
  1102. * will force a SIGSEGV. And if the signal that caused
  1103. * the problem was already a SIGSEGV, we'll want to
  1104. * make sure we don't even try to deliver the signal..
  1105. */
  1106. int
  1107. force_sigsegv(int sig, struct task_struct *p)
  1108. {
  1109. if (sig == SIGSEGV) {
  1110. unsigned long flags;
  1111. spin_lock_irqsave(&p->sighand->siglock, flags);
  1112. p->sighand->action[sig - 1].sa.sa_handler = SIG_DFL;
  1113. spin_unlock_irqrestore(&p->sighand->siglock, flags);
  1114. }
  1115. force_sig(SIGSEGV, p);
  1116. return 0;
  1117. }
  1118. int
  1119. kill_pg(pid_t pgrp, int sig, int priv)
  1120. {
  1121. return kill_pg_info(sig, __si_special(priv), pgrp);
  1122. }
  1123. int
  1124. kill_proc(pid_t pid, int sig, int priv)
  1125. {
  1126. return kill_proc_info(sig, __si_special(priv), pid);
  1127. }
  1128. /*
  1129. * These functions support sending signals using preallocated sigqueue
  1130. * structures. This is needed "because realtime applications cannot
  1131. * afford to lose notifications of asynchronous events, like timer
  1132. * expirations or I/O completions". In the case of Posix Timers
  1133. * we allocate the sigqueue structure from the timer_create. If this
  1134. * allocation fails we are able to report the failure to the application
  1135. * with an EAGAIN error.
  1136. */
  1137. struct sigqueue *sigqueue_alloc(void)
  1138. {
  1139. struct sigqueue *q;
  1140. if ((q = __sigqueue_alloc(current, GFP_KERNEL, 0)))
  1141. q->flags |= SIGQUEUE_PREALLOC;
  1142. return(q);
  1143. }
  1144. void sigqueue_free(struct sigqueue *q)
  1145. {
  1146. unsigned long flags;
  1147. BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
  1148. /*
  1149. * If the signal is still pending remove it from the
  1150. * pending queue.
  1151. */
  1152. if (unlikely(!list_empty(&q->list))) {
  1153. spinlock_t *lock = &current->sighand->siglock;
  1154. read_lock(&tasklist_lock);
  1155. spin_lock_irqsave(lock, flags);
  1156. if (!list_empty(&q->list))
  1157. list_del_init(&q->list);
  1158. spin_unlock_irqrestore(lock, flags);
  1159. read_unlock(&tasklist_lock);
  1160. }
  1161. q->flags &= ~SIGQUEUE_PREALLOC;
  1162. __sigqueue_free(q);
  1163. }
  1164. int
  1165. send_sigqueue(int sig, struct sigqueue *q, struct task_struct *p)
  1166. {
  1167. unsigned long flags;
  1168. int ret = 0;
  1169. struct sighand_struct *sh;
  1170. BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
  1171. /*
  1172. * The rcu based delayed sighand destroy makes it possible to
  1173. * run this without tasklist lock held. The task struct itself
  1174. * cannot go away as create_timer did get_task_struct().
  1175. *
  1176. * We return -1, when the task is marked exiting, so
  1177. * posix_timer_event can redirect it to the group leader
  1178. */
  1179. rcu_read_lock();
  1180. if (unlikely(p->flags & PF_EXITING)) {
  1181. ret = -1;
  1182. goto out_err;
  1183. }
  1184. retry:
  1185. sh = rcu_dereference(p->sighand);
  1186. spin_lock_irqsave(&sh->siglock, flags);
  1187. if (p->sighand != sh) {
  1188. /* We raced with exec() in a multithreaded process... */
  1189. spin_unlock_irqrestore(&sh->siglock, flags);
  1190. goto retry;
  1191. }
  1192. /*
  1193. * We do the check here again to handle the following scenario:
  1194. *
  1195. * CPU 0 CPU 1
  1196. * send_sigqueue
  1197. * check PF_EXITING
  1198. * interrupt exit code running
  1199. * __exit_signal
  1200. * lock sighand->siglock
  1201. * unlock sighand->siglock
  1202. * lock sh->siglock
  1203. * add(tsk->pending) flush_sigqueue(tsk->pending)
  1204. *
  1205. */
  1206. if (unlikely(p->flags & PF_EXITING)) {
  1207. ret = -1;
  1208. goto out;
  1209. }
  1210. if (unlikely(!list_empty(&q->list))) {
  1211. /*
  1212. * If an SI_TIMER entry is already queue just increment
  1213. * the overrun count.
  1214. */
  1215. if (q->info.si_code != SI_TIMER)
  1216. BUG();
  1217. q->info.si_overrun++;
  1218. goto out;
  1219. }
  1220. /* Short-circuit ignored signals. */
  1221. if (sig_ignored(p, sig)) {
  1222. ret = 1;
  1223. goto out;
  1224. }
  1225. list_add_tail(&q->list, &p->pending.list);
  1226. sigaddset(&p->pending.signal, sig);
  1227. if (!sigismember(&p->blocked, sig))
  1228. signal_wake_up(p, sig == SIGKILL);
  1229. out:
  1230. spin_unlock_irqrestore(&sh->siglock, flags);
  1231. out_err:
  1232. rcu_read_unlock();
  1233. return ret;
  1234. }
  1235. int
  1236. send_group_sigqueue(int sig, struct sigqueue *q, struct task_struct *p)
  1237. {
  1238. unsigned long flags;
  1239. int ret = 0;
  1240. BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
  1241. read_lock(&tasklist_lock);
  1242. /* Since it_lock is held, p->sighand cannot be NULL. */
  1243. spin_lock_irqsave(&p->sighand->siglock, flags);
  1244. handle_stop_signal(sig, p);
  1245. /* Short-circuit ignored signals. */
  1246. if (sig_ignored(p, sig)) {
  1247. ret = 1;
  1248. goto out;
  1249. }
  1250. if (unlikely(!list_empty(&q->list))) {
  1251. /*
  1252. * If an SI_TIMER entry is already queue just increment
  1253. * the overrun count. Other uses should not try to
  1254. * send the signal multiple times.
  1255. */
  1256. if (q->info.si_code != SI_TIMER)
  1257. BUG();
  1258. q->info.si_overrun++;
  1259. goto out;
  1260. }
  1261. /*
  1262. * Put this signal on the shared-pending queue.
  1263. * We always use the shared queue for process-wide signals,
  1264. * to avoid several races.
  1265. */
  1266. list_add_tail(&q->list, &p->signal->shared_pending.list);
  1267. sigaddset(&p->signal->shared_pending.signal, sig);
  1268. __group_complete_signal(sig, p);
  1269. out:
  1270. spin_unlock_irqrestore(&p->sighand->siglock, flags);
  1271. read_unlock(&tasklist_lock);
  1272. return ret;
  1273. }
  1274. /*
  1275. * Wake up any threads in the parent blocked in wait* syscalls.
  1276. */
  1277. static inline void __wake_up_parent(struct task_struct *p,
  1278. struct task_struct *parent)
  1279. {
  1280. wake_up_interruptible_sync(&parent->signal->wait_chldexit);
  1281. }
  1282. /*
  1283. * Let a parent know about the death of a child.
  1284. * For a stopped/continued status change, use do_notify_parent_cldstop instead.
  1285. */
  1286. void do_notify_parent(struct task_struct *tsk, int sig)
  1287. {
  1288. struct siginfo info;
  1289. unsigned long flags;
  1290. struct sighand_struct *psig;
  1291. BUG_ON(sig == -1);
  1292. /* do_notify_parent_cldstop should have been called instead. */
  1293. BUG_ON(tsk->state & (TASK_STOPPED|TASK_TRACED));
  1294. BUG_ON(!tsk->ptrace &&
  1295. (tsk->group_leader != tsk || !thread_group_empty(tsk)));
  1296. info.si_signo = sig;
  1297. info.si_errno = 0;
  1298. info.si_pid = tsk->pid;
  1299. info.si_uid = tsk->uid;
  1300. /* FIXME: find out whether or not this is supposed to be c*time. */
  1301. info.si_utime = cputime_to_jiffies(cputime_add(tsk->utime,
  1302. tsk->signal->utime));
  1303. info.si_stime = cputime_to_jiffies(cputime_add(tsk->stime,
  1304. tsk->signal->stime));
  1305. info.si_status = tsk->exit_code & 0x7f;
  1306. if (tsk->exit_code & 0x80)
  1307. info.si_code = CLD_DUMPED;
  1308. else if (tsk->exit_code & 0x7f)
  1309. info.si_code = CLD_KILLED;
  1310. else {
  1311. info.si_code = CLD_EXITED;
  1312. info.si_status = tsk->exit_code >> 8;
  1313. }
  1314. psig = tsk->parent->sighand;
  1315. spin_lock_irqsave(&psig->siglock, flags);
  1316. if (!tsk->ptrace && sig == SIGCHLD &&
  1317. (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN ||
  1318. (psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT))) {
  1319. /*
  1320. * We are exiting and our parent doesn't care. POSIX.1
  1321. * defines special semantics for setting SIGCHLD to SIG_IGN
  1322. * or setting the SA_NOCLDWAIT flag: we should be reaped
  1323. * automatically and not left for our parent's wait4 call.
  1324. * Rather than having the parent do it as a magic kind of
  1325. * signal handler, we just set this to tell do_exit that we
  1326. * can be cleaned up without becoming a zombie. Note that
  1327. * we still call __wake_up_parent in this case, because a
  1328. * blocked sys_wait4 might now return -ECHILD.
  1329. *
  1330. * Whether we send SIGCHLD or not for SA_NOCLDWAIT
  1331. * is implementation-defined: we do (if you don't want
  1332. * it, just use SIG_IGN instead).
  1333. */
  1334. tsk->exit_signal = -1;
  1335. if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN)
  1336. sig = 0;
  1337. }
  1338. if (valid_signal(sig) && sig > 0)
  1339. __group_send_sig_info(sig, &info, tsk->parent);
  1340. __wake_up_parent(tsk, tsk->parent);
  1341. spin_unlock_irqrestore(&psig->siglock, flags);
  1342. }
  1343. static void do_notify_parent_cldstop(struct task_struct *tsk, int to_self, int why)
  1344. {
  1345. struct siginfo info;
  1346. unsigned long flags;
  1347. struct task_struct *parent;
  1348. struct sighand_struct *sighand;
  1349. if (to_self)
  1350. parent = tsk->parent;
  1351. else {
  1352. tsk = tsk->group_leader;
  1353. parent = tsk->real_parent;
  1354. }
  1355. info.si_signo = SIGCHLD;
  1356. info.si_errno = 0;
  1357. info.si_pid = tsk->pid;
  1358. info.si_uid = tsk->uid;
  1359. /* FIXME: find out whether or not this is supposed to be c*time. */
  1360. info.si_utime = cputime_to_jiffies(tsk->utime);
  1361. info.si_stime = cputime_to_jiffies(tsk->stime);
  1362. info.si_code = why;
  1363. switch (why) {
  1364. case CLD_CONTINUED:
  1365. info.si_status = SIGCONT;
  1366. break;
  1367. case CLD_STOPPED:
  1368. info.si_status = tsk->signal->group_exit_code & 0x7f;
  1369. break;
  1370. case CLD_TRAPPED:
  1371. info.si_status = tsk->exit_code & 0x7f;
  1372. break;
  1373. default:
  1374. BUG();
  1375. }
  1376. sighand = parent->sighand;
  1377. spin_lock_irqsave(&sighand->siglock, flags);
  1378. if (sighand->action[SIGCHLD-1].sa.sa_handler != SIG_IGN &&
  1379. !(sighand->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP))
  1380. __group_send_sig_info(SIGCHLD, &info, parent);
  1381. /*
  1382. * Even if SIGCHLD is not generated, we must wake up wait4 calls.
  1383. */
  1384. __wake_up_parent(tsk, parent);
  1385. spin_unlock_irqrestore(&sighand->siglock, flags);
  1386. }
  1387. /*
  1388. * This must be called with current->sighand->siglock held.
  1389. *
  1390. * This should be the path for all ptrace stops.
  1391. * We always set current->last_siginfo while stopped here.
  1392. * That makes it a way to test a stopped process for
  1393. * being ptrace-stopped vs being job-control-stopped.
  1394. *
  1395. * If we actually decide not to stop at all because the tracer is gone,
  1396. * we leave nostop_code in current->exit_code.
  1397. */
  1398. static void ptrace_stop(int exit_code, int nostop_code, siginfo_t *info)
  1399. {
  1400. /*
  1401. * If there is a group stop in progress,
  1402. * we must participate in the bookkeeping.
  1403. */
  1404. if (current->signal->group_stop_count > 0)
  1405. --current->signal->group_stop_count;
  1406. current->last_siginfo = info;
  1407. current->exit_code = exit_code;
  1408. /* Let the debugger run. */
  1409. set_current_state(TASK_TRACED);
  1410. spin_unlock_irq(&current->sighand->siglock);
  1411. read_lock(&tasklist_lock);
  1412. if (likely(current->ptrace & PT_PTRACED) &&
  1413. likely(current->parent != current->real_parent ||
  1414. !(current->ptrace & PT_ATTACHED)) &&
  1415. (likely(current->parent->signal != current->signal) ||
  1416. !unlikely(current->signal->flags & SIGNAL_GROUP_EXIT))) {
  1417. do_notify_parent_cldstop(current, 1, CLD_TRAPPED);
  1418. read_unlock(&tasklist_lock);
  1419. schedule();
  1420. } else {
  1421. /*
  1422. * By the time we got the lock, our tracer went away.
  1423. * Don't stop here.
  1424. */
  1425. read_unlock(&tasklist_lock);
  1426. set_current_state(TASK_RUNNING);
  1427. current->exit_code = nostop_code;
  1428. }
  1429. /*
  1430. * We are back. Now reacquire the siglock before touching
  1431. * last_siginfo, so that we are sure to have synchronized with
  1432. * any signal-sending on another CPU that wants to examine it.
  1433. */
  1434. spin_lock_irq(&current->sighand->siglock);
  1435. current->last_siginfo = NULL;
  1436. /*
  1437. * Queued signals ignored us while we were stopped for tracing.
  1438. * So check for any that we should take before resuming user mode.
  1439. */
  1440. recalc_sigpending();
  1441. }
  1442. void ptrace_notify(int exit_code)
  1443. {
  1444. siginfo_t info;
  1445. BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
  1446. memset(&info, 0, sizeof info);
  1447. info.si_signo = SIGTRAP;
  1448. info.si_code = exit_code;
  1449. info.si_pid = current->pid;
  1450. info.si_uid = current->uid;
  1451. /* Let the debugger run. */
  1452. spin_lock_irq(&current->sighand->siglock);
  1453. ptrace_stop(exit_code, 0, &info);
  1454. spin_unlock_irq(&current->sighand->siglock);
  1455. }
  1456. static void
  1457. finish_stop(int stop_count)
  1458. {
  1459. int to_self;
  1460. /*
  1461. * If there are no other threads in the group, or if there is
  1462. * a group stop in progress and we are the last to stop,
  1463. * report to the parent. When ptraced, every thread reports itself.
  1464. */
  1465. if (stop_count < 0 || (current->ptrace & PT_PTRACED))
  1466. to_self = 1;
  1467. else if (stop_count == 0)
  1468. to_self = 0;
  1469. else
  1470. goto out;
  1471. read_lock(&tasklist_lock);
  1472. do_notify_parent_cldstop(current, to_self, CLD_STOPPED);
  1473. read_unlock(&tasklist_lock);
  1474. out:
  1475. schedule();
  1476. /*
  1477. * Now we don't run again until continued.
  1478. */
  1479. current->exit_code = 0;
  1480. }
  1481. /*
  1482. * This performs the stopping for SIGSTOP and other stop signals.
  1483. * We have to stop all threads in the thread group.
  1484. * Returns nonzero if we've actually stopped and released the siglock.
  1485. * Returns zero if we didn't stop and still hold the siglock.
  1486. */
  1487. static int do_signal_stop(int signr)
  1488. {
  1489. struct signal_struct *sig = current->signal;
  1490. struct sighand_struct *sighand = current->sighand;
  1491. int stop_count = -1;
  1492. if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED))
  1493. return 0;
  1494. if (sig->group_stop_count > 0) {
  1495. /*
  1496. * There is a group stop in progress. We don't need to
  1497. * start another one.
  1498. */
  1499. signr = sig->group_exit_code;
  1500. stop_count = --sig->group_stop_count;
  1501. current->exit_code = signr;
  1502. set_current_state(TASK_STOPPED);
  1503. if (stop_count == 0)
  1504. sig->flags = SIGNAL_STOP_STOPPED;
  1505. }
  1506. else if (thread_group_empty(current)) {
  1507. /*
  1508. * Lock must be held through transition to stopped state.
  1509. */
  1510. current->exit_code = current->signal->group_exit_code = signr;
  1511. set_current_state(TASK_STOPPED);
  1512. sig->flags = SIGNAL_STOP_STOPPED;
  1513. }
  1514. else {
  1515. /*
  1516. * (sig->group_stop_count == 0)
  1517. * There is no group stop already in progress.
  1518. * We must initiate one now.
  1519. */
  1520. struct task_struct *t;
  1521. current->exit_code = signr;
  1522. sig->group_exit_code = signr;
  1523. stop_count = 0;
  1524. for (t = next_thread(current); t != current; t = next_thread(t))
  1525. /*
  1526. * Setting state to TASK_STOPPED for a group
  1527. * stop is always done with the siglock held,
  1528. * so this check has no races.
  1529. */
  1530. if (!t->exit_state &&
  1531. !(t->state & (TASK_STOPPED|TASK_TRACED))) {
  1532. stop_count++;
  1533. signal_wake_up(t, 0);
  1534. }
  1535. sig->group_stop_count = stop_count;
  1536. set_current_state(TASK_STOPPED);
  1537. if (stop_count == 0)
  1538. sig->flags = SIGNAL_STOP_STOPPED;
  1539. }
  1540. spin_unlock_irq(&sighand->siglock);
  1541. finish_stop(stop_count);
  1542. return 1;
  1543. }
  1544. /*
  1545. * Do appropriate magic when group_stop_count > 0.
  1546. * We return nonzero if we stopped, after releasing the siglock.
  1547. * We return zero if we still hold the siglock and should look
  1548. * for another signal without checking group_stop_count again.
  1549. */
  1550. static int handle_group_stop(void)
  1551. {
  1552. int stop_count;
  1553. if (current->signal->group_exit_task == current) {
  1554. /*
  1555. * Group stop is so we can do a core dump,
  1556. * We are the initiating thread, so get on with it.
  1557. */
  1558. current->signal->group_exit_task = NULL;
  1559. return 0;
  1560. }
  1561. if (current->signal->flags & SIGNAL_GROUP_EXIT)
  1562. /*
  1563. * Group stop is so another thread can do a core dump,
  1564. * or else we are racing against a death signal.
  1565. * Just punt the stop so we can get the next signal.
  1566. */
  1567. return 0;
  1568. /*
  1569. * There is a group stop in progress. We stop
  1570. * without any associated signal being in our queue.
  1571. */
  1572. stop_count = --current->signal->group_stop_count;
  1573. if (stop_count == 0)
  1574. current->signal->flags = SIGNAL_STOP_STOPPED;
  1575. current->exit_code = current->signal->group_exit_code;
  1576. set_current_state(TASK_STOPPED);
  1577. spin_unlock_irq(&current->sighand->siglock);
  1578. finish_stop(stop_count);
  1579. return 1;
  1580. }
  1581. int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
  1582. struct pt_regs *regs, void *cookie)
  1583. {
  1584. sigset_t *mask = &current->blocked;
  1585. int signr = 0;
  1586. try_to_freeze();
  1587. relock:
  1588. spin_lock_irq(&current->sighand->siglock);
  1589. for (;;) {
  1590. struct k_sigaction *ka;
  1591. if (unlikely(current->signal->group_stop_count > 0) &&
  1592. handle_group_stop())
  1593. goto relock;
  1594. signr = dequeue_signal(current, mask, info);
  1595. if (!signr)
  1596. break; /* will return 0 */
  1597. if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) {
  1598. ptrace_signal_deliver(regs, cookie);
  1599. /* Let the debugger run. */
  1600. ptrace_stop(signr, signr, info);
  1601. /* We're back. Did the debugger cancel the sig or group_exit? */
  1602. signr = current->exit_code;
  1603. if (signr == 0 || current->signal->flags & SIGNAL_GROUP_EXIT)
  1604. continue;
  1605. current->exit_code = 0;
  1606. /* Update the siginfo structure if the signal has
  1607. changed. If the debugger wanted something
  1608. specific in the siginfo structure then it should
  1609. have updated *info via PTRACE_SETSIGINFO. */
  1610. if (signr != info->si_signo) {
  1611. info->si_signo = signr;
  1612. info->si_errno = 0;
  1613. info->si_code = SI_USER;
  1614. info->si_pid = current->parent->pid;
  1615. info->si_uid = current->parent->uid;
  1616. }
  1617. /* If the (new) signal is now blocked, requeue it. */
  1618. if (sigismember(&current->blocked, signr)) {
  1619. specific_send_sig_info(signr, info, current);
  1620. continue;
  1621. }
  1622. }
  1623. ka = &current->sighand->action[signr-1];
  1624. if (ka->sa.sa_handler == SIG_IGN) /* Do nothing. */
  1625. continue;
  1626. if (ka->sa.sa_handler != SIG_DFL) {
  1627. /* Run the handler. */
  1628. *return_ka = *ka;
  1629. if (ka->sa.sa_flags & SA_ONESHOT)
  1630. ka->sa.sa_handler = SIG_DFL;
  1631. break; /* will return non-zero "signr" value */
  1632. }
  1633. /*
  1634. * Now we are doing the default action for this signal.
  1635. */
  1636. if (sig_kernel_ignore(signr)) /* Default is nothing. */
  1637. continue;
  1638. /* Init gets no signals it doesn't want. */
  1639. if (current == child_reaper)
  1640. continue;
  1641. if (sig_kernel_stop(signr)) {
  1642. /*
  1643. * The default action is to stop all threads in
  1644. * the thread group. The job control signals
  1645. * do nothing in an orphaned pgrp, but SIGSTOP
  1646. * always works. Note that siglock needs to be
  1647. * dropped during the call to is_orphaned_pgrp()
  1648. * because of lock ordering with tasklist_lock.
  1649. * This allows an intervening SIGCONT to be posted.
  1650. * We need to check for that and bail out if necessary.
  1651. */
  1652. if (signr != SIGSTOP) {
  1653. spin_unlock_irq(&current->sighand->siglock);
  1654. /* signals can be posted during this window */
  1655. if (is_orphaned_pgrp(process_group(current)))
  1656. goto relock;
  1657. spin_lock_irq(&current->sighand->siglock);
  1658. }
  1659. if (likely(do_signal_stop(signr))) {
  1660. /* It released the siglock. */
  1661. goto relock;
  1662. }
  1663. /*
  1664. * We didn't actually stop, due to a race
  1665. * with SIGCONT or something like that.
  1666. */
  1667. continue;
  1668. }
  1669. spin_unlock_irq(&current->sighand->siglock);
  1670. /*
  1671. * Anything else is fatal, maybe with a core dump.
  1672. */
  1673. current->flags |= PF_SIGNALED;
  1674. if (sig_kernel_coredump(signr)) {
  1675. /*
  1676. * If it was able to dump core, this kills all
  1677. * other threads in the group and synchronizes with
  1678. * their demise. If we lost the race with another
  1679. * thread getting here, it set group_exit_code
  1680. * first and our do_group_exit call below will use
  1681. * that value and ignore the one we pass it.
  1682. */
  1683. do_coredump((long)signr, signr, regs);
  1684. }
  1685. /*
  1686. * Death signals, no core dump.
  1687. */
  1688. do_group_exit(signr);
  1689. /* NOTREACHED */
  1690. }
  1691. spin_unlock_irq(&current->sighand->siglock);
  1692. return signr;
  1693. }
  1694. EXPORT_SYMBOL(recalc_sigpending);
  1695. EXPORT_SYMBOL_GPL(dequeue_signal);
  1696. EXPORT_SYMBOL(flush_signals);
  1697. EXPORT_SYMBOL(force_sig);
  1698. EXPORT_SYMBOL(kill_pg);
  1699. EXPORT_SYMBOL(kill_proc);
  1700. EXPORT_SYMBOL(ptrace_notify);
  1701. EXPORT_SYMBOL(send_sig);
  1702. EXPORT_SYMBOL(send_sig_info);
  1703. EXPORT_SYMBOL(sigprocmask);
  1704. EXPORT_SYMBOL(block_all_signals);
  1705. EXPORT_SYMBOL(unblock_all_signals);
  1706. /*
  1707. * System call entry points.
  1708. */
  1709. asmlinkage long sys_restart_syscall(void)
  1710. {
  1711. struct restart_block *restart = &current_thread_info()->restart_block;
  1712. return restart->fn(restart);
  1713. }
  1714. long do_no_restart_syscall(struct restart_block *param)
  1715. {
  1716. return -EINTR;
  1717. }
  1718. /*
  1719. * We don't need to get the kernel lock - this is all local to this
  1720. * particular thread.. (and that's good, because this is _heavily_
  1721. * used by various programs)
  1722. */
  1723. /*
  1724. * This is also useful for kernel threads that want to temporarily
  1725. * (or permanently) block certain signals.
  1726. *
  1727. * NOTE! Unlike the user-mode sys_sigprocmask(), the kernel
  1728. * interface happily blocks "unblockable" signals like SIGKILL
  1729. * and friends.
  1730. */
  1731. int sigprocmask(int how, sigset_t *set, sigset_t *oldset)
  1732. {
  1733. int error;
  1734. spin_lock_irq(&current->sighand->siglock);
  1735. if (oldset)
  1736. *oldset = current->blocked;
  1737. error = 0;
  1738. switch (how) {
  1739. case SIG_BLOCK:
  1740. sigorsets(&current->blocked, &current->blocked, set);
  1741. break;
  1742. case SIG_UNBLOCK:
  1743. signandsets(&current->blocked, &current->blocked, set);
  1744. break;
  1745. case SIG_SETMASK:
  1746. current->blocked = *set;
  1747. break;
  1748. default:
  1749. error = -EINVAL;
  1750. }
  1751. recalc_sigpending();
  1752. spin_unlock_irq(&current->sighand->siglock);
  1753. return error;
  1754. }
  1755. asmlinkage long
  1756. sys_rt_sigprocmask(int how, sigset_t __user *set, sigset_t __user *oset, size_t sigsetsize)
  1757. {
  1758. int error = -EINVAL;
  1759. sigset_t old_set, new_set;
  1760. /* XXX: Don't preclude handling different sized sigset_t's. */
  1761. if (sigsetsize != sizeof(sigset_t))
  1762. goto out;
  1763. if (set) {
  1764. error = -EFAULT;
  1765. if (copy_from_user(&new_set, set, sizeof(*set)))
  1766. goto out;
  1767. sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP));
  1768. error = sigprocmask(how, &new_set, &old_set);
  1769. if (error)
  1770. goto out;
  1771. if (oset)
  1772. goto set_old;
  1773. } else if (oset) {
  1774. spin_lock_irq(&current->sighand->siglock);
  1775. old_set = current->blocked;
  1776. spin_unlock_irq(&current->sighand->siglock);
  1777. set_old:
  1778. error = -EFAULT;
  1779. if (copy_to_user(oset, &old_set, sizeof(*oset)))
  1780. goto out;
  1781. }
  1782. error = 0;
  1783. out:
  1784. return error;
  1785. }
  1786. long do_sigpending(void __user *set, unsigned long sigsetsize)
  1787. {
  1788. long error = -EINVAL;
  1789. sigset_t pending;
  1790. if (sigsetsize > sizeof(sigset_t))
  1791. goto out;
  1792. spin_lock_irq(&current->sighand->siglock);
  1793. sigorsets(&pending, &current->pending.signal,
  1794. &current->signal->shared_pending.signal);
  1795. spin_unlock_irq(&current->sighand->siglock);
  1796. /* Outside the lock because only this thread touches it. */
  1797. sigandsets(&pending, &current->blocked, &pending);
  1798. error = -EFAULT;
  1799. if (!copy_to_user(set, &pending, sigsetsize))
  1800. error = 0;
  1801. out:
  1802. return error;
  1803. }
  1804. asmlinkage long
  1805. sys_rt_sigpending(sigset_t __user *set, size_t sigsetsize)
  1806. {
  1807. return do_sigpending(set, sigsetsize);
  1808. }
  1809. #ifndef HAVE_ARCH_COPY_SIGINFO_TO_USER
  1810. int copy_siginfo_to_user(siginfo_t __user *to, siginfo_t *from)
  1811. {
  1812. int err;
  1813. if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
  1814. return -EFAULT;
  1815. if (from->si_code < 0)
  1816. return __copy_to_user(to, from, sizeof(siginfo_t))
  1817. ? -EFAULT : 0;
  1818. /*
  1819. * If you change siginfo_t structure, please be sure
  1820. * this code is fixed accordingly.
  1821. * It should never copy any pad contained in the structure
  1822. * to avoid security leaks, but must copy the generic
  1823. * 3 ints plus the relevant union member.
  1824. */
  1825. err = __put_user(from->si_signo, &to->si_signo);
  1826. err |= __put_user(from->si_errno, &to->si_errno);
  1827. err |= __put_user((short)from->si_code, &to->si_code);
  1828. switch (from->si_code & __SI_MASK) {
  1829. case __SI_KILL:
  1830. err |= __put_user(from->si_pid, &to->si_pid);
  1831. err |= __put_user(from->si_uid, &to->si_uid);
  1832. break;
  1833. case __SI_TIMER:
  1834. err |= __put_user(from->si_tid, &to->si_tid);
  1835. err |= __put_user(from->si_overrun, &to->si_overrun);
  1836. err |= __put_user(from->si_ptr, &to->si_ptr);
  1837. break;
  1838. case __SI_POLL:
  1839. err |= __put_user(from->si_band, &to->si_band);
  1840. err |= __put_user(from->si_fd, &to->si_fd);
  1841. break;
  1842. case __SI_FAULT:
  1843. err |= __put_user(from->si_addr, &to->si_addr);
  1844. #ifdef __ARCH_SI_TRAPNO
  1845. err |= __put_user(from->si_trapno, &to->si_trapno);
  1846. #endif
  1847. break;
  1848. case __SI_CHLD:
  1849. err |= __put_user(from->si_pid, &to->si_pid);
  1850. err |= __put_user(from->si_uid, &to->si_uid);
  1851. err |= __put_user(from->si_status, &to->si_status);
  1852. err |= __put_user(from->si_utime, &to->si_utime);
  1853. err |= __put_user(from->si_stime, &to->si_stime);
  1854. break;
  1855. case __SI_RT: /* This is not generated by the kernel as of now. */
  1856. case __SI_MESGQ: /* But this is */
  1857. err |= __put_user(from->si_pid, &to->si_pid);
  1858. err |= __put_user(from->si_uid, &to->si_uid);
  1859. err |= __put_user(from->si_ptr, &to->si_ptr);
  1860. break;
  1861. default: /* this is just in case for now ... */
  1862. err |= __put_user(from->si_pid, &to->si_pid);
  1863. err |= __put_user(from->si_uid, &to->si_uid);
  1864. break;
  1865. }
  1866. return err;
  1867. }
  1868. #endif
  1869. asmlinkage long
  1870. sys_rt_sigtimedwait(const sigset_t __user *uthese,
  1871. siginfo_t __user *uinfo,
  1872. const struct timespec __user *uts,
  1873. size_t sigsetsize)
  1874. {
  1875. int ret, sig;
  1876. sigset_t these;
  1877. struct timespec ts;
  1878. siginfo_t info;
  1879. long timeout = 0;
  1880. /* XXX: Don't preclude handling different sized sigset_t's. */
  1881. if (sigsetsize != sizeof(sigset_t))
  1882. return -EINVAL;
  1883. if (copy_from_user(&these, uthese, sizeof(these)))
  1884. return -EFAULT;
  1885. /*
  1886. * Invert the set of allowed signals to get those we
  1887. * want to block.
  1888. */
  1889. sigdelsetmask(&these, sigmask(SIGKILL)|sigmask(SIGSTOP));
  1890. signotset(&these);
  1891. if (uts) {
  1892. if (copy_from_user(&ts, uts, sizeof(ts)))
  1893. return -EFAULT;
  1894. if (ts.tv_nsec >= 1000000000L || ts.tv_nsec < 0
  1895. || ts.tv_sec < 0)
  1896. return -EINVAL;
  1897. }
  1898. spin_lock_irq(&current->sighand->siglock);
  1899. sig = dequeue_signal(current, &these, &info);
  1900. if (!sig) {
  1901. timeout = MAX_SCHEDULE_TIMEOUT;
  1902. if (uts)
  1903. timeout = (timespec_to_jiffies(&ts)
  1904. + (ts.tv_sec || ts.tv_nsec));
  1905. if (timeout) {
  1906. /* None ready -- temporarily unblock those we're
  1907. * interested while we are sleeping in so that we'll
  1908. * be awakened when they arrive. */
  1909. current->real_blocked = current->blocked;
  1910. sigandsets(&current->blocked, &current->blocked, &these);
  1911. recalc_sigpending();
  1912. spin_unlock_irq(&current->sighand->siglock);
  1913. timeout = schedule_timeout_interruptible(timeout);
  1914. spin_lock_irq(&current->sighand->siglock);
  1915. sig = dequeue_signal(current, &these, &info);
  1916. current->blocked = current->real_blocked;
  1917. siginitset(&current->real_blocked, 0);
  1918. recalc_sigpending();
  1919. }
  1920. }
  1921. spin_unlock_irq(&current->sighand->siglock);
  1922. if (sig) {
  1923. ret = sig;
  1924. if (uinfo) {
  1925. if (copy_siginfo_to_user(uinfo, &info))
  1926. ret = -EFAULT;
  1927. }
  1928. } else {
  1929. ret = -EAGAIN;
  1930. if (timeout)
  1931. ret = -EINTR;
  1932. }
  1933. return ret;
  1934. }
  1935. asmlinkage long
  1936. sys_kill(int pid, int sig)
  1937. {
  1938. struct siginfo info;
  1939. info.si_signo = sig;
  1940. info.si_errno = 0;
  1941. info.si_code = SI_USER;
  1942. info.si_pid = current->tgid;
  1943. info.si_uid = current->uid;
  1944. return kill_something_info(sig, &info, pid);
  1945. }
  1946. static int do_tkill(int tgid, int pid, int sig)
  1947. {
  1948. int error;
  1949. struct siginfo info;
  1950. struct task_struct *p;
  1951. error = -ESRCH;
  1952. info.si_signo = sig;
  1953. info.si_errno = 0;
  1954. info.si_code = SI_TKILL;
  1955. info.si_pid = current->tgid;
  1956. info.si_uid = current->uid;
  1957. read_lock(&tasklist_lock);
  1958. p = find_task_by_pid(pid);
  1959. if (p && (tgid <= 0 || p->tgid == tgid)) {
  1960. error = check_kill_permission(sig, &info, p);
  1961. /*
  1962. * The null signal is a permissions and process existence
  1963. * probe. No signal is actually delivered.
  1964. */
  1965. if (!error && sig && p->sighand) {
  1966. spin_lock_irq(&p->sighand->siglock);
  1967. handle_stop_signal(sig, p);
  1968. error = specific_send_sig_info(sig, &info, p);
  1969. spin_unlock_irq(&p->sighand->siglock);
  1970. }
  1971. }
  1972. read_unlock(&tasklist_lock);
  1973. return error;
  1974. }
  1975. /**
  1976. * sys_tgkill - send signal to one specific thread
  1977. * @tgid: the thread group ID of the thread
  1978. * @pid: the PID of the thread
  1979. * @sig: signal to be sent
  1980. *
  1981. * This syscall also checks the tgid and returns -ESRCH even if the PID
  1982. * exists but it's not belonging to the target process anymore. This
  1983. * method solves the problem of threads exiting and PIDs getting reused.
  1984. */
  1985. asmlinkage long sys_tgkill(int tgid, int pid, int sig)
  1986. {
  1987. /* This is only valid for single tasks */
  1988. if (pid <= 0 || tgid <= 0)
  1989. return -EINVAL;
  1990. return do_tkill(tgid, pid, sig);
  1991. }
  1992. /*
  1993. * Send a signal to only one task, even if it's a CLONE_THREAD task.
  1994. */
  1995. asmlinkage long
  1996. sys_tkill(int pid, int sig)
  1997. {
  1998. /* This is only valid for single tasks */
  1999. if (pid <= 0)
  2000. return -EINVAL;
  2001. return do_tkill(0, pid, sig);
  2002. }
  2003. asmlinkage long
  2004. sys_rt_sigqueueinfo(int pid, int sig, siginfo_t __user *uinfo)
  2005. {
  2006. siginfo_t info;
  2007. if (copy_from_user(&info, uinfo, sizeof(siginfo_t)))
  2008. return -EFAULT;
  2009. /* Not even root can pretend to send signals from the kernel.
  2010. Nor can they impersonate a kill(), which adds source info. */
  2011. if (info.si_code >= 0)
  2012. return -EPERM;
  2013. info.si_signo = sig;
  2014. /* POSIX.1b doesn't mention process groups. */
  2015. return kill_proc_info(sig, &info, pid);
  2016. }
  2017. int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
  2018. {
  2019. struct k_sigaction *k;
  2020. sigset_t mask;
  2021. if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig)))
  2022. return -EINVAL;
  2023. k = &current->sighand->action[sig-1];
  2024. spin_lock_irq(&current->sighand->siglock);
  2025. if (signal_pending(current)) {
  2026. /*
  2027. * If there might be a fatal signal pending on multiple
  2028. * threads, make sure we take it before changing the action.
  2029. */
  2030. spin_unlock_irq(&current->sighand->siglock);
  2031. return -ERESTARTNOINTR;
  2032. }
  2033. if (oact)
  2034. *oact = *k;
  2035. if (act) {
  2036. sigdelsetmask(&act->sa.sa_mask,
  2037. sigmask(SIGKILL) | sigmask(SIGSTOP));
  2038. *k = *act;
  2039. /*
  2040. * POSIX 3.3.1.3:
  2041. * "Setting a signal action to SIG_IGN for a signal that is
  2042. * pending shall cause the pending signal to be discarded,
  2043. * whether or not it is blocked."
  2044. *
  2045. * "Setting a signal action to SIG_DFL for a signal that is
  2046. * pending and whose default action is to ignore the signal
  2047. * (for example, SIGCHLD), shall cause the pending signal to
  2048. * be discarded, whether or not it is blocked"
  2049. */
  2050. if (act->sa.sa_handler == SIG_IGN ||
  2051. (act->sa.sa_handler == SIG_DFL && sig_kernel_ignore(sig))) {
  2052. struct task_struct *t = current;
  2053. sigemptyset(&mask);
  2054. sigaddset(&mask, sig);
  2055. rm_from_queue_full(&mask, &t->signal->shared_pending);
  2056. do {
  2057. rm_from_queue_full(&mask, &t->pending);
  2058. recalc_sigpending_tsk(t);
  2059. t = next_thread(t);
  2060. } while (t != current);
  2061. }
  2062. }
  2063. spin_unlock_irq(&current->sighand->siglock);
  2064. return 0;
  2065. }
  2066. int
  2067. do_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, unsigned long sp)
  2068. {
  2069. stack_t oss;
  2070. int error;
  2071. if (uoss) {
  2072. oss.ss_sp = (void __user *) current->sas_ss_sp;
  2073. oss.ss_size = current->sas_ss_size;
  2074. oss.ss_flags = sas_ss_flags(sp);
  2075. }
  2076. if (uss) {
  2077. void __user *ss_sp;
  2078. size_t ss_size;
  2079. int ss_flags;
  2080. error = -EFAULT;
  2081. if (!access_ok(VERIFY_READ, uss, sizeof(*uss))
  2082. || __get_user(ss_sp, &uss->ss_sp)
  2083. || __get_user(ss_flags, &uss->ss_flags)
  2084. || __get_user(ss_size, &uss->ss_size))
  2085. goto out;
  2086. error = -EPERM;
  2087. if (on_sig_stack(sp))
  2088. goto out;
  2089. error = -EINVAL;
  2090. /*
  2091. *
  2092. * Note - this code used to test ss_flags incorrectly
  2093. * old code may have been written using ss_flags==0
  2094. * to mean ss_flags==SS_ONSTACK (as this was the only
  2095. * way that worked) - this fix preserves that older
  2096. * mechanism
  2097. */
  2098. if (ss_flags != SS_DISABLE && ss_flags != SS_ONSTACK && ss_flags != 0)
  2099. goto out;
  2100. if (ss_flags == SS_DISABLE) {
  2101. ss_size = 0;
  2102. ss_sp = NULL;
  2103. } else {
  2104. error = -ENOMEM;
  2105. if (ss_size < MINSIGSTKSZ)
  2106. goto out;
  2107. }
  2108. current->sas_ss_sp = (unsigned long) ss_sp;
  2109. current->sas_ss_size = ss_size;
  2110. }
  2111. if (uoss) {
  2112. error = -EFAULT;
  2113. if (copy_to_user(uoss, &oss, sizeof(oss)))
  2114. goto out;
  2115. }
  2116. error = 0;
  2117. out:
  2118. return error;
  2119. }
  2120. #ifdef __ARCH_WANT_SYS_SIGPENDING
  2121. asmlinkage long
  2122. sys_sigpending(old_sigset_t __user *set)
  2123. {
  2124. return do_sigpending(set, sizeof(*set));
  2125. }
  2126. #endif
  2127. #ifdef __ARCH_WANT_SYS_SIGPROCMASK
  2128. /* Some platforms have their own version with special arguments others
  2129. support only sys_rt_sigprocmask. */
  2130. asmlinkage long
  2131. sys_sigprocmask(int how, old_sigset_t __user *set, old_sigset_t __user *oset)
  2132. {
  2133. int error;
  2134. old_sigset_t old_set, new_set;
  2135. if (set) {
  2136. error = -EFAULT;
  2137. if (copy_from_user(&new_set, set, sizeof(*set)))
  2138. goto out;
  2139. new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP));
  2140. spin_lock_irq(&current->sighand->siglock);
  2141. old_set = current->blocked.sig[0];
  2142. error = 0;
  2143. switch (how) {
  2144. default:
  2145. error = -EINVAL;
  2146. break;
  2147. case SIG_BLOCK:
  2148. sigaddsetmask(&current->blocked, new_set);
  2149. break;
  2150. case SIG_UNBLOCK:
  2151. sigdelsetmask(&current->blocked, new_set);
  2152. break;
  2153. case SIG_SETMASK:
  2154. current->blocked.sig[0] = new_set;
  2155. break;
  2156. }
  2157. recalc_sigpending();
  2158. spin_unlock_irq(&current->sighand->siglock);
  2159. if (error)
  2160. goto out;
  2161. if (oset)
  2162. goto set_old;
  2163. } else if (oset) {
  2164. old_set = current->blocked.sig[0];
  2165. set_old:
  2166. error = -EFAULT;
  2167. if (copy_to_user(oset, &old_set, sizeof(*oset)))
  2168. goto out;
  2169. }
  2170. error = 0;
  2171. out:
  2172. return error;
  2173. }
  2174. #endif /* __ARCH_WANT_SYS_SIGPROCMASK */
  2175. #ifdef __ARCH_WANT_SYS_RT_SIGACTION
  2176. asmlinkage long
  2177. sys_rt_sigaction(int sig,
  2178. const struct sigaction __user *act,
  2179. struct sigaction __user *oact,
  2180. size_t sigsetsize)
  2181. {
  2182. struct k_sigaction new_sa, old_sa;
  2183. int ret = -EINVAL;
  2184. /* XXX: Don't preclude handling different sized sigset_t's. */
  2185. if (sigsetsize != sizeof(sigset_t))
  2186. goto out;
  2187. if (act) {
  2188. if (copy_from_user(&new_sa.sa, act, sizeof(new_sa.sa)))
  2189. return -EFAULT;
  2190. }
  2191. ret = do_sigaction(sig, act ? &new_sa : NULL, oact ? &old_sa : NULL);
  2192. if (!ret && oact) {
  2193. if (copy_to_user(oact, &old_sa.sa, sizeof(old_sa.sa)))
  2194. return -EFAULT;
  2195. }
  2196. out:
  2197. return ret;
  2198. }
  2199. #endif /* __ARCH_WANT_SYS_RT_SIGACTION */
  2200. #ifdef __ARCH_WANT_SYS_SGETMASK
  2201. /*
  2202. * For backwards compatibility. Functionality superseded by sigprocmask.
  2203. */
  2204. asmlinkage long
  2205. sys_sgetmask(void)
  2206. {
  2207. /* SMP safe */
  2208. return current->blocked.sig[0];
  2209. }
  2210. asmlinkage long
  2211. sys_ssetmask(int newmask)
  2212. {
  2213. int old;
  2214. spin_lock_irq(&current->sighand->siglock);
  2215. old = current->blocked.sig[0];
  2216. siginitset(&current->blocked, newmask & ~(sigmask(SIGKILL)|
  2217. sigmask(SIGSTOP)));
  2218. recalc_sigpending();
  2219. spin_unlock_irq(&current->sighand->siglock);
  2220. return old;
  2221. }
  2222. #endif /* __ARCH_WANT_SGETMASK */
  2223. #ifdef __ARCH_WANT_SYS_SIGNAL
  2224. /*
  2225. * For backwards compatibility. Functionality superseded by sigaction.
  2226. */
  2227. asmlinkage unsigned long
  2228. sys_signal(int sig, __sighandler_t handler)
  2229. {
  2230. struct k_sigaction new_sa, old_sa;
  2231. int ret;
  2232. new_sa.sa.sa_handler = handler;
  2233. new_sa.sa.sa_flags = SA_ONESHOT | SA_NOMASK;
  2234. sigemptyset(&new_sa.sa.sa_mask);
  2235. ret = do_sigaction(sig, &new_sa, &old_sa);
  2236. return ret ? ret : (unsigned long)old_sa.sa.sa_handler;
  2237. }
  2238. #endif /* __ARCH_WANT_SYS_SIGNAL */
  2239. #ifdef __ARCH_WANT_SYS_PAUSE
  2240. asmlinkage long
  2241. sys_pause(void)
  2242. {
  2243. current->state = TASK_INTERRUPTIBLE;
  2244. schedule();
  2245. return -ERESTARTNOHAND;
  2246. }
  2247. #endif
  2248. #ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND
  2249. asmlinkage long sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize)
  2250. {
  2251. sigset_t newset;
  2252. /* XXX: Don't preclude handling different sized sigset_t's. */
  2253. if (sigsetsize != sizeof(sigset_t))
  2254. return -EINVAL;
  2255. if (copy_from_user(&newset, unewset, sizeof(newset)))
  2256. return -EFAULT;
  2257. sigdelsetmask(&newset, sigmask(SIGKILL)|sigmask(SIGSTOP));
  2258. spin_lock_irq(&current->sighand->siglock);
  2259. current->saved_sigmask = current->blocked;
  2260. current->blocked = newset;
  2261. recalc_sigpending();
  2262. spin_unlock_irq(&current->sighand->siglock);
  2263. current->state = TASK_INTERRUPTIBLE;
  2264. schedule();
  2265. set_thread_flag(TIF_RESTORE_SIGMASK);
  2266. return -ERESTARTNOHAND;
  2267. }
  2268. #endif /* __ARCH_WANT_SYS_RT_SIGSUSPEND */
  2269. void __init signals_init(void)
  2270. {
  2271. sigqueue_cachep =
  2272. kmem_cache_create("sigqueue",
  2273. sizeof(struct sigqueue),
  2274. __alignof__(struct sigqueue),
  2275. SLAB_PANIC, NULL, NULL);
  2276. }