1
2
3
4
5
6
7
8
9#include <linux/config.h>
10#include <linux/slab.h>
11#include <linux/module.h>
12#include <linux/unistd.h>
13#include <linux/smp_lock.h>
14#include <linux/init.h>
15#include <linux/sched.h>
16
17#include <asm/uaccess.h>
18
19
20
21
22
23#define DEBUG_SIG 0
24
25#if DEBUG_SIG
26#define SIG_SLAB_DEBUG (SLAB_DEBUG_FREE | SLAB_RED_ZONE )
27#else
28#define SIG_SLAB_DEBUG 0
29#endif
30
31static kmem_cache_t *sigqueue_cachep;
32
33atomic_t nr_queued_signals;
34int max_queued_signals = 1024;
35
36void __init signals_init(void)
37{
38 sigqueue_cachep =
39 kmem_cache_create("sigqueue",
40 sizeof(struct sigqueue),
41 __alignof__(struct sigqueue),
42 SIG_SLAB_DEBUG, NULL, NULL);
43 if (!sigqueue_cachep)
44 panic("signals_init(): cannot create sigqueue SLAB cache");
45}
46
47
48
49
50static int
51next_signal(struct task_struct *tsk, sigset_t *mask)
52{
53 unsigned long i, *s, *m, x;
54 int sig = 0;
55
56 s = tsk->pending.signal.sig;
57 m = mask->sig;
58 switch (_NSIG_WORDS) {
59 default:
60 for (i = 0; i < _NSIG_WORDS; ++i, ++s, ++m)
61 if ((x = *s &~ *m) != 0) {
62 sig = ffz(~x) + i*_NSIG_BPW + 1;
63 break;
64 }
65 break;
66
67 case 2: if ((x = s[0] &~ m[0]) != 0)
68 sig = 1;
69 else if ((x = s[1] &~ m[1]) != 0)
70 sig = _NSIG_BPW + 1;
71 else
72 break;
73 sig += ffz(~x);
74 break;
75
76 case 1: if ((x = *s &~ *m) != 0)
77 sig = ffz(~x) + 1;
78 break;
79 }
80
81 return sig;
82}
83
84static void flush_sigqueue(struct sigpending *queue)
85{
86 struct sigqueue *q, *n;
87
88 sigemptyset(&queue->signal);
89 q = queue->head;
90 queue->head = NULL;
91 queue->tail = &queue->head;
92
93 while (q) {
94 n = q->next;
95 kmem_cache_free(sigqueue_cachep, q);
96 atomic_dec(&nr_queued_signals);
97 q = n;
98 }
99}
100
101
102
103
104
105void
106flush_signals(struct task_struct *t)
107{
108 t->sigpending = 0;
109 flush_sigqueue(&t->pending);
110}
111
112void exit_sighand(struct task_struct *tsk)
113{
114 struct signal_struct * sig = tsk->sig;
115
116 spin_lock_irq(&tsk->sigmask_lock);
117 if (sig) {
118 tsk->sig = NULL;
119 if (atomic_dec_and_test(&sig->count))
120 kmem_cache_free(sigact_cachep, sig);
121 }
122 tsk->sigpending = 0;
123 flush_sigqueue(&tsk->pending);
124 spin_unlock_irq(&tsk->sigmask_lock);
125}
126
127
128
129
130
131void
132flush_signal_handlers(struct task_struct *t)
133{
134 int i;
135 struct k_sigaction *ka = &t->sig->action[0];
136 for (i = _NSIG ; i != 0 ; i--) {
137 if (ka->sa.sa_handler != SIG_IGN)
138 ka->sa.sa_handler = SIG_DFL;
139 ka->sa.sa_flags = 0;
140 sigemptyset(&ka->sa.sa_mask);
141 ka++;
142 }
143}
144
145
146
147
148
149void
150sig_exit(int sig, int exit_code, struct siginfo *info)
151{
152 struct task_struct *t;
153
154 sigaddset(¤t->pending.signal, sig);
155 recalc_sigpending(current);
156 current->flags |= PF_SIGNALED;
157
158
159
160
161 if (info && (unsigned long)info != 1
162 && info->si_code != SI_TKILL) {
163 read_lock(&tasklist_lock);
164 for_each_thread(t) {
165 force_sig_info(sig, info, t);
166 }
167 read_unlock(&tasklist_lock);
168 }
169
170 do_exit(exit_code);
171
172}
173
174
175
176
177
178
179
180
181
182void
183block_all_signals(int (*notifier)(void *priv), void *priv, sigset_t *mask)
184{
185 unsigned long flags;
186
187 spin_lock_irqsave(¤t->sigmask_lock, flags);
188 current->notifier_mask = mask;
189 current->notifier_data = priv;
190 current->notifier = notifier;
191 spin_unlock_irqrestore(¤t->sigmask_lock, flags);
192}
193
194
195
196void
197unblock_all_signals(void)
198{
199 unsigned long flags;
200
201 spin_lock_irqsave(¤t->sigmask_lock, flags);
202 current->notifier = NULL;
203 current->notifier_data = NULL;
204 recalc_sigpending(current);
205 spin_unlock_irqrestore(¤t->sigmask_lock, flags);
206}
207
208static int collect_signal(int sig, struct sigpending *list, siginfo_t *info)
209{
210 if (sigismember(&list->signal, sig)) {
211
212 struct sigqueue *q, **pp;
213 pp = &list->head;
214 while ((q = *pp) != NULL) {
215 if (q->info.si_signo == sig)
216 goto found_it;
217 pp = &q->next;
218 }
219
220
221
222
223 sigdelset(&list->signal, sig);
224 info->si_signo = sig;
225 info->si_errno = 0;
226 info->si_code = 0;
227 info->si_pid = 0;
228 info->si_uid = 0;
229 return 1;
230
231found_it:
232 if ((*pp = q->next) == NULL)
233 list->tail = pp;
234
235
236 copy_siginfo(info, &q->info);
237 kmem_cache_free(sigqueue_cachep,q);
238 atomic_dec(&nr_queued_signals);
239
240
241 if (sig >= SIGRTMIN) {
242 while ((q = *pp) != NULL) {
243 if (q->info.si_signo == sig)
244 goto found_another;
245 pp = &q->next;
246 }
247 }
248
249 sigdelset(&list->signal, sig);
250found_another:
251 return 1;
252 }
253 return 0;
254}
255
256
257
258
259
260
261
262
263int
264dequeue_signal(sigset_t *mask, siginfo_t *info)
265{
266 int sig = 0;
267
268#if DEBUG_SIG
269printk("SIG dequeue (%s:%d): %d ", current->comm, current->pid,
270 signal_pending(current));
271#endif
272
273 sig = next_signal(current, mask);
274 if (sig) {
275 if (current->notifier) {
276 if (sigismember(current->notifier_mask, sig)) {
277 if (!(current->notifier)(current->notifier_data)) {
278 current->sigpending = 0;
279 return 0;
280 }
281 }
282 }
283
284 if (!collect_signal(sig, ¤t->pending, info))
285 sig = 0;
286
287
288
289 }
290 recalc_sigpending(current);
291
292#if DEBUG_SIG
293printk(" %d -> %d\n", signal_pending(current), sig);
294#endif
295
296 return sig;
297}
298
299static int rm_from_queue(int sig, struct sigpending *s)
300{
301 struct sigqueue *q, **pp;
302
303 if (!sigismember(&s->signal, sig))
304 return 0;
305
306 sigdelset(&s->signal, sig);
307
308 pp = &s->head;
309
310 while ((q = *pp) != NULL) {
311 if (q->info.si_signo == sig) {
312 if ((*pp = q->next) == NULL)
313 s->tail = pp;
314 kmem_cache_free(sigqueue_cachep,q);
315 atomic_dec(&nr_queued_signals);
316 continue;
317 }
318 pp = &q->next;
319 }
320 return 1;
321}
322
323
324
325
326
327
328
329static int rm_sig_from_queue(int sig, struct task_struct *t)
330{
331 return rm_from_queue(sig, &t->pending);
332}
333
334
335
336
337int bad_signal(int sig, struct siginfo *info, struct task_struct *t)
338{
339 return (!info || ((unsigned long)info != 1 && SI_FROMUSER(info)))
340 && ((sig != SIGCONT) || (current->session != t->session))
341 && (current->euid ^ t->suid) && (current->euid ^ t->uid)
342 && (current->uid ^ t->suid) && (current->uid ^ t->uid)
343 && !capable(CAP_KILL);
344}
345
346
347
348
349
350
351
352static int signal_type(int sig, struct signal_struct *signals)
353{
354 unsigned long handler;
355
356 if (!signals)
357 return 0;
358
359 handler = (unsigned long) signals->action[sig-1].sa.sa_handler;
360 if (handler > 1)
361 return 1;
362
363
364 if (handler == 1)
365 return sig == SIGCHLD;
366
367
368 switch (sig) {
369
370
371 case SIGCONT: case SIGWINCH:
372 case SIGCHLD: case SIGURG:
373 return 0;
374
375
376 case SIGTSTP: case SIGTTIN: case SIGTTOU:
377 return 1;
378
379
380 default:
381 return -1;
382 }
383}
384
385
386
387
388
389
390
391
392
393
394static int ignored_signal(int sig, struct task_struct *t)
395{
396
397 if ((t->ptrace & PT_PTRACED) || sigismember(&t->blocked, sig))
398 return 0;
399
400 return signal_type(sig, t->sig) == 0;
401}
402
403
404
405
406
407
408
409static void handle_stop_signal(int sig, struct task_struct *t)
410{
411 switch (sig) {
412 case SIGKILL: case SIGCONT:
413
414 if (t->state == TASK_STOPPED)
415 wake_up_process(t);
416 t->exit_code = 0;
417 rm_sig_from_queue(SIGSTOP, t);
418 rm_sig_from_queue(SIGTSTP, t);
419 rm_sig_from_queue(SIGTTOU, t);
420 rm_sig_from_queue(SIGTTIN, t);
421 break;
422
423 case SIGSTOP: case SIGTSTP:
424 case SIGTTIN: case SIGTTOU:
425
426 rm_sig_from_queue(SIGCONT, t);
427 break;
428 }
429}
430
431static int send_signal(int sig, struct siginfo *info, struct sigpending *signals)
432{
433 struct sigqueue * q = NULL;
434
435
436
437
438
439
440
441
442
443 if (atomic_read(&nr_queued_signals) < max_queued_signals) {
444 q = kmem_cache_alloc(sigqueue_cachep, GFP_ATOMIC);
445 }
446
447 if (q) {
448 atomic_inc(&nr_queued_signals);
449 q->next = NULL;
450 *signals->tail = q;
451 signals->tail = &q->next;
452 switch ((unsigned long) info) {
453 case 0:
454 q->info.si_signo = sig;
455 q->info.si_errno = 0;
456 q->info.si_code = SI_USER;
457 q->info.si_pid = current->pid;
458 q->info.si_uid = current->uid;
459 break;
460 case 1:
461 q->info.si_signo = sig;
462 q->info.si_errno = 0;
463 q->info.si_code = SI_KERNEL;
464 q->info.si_pid = 0;
465 q->info.si_uid = 0;
466 break;
467 default:
468 copy_siginfo(&q->info, info);
469 break;
470 }
471 } else if (sig >= SIGRTMIN && info && (unsigned long)info != 1
472 && info->si_code != SI_USER) {
473
474
475
476
477 return -EAGAIN;
478 }
479
480 sigaddset(&signals->signal, sig);
481 return 0;
482}
483
484
485
486
487
488
489
490
491
492
493
494
495static inline void signal_wake_up(struct task_struct *t)
496{
497 t->sigpending = 1;
498
499#ifdef CONFIG_SMP
500
501
502
503
504
505
506
507
508
509
510 spin_lock(&runqueue_lock);
511 if (task_has_cpu(t) && t->processor != smp_processor_id())
512 smp_send_reschedule(t->processor);
513 spin_unlock(&runqueue_lock);
514#endif
515
516 if (t->state & TASK_INTERRUPTIBLE) {
517 wake_up_process(t);
518 return;
519 }
520}
521
522static int deliver_signal(int sig, struct siginfo *info, struct task_struct *t)
523{
524 int retval = send_signal(sig, info, &t->pending);
525
526 if (!retval && !sigismember(&t->blocked, sig))
527 signal_wake_up(t);
528
529 return retval;
530}
531
532int
533send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
534{
535 unsigned long flags;
536 int ret;
537
538
539#if DEBUG_SIG
540printk("SIG queue (%s:%d): %d ", t->comm, t->pid, sig);
541#endif
542
543 ret = -EINVAL;
544 if (sig < 0 || sig > _NSIG)
545 goto out_nolock;
546
547 ret = -EPERM;
548 if (bad_signal(sig, info, t))
549 goto out_nolock;
550
551
552
553 ret = 0;
554 if (!sig || !t->sig)
555 goto out_nolock;
556
557 spin_lock_irqsave(&t->sigmask_lock, flags);
558 handle_stop_signal(sig, t);
559
560
561
562
563
564 if (ignored_signal(sig, t))
565 goto out;
566
567
568
569
570 if (sig < SIGRTMIN && sigismember(&t->pending.signal, sig))
571 goto out;
572
573 ret = deliver_signal(sig, info, t);
574out:
575 spin_unlock_irqrestore(&t->sigmask_lock, flags);
576out_nolock:
577#if DEBUG_SIG
578printk(" %d -> %d\n", signal_pending(t), ret);
579#endif
580
581 return ret;
582}
583
584
585
586
587
588
589int
590force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
591{
592 unsigned long int flags;
593
594 spin_lock_irqsave(&t->sigmask_lock, flags);
595 if (t->sig == NULL) {
596 spin_unlock_irqrestore(&t->sigmask_lock, flags);
597 return -ESRCH;
598 }
599
600 if (t->sig->action[sig-1].sa.sa_handler == SIG_IGN)
601 t->sig->action[sig-1].sa.sa_handler = SIG_DFL;
602 sigdelset(&t->blocked, sig);
603 recalc_sigpending(t);
604 spin_unlock_irqrestore(&t->sigmask_lock, flags);
605
606 return send_sig_info(sig, info, t);
607}
608
609
610
611
612
613
614int
615kill_pg_info(int sig, struct siginfo *info, pid_t pgrp)
616{
617 int retval = -EINVAL;
618 if (pgrp > 0) {
619 struct task_struct *p;
620
621 retval = -ESRCH;
622 read_lock(&tasklist_lock);
623 for_each_task(p) {
624 if (p->pgrp == pgrp && thread_group_leader(p)) {
625 int err = send_sig_info(sig, info, p);
626 if (retval)
627 retval = err;
628 }
629 }
630 read_unlock(&tasklist_lock);
631 }
632 return retval;
633}
634
635
636
637
638
639
640
641int
642kill_sl_info(int sig, struct siginfo *info, pid_t sess)
643{
644 int retval = -EINVAL;
645 if (sess > 0) {
646 struct task_struct *p;
647
648 retval = -ESRCH;
649 read_lock(&tasklist_lock);
650 for_each_task(p) {
651 if (p->leader && p->session == sess) {
652 int err = send_sig_info(sig, info, p);
653 if (retval)
654 retval = err;
655 }
656 }
657 read_unlock(&tasklist_lock);
658 }
659 return retval;
660}
661
662inline int
663kill_proc_info(int sig, struct siginfo *info, pid_t pid)
664{
665 int error;
666 struct task_struct *p;
667
668 read_lock(&tasklist_lock);
669 p = find_task_by_pid(pid);
670 error = -ESRCH;
671 if (p) {
672 if (!thread_group_leader(p)) {
673 struct task_struct *tg;
674 tg = find_task_by_pid(p->tgid);
675 if (tg)
676 p = tg;
677 }
678 error = send_sig_info(sig, info, p);
679 }
680 read_unlock(&tasklist_lock);
681 return error;
682}
683
684
685
686
687
688
689
690
691
692static int kill_something_info(int sig, struct siginfo *info, int pid)
693{
694 if (!pid) {
695 return kill_pg_info(sig, info, current->pgrp);
696 } else if (pid == -1) {
697 int retval = 0, count = 0;
698 struct task_struct * p;
699
700 read_lock(&tasklist_lock);
701 for_each_task(p) {
702 if (p->pid > 1 && p != current && thread_group_leader(p)) {
703 int err = send_sig_info(sig, info, p);
704 ++count;
705 if (err != -EPERM)
706 retval = err;
707 }
708 }
709 read_unlock(&tasklist_lock);
710 return count ? retval : -ESRCH;
711 } else if (pid < 0) {
712 return kill_pg_info(sig, info, -pid);
713 } else {
714 return kill_proc_info(sig, info, pid);
715 }
716}
717
718
719
720
721
722int
723send_sig(int sig, struct task_struct *p, int priv)
724{
725 return send_sig_info(sig, (void*)(long)(priv != 0), p);
726}
727
728void
729force_sig(int sig, struct task_struct *p)
730{
731 force_sig_info(sig, (void*)1L, p);
732}
733
734int
735kill_pg(pid_t pgrp, int sig, int priv)
736{
737 return kill_pg_info(sig, (void *)(long)(priv != 0), pgrp);
738}
739
740int
741kill_sl(pid_t sess, int sig, int priv)
742{
743 return kill_sl_info(sig, (void *)(long)(priv != 0), sess);
744}
745
746int
747kill_proc(pid_t pid, int sig, int priv)
748{
749 return kill_proc_info(sig, (void *)(long)(priv != 0), pid);
750}
751
752
753
754
755
756static void wake_up_parent(struct task_struct *parent)
757{
758 struct task_struct *tsk = parent;
759
760 do {
761 wake_up_interruptible(&tsk->wait_chldexit);
762 tsk = next_thread(tsk);
763 } while (tsk != parent);
764}
765
766
767
768
769
770void do_notify_parent(struct task_struct *tsk, int sig)
771{
772 struct siginfo info;
773 int why, status;
774
775 info.si_signo = sig;
776 info.si_errno = 0;
777 info.si_pid = tsk->pid;
778 info.si_uid = tsk->uid;
779
780
781 info.si_utime = tsk->times.tms_utime;
782 info.si_stime = tsk->times.tms_stime;
783
784 status = tsk->exit_code & 0x7f;
785 why = SI_KERNEL;
786 switch (tsk->state) {
787 case TASK_STOPPED:
788
789 if (tsk->ptrace & PT_PTRACED)
790 why = CLD_TRAPPED;
791 else
792 why = CLD_STOPPED;
793 break;
794
795 default:
796 if (tsk->exit_code & 0x80)
797 why = CLD_DUMPED;
798 else if (tsk->exit_code & 0x7f)
799 why = CLD_KILLED;
800 else {
801 why = CLD_EXITED;
802 status = tsk->exit_code >> 8;
803 }
804 break;
805 }
806 info.si_code = why;
807 info.si_status = status;
808
809 send_sig_info(sig, &info, tsk->p_pptr);
810 wake_up_parent(tsk->p_pptr);
811}
812
813
814
815
816
817
818
819
820
821void
822notify_parent(struct task_struct *tsk, int sig)
823{
824 read_lock(&tasklist_lock);
825 do_notify_parent(tsk, sig);
826 read_unlock(&tasklist_lock);
827}
828
829EXPORT_SYMBOL(dequeue_signal);
830EXPORT_SYMBOL(flush_signals);
831EXPORT_SYMBOL(force_sig);
832EXPORT_SYMBOL(force_sig_info);
833EXPORT_SYMBOL(kill_pg);
834EXPORT_SYMBOL(kill_pg_info);
835EXPORT_SYMBOL(kill_proc);
836EXPORT_SYMBOL(kill_proc_info);
837EXPORT_SYMBOL(kill_sl);
838EXPORT_SYMBOL(kill_sl_info);
839EXPORT_SYMBOL(notify_parent);
840EXPORT_SYMBOL(recalc_sigpending);
841EXPORT_SYMBOL(send_sig);
842EXPORT_SYMBOL(send_sig_info);
843EXPORT_SYMBOL(block_all_signals);
844EXPORT_SYMBOL(unblock_all_signals);
845
846
847
848
849
850
851
852
853
854
855
856
857asmlinkage long
858sys_rt_sigprocmask(int how, sigset_t *set, sigset_t *oset, size_t sigsetsize)
859{
860 int error = -EINVAL;
861 sigset_t old_set, new_set;
862
863
864 if (sigsetsize != sizeof(sigset_t))
865 goto out;
866
867 if (set) {
868 error = -EFAULT;
869 if (copy_from_user(&new_set, set, sizeof(*set)))
870 goto out;
871 sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP));
872
873 spin_lock_irq(¤t->sigmask_lock);
874 old_set = current->blocked;
875
876 error = 0;
877 switch (how) {
878 default:
879 error = -EINVAL;
880 break;
881 case SIG_BLOCK:
882 sigorsets(¤t->blocked, &old_set, &new_set);
883 break;
884 case SIG_UNBLOCK:
885 signandsets(¤t->blocked, &old_set, &new_set);
886 break;
887 case SIG_SETMASK:
888 current->blocked = new_set;
889 break;
890 }
891
892 recalc_sigpending(current);
893 spin_unlock_irq(¤t->sigmask_lock);
894 if (error)
895 goto out;
896 if (oset)
897 goto set_old;
898 } else if (oset) {
899 spin_lock_irq(¤t->sigmask_lock);
900 old_set = current->blocked;
901 spin_unlock_irq(¤t->sigmask_lock);
902
903 set_old:
904 error = -EFAULT;
905 if (copy_to_user(oset, &old_set, sizeof(*oset)))
906 goto out;
907 }
908 error = 0;
909out:
910 return error;
911}
912
913long do_sigpending(void *set, unsigned long sigsetsize)
914{
915 long error = -EINVAL;
916 sigset_t pending;
917
918 if (sigsetsize > sizeof(sigset_t))
919 goto out;
920
921 spin_lock_irq(¤t->sigmask_lock);
922 sigandsets(&pending, ¤t->blocked, ¤t->pending.signal);
923 spin_unlock_irq(¤t->sigmask_lock);
924
925 error = -EFAULT;
926 if (!copy_to_user(set, &pending, sigsetsize))
927 error = 0;
928out:
929 return error;
930}
931
932asmlinkage long
933sys_rt_sigpending(sigset_t *set, size_t sigsetsize)
934{
935 return do_sigpending(set, sigsetsize);
936}
937
938asmlinkage long
939sys_rt_sigtimedwait(const sigset_t *uthese, siginfo_t *uinfo,
940 const struct timespec *uts, size_t sigsetsize)
941{
942 int ret, sig;
943 sigset_t these;
944 struct timespec ts;
945 siginfo_t info;
946 long timeout = 0;
947
948
949 if (sigsetsize != sizeof(sigset_t))
950 return -EINVAL;
951
952 if (copy_from_user(&these, uthese, sizeof(these)))
953 return -EFAULT;
954
955
956
957
958
959 sigdelsetmask(&these, sigmask(SIGKILL)|sigmask(SIGSTOP));
960 signotset(&these);
961
962 if (uts) {
963 if (copy_from_user(&ts, uts, sizeof(ts)))
964 return -EFAULT;
965 if (ts.tv_nsec >= 1000000000L || ts.tv_nsec < 0
966 || ts.tv_sec < 0)
967 return -EINVAL;
968 }
969
970 spin_lock_irq(¤t->sigmask_lock);
971 sig = dequeue_signal(&these, &info);
972 if (!sig) {
973 timeout = MAX_SCHEDULE_TIMEOUT;
974 if (uts)
975 timeout = (timespec_to_jiffies(&ts)
976 + (ts.tv_sec || ts.tv_nsec));
977
978 if (timeout) {
979
980
981
982 sigset_t oldblocked = current->blocked;
983 sigandsets(¤t->blocked, ¤t->blocked, &these);
984 recalc_sigpending(current);
985 spin_unlock_irq(¤t->sigmask_lock);
986
987 current->state = TASK_INTERRUPTIBLE;
988 timeout = schedule_timeout(timeout);
989
990 spin_lock_irq(¤t->sigmask_lock);
991 sig = dequeue_signal(&these, &info);
992 current->blocked = oldblocked;
993 recalc_sigpending(current);
994 }
995 }
996 spin_unlock_irq(¤t->sigmask_lock);
997
998 if (sig) {
999 ret = sig;
1000 if (uinfo) {
1001 if (copy_siginfo_to_user(uinfo, &info))
1002 ret = -EFAULT;
1003 }
1004 } else {
1005 ret = -EAGAIN;
1006 if (timeout)
1007 ret = -EINTR;
1008 }
1009
1010 return ret;
1011}
1012
1013asmlinkage long
1014sys_kill(int pid, int sig)
1015{
1016 struct siginfo info;
1017
1018 info.si_signo = sig;
1019 info.si_errno = 0;
1020 info.si_code = SI_USER;
1021 info.si_pid = current->pid;
1022 info.si_uid = current->uid;
1023
1024 return kill_something_info(sig, &info, pid);
1025}
1026
1027
1028
1029
1030asmlinkage long
1031sys_tkill(int pid, int sig)
1032{
1033 struct siginfo info;
1034 int error;
1035 struct task_struct *p;
1036
1037
1038 if (pid <= 0)
1039 return -EINVAL;
1040
1041 info.si_signo = sig;
1042 info.si_errno = 0;
1043 info.si_code = SI_TKILL;
1044 info.si_pid = current->pid;
1045 info.si_uid = current->uid;
1046
1047 read_lock(&tasklist_lock);
1048 p = find_task_by_pid(pid);
1049 error = -ESRCH;
1050 if (p) {
1051 error = send_sig_info(sig, &info, p);
1052 }
1053 read_unlock(&tasklist_lock);
1054 return error;
1055}
1056
1057asmlinkage long
1058sys_rt_sigqueueinfo(int pid, int sig, siginfo_t *uinfo)
1059{
1060 siginfo_t info;
1061
1062 if (copy_from_user(&info, uinfo, sizeof(siginfo_t)))
1063 return -EFAULT;
1064
1065
1066
1067 if (info.si_code >= 0)
1068 return -EPERM;
1069 info.si_signo = sig;
1070
1071
1072 return kill_proc_info(sig, &info, pid);
1073}
1074
1075int
1076do_sigaction(int sig, const struct k_sigaction *act, struct k_sigaction *oact)
1077{
1078 struct k_sigaction *k;
1079
1080 if (sig < 1 || sig > _NSIG ||
1081 (act && (sig == SIGKILL || sig == SIGSTOP)))
1082 return -EINVAL;
1083
1084 k = ¤t->sig->action[sig-1];
1085
1086 spin_lock(¤t->sig->siglock);
1087
1088 if (oact)
1089 *oact = *k;
1090
1091 if (act) {
1092 *k = *act;
1093 sigdelsetmask(&k->sa.sa_mask, sigmask(SIGKILL) | sigmask(SIGSTOP));
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112 if (k->sa.sa_handler == SIG_IGN
1113 || (k->sa.sa_handler == SIG_DFL
1114 && (sig == SIGCONT ||
1115 sig == SIGCHLD ||
1116 sig == SIGURG ||
1117 sig == SIGWINCH))) {
1118 spin_lock_irq(¤t->sigmask_lock);
1119 if (rm_sig_from_queue(sig, current))
1120 recalc_sigpending(current);
1121 spin_unlock_irq(¤t->sigmask_lock);
1122 }
1123 }
1124
1125 spin_unlock(¤t->sig->siglock);
1126 return 0;
1127}
1128
1129int
1130do_sigaltstack (const stack_t *uss, stack_t *uoss, unsigned long sp)
1131{
1132 stack_t oss;
1133 int error;
1134
1135 if (uoss) {
1136 oss.ss_sp = (void *) current->sas_ss_sp;
1137 oss.ss_size = current->sas_ss_size;
1138 oss.ss_flags = sas_ss_flags(sp);
1139 }
1140
1141 if (uss) {
1142 void *ss_sp;
1143 size_t ss_size;
1144 int ss_flags;
1145
1146 error = -EFAULT;
1147 if (verify_area(VERIFY_READ, uss, sizeof(*uss))
1148 || __get_user(ss_sp, &uss->ss_sp)
1149 || __get_user(ss_flags, &uss->ss_flags)
1150 || __get_user(ss_size, &uss->ss_size))
1151 goto out;
1152
1153 error = -EPERM;
1154 if (on_sig_stack (sp))
1155 goto out;
1156
1157 error = -EINVAL;
1158
1159
1160
1161
1162
1163
1164
1165
1166 if (ss_flags != SS_DISABLE && ss_flags != SS_ONSTACK && ss_flags != 0)
1167 goto out;
1168
1169 if (ss_flags == SS_DISABLE) {
1170 ss_size = 0;
1171 ss_sp = NULL;
1172 } else {
1173 error = -ENOMEM;
1174 if (ss_size < MINSIGSTKSZ)
1175 goto out;
1176 }
1177
1178 current->sas_ss_sp = (unsigned long) ss_sp;
1179 current->sas_ss_size = ss_size;
1180 }
1181
1182 if (uoss) {
1183 error = -EFAULT;
1184 if (copy_to_user(uoss, &oss, sizeof(oss)))
1185 goto out;
1186 }
1187
1188 error = 0;
1189out:
1190 return error;
1191}
1192
1193asmlinkage long
1194sys_sigpending(old_sigset_t *set)
1195{
1196 return do_sigpending(set, sizeof(*set));
1197}
1198
1199#if !defined(__alpha__)
1200
1201
1202asmlinkage long
1203sys_sigprocmask(int how, old_sigset_t *set, old_sigset_t *oset)
1204{
1205 int error;
1206 old_sigset_t old_set, new_set;
1207
1208 if (set) {
1209 error = -EFAULT;
1210 if (copy_from_user(&new_set, set, sizeof(*set)))
1211 goto out;
1212 new_set &= ~(sigmask(SIGKILL)|sigmask(SIGSTOP));
1213
1214 spin_lock_irq(¤t->sigmask_lock);
1215 old_set = current->blocked.sig[0];
1216
1217 error = 0;
1218 switch (how) {
1219 default:
1220 error = -EINVAL;
1221 break;
1222 case SIG_BLOCK:
1223 sigaddsetmask(¤t->blocked, new_set);
1224 break;
1225 case SIG_UNBLOCK:
1226 sigdelsetmask(¤t->blocked, new_set);
1227 break;
1228 case SIG_SETMASK:
1229 current->blocked.sig[0] = new_set;
1230 break;
1231 }
1232
1233 recalc_sigpending(current);
1234 spin_unlock_irq(¤t->sigmask_lock);
1235 if (error)
1236 goto out;
1237 if (oset)
1238 goto set_old;
1239 } else if (oset) {
1240 old_set = current->blocked.sig[0];
1241 set_old:
1242 error = -EFAULT;
1243 if (copy_to_user(oset, &old_set, sizeof(*oset)))
1244 goto out;
1245 }
1246 error = 0;
1247out:
1248 return error;
1249}
1250
1251#ifndef __sparc__
1252asmlinkage long
1253sys_rt_sigaction(int sig, const struct sigaction *act, struct sigaction *oact,
1254 size_t sigsetsize)
1255{
1256 struct k_sigaction new_sa, old_sa;
1257 int ret = -EINVAL;
1258
1259
1260 if (sigsetsize != sizeof(sigset_t))
1261 goto out;
1262
1263 if (act) {
1264 if (copy_from_user(&new_sa.sa, act, sizeof(new_sa.sa)))
1265 return -EFAULT;
1266 }
1267
1268 ret = do_sigaction(sig, act ? &new_sa : NULL, oact ? &old_sa : NULL);
1269
1270 if (!ret && oact) {
1271 if (copy_to_user(oact, &old_sa.sa, sizeof(old_sa.sa)))
1272 return -EFAULT;
1273 }
1274out:
1275 return ret;
1276}
1277#endif
1278#endif
1279
1280#if !defined(__alpha__) && !defined(__ia64__)
1281
1282
1283
1284asmlinkage long
1285sys_sgetmask(void)
1286{
1287
1288 return current->blocked.sig[0];
1289}
1290
1291asmlinkage long
1292sys_ssetmask(int newmask)
1293{
1294 int old;
1295
1296 spin_lock_irq(¤t->sigmask_lock);
1297 old = current->blocked.sig[0];
1298
1299 siginitset(¤t->blocked, newmask & ~(sigmask(SIGKILL)|
1300 sigmask(SIGSTOP)));
1301 recalc_sigpending(current);
1302 spin_unlock_irq(¤t->sigmask_lock);
1303
1304 return old;
1305}
1306#endif
1307
1308#if !defined(__alpha__) && !defined(__ia64__) && !defined(__mips__)
1309
1310
1311
1312asmlinkage unsigned long
1313sys_signal(int sig, __sighandler_t handler)
1314{
1315 struct k_sigaction new_sa, old_sa;
1316 int ret;
1317
1318 new_sa.sa.sa_handler = handler;
1319 new_sa.sa.sa_flags = SA_ONESHOT | SA_NOMASK;
1320
1321 ret = do_sigaction(sig, &new_sa, &old_sa);
1322
1323 return ret ? ret : (unsigned long)old_sa.sa.sa_handler;
1324}
1325#endif
1326