2 * linux/kernel/signal.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * 1997-11-02 Modified for POSIX.1b signals by Richard Henderson
8 * 2003-06-02 Jim Houston - Concurrent Computer Corp.
9 * Changes to use preallocated sigqueue structures
10 * to allow signals to be sent reliably.
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/sched.h>
18 #include <linux/tty.h>
19 #include <linux/binfmts.h>
20 #include <linux/security.h>
21 #include <linux/syscalls.h>
22 #include <linux/ptrace.h>
23 #include <linux/signal.h>
24 #include <linux/signalfd.h>
25 #include <linux/tracehook.h>
26 #include <linux/capability.h>
27 #include <linux/freezer.h>
28 #include <linux/pid_namespace.h>
29 #include <linux/nsproxy.h>
30 #include <trace/events/sched.h>
32 #include <asm/param.h>
33 #include <asm/uaccess.h>
34 #include <asm/unistd.h>
35 #include <asm/siginfo.h>
36 #include "audit.h" /* audit_signal_info() */
39 * SLAB caches for signal bits.
42 static struct kmem_cache
*sigqueue_cachep
;
44 static void __user
*sig_handler(struct task_struct
*t
, int sig
)
46 return t
->sighand
->action
[sig
- 1].sa
.sa_handler
;
49 static int sig_handler_ignored(void __user
*handler
, int sig
)
51 /* Is it explicitly or implicitly ignored? */
52 return handler
== SIG_IGN
||
53 (handler
== SIG_DFL
&& sig_kernel_ignore(sig
));
56 static int sig_task_ignored(struct task_struct
*t
, int sig
,
61 handler
= sig_handler(t
, sig
);
63 if (unlikely(t
->signal
->flags
& SIGNAL_UNKILLABLE
) &&
64 handler
== SIG_DFL
&& !from_ancestor_ns
)
67 return sig_handler_ignored(handler
, sig
);
70 static int sig_ignored(struct task_struct
*t
, int sig
, int from_ancestor_ns
)
73 * Blocked signals are never ignored, since the
74 * signal handler may change by the time it is
77 if (sigismember(&t
->blocked
, sig
) || sigismember(&t
->real_blocked
, sig
))
80 if (!sig_task_ignored(t
, sig
, from_ancestor_ns
))
84 * Tracers may want to know about even ignored signals.
86 return !tracehook_consider_ignored_signal(t
, sig
);
90 * Re-calculate pending state from the set of locally pending
91 * signals, globally pending signals, and blocked signals.
93 static inline int has_pending_signals(sigset_t
*signal
, sigset_t
*blocked
)
98 switch (_NSIG_WORDS
) {
100 for (i
= _NSIG_WORDS
, ready
= 0; --i
>= 0 ;)
101 ready
|= signal
->sig
[i
] &~ blocked
->sig
[i
];
104 case 4: ready
= signal
->sig
[3] &~ blocked
->sig
[3];
105 ready
|= signal
->sig
[2] &~ blocked
->sig
[2];
106 ready
|= signal
->sig
[1] &~ blocked
->sig
[1];
107 ready
|= signal
->sig
[0] &~ blocked
->sig
[0];
110 case 2: ready
= signal
->sig
[1] &~ blocked
->sig
[1];
111 ready
|= signal
->sig
[0] &~ blocked
->sig
[0];
114 case 1: ready
= signal
->sig
[0] &~ blocked
->sig
[0];
119 #define PENDING(p,b) has_pending_signals(&(p)->signal, (b))
121 static int recalc_sigpending_tsk(struct task_struct
*t
)
123 if (t
->signal
->group_stop_count
> 0 ||
124 PENDING(&t
->pending
, &t
->blocked
) ||
125 PENDING(&t
->signal
->shared_pending
, &t
->blocked
)) {
126 set_tsk_thread_flag(t
, TIF_SIGPENDING
);
130 * We must never clear the flag in another thread, or in current
131 * when it's possible the current syscall is returning -ERESTART*.
132 * So we don't clear it here, and only callers who know they should do.
138 * After recalculating TIF_SIGPENDING, we need to make sure the task wakes up.
139 * This is superfluous when called on current, the wakeup is a harmless no-op.
141 void recalc_sigpending_and_wake(struct task_struct
*t
)
143 if (recalc_sigpending_tsk(t
))
144 signal_wake_up(t
, 0);
147 void recalc_sigpending(void)
149 if (unlikely(tracehook_force_sigpending()))
150 set_thread_flag(TIF_SIGPENDING
);
151 else if (!recalc_sigpending_tsk(current
) && !freezing(current
))
152 clear_thread_flag(TIF_SIGPENDING
);
156 /* Given the mask, find the first available signal that should be serviced. */
158 int next_signal(struct sigpending
*pending
, sigset_t
*mask
)
160 unsigned long i
, *s
, *m
, x
;
163 s
= pending
->signal
.sig
;
165 switch (_NSIG_WORDS
) {
167 for (i
= 0; i
< _NSIG_WORDS
; ++i
, ++s
, ++m
)
168 if ((x
= *s
&~ *m
) != 0) {
169 sig
= ffz(~x
) + i
*_NSIG_BPW
+ 1;
174 case 2: if ((x
= s
[0] &~ m
[0]) != 0)
176 else if ((x
= s
[1] &~ m
[1]) != 0)
183 case 1: if ((x
= *s
&~ *m
) != 0)
192 * allocate a new signal queue record
193 * - this may be called without locks if and only if t == current, otherwise an
194 * appopriate lock must be held to stop the target task from exiting
196 static struct sigqueue
*__sigqueue_alloc(struct task_struct
*t
, gfp_t flags
,
199 struct sigqueue
*q
= NULL
;
200 struct user_struct
*user
;
203 * We won't get problems with the target's UID changing under us
204 * because changing it requires RCU be used, and if t != current, the
205 * caller must be holding the RCU readlock (by way of a spinlock) and
206 * we use RCU protection here
208 user
= get_uid(__task_cred(t
)->user
);
209 atomic_inc(&user
->sigpending
);
210 if (override_rlimit
||
211 atomic_read(&user
->sigpending
) <=
212 t
->signal
->rlim
[RLIMIT_SIGPENDING
].rlim_cur
)
213 q
= kmem_cache_alloc(sigqueue_cachep
, flags
);
214 if (unlikely(q
== NULL
)) {
215 atomic_dec(&user
->sigpending
);
218 INIT_LIST_HEAD(&q
->list
);
226 static void __sigqueue_free(struct sigqueue
*q
)
228 if (q
->flags
& SIGQUEUE_PREALLOC
)
230 atomic_dec(&q
->user
->sigpending
);
232 kmem_cache_free(sigqueue_cachep
, q
);
235 void flush_sigqueue(struct sigpending
*queue
)
239 sigemptyset(&queue
->signal
);
240 while (!list_empty(&queue
->list
)) {
241 q
= list_entry(queue
->list
.next
, struct sigqueue
, list
);
242 list_del_init(&q
->list
);
248 * Flush all pending signals for a task.
250 void flush_signals(struct task_struct
*t
)
254 spin_lock_irqsave(&t
->sighand
->siglock
, flags
);
255 clear_tsk_thread_flag(t
, TIF_SIGPENDING
);
256 flush_sigqueue(&t
->pending
);
257 flush_sigqueue(&t
->signal
->shared_pending
);
258 spin_unlock_irqrestore(&t
->sighand
->siglock
, flags
);
261 static void __flush_itimer_signals(struct sigpending
*pending
)
263 sigset_t signal
, retain
;
264 struct sigqueue
*q
, *n
;
266 signal
= pending
->signal
;
267 sigemptyset(&retain
);
269 list_for_each_entry_safe(q
, n
, &pending
->list
, list
) {
270 int sig
= q
->info
.si_signo
;
272 if (likely(q
->info
.si_code
!= SI_TIMER
)) {
273 sigaddset(&retain
, sig
);
275 sigdelset(&signal
, sig
);
276 list_del_init(&q
->list
);
281 sigorsets(&pending
->signal
, &signal
, &retain
);
284 void flush_itimer_signals(void)
286 struct task_struct
*tsk
= current
;
289 spin_lock_irqsave(&tsk
->sighand
->siglock
, flags
);
290 __flush_itimer_signals(&tsk
->pending
);
291 __flush_itimer_signals(&tsk
->signal
->shared_pending
);
292 spin_unlock_irqrestore(&tsk
->sighand
->siglock
, flags
);
295 void ignore_signals(struct task_struct
*t
)
299 for (i
= 0; i
< _NSIG
; ++i
)
300 t
->sighand
->action
[i
].sa
.sa_handler
= SIG_IGN
;
306 * Flush all handlers for a task.
310 flush_signal_handlers(struct task_struct
*t
, int force_default
)
313 struct k_sigaction
*ka
= &t
->sighand
->action
[0];
314 for (i
= _NSIG
; i
!= 0 ; i
--) {
315 if (force_default
|| ka
->sa
.sa_handler
!= SIG_IGN
)
316 ka
->sa
.sa_handler
= SIG_DFL
;
318 sigemptyset(&ka
->sa
.sa_mask
);
323 int unhandled_signal(struct task_struct
*tsk
, int sig
)
325 void __user
*handler
= tsk
->sighand
->action
[sig
-1].sa
.sa_handler
;
326 if (is_global_init(tsk
))
328 if (handler
!= SIG_IGN
&& handler
!= SIG_DFL
)
330 return !tracehook_consider_fatal_signal(tsk
, sig
);
334 /* Notify the system that a driver wants to block all signals for this
335 * process, and wants to be notified if any signals at all were to be
336 * sent/acted upon. If the notifier routine returns non-zero, then the
337 * signal will be acted upon after all. If the notifier routine returns 0,
338 * then then signal will be blocked. Only one block per process is
339 * allowed. priv is a pointer to private data that the notifier routine
340 * can use to determine if the signal should be blocked or not. */
343 block_all_signals(int (*notifier
)(void *priv
), void *priv
, sigset_t
*mask
)
347 spin_lock_irqsave(¤t
->sighand
->siglock
, flags
);
348 current
->notifier_mask
= mask
;
349 current
->notifier_data
= priv
;
350 current
->notifier
= notifier
;
351 spin_unlock_irqrestore(¤t
->sighand
->siglock
, flags
);
354 /* Notify the system that blocking has ended. */
357 unblock_all_signals(void)
361 spin_lock_irqsave(¤t
->sighand
->siglock
, flags
);
362 current
->notifier
= NULL
;
363 current
->notifier_data
= NULL
;
365 spin_unlock_irqrestore(¤t
->sighand
->siglock
, flags
);
368 static void collect_signal(int sig
, struct sigpending
*list
, siginfo_t
*info
)
370 struct sigqueue
*q
, *first
= NULL
;
373 * Collect the siginfo appropriate to this signal. Check if
374 * there is another siginfo for the same signal.
376 list_for_each_entry(q
, &list
->list
, list
) {
377 if (q
->info
.si_signo
== sig
) {
384 sigdelset(&list
->signal
, sig
);
388 list_del_init(&first
->list
);
389 copy_siginfo(info
, &first
->info
);
390 __sigqueue_free(first
);
392 /* Ok, it wasn't in the queue. This must be
393 a fast-pathed signal or we must have been
394 out of queue space. So zero out the info.
396 info
->si_signo
= sig
;
404 static int __dequeue_signal(struct sigpending
*pending
, sigset_t
*mask
,
407 int sig
= next_signal(pending
, mask
);
410 if (current
->notifier
) {
411 if (sigismember(current
->notifier_mask
, sig
)) {
412 if (!(current
->notifier
)(current
->notifier_data
)) {
413 clear_thread_flag(TIF_SIGPENDING
);
419 collect_signal(sig
, pending
, info
);
426 * Dequeue a signal and return the element to the caller, which is
427 * expected to free it.
429 * All callers have to hold the siglock.
431 int dequeue_signal(struct task_struct
*tsk
, sigset_t
*mask
, siginfo_t
*info
)
435 /* We only dequeue private signals from ourselves, we don't let
436 * signalfd steal them
438 signr
= __dequeue_signal(&tsk
->pending
, mask
, info
);
440 signr
= __dequeue_signal(&tsk
->signal
->shared_pending
,
445 * itimers are process shared and we restart periodic
446 * itimers in the signal delivery path to prevent DoS
447 * attacks in the high resolution timer case. This is
448 * compliant with the old way of self restarting
449 * itimers, as the SIGALRM is a legacy signal and only
450 * queued once. Changing the restart behaviour to
451 * restart the timer in the signal dequeue path is
452 * reducing the timer noise on heavy loaded !highres
455 if (unlikely(signr
== SIGALRM
)) {
456 struct hrtimer
*tmr
= &tsk
->signal
->real_timer
;
458 if (!hrtimer_is_queued(tmr
) &&
459 tsk
->signal
->it_real_incr
.tv64
!= 0) {
460 hrtimer_forward(tmr
, tmr
->base
->get_time(),
461 tsk
->signal
->it_real_incr
);
462 hrtimer_restart(tmr
);
471 if (unlikely(sig_kernel_stop(signr
))) {
473 * Set a marker that we have dequeued a stop signal. Our
474 * caller might release the siglock and then the pending
475 * stop signal it is about to process is no longer in the
476 * pending bitmasks, but must still be cleared by a SIGCONT
477 * (and overruled by a SIGKILL). So those cases clear this
478 * shared flag after we've set it. Note that this flag may
479 * remain set after the signal we return is ignored or
480 * handled. That doesn't matter because its only purpose
481 * is to alert stop-signal processing code when another
482 * processor has come along and cleared the flag.
484 tsk
->signal
->flags
|= SIGNAL_STOP_DEQUEUED
;
486 if ((info
->si_code
& __SI_MASK
) == __SI_TIMER
&& info
->si_sys_private
) {
488 * Release the siglock to ensure proper locking order
489 * of timer locks outside of siglocks. Note, we leave
490 * irqs disabled here, since the posix-timers code is
491 * about to disable them again anyway.
493 spin_unlock(&tsk
->sighand
->siglock
);
494 do_schedule_next_timer(info
);
495 spin_lock(&tsk
->sighand
->siglock
);
501 * Tell a process that it has a new active signal..
503 * NOTE! we rely on the previous spin_lock to
504 * lock interrupts for us! We can only be called with
505 * "siglock" held, and the local interrupt must
506 * have been disabled when that got acquired!
508 * No need to set need_resched since signal event passing
509 * goes through ->blocked
511 void signal_wake_up(struct task_struct
*t
, int resume
)
515 set_tsk_thread_flag(t
, TIF_SIGPENDING
);
518 * For SIGKILL, we want to wake it up in the stopped/traced/killable
519 * case. We don't check t->state here because there is a race with it
520 * executing another processor and just now entering stopped state.
521 * By using wake_up_state, we ensure the process will wake up and
522 * handle its death signal.
524 mask
= TASK_INTERRUPTIBLE
;
526 mask
|= TASK_WAKEKILL
;
527 if (!wake_up_state(t
, mask
))
532 * Remove signals in mask from the pending set and queue.
533 * Returns 1 if any signals were found.
535 * All callers must be holding the siglock.
537 * This version takes a sigset mask and looks at all signals,
538 * not just those in the first mask word.
540 static int rm_from_queue_full(sigset_t
*mask
, struct sigpending
*s
)
542 struct sigqueue
*q
, *n
;
545 sigandsets(&m
, mask
, &s
->signal
);
546 if (sigisemptyset(&m
))
549 signandsets(&s
->signal
, &s
->signal
, mask
);
550 list_for_each_entry_safe(q
, n
, &s
->list
, list
) {
551 if (sigismember(mask
, q
->info
.si_signo
)) {
552 list_del_init(&q
->list
);
559 * Remove signals in mask from the pending set and queue.
560 * Returns 1 if any signals were found.
562 * All callers must be holding the siglock.
564 static int rm_from_queue(unsigned long mask
, struct sigpending
*s
)
566 struct sigqueue
*q
, *n
;
568 if (!sigtestsetmask(&s
->signal
, mask
))
571 sigdelsetmask(&s
->signal
, mask
);
572 list_for_each_entry_safe(q
, n
, &s
->list
, list
) {
573 if (q
->info
.si_signo
< SIGRTMIN
&&
574 (mask
& sigmask(q
->info
.si_signo
))) {
575 list_del_init(&q
->list
);
583 * Bad permissions for sending the signal
584 * - the caller must hold at least the RCU read lock
586 static int check_kill_permission(int sig
, struct siginfo
*info
,
587 struct task_struct
*t
)
589 const struct cred
*cred
= current_cred(), *tcred
;
593 if (!valid_signal(sig
))
596 if (info
!= SEND_SIG_NOINFO
&& (is_si_special(info
) || SI_FROMKERNEL(info
)))
599 error
= audit_signal_info(sig
, t
); /* Let audit system see the signal */
603 tcred
= __task_cred(t
);
604 if ((cred
->euid
^ tcred
->suid
) &&
605 (cred
->euid
^ tcred
->uid
) &&
606 (cred
->uid
^ tcred
->suid
) &&
607 (cred
->uid
^ tcred
->uid
) &&
608 !capable(CAP_KILL
)) {
611 sid
= task_session(t
);
613 * We don't return the error if sid == NULL. The
614 * task was unhashed, the caller must notice this.
616 if (!sid
|| sid
== task_session(current
))
623 return security_task_kill(t
, info
, sig
, 0);
627 * Handle magic process-wide effects of stop/continue signals. Unlike
628 * the signal actions, these happen immediately at signal-generation
629 * time regardless of blocking, ignoring, or handling. This does the
630 * actual continuing for SIGCONT, but not the actual stopping for stop
631 * signals. The process stop is done as a signal action for SIG_DFL.
633 * Returns true if the signal should be actually delivered, otherwise
634 * it should be dropped.
636 static int prepare_signal(int sig
, struct task_struct
*p
, int from_ancestor_ns
)
638 struct signal_struct
*signal
= p
->signal
;
639 struct task_struct
*t
;
641 if (unlikely(signal
->flags
& SIGNAL_GROUP_EXIT
)) {
643 * The process is in the middle of dying, nothing to do.
645 } else if (sig_kernel_stop(sig
)) {
647 * This is a stop signal. Remove SIGCONT from all queues.
649 rm_from_queue(sigmask(SIGCONT
), &signal
->shared_pending
);
652 rm_from_queue(sigmask(SIGCONT
), &t
->pending
);
653 } while_each_thread(p
, t
);
654 } else if (sig
== SIGCONT
) {
657 * Remove all stop signals from all queues,
658 * and wake all threads.
660 rm_from_queue(SIG_KERNEL_STOP_MASK
, &signal
->shared_pending
);
664 rm_from_queue(SIG_KERNEL_STOP_MASK
, &t
->pending
);
666 * If there is a handler for SIGCONT, we must make
667 * sure that no thread returns to user mode before
668 * we post the signal, in case it was the only
669 * thread eligible to run the signal handler--then
670 * it must not do anything between resuming and
671 * running the handler. With the TIF_SIGPENDING
672 * flag set, the thread will pause and acquire the
673 * siglock that we hold now and until we've queued
674 * the pending signal.
676 * Wake up the stopped thread _after_ setting
679 state
= __TASK_STOPPED
;
680 if (sig_user_defined(t
, SIGCONT
) && !sigismember(&t
->blocked
, SIGCONT
)) {
681 set_tsk_thread_flag(t
, TIF_SIGPENDING
);
682 state
|= TASK_INTERRUPTIBLE
;
684 wake_up_state(t
, state
);
685 } while_each_thread(p
, t
);
688 * Notify the parent with CLD_CONTINUED if we were stopped.
690 * If we were in the middle of a group stop, we pretend it
691 * was already finished, and then continued. Since SIGCHLD
692 * doesn't queue we report only CLD_STOPPED, as if the next
693 * CLD_CONTINUED was dropped.
696 if (signal
->flags
& SIGNAL_STOP_STOPPED
)
697 why
|= SIGNAL_CLD_CONTINUED
;
698 else if (signal
->group_stop_count
)
699 why
|= SIGNAL_CLD_STOPPED
;
703 * The first thread which returns from finish_stop()
704 * will take ->siglock, notice SIGNAL_CLD_MASK, and
705 * notify its parent. See get_signal_to_deliver().
707 signal
->flags
= why
| SIGNAL_STOP_CONTINUED
;
708 signal
->group_stop_count
= 0;
709 signal
->group_exit_code
= 0;
712 * We are not stopped, but there could be a stop
713 * signal in the middle of being processed after
714 * being removed from the queue. Clear that too.
716 signal
->flags
&= ~SIGNAL_STOP_DEQUEUED
;
720 return !sig_ignored(p
, sig
, from_ancestor_ns
);
724 * Test if P wants to take SIG. After we've checked all threads with this,
725 * it's equivalent to finding no threads not blocking SIG. Any threads not
726 * blocking SIG were ruled out because they are not running and already
727 * have pending signals. Such threads will dequeue from the shared queue
728 * as soon as they're available, so putting the signal on the shared queue
729 * will be equivalent to sending it to one such thread.
731 static inline int wants_signal(int sig
, struct task_struct
*p
)
733 if (sigismember(&p
->blocked
, sig
))
735 if (p
->flags
& PF_EXITING
)
739 if (task_is_stopped_or_traced(p
))
741 return task_curr(p
) || !signal_pending(p
);
744 static void complete_signal(int sig
, struct task_struct
*p
, int group
)
746 struct signal_struct
*signal
= p
->signal
;
747 struct task_struct
*t
;
750 * Now find a thread we can wake up to take the signal off the queue.
752 * If the main thread wants the signal, it gets first crack.
753 * Probably the least surprising to the average bear.
755 if (wants_signal(sig
, p
))
757 else if (!group
|| thread_group_empty(p
))
759 * There is just one thread and it does not need to be woken.
760 * It will dequeue unblocked signals before it runs again.
765 * Otherwise try to find a suitable thread.
767 t
= signal
->curr_target
;
768 while (!wants_signal(sig
, t
)) {
770 if (t
== signal
->curr_target
)
772 * No thread needs to be woken.
773 * Any eligible threads will see
774 * the signal in the queue soon.
778 signal
->curr_target
= t
;
782 * Found a killable thread. If the signal will be fatal,
783 * then start taking the whole group down immediately.
785 if (sig_fatal(p
, sig
) &&
786 !(signal
->flags
& (SIGNAL_UNKILLABLE
| SIGNAL_GROUP_EXIT
)) &&
787 !sigismember(&t
->real_blocked
, sig
) &&
789 !tracehook_consider_fatal_signal(t
, sig
))) {
791 * This signal will be fatal to the whole group.
793 if (!sig_kernel_coredump(sig
)) {
795 * Start a group exit and wake everybody up.
796 * This way we don't have other threads
797 * running and doing things after a slower
798 * thread has the fatal signal pending.
800 signal
->flags
= SIGNAL_GROUP_EXIT
;
801 signal
->group_exit_code
= sig
;
802 signal
->group_stop_count
= 0;
805 sigaddset(&t
->pending
.signal
, SIGKILL
);
806 signal_wake_up(t
, 1);
807 } while_each_thread(p
, t
);
813 * The signal is already in the shared-pending queue.
814 * Tell the chosen thread to wake up and dequeue it.
816 signal_wake_up(t
, sig
== SIGKILL
);
820 static inline int legacy_queue(struct sigpending
*signals
, int sig
)
822 return (sig
< SIGRTMIN
) && sigismember(&signals
->signal
, sig
);
825 static int __send_signal(int sig
, struct siginfo
*info
, struct task_struct
*t
,
826 int group
, int from_ancestor_ns
)
828 struct sigpending
*pending
;
831 trace_sched_signal_send(sig
, t
);
833 assert_spin_locked(&t
->sighand
->siglock
);
835 if (!prepare_signal(sig
, t
, from_ancestor_ns
))
838 pending
= group
? &t
->signal
->shared_pending
: &t
->pending
;
840 * Short-circuit ignored signals and support queuing
841 * exactly one non-rt signal, so that we can get more
842 * detailed information about the cause of the signal.
844 if (legacy_queue(pending
, sig
))
847 * fast-pathed signals for kernel-internal things like SIGSTOP
850 if (info
== SEND_SIG_FORCED
)
853 /* Real-time signals must be queued if sent by sigqueue, or
854 some other real-time mechanism. It is implementation
855 defined whether kill() does so. We attempt to do so, on
856 the principle of least surprise, but since kill is not
857 allowed to fail with EAGAIN when low on memory we just
858 make sure at least one signal gets delivered and don't
859 pass on the info struct. */
861 q
= __sigqueue_alloc(t
, GFP_ATOMIC
, (sig
< SIGRTMIN
&&
862 (is_si_special(info
) ||
863 info
->si_code
>= 0)));
865 list_add_tail(&q
->list
, &pending
->list
);
866 switch ((unsigned long) info
) {
867 case (unsigned long) SEND_SIG_NOINFO
:
868 q
->info
.si_signo
= sig
;
869 q
->info
.si_errno
= 0;
870 q
->info
.si_code
= SI_USER
;
871 q
->info
.si_pid
= task_tgid_nr_ns(current
,
872 task_active_pid_ns(t
));
873 q
->info
.si_uid
= current_uid();
875 case (unsigned long) SEND_SIG_PRIV
:
876 q
->info
.si_signo
= sig
;
877 q
->info
.si_errno
= 0;
878 q
->info
.si_code
= SI_KERNEL
;
883 copy_siginfo(&q
->info
, info
);
884 if (from_ancestor_ns
)
888 } else if (!is_si_special(info
)) {
889 if (sig
>= SIGRTMIN
&& info
->si_code
!= SI_USER
)
891 * Queue overflow, abort. We may abort if the signal was rt
892 * and sent by user using something other than kill().
898 signalfd_notify(t
, sig
);
899 sigaddset(&pending
->signal
, sig
);
900 complete_signal(sig
, t
, group
);
904 static int send_signal(int sig
, struct siginfo
*info
, struct task_struct
*t
,
907 int from_ancestor_ns
= 0;
910 if (!is_si_special(info
) && SI_FROMUSER(info
) &&
911 task_pid_nr_ns(current
, task_active_pid_ns(t
)) <= 0)
912 from_ancestor_ns
= 1;
915 return __send_signal(sig
, info
, t
, group
, from_ancestor_ns
);
918 int print_fatal_signals
;
920 static void print_fatal_signal(struct pt_regs
*regs
, int signr
)
922 printk("%s/%d: potentially unexpected fatal signal %d.\n",
923 current
->comm
, task_pid_nr(current
), signr
);
925 #if defined(__i386__) && !defined(__arch_um__)
926 printk("code at %08lx: ", regs
->ip
);
929 for (i
= 0; i
< 16; i
++) {
932 __get_user(insn
, (unsigned char *)(regs
->ip
+ i
));
933 printk("%02x ", insn
);
943 static int __init
setup_print_fatal_signals(char *str
)
945 get_option (&str
, &print_fatal_signals
);
950 __setup("print-fatal-signals=", setup_print_fatal_signals
);
953 __group_send_sig_info(int sig
, struct siginfo
*info
, struct task_struct
*p
)
955 return send_signal(sig
, info
, p
, 1);
959 specific_send_sig_info(int sig
, struct siginfo
*info
, struct task_struct
*t
)
961 return send_signal(sig
, info
, t
, 0);
965 * Force a signal that the process can't ignore: if necessary
966 * we unblock the signal and change any SIG_IGN to SIG_DFL.
968 * Note: If we unblock the signal, we always reset it to SIG_DFL,
969 * since we do not want to have a signal handler that was blocked
970 * be invoked when user space had explicitly blocked it.
972 * We don't want to have recursive SIGSEGV's etc, for example,
973 * that is why we also clear SIGNAL_UNKILLABLE.
976 force_sig_info(int sig
, struct siginfo
*info
, struct task_struct
*t
)
978 unsigned long int flags
;
979 int ret
, blocked
, ignored
;
980 struct k_sigaction
*action
;
982 spin_lock_irqsave(&t
->sighand
->siglock
, flags
);
983 action
= &t
->sighand
->action
[sig
-1];
984 ignored
= action
->sa
.sa_handler
== SIG_IGN
;
985 blocked
= sigismember(&t
->blocked
, sig
);
986 if (blocked
|| ignored
) {
987 action
->sa
.sa_handler
= SIG_DFL
;
989 sigdelset(&t
->blocked
, sig
);
990 recalc_sigpending_and_wake(t
);
993 if (action
->sa
.sa_handler
== SIG_DFL
)
994 t
->signal
->flags
&= ~SIGNAL_UNKILLABLE
;
995 ret
= specific_send_sig_info(sig
, info
, t
);
996 spin_unlock_irqrestore(&t
->sighand
->siglock
, flags
);
1002 force_sig_specific(int sig
, struct task_struct
*t
)
1004 force_sig_info(sig
, SEND_SIG_FORCED
, t
);
1008 * Nuke all other threads in the group.
1010 void zap_other_threads(struct task_struct
*p
)
1012 struct task_struct
*t
;
1014 p
->signal
->group_stop_count
= 0;
1016 for (t
= next_thread(p
); t
!= p
; t
= next_thread(t
)) {
1018 * Don't bother with already dead threads
1023 /* SIGKILL will be handled before any pending SIGSTOP */
1024 sigaddset(&t
->pending
.signal
, SIGKILL
);
1025 signal_wake_up(t
, 1);
1029 int __fatal_signal_pending(struct task_struct
*tsk
)
1031 return sigismember(&tsk
->pending
.signal
, SIGKILL
);
1033 EXPORT_SYMBOL(__fatal_signal_pending
);
1035 struct sighand_struct
*lock_task_sighand(struct task_struct
*tsk
, unsigned long *flags
)
1037 struct sighand_struct
*sighand
;
1041 sighand
= rcu_dereference(tsk
->sighand
);
1042 if (unlikely(sighand
== NULL
))
1045 spin_lock_irqsave(&sighand
->siglock
, *flags
);
1046 if (likely(sighand
== tsk
->sighand
))
1048 spin_unlock_irqrestore(&sighand
->siglock
, *flags
);
1056 * send signal info to all the members of a group
1057 * - the caller must hold the RCU read lock at least
1059 int group_send_sig_info(int sig
, struct siginfo
*info
, struct task_struct
*p
)
1061 unsigned long flags
;
1064 ret
= check_kill_permission(sig
, info
, p
);
1068 if (lock_task_sighand(p
, &flags
)) {
1069 ret
= __group_send_sig_info(sig
, info
, p
);
1070 unlock_task_sighand(p
, &flags
);
1078 * __kill_pgrp_info() sends a signal to a process group: this is what the tty
1079 * control characters do (^C, ^Z etc)
1080 * - the caller must hold at least a readlock on tasklist_lock
1082 int __kill_pgrp_info(int sig
, struct siginfo
*info
, struct pid
*pgrp
)
1084 struct task_struct
*p
= NULL
;
1085 int retval
, success
;
1089 do_each_pid_task(pgrp
, PIDTYPE_PGID
, p
) {
1090 int err
= group_send_sig_info(sig
, info
, p
);
1093 } while_each_pid_task(pgrp
, PIDTYPE_PGID
, p
);
1094 return success
? 0 : retval
;
1097 int kill_pid_info(int sig
, struct siginfo
*info
, struct pid
*pid
)
1100 struct task_struct
*p
;
1104 p
= pid_task(pid
, PIDTYPE_PID
);
1106 error
= group_send_sig_info(sig
, info
, p
);
1107 if (unlikely(error
== -ESRCH
))
1109 * The task was unhashed in between, try again.
1110 * If it is dead, pid_task() will return NULL,
1111 * if we race with de_thread() it will find the
1122 kill_proc_info(int sig
, struct siginfo
*info
, pid_t pid
)
1126 error
= kill_pid_info(sig
, info
, find_vpid(pid
));
1131 /* like kill_pid_info(), but doesn't use uid/euid of "current" */
1132 int kill_pid_info_as_uid(int sig
, struct siginfo
*info
, struct pid
*pid
,
1133 uid_t uid
, uid_t euid
, u32 secid
)
1136 struct task_struct
*p
;
1137 const struct cred
*pcred
;
1139 if (!valid_signal(sig
))
1142 read_lock(&tasklist_lock
);
1143 p
= pid_task(pid
, PIDTYPE_PID
);
1148 pcred
= __task_cred(p
);
1149 if ((info
== SEND_SIG_NOINFO
||
1150 (!is_si_special(info
) && SI_FROMUSER(info
))) &&
1151 euid
!= pcred
->suid
&& euid
!= pcred
->uid
&&
1152 uid
!= pcred
->suid
&& uid
!= pcred
->uid
) {
1156 ret
= security_task_kill(p
, info
, sig
, secid
);
1159 if (sig
&& p
->sighand
) {
1160 unsigned long flags
;
1161 spin_lock_irqsave(&p
->sighand
->siglock
, flags
);
1162 ret
= __send_signal(sig
, info
, p
, 1, 0);
1163 spin_unlock_irqrestore(&p
->sighand
->siglock
, flags
);
1166 read_unlock(&tasklist_lock
);
1169 EXPORT_SYMBOL_GPL(kill_pid_info_as_uid
);
1172 * kill_something_info() interprets pid in interesting ways just like kill(2).
1174 * POSIX specifies that kill(-1,sig) is unspecified, but what we have
1175 * is probably wrong. Should make it like BSD or SYSV.
1178 static int kill_something_info(int sig
, struct siginfo
*info
, pid_t pid
)
1184 ret
= kill_pid_info(sig
, info
, find_vpid(pid
));
1189 read_lock(&tasklist_lock
);
1191 ret
= __kill_pgrp_info(sig
, info
,
1192 pid
? find_vpid(-pid
) : task_pgrp(current
));
1194 int retval
= 0, count
= 0;
1195 struct task_struct
* p
;
1197 for_each_process(p
) {
1198 if (task_pid_vnr(p
) > 1 &&
1199 !same_thread_group(p
, current
)) {
1200 int err
= group_send_sig_info(sig
, info
, p
);
1206 ret
= count
? retval
: -ESRCH
;
1208 read_unlock(&tasklist_lock
);
1214 * These are for backward compatibility with the rest of the kernel source.
1218 * The caller must ensure the task can't exit.
1221 send_sig_info(int sig
, struct siginfo
*info
, struct task_struct
*p
)
1224 unsigned long flags
;
1227 * Make sure legacy kernel users don't send in bad values
1228 * (normal paths check this in check_kill_permission).
1230 if (!valid_signal(sig
))
1233 spin_lock_irqsave(&p
->sighand
->siglock
, flags
);
1234 ret
= specific_send_sig_info(sig
, info
, p
);
1235 spin_unlock_irqrestore(&p
->sighand
->siglock
, flags
);
1239 #define __si_special(priv) \
1240 ((priv) ? SEND_SIG_PRIV : SEND_SIG_NOINFO)
1243 send_sig(int sig
, struct task_struct
*p
, int priv
)
1245 return send_sig_info(sig
, __si_special(priv
), p
);
1249 force_sig(int sig
, struct task_struct
*p
)
1251 force_sig_info(sig
, SEND_SIG_PRIV
, p
);
1255 * When things go south during signal handling, we
1256 * will force a SIGSEGV. And if the signal that caused
1257 * the problem was already a SIGSEGV, we'll want to
1258 * make sure we don't even try to deliver the signal..
1261 force_sigsegv(int sig
, struct task_struct
*p
)
1263 if (sig
== SIGSEGV
) {
1264 unsigned long flags
;
1265 spin_lock_irqsave(&p
->sighand
->siglock
, flags
);
1266 p
->sighand
->action
[sig
- 1].sa
.sa_handler
= SIG_DFL
;
1267 spin_unlock_irqrestore(&p
->sighand
->siglock
, flags
);
1269 force_sig(SIGSEGV
, p
);
1273 int kill_pgrp(struct pid
*pid
, int sig
, int priv
)
1277 read_lock(&tasklist_lock
);
1278 ret
= __kill_pgrp_info(sig
, __si_special(priv
), pid
);
1279 read_unlock(&tasklist_lock
);
1283 EXPORT_SYMBOL(kill_pgrp
);
1285 int kill_pid(struct pid
*pid
, int sig
, int priv
)
1287 return kill_pid_info(sig
, __si_special(priv
), pid
);
1289 EXPORT_SYMBOL(kill_pid
);
1292 * These functions support sending signals using preallocated sigqueue
1293 * structures. This is needed "because realtime applications cannot
1294 * afford to lose notifications of asynchronous events, like timer
1295 * expirations or I/O completions". In the case of Posix Timers
1296 * we allocate the sigqueue structure from the timer_create. If this
1297 * allocation fails we are able to report the failure to the application
1298 * with an EAGAIN error.
1301 struct sigqueue
*sigqueue_alloc(void)
1305 if ((q
= __sigqueue_alloc(current
, GFP_KERNEL
, 0)))
1306 q
->flags
|= SIGQUEUE_PREALLOC
;
1310 void sigqueue_free(struct sigqueue
*q
)
1312 unsigned long flags
;
1313 spinlock_t
*lock
= ¤t
->sighand
->siglock
;
1315 BUG_ON(!(q
->flags
& SIGQUEUE_PREALLOC
));
1317 * We must hold ->siglock while testing q->list
1318 * to serialize with collect_signal() or with
1319 * __exit_signal()->flush_sigqueue().
1321 spin_lock_irqsave(lock
, flags
);
1322 q
->flags
&= ~SIGQUEUE_PREALLOC
;
1324 * If it is queued it will be freed when dequeued,
1325 * like the "regular" sigqueue.
1327 if (!list_empty(&q
->list
))
1329 spin_unlock_irqrestore(lock
, flags
);
1335 int send_sigqueue(struct sigqueue
*q
, struct task_struct
*t
, int group
)
1337 int sig
= q
->info
.si_signo
;
1338 struct sigpending
*pending
;
1339 unsigned long flags
;
1342 BUG_ON(!(q
->flags
& SIGQUEUE_PREALLOC
));
1345 if (!likely(lock_task_sighand(t
, &flags
)))
1348 ret
= 1; /* the signal is ignored */
1349 if (!prepare_signal(sig
, t
, 0))
1353 if (unlikely(!list_empty(&q
->list
))) {
1355 * If an SI_TIMER entry is already queue just increment
1356 * the overrun count.
1358 BUG_ON(q
->info
.si_code
!= SI_TIMER
);
1359 q
->info
.si_overrun
++;
1362 q
->info
.si_overrun
= 0;
1364 signalfd_notify(t
, sig
);
1365 pending
= group
? &t
->signal
->shared_pending
: &t
->pending
;
1366 list_add_tail(&q
->list
, &pending
->list
);
1367 sigaddset(&pending
->signal
, sig
);
1368 complete_signal(sig
, t
, group
);
1370 unlock_task_sighand(t
, &flags
);
1376 * Wake up any threads in the parent blocked in wait* syscalls.
1378 static inline void __wake_up_parent(struct task_struct
*p
,
1379 struct task_struct
*parent
)
1381 wake_up_interruptible_sync(&parent
->signal
->wait_chldexit
);
1385 * Let a parent know about the death of a child.
1386 * For a stopped/continued status change, use do_notify_parent_cldstop instead.
1388 * Returns -1 if our parent ignored us and so we've switched to
1389 * self-reaping, or else @sig.
1391 int do_notify_parent(struct task_struct
*tsk
, int sig
)
1393 struct siginfo info
;
1394 unsigned long flags
;
1395 struct sighand_struct
*psig
;
1400 /* do_notify_parent_cldstop should have been called instead. */
1401 BUG_ON(task_is_stopped_or_traced(tsk
));
1403 BUG_ON(!tsk
->ptrace
&&
1404 (tsk
->group_leader
!= tsk
|| !thread_group_empty(tsk
)));
1406 info
.si_signo
= sig
;
1409 * we are under tasklist_lock here so our parent is tied to
1410 * us and cannot exit and release its namespace.
1412 * the only it can is to switch its nsproxy with sys_unshare,
1413 * bu uncharing pid namespaces is not allowed, so we'll always
1414 * see relevant namespace
1416 * write_lock() currently calls preempt_disable() which is the
1417 * same as rcu_read_lock(), but according to Oleg, this is not
1418 * correct to rely on this
1421 info
.si_pid
= task_pid_nr_ns(tsk
, tsk
->parent
->nsproxy
->pid_ns
);
1422 info
.si_uid
= __task_cred(tsk
)->uid
;
1425 info
.si_utime
= cputime_to_clock_t(cputime_add(tsk
->utime
,
1426 tsk
->signal
->utime
));
1427 info
.si_stime
= cputime_to_clock_t(cputime_add(tsk
->stime
,
1428 tsk
->signal
->stime
));
1430 info
.si_status
= tsk
->exit_code
& 0x7f;
1431 if (tsk
->exit_code
& 0x80)
1432 info
.si_code
= CLD_DUMPED
;
1433 else if (tsk
->exit_code
& 0x7f)
1434 info
.si_code
= CLD_KILLED
;
1436 info
.si_code
= CLD_EXITED
;
1437 info
.si_status
= tsk
->exit_code
>> 8;
1440 psig
= tsk
->parent
->sighand
;
1441 spin_lock_irqsave(&psig
->siglock
, flags
);
1442 if (!tsk
->ptrace
&& sig
== SIGCHLD
&&
1443 (psig
->action
[SIGCHLD
-1].sa
.sa_handler
== SIG_IGN
||
1444 (psig
->action
[SIGCHLD
-1].sa
.sa_flags
& SA_NOCLDWAIT
))) {
1446 * We are exiting and our parent doesn't care. POSIX.1
1447 * defines special semantics for setting SIGCHLD to SIG_IGN
1448 * or setting the SA_NOCLDWAIT flag: we should be reaped
1449 * automatically and not left for our parent's wait4 call.
1450 * Rather than having the parent do it as a magic kind of
1451 * signal handler, we just set this to tell do_exit that we
1452 * can be cleaned up without becoming a zombie. Note that
1453 * we still call __wake_up_parent in this case, because a
1454 * blocked sys_wait4 might now return -ECHILD.
1456 * Whether we send SIGCHLD or not for SA_NOCLDWAIT
1457 * is implementation-defined: we do (if you don't want
1458 * it, just use SIG_IGN instead).
1460 ret
= tsk
->exit_signal
= -1;
1461 if (psig
->action
[SIGCHLD
-1].sa
.sa_handler
== SIG_IGN
)
1464 if (valid_signal(sig
) && sig
> 0)
1465 __group_send_sig_info(sig
, &info
, tsk
->parent
);
1466 __wake_up_parent(tsk
, tsk
->parent
);
1467 spin_unlock_irqrestore(&psig
->siglock
, flags
);
1472 static void do_notify_parent_cldstop(struct task_struct
*tsk
, int why
)
1474 struct siginfo info
;
1475 unsigned long flags
;
1476 struct task_struct
*parent
;
1477 struct sighand_struct
*sighand
;
1479 if (tsk
->ptrace
& PT_PTRACED
)
1480 parent
= tsk
->parent
;
1482 tsk
= tsk
->group_leader
;
1483 parent
= tsk
->real_parent
;
1486 info
.si_signo
= SIGCHLD
;
1489 * see comment in do_notify_parent() abot the following 3 lines
1492 info
.si_pid
= task_pid_nr_ns(tsk
, tsk
->parent
->nsproxy
->pid_ns
);
1493 info
.si_uid
= __task_cred(tsk
)->uid
;
1496 info
.si_utime
= cputime_to_clock_t(tsk
->utime
);
1497 info
.si_stime
= cputime_to_clock_t(tsk
->stime
);
1502 info
.si_status
= SIGCONT
;
1505 info
.si_status
= tsk
->signal
->group_exit_code
& 0x7f;
1508 info
.si_status
= tsk
->exit_code
& 0x7f;
1514 sighand
= parent
->sighand
;
1515 spin_lock_irqsave(&sighand
->siglock
, flags
);
1516 if (sighand
->action
[SIGCHLD
-1].sa
.sa_handler
!= SIG_IGN
&&
1517 !(sighand
->action
[SIGCHLD
-1].sa
.sa_flags
& SA_NOCLDSTOP
))
1518 __group_send_sig_info(SIGCHLD
, &info
, parent
);
1520 * Even if SIGCHLD is not generated, we must wake up wait4 calls.
1522 __wake_up_parent(tsk
, parent
);
1523 spin_unlock_irqrestore(&sighand
->siglock
, flags
);
1526 static inline int may_ptrace_stop(void)
1528 if (!likely(current
->ptrace
& PT_PTRACED
))
1531 * Are we in the middle of do_coredump?
1532 * If so and our tracer is also part of the coredump stopping
1533 * is a deadlock situation, and pointless because our tracer
1534 * is dead so don't allow us to stop.
1535 * If SIGKILL was already sent before the caller unlocked
1536 * ->siglock we must see ->core_state != NULL. Otherwise it
1537 * is safe to enter schedule().
1539 if (unlikely(current
->mm
->core_state
) &&
1540 unlikely(current
->mm
== current
->parent
->mm
))
1547 * Return nonzero if there is a SIGKILL that should be waking us up.
1548 * Called with the siglock held.
1550 static int sigkill_pending(struct task_struct
*tsk
)
1552 return sigismember(&tsk
->pending
.signal
, SIGKILL
) ||
1553 sigismember(&tsk
->signal
->shared_pending
.signal
, SIGKILL
);
1557 * This must be called with current->sighand->siglock held.
1559 * This should be the path for all ptrace stops.
1560 * We always set current->last_siginfo while stopped here.
1561 * That makes it a way to test a stopped process for
1562 * being ptrace-stopped vs being job-control-stopped.
1564 * If we actually decide not to stop at all because the tracer
1565 * is gone, we keep current->exit_code unless clear_code.
1567 static void ptrace_stop(int exit_code
, int clear_code
, siginfo_t
*info
)
1569 if (arch_ptrace_stop_needed(exit_code
, info
)) {
1571 * The arch code has something special to do before a
1572 * ptrace stop. This is allowed to block, e.g. for faults
1573 * on user stack pages. We can't keep the siglock while
1574 * calling arch_ptrace_stop, so we must release it now.
1575 * To preserve proper semantics, we must do this before
1576 * any signal bookkeeping like checking group_stop_count.
1577 * Meanwhile, a SIGKILL could come in before we retake the
1578 * siglock. That must prevent us from sleeping in TASK_TRACED.
1579 * So after regaining the lock, we must check for SIGKILL.
1581 spin_unlock_irq(¤t
->sighand
->siglock
);
1582 arch_ptrace_stop(exit_code
, info
);
1583 spin_lock_irq(¤t
->sighand
->siglock
);
1584 if (sigkill_pending(current
))
1589 * If there is a group stop in progress,
1590 * we must participate in the bookkeeping.
1592 if (current
->signal
->group_stop_count
> 0)
1593 --current
->signal
->group_stop_count
;
1595 current
->last_siginfo
= info
;
1596 current
->exit_code
= exit_code
;
1598 /* Let the debugger run. */
1599 __set_current_state(TASK_TRACED
);
1600 spin_unlock_irq(¤t
->sighand
->siglock
);
1601 read_lock(&tasklist_lock
);
1602 if (may_ptrace_stop()) {
1603 do_notify_parent_cldstop(current
, CLD_TRAPPED
);
1605 * Don't want to allow preemption here, because
1606 * sys_ptrace() needs this task to be inactive.
1608 * XXX: implement read_unlock_no_resched().
1611 read_unlock(&tasklist_lock
);
1612 preempt_enable_no_resched();
1616 * By the time we got the lock, our tracer went away.
1617 * Don't drop the lock yet, another tracer may come.
1619 __set_current_state(TASK_RUNNING
);
1621 current
->exit_code
= 0;
1622 read_unlock(&tasklist_lock
);
1626 * While in TASK_TRACED, we were considered "frozen enough".
1627 * Now that we woke up, it's crucial if we're supposed to be
1628 * frozen that we freeze now before running anything substantial.
1633 * We are back. Now reacquire the siglock before touching
1634 * last_siginfo, so that we are sure to have synchronized with
1635 * any signal-sending on another CPU that wants to examine it.
1637 spin_lock_irq(¤t
->sighand
->siglock
);
1638 current
->last_siginfo
= NULL
;
1641 * Queued signals ignored us while we were stopped for tracing.
1642 * So check for any that we should take before resuming user mode.
1643 * This sets TIF_SIGPENDING, but never clears it.
1645 recalc_sigpending_tsk(current
);
1648 void ptrace_notify(int exit_code
)
1652 BUG_ON((exit_code
& (0x7f | ~0xffff)) != SIGTRAP
);
1654 memset(&info
, 0, sizeof info
);
1655 info
.si_signo
= SIGTRAP
;
1656 info
.si_code
= exit_code
;
1657 info
.si_pid
= task_pid_vnr(current
);
1658 info
.si_uid
= current_uid();
1660 /* Let the debugger run. */
1661 spin_lock_irq(¤t
->sighand
->siglock
);
1662 ptrace_stop(exit_code
, 1, &info
);
1663 spin_unlock_irq(¤t
->sighand
->siglock
);
1667 finish_stop(int stop_count
)
1670 * If there are no other threads in the group, or if there is
1671 * a group stop in progress and we are the last to stop,
1672 * report to the parent. When ptraced, every thread reports itself.
1674 if (tracehook_notify_jctl(stop_count
== 0, CLD_STOPPED
)) {
1675 read_lock(&tasklist_lock
);
1676 do_notify_parent_cldstop(current
, CLD_STOPPED
);
1677 read_unlock(&tasklist_lock
);
1682 } while (try_to_freeze());
1684 * Now we don't run again until continued.
1686 current
->exit_code
= 0;
1690 * This performs the stopping for SIGSTOP and other stop signals.
1691 * We have to stop all threads in the thread group.
1692 * Returns nonzero if we've actually stopped and released the siglock.
1693 * Returns zero if we didn't stop and still hold the siglock.
1695 static int do_signal_stop(int signr
)
1697 struct signal_struct
*sig
= current
->signal
;
1700 if (sig
->group_stop_count
> 0) {
1702 * There is a group stop in progress. We don't need to
1703 * start another one.
1705 stop_count
= --sig
->group_stop_count
;
1707 struct task_struct
*t
;
1709 if (!likely(sig
->flags
& SIGNAL_STOP_DEQUEUED
) ||
1710 unlikely(signal_group_exit(sig
)))
1713 * There is no group stop already in progress.
1714 * We must initiate one now.
1716 sig
->group_exit_code
= signr
;
1719 for (t
= next_thread(current
); t
!= current
; t
= next_thread(t
))
1721 * Setting state to TASK_STOPPED for a group
1722 * stop is always done with the siglock held,
1723 * so this check has no races.
1725 if (!(t
->flags
& PF_EXITING
) &&
1726 !task_is_stopped_or_traced(t
)) {
1728 signal_wake_up(t
, 0);
1730 sig
->group_stop_count
= stop_count
;
1733 if (stop_count
== 0)
1734 sig
->flags
= SIGNAL_STOP_STOPPED
;
1735 current
->exit_code
= sig
->group_exit_code
;
1736 __set_current_state(TASK_STOPPED
);
1738 spin_unlock_irq(¤t
->sighand
->siglock
);
1739 finish_stop(stop_count
);
1743 static int ptrace_signal(int signr
, siginfo_t
*info
,
1744 struct pt_regs
*regs
, void *cookie
)
1746 if (!(current
->ptrace
& PT_PTRACED
))
1749 ptrace_signal_deliver(regs
, cookie
);
1751 /* Let the debugger run. */
1752 ptrace_stop(signr
, 0, info
);
1754 /* We're back. Did the debugger cancel the sig? */
1755 signr
= current
->exit_code
;
1759 current
->exit_code
= 0;
1761 /* Update the siginfo structure if the signal has
1762 changed. If the debugger wanted something
1763 specific in the siginfo structure then it should
1764 have updated *info via PTRACE_SETSIGINFO. */
1765 if (signr
!= info
->si_signo
) {
1766 info
->si_signo
= signr
;
1768 info
->si_code
= SI_USER
;
1769 info
->si_pid
= task_pid_vnr(current
->parent
);
1770 info
->si_uid
= task_uid(current
->parent
);
1773 /* If the (new) signal is now blocked, requeue it. */
1774 if (sigismember(¤t
->blocked
, signr
)) {
1775 specific_send_sig_info(signr
, info
, current
);
1782 int get_signal_to_deliver(siginfo_t
*info
, struct k_sigaction
*return_ka
,
1783 struct pt_regs
*regs
, void *cookie
)
1785 struct sighand_struct
*sighand
= current
->sighand
;
1786 struct signal_struct
*signal
= current
->signal
;
1791 * We'll jump back here after any time we were stopped in TASK_STOPPED.
1792 * While in TASK_STOPPED, we were considered "frozen enough".
1793 * Now that we woke up, it's crucial if we're supposed to be
1794 * frozen that we freeze now before running anything substantial.
1798 spin_lock_irq(&sighand
->siglock
);
1800 * Every stopped thread goes here after wakeup. Check to see if
1801 * we should notify the parent, prepare_signal(SIGCONT) encodes
1802 * the CLD_ si_code into SIGNAL_CLD_MASK bits.
1804 if (unlikely(signal
->flags
& SIGNAL_CLD_MASK
)) {
1805 int why
= (signal
->flags
& SIGNAL_STOP_CONTINUED
)
1806 ? CLD_CONTINUED
: CLD_STOPPED
;
1807 signal
->flags
&= ~SIGNAL_CLD_MASK
;
1808 spin_unlock_irq(&sighand
->siglock
);
1810 if (unlikely(!tracehook_notify_jctl(1, why
)))
1813 read_lock(&tasklist_lock
);
1814 do_notify_parent_cldstop(current
->group_leader
, why
);
1815 read_unlock(&tasklist_lock
);
1820 struct k_sigaction
*ka
;
1822 if (unlikely(signal
->group_stop_count
> 0) &&
1827 * Tracing can induce an artifical signal and choose sigaction.
1828 * The return value in @signr determines the default action,
1829 * but @info->si_signo is the signal number we will report.
1831 signr
= tracehook_get_signal(current
, regs
, info
, return_ka
);
1832 if (unlikely(signr
< 0))
1834 if (unlikely(signr
!= 0))
1837 signr
= dequeue_signal(current
, ¤t
->blocked
,
1841 break; /* will return 0 */
1843 if (signr
!= SIGKILL
) {
1844 signr
= ptrace_signal(signr
, info
,
1850 ka
= &sighand
->action
[signr
-1];
1853 if (ka
->sa
.sa_handler
== SIG_IGN
) /* Do nothing. */
1855 if (ka
->sa
.sa_handler
!= SIG_DFL
) {
1856 /* Run the handler. */
1859 if (ka
->sa
.sa_flags
& SA_ONESHOT
)
1860 ka
->sa
.sa_handler
= SIG_DFL
;
1862 break; /* will return non-zero "signr" value */
1866 * Now we are doing the default action for this signal.
1868 if (sig_kernel_ignore(signr
)) /* Default is nothing. */
1872 * Global init gets no signals it doesn't want.
1873 * Container-init gets no signals it doesn't want from same
1876 * Note that if global/container-init sees a sig_kernel_only()
1877 * signal here, the signal must have been generated internally
1878 * or must have come from an ancestor namespace. In either
1879 * case, the signal cannot be dropped.
1881 if (unlikely(signal
->flags
& SIGNAL_UNKILLABLE
) &&
1882 !sig_kernel_only(signr
))
1885 if (sig_kernel_stop(signr
)) {
1887 * The default action is to stop all threads in
1888 * the thread group. The job control signals
1889 * do nothing in an orphaned pgrp, but SIGSTOP
1890 * always works. Note that siglock needs to be
1891 * dropped during the call to is_orphaned_pgrp()
1892 * because of lock ordering with tasklist_lock.
1893 * This allows an intervening SIGCONT to be posted.
1894 * We need to check for that and bail out if necessary.
1896 if (signr
!= SIGSTOP
) {
1897 spin_unlock_irq(&sighand
->siglock
);
1899 /* signals can be posted during this window */
1901 if (is_current_pgrp_orphaned())
1904 spin_lock_irq(&sighand
->siglock
);
1907 if (likely(do_signal_stop(info
->si_signo
))) {
1908 /* It released the siglock. */
1913 * We didn't actually stop, due to a race
1914 * with SIGCONT or something like that.
1919 spin_unlock_irq(&sighand
->siglock
);
1922 * Anything else is fatal, maybe with a core dump.
1924 current
->flags
|= PF_SIGNALED
;
1926 if (sig_kernel_coredump(signr
)) {
1927 if (print_fatal_signals
)
1928 print_fatal_signal(regs
, info
->si_signo
);
1930 * If it was able to dump core, this kills all
1931 * other threads in the group and synchronizes with
1932 * their demise. If we lost the race with another
1933 * thread getting here, it set group_exit_code
1934 * first and our do_group_exit call below will use
1935 * that value and ignore the one we pass it.
1937 do_coredump(info
->si_signo
, info
->si_signo
, regs
);
1941 * Death signals, no core dump.
1943 do_group_exit(info
->si_signo
);
1946 spin_unlock_irq(&sighand
->siglock
);
1950 void exit_signals(struct task_struct
*tsk
)
1953 struct task_struct
*t
;
1955 if (thread_group_empty(tsk
) || signal_group_exit(tsk
->signal
)) {
1956 tsk
->flags
|= PF_EXITING
;
1960 spin_lock_irq(&tsk
->sighand
->siglock
);
1962 * From now this task is not visible for group-wide signals,
1963 * see wants_signal(), do_signal_stop().
1965 tsk
->flags
|= PF_EXITING
;
1966 if (!signal_pending(tsk
))
1969 /* It could be that __group_complete_signal() choose us to
1970 * notify about group-wide signal. Another thread should be
1971 * woken now to take the signal since we will not.
1973 for (t
= tsk
; (t
= next_thread(t
)) != tsk
; )
1974 if (!signal_pending(t
) && !(t
->flags
& PF_EXITING
))
1975 recalc_sigpending_and_wake(t
);
1977 if (unlikely(tsk
->signal
->group_stop_count
) &&
1978 !--tsk
->signal
->group_stop_count
) {
1979 tsk
->signal
->flags
= SIGNAL_STOP_STOPPED
;
1983 spin_unlock_irq(&tsk
->sighand
->siglock
);
1985 if (unlikely(group_stop
) && tracehook_notify_jctl(1, CLD_STOPPED
)) {
1986 read_lock(&tasklist_lock
);
1987 do_notify_parent_cldstop(tsk
, CLD_STOPPED
);
1988 read_unlock(&tasklist_lock
);
1992 EXPORT_SYMBOL(recalc_sigpending
);
1993 EXPORT_SYMBOL_GPL(dequeue_signal
);
1994 EXPORT_SYMBOL(flush_signals
);
1995 EXPORT_SYMBOL(force_sig
);
1996 EXPORT_SYMBOL(send_sig
);
1997 EXPORT_SYMBOL(send_sig_info
);
1998 EXPORT_SYMBOL(sigprocmask
);
1999 EXPORT_SYMBOL(block_all_signals
);
2000 EXPORT_SYMBOL(unblock_all_signals
);
2004 * System call entry points.
2007 SYSCALL_DEFINE0(restart_syscall
)
2009 struct restart_block
*restart
= ¤t_thread_info()->restart_block
;
2010 return restart
->fn(restart
);
2013 long do_no_restart_syscall(struct restart_block
*param
)
2019 * We don't need to get the kernel lock - this is all local to this
2020 * particular thread.. (and that's good, because this is _heavily_
2021 * used by various programs)
2025 * This is also useful for kernel threads that want to temporarily
2026 * (or permanently) block certain signals.
2028 * NOTE! Unlike the user-mode sys_sigprocmask(), the kernel
2029 * interface happily blocks "unblockable" signals like SIGKILL
2032 int sigprocmask(int how
, sigset_t
*set
, sigset_t
*oldset
)
2036 spin_lock_irq(¤t
->sighand
->siglock
);
2038 *oldset
= current
->blocked
;
2043 sigorsets(¤t
->blocked
, ¤t
->blocked
, set
);
2046 signandsets(¤t
->blocked
, ¤t
->blocked
, set
);
2049 current
->blocked
= *set
;
2054 recalc_sigpending();
2055 spin_unlock_irq(¤t
->sighand
->siglock
);
2060 SYSCALL_DEFINE4(rt_sigprocmask
, int, how
, sigset_t __user
*, set
,
2061 sigset_t __user
*, oset
, size_t, sigsetsize
)
2063 int error
= -EINVAL
;
2064 sigset_t old_set
, new_set
;
2066 /* XXX: Don't preclude handling different sized sigset_t's. */
2067 if (sigsetsize
!= sizeof(sigset_t
))
2072 if (copy_from_user(&new_set
, set
, sizeof(*set
)))
2074 sigdelsetmask(&new_set
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
2076 error
= sigprocmask(how
, &new_set
, &old_set
);
2082 spin_lock_irq(¤t
->sighand
->siglock
);
2083 old_set
= current
->blocked
;
2084 spin_unlock_irq(¤t
->sighand
->siglock
);
2088 if (copy_to_user(oset
, &old_set
, sizeof(*oset
)))
2096 long do_sigpending(void __user
*set
, unsigned long sigsetsize
)
2098 long error
= -EINVAL
;
2101 if (sigsetsize
> sizeof(sigset_t
))
2104 spin_lock_irq(¤t
->sighand
->siglock
);
2105 sigorsets(&pending
, ¤t
->pending
.signal
,
2106 ¤t
->signal
->shared_pending
.signal
);
2107 spin_unlock_irq(¤t
->sighand
->siglock
);
2109 /* Outside the lock because only this thread touches it. */
2110 sigandsets(&pending
, ¤t
->blocked
, &pending
);
2113 if (!copy_to_user(set
, &pending
, sigsetsize
))
2120 SYSCALL_DEFINE2(rt_sigpending
, sigset_t __user
*, set
, size_t, sigsetsize
)
2122 return do_sigpending(set
, sigsetsize
);
2125 #ifndef HAVE_ARCH_COPY_SIGINFO_TO_USER
2127 int copy_siginfo_to_user(siginfo_t __user
*to
, siginfo_t
*from
)
2131 if (!access_ok (VERIFY_WRITE
, to
, sizeof(siginfo_t
)))
2133 if (from
->si_code
< 0)
2134 return __copy_to_user(to
, from
, sizeof(siginfo_t
))
2137 * If you change siginfo_t structure, please be sure
2138 * this code is fixed accordingly.
2139 * Please remember to update the signalfd_copyinfo() function
2140 * inside fs/signalfd.c too, in case siginfo_t changes.
2141 * It should never copy any pad contained in the structure
2142 * to avoid security leaks, but must copy the generic
2143 * 3 ints plus the relevant union member.
2145 err
= __put_user(from
->si_signo
, &to
->si_signo
);
2146 err
|= __put_user(from
->si_errno
, &to
->si_errno
);
2147 err
|= __put_user((short)from
->si_code
, &to
->si_code
);
2148 switch (from
->si_code
& __SI_MASK
) {
2150 err
|= __put_user(from
->si_pid
, &to
->si_pid
);
2151 err
|= __put_user(from
->si_uid
, &to
->si_uid
);
2154 err
|= __put_user(from
->si_tid
, &to
->si_tid
);
2155 err
|= __put_user(from
->si_overrun
, &to
->si_overrun
);
2156 err
|= __put_user(from
->si_ptr
, &to
->si_ptr
);
2159 err
|= __put_user(from
->si_band
, &to
->si_band
);
2160 err
|= __put_user(from
->si_fd
, &to
->si_fd
);
2163 err
|= __put_user(from
->si_addr
, &to
->si_addr
);
2164 #ifdef __ARCH_SI_TRAPNO
2165 err
|= __put_user(from
->si_trapno
, &to
->si_trapno
);
2169 err
|= __put_user(from
->si_pid
, &to
->si_pid
);
2170 err
|= __put_user(from
->si_uid
, &to
->si_uid
);
2171 err
|= __put_user(from
->si_status
, &to
->si_status
);
2172 err
|= __put_user(from
->si_utime
, &to
->si_utime
);
2173 err
|= __put_user(from
->si_stime
, &to
->si_stime
);
2175 case __SI_RT
: /* This is not generated by the kernel as of now. */
2176 case __SI_MESGQ
: /* But this is */
2177 err
|= __put_user(from
->si_pid
, &to
->si_pid
);
2178 err
|= __put_user(from
->si_uid
, &to
->si_uid
);
2179 err
|= __put_user(from
->si_ptr
, &to
->si_ptr
);
2181 default: /* this is just in case for now ... */
2182 err
|= __put_user(from
->si_pid
, &to
->si_pid
);
2183 err
|= __put_user(from
->si_uid
, &to
->si_uid
);
2191 SYSCALL_DEFINE4(rt_sigtimedwait
, const sigset_t __user
*, uthese
,
2192 siginfo_t __user
*, uinfo
, const struct timespec __user
*, uts
,
2201 /* XXX: Don't preclude handling different sized sigset_t's. */
2202 if (sigsetsize
!= sizeof(sigset_t
))
2205 if (copy_from_user(&these
, uthese
, sizeof(these
)))
2209 * Invert the set of allowed signals to get those we
2212 sigdelsetmask(&these
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
2216 if (copy_from_user(&ts
, uts
, sizeof(ts
)))
2218 if (ts
.tv_nsec
>= 1000000000L || ts
.tv_nsec
< 0
2223 spin_lock_irq(¤t
->sighand
->siglock
);
2224 sig
= dequeue_signal(current
, &these
, &info
);
2226 timeout
= MAX_SCHEDULE_TIMEOUT
;
2228 timeout
= (timespec_to_jiffies(&ts
)
2229 + (ts
.tv_sec
|| ts
.tv_nsec
));
2232 /* None ready -- temporarily unblock those we're
2233 * interested while we are sleeping in so that we'll
2234 * be awakened when they arrive. */
2235 current
->real_blocked
= current
->blocked
;
2236 sigandsets(¤t
->blocked
, ¤t
->blocked
, &these
);
2237 recalc_sigpending();
2238 spin_unlock_irq(¤t
->sighand
->siglock
);
2240 timeout
= schedule_timeout_interruptible(timeout
);
2242 spin_lock_irq(¤t
->sighand
->siglock
);
2243 sig
= dequeue_signal(current
, &these
, &info
);
2244 current
->blocked
= current
->real_blocked
;
2245 siginitset(¤t
->real_blocked
, 0);
2246 recalc_sigpending();
2249 spin_unlock_irq(¤t
->sighand
->siglock
);
2254 if (copy_siginfo_to_user(uinfo
, &info
))
2266 SYSCALL_DEFINE2(kill
, pid_t
, pid
, int, sig
)
2268 struct siginfo info
;
2270 info
.si_signo
= sig
;
2272 info
.si_code
= SI_USER
;
2273 info
.si_pid
= task_tgid_vnr(current
);
2274 info
.si_uid
= current_uid();
2276 return kill_something_info(sig
, &info
, pid
);
2279 static int do_tkill(pid_t tgid
, pid_t pid
, int sig
)
2282 struct siginfo info
;
2283 struct task_struct
*p
;
2284 unsigned long flags
;
2287 info
.si_signo
= sig
;
2289 info
.si_code
= SI_TKILL
;
2290 info
.si_pid
= task_tgid_vnr(current
);
2291 info
.si_uid
= current_uid();
2294 p
= find_task_by_vpid(pid
);
2295 if (p
&& (tgid
<= 0 || task_tgid_vnr(p
) == tgid
)) {
2296 error
= check_kill_permission(sig
, &info
, p
);
2298 * The null signal is a permissions and process existence
2299 * probe. No signal is actually delivered.
2301 * If lock_task_sighand() fails we pretend the task dies
2302 * after receiving the signal. The window is tiny, and the
2303 * signal is private anyway.
2305 if (!error
&& sig
&& lock_task_sighand(p
, &flags
)) {
2306 error
= specific_send_sig_info(sig
, &info
, p
);
2307 unlock_task_sighand(p
, &flags
);
2316 * sys_tgkill - send signal to one specific thread
2317 * @tgid: the thread group ID of the thread
2318 * @pid: the PID of the thread
2319 * @sig: signal to be sent
2321 * This syscall also checks the @tgid and returns -ESRCH even if the PID
2322 * exists but it's not belonging to the target process anymore. This
2323 * method solves the problem of threads exiting and PIDs getting reused.
2325 SYSCALL_DEFINE3(tgkill
, pid_t
, tgid
, pid_t
, pid
, int, sig
)
2327 /* This is only valid for single tasks */
2328 if (pid
<= 0 || tgid
<= 0)
2331 return do_tkill(tgid
, pid
, sig
);
2335 * Send a signal to only one task, even if it's a CLONE_THREAD task.
2337 SYSCALL_DEFINE2(tkill
, pid_t
, pid
, int, sig
)
2339 /* This is only valid for single tasks */
2343 return do_tkill(0, pid
, sig
);
2346 SYSCALL_DEFINE3(rt_sigqueueinfo
, pid_t
, pid
, int, sig
,
2347 siginfo_t __user
*, uinfo
)
2351 if (copy_from_user(&info
, uinfo
, sizeof(siginfo_t
)))
2354 /* Not even root can pretend to send signals from the kernel.
2355 Nor can they impersonate a kill(), which adds source info. */
2356 if (info
.si_code
>= 0)
2358 info
.si_signo
= sig
;
2360 /* POSIX.1b doesn't mention process groups. */
2361 return kill_proc_info(sig
, &info
, pid
);
2364 int do_sigaction(int sig
, struct k_sigaction
*act
, struct k_sigaction
*oact
)
2366 struct task_struct
*t
= current
;
2367 struct k_sigaction
*k
;
2370 if (!valid_signal(sig
) || sig
< 1 || (act
&& sig_kernel_only(sig
)))
2373 k
= &t
->sighand
->action
[sig
-1];
2375 spin_lock_irq(¤t
->sighand
->siglock
);
2380 sigdelsetmask(&act
->sa
.sa_mask
,
2381 sigmask(SIGKILL
) | sigmask(SIGSTOP
));
2385 * "Setting a signal action to SIG_IGN for a signal that is
2386 * pending shall cause the pending signal to be discarded,
2387 * whether or not it is blocked."
2389 * "Setting a signal action to SIG_DFL for a signal that is
2390 * pending and whose default action is to ignore the signal
2391 * (for example, SIGCHLD), shall cause the pending signal to
2392 * be discarded, whether or not it is blocked"
2394 if (sig_handler_ignored(sig_handler(t
, sig
), sig
)) {
2396 sigaddset(&mask
, sig
);
2397 rm_from_queue_full(&mask
, &t
->signal
->shared_pending
);
2399 rm_from_queue_full(&mask
, &t
->pending
);
2401 } while (t
!= current
);
2405 spin_unlock_irq(¤t
->sighand
->siglock
);
2410 do_sigaltstack (const stack_t __user
*uss
, stack_t __user
*uoss
, unsigned long sp
)
2416 oss
.ss_sp
= (void __user
*) current
->sas_ss_sp
;
2417 oss
.ss_size
= current
->sas_ss_size
;
2418 oss
.ss_flags
= sas_ss_flags(sp
);
2427 if (!access_ok(VERIFY_READ
, uss
, sizeof(*uss
))
2428 || __get_user(ss_sp
, &uss
->ss_sp
)
2429 || __get_user(ss_flags
, &uss
->ss_flags
)
2430 || __get_user(ss_size
, &uss
->ss_size
))
2434 if (on_sig_stack(sp
))
2440 * Note - this code used to test ss_flags incorrectly
2441 * old code may have been written using ss_flags==0
2442 * to mean ss_flags==SS_ONSTACK (as this was the only
2443 * way that worked) - this fix preserves that older
2446 if (ss_flags
!= SS_DISABLE
&& ss_flags
!= SS_ONSTACK
&& ss_flags
!= 0)
2449 if (ss_flags
== SS_DISABLE
) {
2454 if (ss_size
< MINSIGSTKSZ
)
2458 current
->sas_ss_sp
= (unsigned long) ss_sp
;
2459 current
->sas_ss_size
= ss_size
;
2464 if (copy_to_user(uoss
, &oss
, sizeof(oss
)))
2473 #ifdef __ARCH_WANT_SYS_SIGPENDING
2475 SYSCALL_DEFINE1(sigpending
, old_sigset_t __user
*, set
)
2477 return do_sigpending(set
, sizeof(*set
));
2482 #ifdef __ARCH_WANT_SYS_SIGPROCMASK
2483 /* Some platforms have their own version with special arguments others
2484 support only sys_rt_sigprocmask. */
2486 SYSCALL_DEFINE3(sigprocmask
, int, how
, old_sigset_t __user
*, set
,
2487 old_sigset_t __user
*, oset
)
2490 old_sigset_t old_set
, new_set
;
2494 if (copy_from_user(&new_set
, set
, sizeof(*set
)))
2496 new_set
&= ~(sigmask(SIGKILL
) | sigmask(SIGSTOP
));
2498 spin_lock_irq(¤t
->sighand
->siglock
);
2499 old_set
= current
->blocked
.sig
[0];
2507 sigaddsetmask(¤t
->blocked
, new_set
);
2510 sigdelsetmask(¤t
->blocked
, new_set
);
2513 current
->blocked
.sig
[0] = new_set
;
2517 recalc_sigpending();
2518 spin_unlock_irq(¤t
->sighand
->siglock
);
2524 old_set
= current
->blocked
.sig
[0];
2527 if (copy_to_user(oset
, &old_set
, sizeof(*oset
)))
2534 #endif /* __ARCH_WANT_SYS_SIGPROCMASK */
2536 #ifdef __ARCH_WANT_SYS_RT_SIGACTION
2537 SYSCALL_DEFINE4(rt_sigaction
, int, sig
,
2538 const struct sigaction __user
*, act
,
2539 struct sigaction __user
*, oact
,
2542 struct k_sigaction new_sa
, old_sa
;
2545 /* XXX: Don't preclude handling different sized sigset_t's. */
2546 if (sigsetsize
!= sizeof(sigset_t
))
2550 if (copy_from_user(&new_sa
.sa
, act
, sizeof(new_sa
.sa
)))
2554 ret
= do_sigaction(sig
, act
? &new_sa
: NULL
, oact
? &old_sa
: NULL
);
2557 if (copy_to_user(oact
, &old_sa
.sa
, sizeof(old_sa
.sa
)))
2563 #endif /* __ARCH_WANT_SYS_RT_SIGACTION */
2565 #ifdef __ARCH_WANT_SYS_SGETMASK
2568 * For backwards compatibility. Functionality superseded by sigprocmask.
2570 SYSCALL_DEFINE0(sgetmask
)
2573 return current
->blocked
.sig
[0];
2576 SYSCALL_DEFINE1(ssetmask
, int, newmask
)
2580 spin_lock_irq(¤t
->sighand
->siglock
);
2581 old
= current
->blocked
.sig
[0];
2583 siginitset(¤t
->blocked
, newmask
& ~(sigmask(SIGKILL
)|
2585 recalc_sigpending();
2586 spin_unlock_irq(¤t
->sighand
->siglock
);
2590 #endif /* __ARCH_WANT_SGETMASK */
2592 #ifdef __ARCH_WANT_SYS_SIGNAL
2594 * For backwards compatibility. Functionality superseded by sigaction.
2596 SYSCALL_DEFINE2(signal
, int, sig
, __sighandler_t
, handler
)
2598 struct k_sigaction new_sa
, old_sa
;
2601 new_sa
.sa
.sa_handler
= handler
;
2602 new_sa
.sa
.sa_flags
= SA_ONESHOT
| SA_NOMASK
;
2603 sigemptyset(&new_sa
.sa
.sa_mask
);
2605 ret
= do_sigaction(sig
, &new_sa
, &old_sa
);
2607 return ret
? ret
: (unsigned long)old_sa
.sa
.sa_handler
;
2609 #endif /* __ARCH_WANT_SYS_SIGNAL */
2611 #ifdef __ARCH_WANT_SYS_PAUSE
2613 SYSCALL_DEFINE0(pause
)
2615 current
->state
= TASK_INTERRUPTIBLE
;
2617 return -ERESTARTNOHAND
;
2622 #ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND
2623 SYSCALL_DEFINE2(rt_sigsuspend
, sigset_t __user
*, unewset
, size_t, sigsetsize
)
2627 /* XXX: Don't preclude handling different sized sigset_t's. */
2628 if (sigsetsize
!= sizeof(sigset_t
))
2631 if (copy_from_user(&newset
, unewset
, sizeof(newset
)))
2633 sigdelsetmask(&newset
, sigmask(SIGKILL
)|sigmask(SIGSTOP
));
2635 spin_lock_irq(¤t
->sighand
->siglock
);
2636 current
->saved_sigmask
= current
->blocked
;
2637 current
->blocked
= newset
;
2638 recalc_sigpending();
2639 spin_unlock_irq(¤t
->sighand
->siglock
);
2641 current
->state
= TASK_INTERRUPTIBLE
;
2643 set_restore_sigmask();
2644 return -ERESTARTNOHAND
;
2646 #endif /* __ARCH_WANT_SYS_RT_SIGSUSPEND */
2648 __attribute__((weak
)) const char *arch_vma_name(struct vm_area_struct
*vma
)
2653 void __init
signals_init(void)
2655 sigqueue_cachep
= KMEM_CACHE(sigqueue
, SLAB_PANIC
);