signals.c revision 1.1 1 /* $NetBSD: signals.c,v 1.1 2010/04/21 11:38:05 pooka Exp $ */
2
3 /*
4 * Copyright (c) 2010 Antti Kantee. All Rights Reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: signals.c,v 1.1 2010/04/21 11:38:05 pooka Exp $");
30
31 #include <sys/param.h>
32 #include <sys/atomic.h>
33 #include <sys/event.h>
34 #include <sys/proc.h>
35 #include <sys/signal.h>
36
37 #include <rump/rump.h>
38 #include <rump/rumpuser.h>
39
40 #include "rumpkern_if_priv.h"
41
42 const struct filterops sig_filtops;
43
44 /* RUMP_SIGMODEL_PANIC */
45
46 static void
47 rumpsig_panic(pid_t target, int signo)
48 {
49
50 switch (signo) {
51 case SIGSYS:
52 break;
53 default:
54 panic("unhandled signal %d", signo);
55 }
56 }
57
58 /* RUMP_SIGMODEL_IGNORE */
59
60 static void
61 rumpsig_ignore(pid_t target, int signo)
62 {
63
64 return;
65 }
66
67 /* RUMP_SIGMODEL_HOST */
68
69 static void
70 rumpsig_host(pid_t target, int signo)
71 {
72 int error;
73
74 rumpuser_kill(target, signo, &error);
75 }
76
77 /* RUMP_SIGMODEL_RAISE */
78
79 static void
80 rumpsig_raise(pid_t target, int signo)
81 {
82 int error;
83
84 rumpuser_kill(RUMPUSER_PID_SELF, signo, &error);
85 }
86
87 typedef void (*rumpsig_fn)(pid_t pid, int sig);
88
89 rumpsig_fn rumpsig = rumpsig_panic;
90
91 /*
92 * Set signal delivery model. It would be nice if we could
93 * take a functional argument. But then we'd need some
94 * OS independent way to represent a signal number and also
95 * a method for easy processing (parsing is boring).
96 *
97 * Plus, upcalls from the rump kernel into process space except
98 * via rumpuser is a somewhat gray area now.
99 */
100 void
101 rump_boot_setsigmodel(enum rump_sigmodel model)
102 {
103
104 switch (model) {
105 case RUMP_SIGMODEL_PANIC:
106 atomic_swap_ptr(&rumpsig, rumpsig_panic);
107 break;
108 case RUMP_SIGMODEL_IGNORE:
109 atomic_swap_ptr(&rumpsig, rumpsig_ignore);
110 break;
111 case RUMP_SIGMODEL_HOST:
112 atomic_swap_ptr(&rumpsig, rumpsig_host);
113 break;
114 case RUMP_SIGMODEL_RAISE:
115 atomic_swap_ptr(&rumpsig, rumpsig_raise);
116 break;
117 }
118 }
119
120 void
121 psignal(struct proc *p, int sig)
122 {
123
124 rumpsig(p->p_pid, sig);
125 }
126
127 void
128 pgsignal(struct pgrp *pgrp, int sig, int checktty)
129 {
130
131 rumpsig(-pgrp->pg_id, sig);
132 }
133
134 void
135 kpsignal(struct proc *p, ksiginfo_t *ksi, void *data)
136 {
137
138 rumpsig(p->p_pid, ksi->ksi_signo);
139 }
140
141 void
142 kpgsignal(struct pgrp *pgrp, ksiginfo_t *ksi, void *data, int checkctty)
143 {
144
145 rumpsig(-pgrp->pg_id, ksi->ksi_signo);
146 }
147
148 int
149 sigispending(struct lwp *l, int signo)
150 {
151
152 return 0;
153 }
154
155 void
156 sigpending1(struct lwp *l, sigset_t *ss)
157 {
158
159 sigemptyset(ss);
160 }
161
162 int
163 sigismasked(struct lwp *l, int sig)
164 {
165
166 return 0;
167 }
168
169 void
170 sigclearall(struct proc *p, const sigset_t *mask, ksiginfoq_t *kq)
171 {
172
173 /* nada */
174 }
175
176 void
177 ksiginfo_queue_drain0(ksiginfoq_t *kq)
178 {
179
180 if (!(CIRCLEQ_EMPTY(kq)))
181 panic("how did that get there?");
182 }
183