root / darwin-user / signal.c @ 371c6489
History | View | Annotate | Download (12.1 kB)
1 | 831b7825 | ths | /*
|
---|---|---|---|
2 | 831b7825 | ths | * Emulation of Linux signals
|
3 | 831b7825 | ths | *
|
4 | 831b7825 | ths | * Copyright (c) 2003 Fabrice Bellard
|
5 | 831b7825 | ths | *
|
6 | 831b7825 | ths | * This program is free software; you can redistribute it and/or modify
|
7 | 831b7825 | ths | * it under the terms of the GNU General Public License as published by
|
8 | 831b7825 | ths | * the Free Software Foundation; either version 2 of the License, or
|
9 | 831b7825 | ths | * (at your option) any later version.
|
10 | 831b7825 | ths | *
|
11 | 831b7825 | ths | * This program is distributed in the hope that it will be useful,
|
12 | 831b7825 | ths | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 831b7825 | ths | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 831b7825 | ths | * GNU General Public License for more details.
|
15 | 831b7825 | ths | *
|
16 | 831b7825 | ths | * You should have received a copy of the GNU General Public License
|
17 | 8167ee88 | Blue Swirl | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
18 | 831b7825 | ths | */
|
19 | 831b7825 | ths | #include <stdlib.h> |
20 | 831b7825 | ths | #include <stdio.h> |
21 | 831b7825 | ths | #include <string.h> |
22 | 831b7825 | ths | #include <stdarg.h> |
23 | 831b7825 | ths | #include <unistd.h> |
24 | 831b7825 | ths | #include <errno.h> |
25 | 831b7825 | ths | #include <sys/ucontext.h> |
26 | 831b7825 | ths | |
27 | 831b7825 | ths | #ifdef __ia64__
|
28 | 831b7825 | ths | #undef uc_mcontext
|
29 | 831b7825 | ths | #undef uc_sigmask
|
30 | 831b7825 | ths | #undef uc_stack
|
31 | 831b7825 | ths | #undef uc_link
|
32 | 831b7825 | ths | #endif
|
33 | 831b7825 | ths | |
34 | 831b7825 | ths | #include "qemu.h" |
35 | 7d99a001 | blueswir1 | #include "qemu-common.h" |
36 | 831b7825 | ths | |
37 | 831b7825 | ths | #define DEBUG_SIGNAL
|
38 | 831b7825 | ths | |
39 | 831b7825 | ths | #define MAX_SIGQUEUE_SIZE 1024 |
40 | 831b7825 | ths | |
41 | 831b7825 | ths | struct sigqueue {
|
42 | 831b7825 | ths | struct sigqueue *next;
|
43 | 831b7825 | ths | target_siginfo_t info; |
44 | 831b7825 | ths | }; |
45 | 831b7825 | ths | |
46 | 831b7825 | ths | struct emulated_sigaction {
|
47 | 831b7825 | ths | struct target_sigaction sa;
|
48 | 831b7825 | ths | int pending; /* true if signal is pending */ |
49 | 831b7825 | ths | struct sigqueue *first;
|
50 | 831b7825 | ths | struct sigqueue info; /* in order to always have memory for the |
51 | 831b7825 | ths | first signal, we put it here */
|
52 | 831b7825 | ths | }; |
53 | 831b7825 | ths | |
54 | 249c4c32 | blueswir1 | static struct sigaltstack target_sigaltstack_used = { |
55 | 831b7825 | ths | 0, 0, SA_DISABLE |
56 | 831b7825 | ths | }; |
57 | 831b7825 | ths | |
58 | 831b7825 | ths | static struct emulated_sigaction sigact_table[NSIG]; |
59 | 831b7825 | ths | static struct sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE]; /* siginfo queue */ |
60 | 831b7825 | ths | static struct sigqueue *first_free; /* first free siginfo queue entry */ |
61 | 831b7825 | ths | static int signal_pending; /* non zero if a signal may be pending */ |
62 | 831b7825 | ths | |
63 | 831b7825 | ths | static void host_signal_handler(int host_signum, siginfo_t *info, |
64 | 831b7825 | ths | void *puc);
|
65 | 831b7825 | ths | |
66 | 831b7825 | ths | |
67 | 831b7825 | ths | static inline int host_to_target_signal(int sig) |
68 | 831b7825 | ths | { |
69 | 831b7825 | ths | return sig;
|
70 | 831b7825 | ths | } |
71 | 831b7825 | ths | |
72 | 831b7825 | ths | static inline int target_to_host_signal(int sig) |
73 | 831b7825 | ths | { |
74 | 831b7825 | ths | return sig;
|
75 | 831b7825 | ths | } |
76 | 831b7825 | ths | |
77 | 831b7825 | ths | /* siginfo conversion */
|
78 | 831b7825 | ths | |
79 | 831b7825 | ths | |
80 | 831b7825 | ths | |
81 | 831b7825 | ths | void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info) |
82 | 831b7825 | ths | { |
83 | 831b7825 | ths | |
84 | 831b7825 | ths | } |
85 | 831b7825 | ths | |
86 | 831b7825 | ths | void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo) |
87 | 831b7825 | ths | { |
88 | 831b7825 | ths | |
89 | 831b7825 | ths | } |
90 | 831b7825 | ths | |
91 | 831b7825 | ths | void signal_init(void) |
92 | 831b7825 | ths | { |
93 | 831b7825 | ths | struct sigaction act;
|
94 | 831b7825 | ths | int i;
|
95 | 831b7825 | ths | |
96 | 831b7825 | ths | /* set all host signal handlers. ALL signals are blocked during
|
97 | 831b7825 | ths | the handlers to serialize them. */
|
98 | 831b7825 | ths | sigfillset(&act.sa_mask); |
99 | 831b7825 | ths | act.sa_flags = SA_SIGINFO; |
100 | 831b7825 | ths | act.sa_sigaction = host_signal_handler; |
101 | 831b7825 | ths | for(i = 1; i < NSIG; i++) { |
102 | 831b7825 | ths | sigaction(i, &act, NULL);
|
103 | 831b7825 | ths | } |
104 | 831b7825 | ths | |
105 | 831b7825 | ths | memset(sigact_table, 0, sizeof(sigact_table)); |
106 | 831b7825 | ths | |
107 | 831b7825 | ths | first_free = &sigqueue_table[0];
|
108 | 831b7825 | ths | for(i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) |
109 | 831b7825 | ths | sigqueue_table[i].next = &sigqueue_table[i + 1];
|
110 | 831b7825 | ths | sigqueue_table[MAX_SIGQUEUE_SIZE - 1].next = NULL; |
111 | 831b7825 | ths | } |
112 | 831b7825 | ths | |
113 | 831b7825 | ths | /* signal queue handling */
|
114 | 831b7825 | ths | |
115 | 831b7825 | ths | static inline struct sigqueue *alloc_sigqueue(void) |
116 | 831b7825 | ths | { |
117 | 831b7825 | ths | struct sigqueue *q = first_free;
|
118 | 831b7825 | ths | if (!q)
|
119 | 831b7825 | ths | return NULL; |
120 | 831b7825 | ths | first_free = q->next; |
121 | 831b7825 | ths | return q;
|
122 | 831b7825 | ths | } |
123 | 831b7825 | ths | |
124 | 831b7825 | ths | static inline void free_sigqueue(struct sigqueue *q) |
125 | 831b7825 | ths | { |
126 | 831b7825 | ths | q->next = first_free; |
127 | 831b7825 | ths | first_free = q; |
128 | 831b7825 | ths | } |
129 | 831b7825 | ths | |
130 | 831b7825 | ths | /* abort execution with signal */
|
131 | a5e50b26 | malc | void QEMU_NORETURN force_sig(int sig) |
132 | 831b7825 | ths | { |
133 | 831b7825 | ths | int host_sig;
|
134 | 831b7825 | ths | host_sig = target_to_host_signal(sig); |
135 | 831b7825 | ths | fprintf(stderr, "qemu: uncaught target signal %d (%s) - exiting\n",
|
136 | 831b7825 | ths | sig, strsignal(host_sig)); |
137 | 831b7825 | ths | _exit(-host_sig); |
138 | 831b7825 | ths | } |
139 | 831b7825 | ths | |
140 | 831b7825 | ths | /* queue a signal so that it will be send to the virtual CPU as soon
|
141 | 831b7825 | ths | as possible */
|
142 | 831b7825 | ths | int queue_signal(int sig, target_siginfo_t *info) |
143 | 831b7825 | ths | { |
144 | 831b7825 | ths | struct emulated_sigaction *k;
|
145 | 831b7825 | ths | struct sigqueue *q, **pq;
|
146 | 831b7825 | ths | target_ulong handler; |
147 | 831b7825 | ths | |
148 | 831b7825 | ths | #if defined(DEBUG_SIGNAL)
|
149 | 831b7825 | ths | fprintf(stderr, "queue_signal: sig=%d\n",
|
150 | 831b7825 | ths | sig); |
151 | 831b7825 | ths | #endif
|
152 | 831b7825 | ths | k = &sigact_table[sig - 1];
|
153 | 831b7825 | ths | handler = (target_ulong)k->sa.sa_handler; |
154 | 831b7825 | ths | if (handler == SIG_DFL) {
|
155 | 831b7825 | ths | /* default handler : ignore some signal. The other are fatal */
|
156 | 831b7825 | ths | if (sig != SIGCHLD &&
|
157 | 831b7825 | ths | sig != SIGURG && |
158 | 831b7825 | ths | sig != SIGWINCH) { |
159 | 831b7825 | ths | force_sig(sig); |
160 | 831b7825 | ths | } else {
|
161 | 831b7825 | ths | return 0; /* indicate ignored */ |
162 | 831b7825 | ths | } |
163 | 831b7825 | ths | } else if (handler == host_to_target_signal(SIG_IGN)) { |
164 | 831b7825 | ths | /* ignore signal */
|
165 | 831b7825 | ths | return 0; |
166 | 831b7825 | ths | } else if (handler == host_to_target_signal(SIG_ERR)) { |
167 | 831b7825 | ths | force_sig(sig); |
168 | 831b7825 | ths | } else {
|
169 | 831b7825 | ths | pq = &k->first; |
170 | 831b7825 | ths | if (!k->pending) {
|
171 | 831b7825 | ths | /* first signal */
|
172 | 831b7825 | ths | q = &k->info; |
173 | 831b7825 | ths | } else {
|
174 | 831b7825 | ths | q = alloc_sigqueue(); |
175 | 831b7825 | ths | if (!q)
|
176 | 831b7825 | ths | return -EAGAIN;
|
177 | 831b7825 | ths | while (*pq != NULL) |
178 | 831b7825 | ths | pq = &(*pq)->next; |
179 | 831b7825 | ths | } |
180 | 831b7825 | ths | *pq = q; |
181 | 831b7825 | ths | q->info = *info; |
182 | 831b7825 | ths | q->next = NULL;
|
183 | 831b7825 | ths | k->pending = 1;
|
184 | 831b7825 | ths | /* signal that a new signal is pending */
|
185 | 831b7825 | ths | signal_pending = 1;
|
186 | 831b7825 | ths | return 1; /* indicates that the signal was queued */ |
187 | 831b7825 | ths | } |
188 | 831b7825 | ths | } |
189 | 831b7825 | ths | |
190 | 831b7825 | ths | static void host_signal_handler(int host_signum, siginfo_t *info, |
191 | 831b7825 | ths | void *puc)
|
192 | 831b7825 | ths | { |
193 | 831b7825 | ths | int sig;
|
194 | 831b7825 | ths | target_siginfo_t tinfo; |
195 | 831b7825 | ths | |
196 | 831b7825 | ths | /* the CPU emulator uses some host signals to detect exceptions,
|
197 | 831b7825 | ths | we we forward to it some signals */
|
198 | ec6338ba | bellard | if (host_signum == SIGSEGV || host_signum == SIGBUS) {
|
199 | 831b7825 | ths | if (cpu_signal_handler(host_signum, (void*)info, puc)) |
200 | 831b7825 | ths | return;
|
201 | 831b7825 | ths | } |
202 | 831b7825 | ths | |
203 | 831b7825 | ths | /* get target signal number */
|
204 | 831b7825 | ths | sig = host_to_target_signal(host_signum); |
205 | 831b7825 | ths | if (sig < 1 || sig > NSIG) |
206 | 831b7825 | ths | return;
|
207 | 831b7825 | ths | |
208 | 831b7825 | ths | #if defined(DEBUG_SIGNAL)
|
209 | 831b7825 | ths | fprintf(stderr, "qemu: got signal %d\n", sig);
|
210 | 831b7825 | ths | #endif
|
211 | 831b7825 | ths | if (queue_signal(sig, &tinfo) == 1) { |
212 | 831b7825 | ths | /* interrupt the virtual CPU as soon as possible */
|
213 | 3098dba0 | aurel32 | cpu_exit(global_env); |
214 | 831b7825 | ths | } |
215 | 831b7825 | ths | } |
216 | 831b7825 | ths | |
217 | 831b7825 | ths | int do_sigaltstack(const struct sigaltstack *ss, struct sigaltstack *oss) |
218 | 831b7825 | ths | { |
219 | 831b7825 | ths | /* XXX: test errors */
|
220 | 831b7825 | ths | if(oss)
|
221 | 831b7825 | ths | { |
222 | 831b7825 | ths | oss->ss_sp = tswap32(target_sigaltstack_used.ss_sp); |
223 | 831b7825 | ths | oss->ss_size = tswap32(target_sigaltstack_used.ss_size); |
224 | 831b7825 | ths | oss->ss_flags = tswap32(target_sigaltstack_used.ss_flags); |
225 | 831b7825 | ths | } |
226 | 831b7825 | ths | if(ss)
|
227 | 831b7825 | ths | { |
228 | 831b7825 | ths | target_sigaltstack_used.ss_sp = tswap32(ss->ss_sp); |
229 | 831b7825 | ths | target_sigaltstack_used.ss_size = tswap32(ss->ss_size); |
230 | 831b7825 | ths | target_sigaltstack_used.ss_flags = tswap32(ss->ss_flags); |
231 | 831b7825 | ths | } |
232 | 831b7825 | ths | return 0; |
233 | 831b7825 | ths | } |
234 | 831b7825 | ths | |
235 | 831b7825 | ths | int do_sigaction(int sig, const struct sigaction *act, |
236 | 831b7825 | ths | struct sigaction *oact)
|
237 | 831b7825 | ths | { |
238 | 831b7825 | ths | struct emulated_sigaction *k;
|
239 | 831b7825 | ths | struct sigaction act1;
|
240 | 831b7825 | ths | int host_sig;
|
241 | 831b7825 | ths | |
242 | 831b7825 | ths | if (sig < 1 || sig > NSIG) |
243 | 831b7825 | ths | return -EINVAL;
|
244 | 831b7825 | ths | |
245 | 831b7825 | ths | k = &sigact_table[sig - 1];
|
246 | 831b7825 | ths | #if defined(DEBUG_SIGNAL)
|
247 | 831b7825 | ths | fprintf(stderr, "sigaction 1 sig=%d act=0x%08x, oact=0x%08x\n",
|
248 | 831b7825 | ths | sig, (int)act, (int)oact); |
249 | 831b7825 | ths | #endif
|
250 | 831b7825 | ths | if (oact) {
|
251 | 831b7825 | ths | #if defined(DEBUG_SIGNAL)
|
252 | 831b7825 | ths | fprintf(stderr, "sigaction 1 sig=%d act=0x%08x, oact=0x%08x\n",
|
253 | 831b7825 | ths | sig, (int)act, (int)oact); |
254 | 831b7825 | ths | #endif
|
255 | 831b7825 | ths | |
256 | 831b7825 | ths | oact->sa_handler = tswapl(k->sa.sa_handler); |
257 | 831b7825 | ths | oact->sa_flags = tswapl(k->sa.sa_flags); |
258 | 831b7825 | ths | oact->sa_mask = tswapl(k->sa.sa_mask); |
259 | 831b7825 | ths | } |
260 | 831b7825 | ths | if (act) {
|
261 | 831b7825 | ths | #if defined(DEBUG_SIGNAL)
|
262 | 831b7825 | ths | fprintf(stderr, "sigaction handler 0x%x flag 0x%x mask 0x%x\n",
|
263 | 831b7825 | ths | act->sa_handler, act->sa_flags, act->sa_mask); |
264 | 831b7825 | ths | #endif
|
265 | 831b7825 | ths | |
266 | 831b7825 | ths | k->sa.sa_handler = tswapl(act->sa_handler); |
267 | 831b7825 | ths | k->sa.sa_flags = tswapl(act->sa_flags); |
268 | 831b7825 | ths | k->sa.sa_mask = tswapl(act->sa_mask); |
269 | 831b7825 | ths | /* we update the host signal state */
|
270 | 831b7825 | ths | host_sig = target_to_host_signal(sig); |
271 | 831b7825 | ths | if (host_sig != SIGSEGV && host_sig != SIGBUS) {
|
272 | 831b7825 | ths | #if defined(DEBUG_SIGNAL)
|
273 | 7a4bbe8d | Stefan Weil | fprintf(stderr, "sigaction handler going to call sigaction\n");
|
274 | 831b7825 | ths | #endif
|
275 | 831b7825 | ths | |
276 | 831b7825 | ths | sigfillset(&act1.sa_mask); |
277 | 831b7825 | ths | act1.sa_flags = SA_SIGINFO; |
278 | 831b7825 | ths | if (k->sa.sa_flags & SA_RESTART)
|
279 | 831b7825 | ths | act1.sa_flags |= SA_RESTART; |
280 | 831b7825 | ths | /* NOTE: it is important to update the host kernel signal
|
281 | 831b7825 | ths | ignore state to avoid getting unexpected interrupted
|
282 | 831b7825 | ths | syscalls */
|
283 | 831b7825 | ths | if (k->sa.sa_handler == SIG_IGN) {
|
284 | 831b7825 | ths | act1.sa_sigaction = (void *)SIG_IGN;
|
285 | 831b7825 | ths | } else if (k->sa.sa_handler == SIG_DFL) { |
286 | 831b7825 | ths | act1.sa_sigaction = (void *)SIG_DFL;
|
287 | 831b7825 | ths | } else {
|
288 | 831b7825 | ths | act1.sa_sigaction = host_signal_handler; |
289 | 831b7825 | ths | } |
290 | 831b7825 | ths | sigaction(host_sig, &act1, NULL);
|
291 | 831b7825 | ths | } |
292 | 831b7825 | ths | } |
293 | 831b7825 | ths | return 0; |
294 | 831b7825 | ths | } |
295 | 831b7825 | ths | |
296 | 831b7825 | ths | |
297 | 831b7825 | ths | #ifdef TARGET_I386
|
298 | 831b7825 | ths | |
299 | 831b7825 | ths | static inline void * |
300 | 831b7825 | ths | get_sigframe(struct emulated_sigaction *ka, CPUX86State *env, size_t frame_size)
|
301 | 831b7825 | ths | { |
302 | 831b7825 | ths | /* XXX Fix that */
|
303 | 831b7825 | ths | if(target_sigaltstack_used.ss_flags & SA_DISABLE)
|
304 | 831b7825 | ths | { |
305 | 831b7825 | ths | int esp;
|
306 | 831b7825 | ths | /* Default to using normal stack */
|
307 | 831b7825 | ths | esp = env->regs[R_ESP]; |
308 | 831b7825 | ths | |
309 | 831b7825 | ths | return (void *)((esp - frame_size) & -8ul); |
310 | 831b7825 | ths | } |
311 | 831b7825 | ths | else
|
312 | 831b7825 | ths | { |
313 | 831b7825 | ths | return target_sigaltstack_used.ss_sp;
|
314 | 831b7825 | ths | } |
315 | 831b7825 | ths | } |
316 | 831b7825 | ths | |
317 | 831b7825 | ths | static void setup_frame(int sig, struct emulated_sigaction *ka, |
318 | 831b7825 | ths | void *set, CPUState *env)
|
319 | 831b7825 | ths | { |
320 | 831b7825 | ths | void *frame;
|
321 | 831b7825 | ths | |
322 | 831b7825 | ths | fprintf(stderr, "setup_frame %d\n", sig);
|
323 | 831b7825 | ths | frame = get_sigframe(ka, env, sizeof(*frame));
|
324 | 831b7825 | ths | |
325 | 831b7825 | ths | /* Set up registers for signal handler */
|
326 | 831b7825 | ths | env->regs[R_ESP] = (unsigned long) frame; |
327 | 831b7825 | ths | env->eip = (unsigned long) ka->sa.sa_handler; |
328 | 831b7825 | ths | |
329 | 831b7825 | ths | env->eflags &= ~TF_MASK; |
330 | 831b7825 | ths | |
331 | 831b7825 | ths | return;
|
332 | 831b7825 | ths | |
333 | 831b7825 | ths | give_sigsegv:
|
334 | 831b7825 | ths | if (sig == SIGSEGV)
|
335 | 831b7825 | ths | ka->sa.sa_handler = SIG_DFL; |
336 | 831b7825 | ths | force_sig(SIGSEGV /* , current */);
|
337 | 831b7825 | ths | } |
338 | 831b7825 | ths | |
339 | 831b7825 | ths | long do_sigreturn(CPUState *env, int num) |
340 | 831b7825 | ths | { |
341 | 831b7825 | ths | int i = 0; |
342 | 831b7825 | ths | struct target_sigcontext *scp = get_int_arg(&i, env);
|
343 | 831b7825 | ths | /* XXX Get current signal number */
|
344 | 831b7825 | ths | /* XXX Adjust accordin to sc_onstack, sc_mask */
|
345 | 831b7825 | ths | if(tswapl(scp->sc_onstack) & 0x1) |
346 | 831b7825 | ths | target_sigaltstack_used.ss_flags |= ~SA_DISABLE; |
347 | 831b7825 | ths | else
|
348 | 831b7825 | ths | target_sigaltstack_used.ss_flags &= SA_DISABLE; |
349 | 831b7825 | ths | int set = tswapl(scp->sc_eax);
|
350 | 831b7825 | ths | sigprocmask(SIG_SETMASK, &set, NULL);
|
351 | 831b7825 | ths | |
352 | 831b7825 | ths | fprintf(stderr, "do_sigreturn: partially implemented %x EAX:%x EBX:%x\n", scp->sc_mask, tswapl(scp->sc_eax), tswapl(scp->sc_ebx));
|
353 | 831b7825 | ths | fprintf(stderr, "ECX:%x EDX:%x EDI:%x\n", scp->sc_ecx, tswapl(scp->sc_edx), tswapl(scp->sc_edi));
|
354 | 831b7825 | ths | fprintf(stderr, "EIP:%x\n", tswapl(scp->sc_eip));
|
355 | 831b7825 | ths | |
356 | 831b7825 | ths | env->regs[R_EAX] = tswapl(scp->sc_eax); |
357 | 831b7825 | ths | env->regs[R_EBX] = tswapl(scp->sc_ebx); |
358 | 831b7825 | ths | env->regs[R_ECX] = tswapl(scp->sc_ecx); |
359 | 831b7825 | ths | env->regs[R_EDX] = tswapl(scp->sc_edx); |
360 | 831b7825 | ths | env->regs[R_EDI] = tswapl(scp->sc_edi); |
361 | 831b7825 | ths | env->regs[R_ESI] = tswapl(scp->sc_esi); |
362 | 831b7825 | ths | env->regs[R_EBP] = tswapl(scp->sc_ebp); |
363 | 831b7825 | ths | env->regs[R_ESP] = tswapl(scp->sc_esp); |
364 | 831b7825 | ths | env->segs[R_SS].selector = (void*)tswapl(scp->sc_ss);
|
365 | 831b7825 | ths | env->eflags = tswapl(scp->sc_eflags); |
366 | 831b7825 | ths | env->eip = tswapl(scp->sc_eip); |
367 | 831b7825 | ths | env->segs[R_CS].selector = (void*)tswapl(scp->sc_cs);
|
368 | 831b7825 | ths | env->segs[R_DS].selector = (void*)tswapl(scp->sc_ds);
|
369 | 831b7825 | ths | env->segs[R_ES].selector = (void*)tswapl(scp->sc_es);
|
370 | 831b7825 | ths | env->segs[R_FS].selector = (void*)tswapl(scp->sc_fs);
|
371 | 831b7825 | ths | env->segs[R_GS].selector = (void*)tswapl(scp->sc_gs);
|
372 | 831b7825 | ths | |
373 | 831b7825 | ths | /* Again, because our caller's caller will reset EAX */
|
374 | 831b7825 | ths | return env->regs[R_EAX];
|
375 | 831b7825 | ths | } |
376 | 831b7825 | ths | |
377 | 831b7825 | ths | #else
|
378 | 831b7825 | ths | |
379 | 831b7825 | ths | static void setup_frame(int sig, struct emulated_sigaction *ka, |
380 | 831b7825 | ths | void *set, CPUState *env)
|
381 | 831b7825 | ths | { |
382 | 831b7825 | ths | fprintf(stderr, "setup_frame: not implemented\n");
|
383 | 831b7825 | ths | } |
384 | 831b7825 | ths | |
385 | 831b7825 | ths | long do_sigreturn(CPUState *env, int num) |
386 | 831b7825 | ths | { |
387 | 831b7825 | ths | int i = 0; |
388 | 831b7825 | ths | struct target_sigcontext *scp = get_int_arg(&i, env);
|
389 | 831b7825 | ths | fprintf(stderr, "do_sigreturn: not implemented\n");
|
390 | 831b7825 | ths | return -ENOSYS;
|
391 | 831b7825 | ths | } |
392 | 831b7825 | ths | |
393 | 831b7825 | ths | #endif
|
394 | 831b7825 | ths | |
395 | 831b7825 | ths | void process_pending_signals(void *cpu_env) |
396 | 831b7825 | ths | { |
397 | 831b7825 | ths | struct emulated_sigaction *k;
|
398 | 831b7825 | ths | struct sigqueue *q;
|
399 | 831b7825 | ths | target_ulong handler; |
400 | 831b7825 | ths | int sig;
|
401 | 831b7825 | ths | |
402 | 831b7825 | ths | if (!signal_pending)
|
403 | 831b7825 | ths | return;
|
404 | 831b7825 | ths | |
405 | 831b7825 | ths | k = sigact_table; |
406 | 831b7825 | ths | |
407 | 831b7825 | ths | for(sig = 1; sig <= NSIG; sig++) { |
408 | 831b7825 | ths | if (k->pending)
|
409 | 831b7825 | ths | goto handle_signal;
|
410 | 831b7825 | ths | k++; |
411 | 831b7825 | ths | } |
412 | 831b7825 | ths | |
413 | 831b7825 | ths | /* if no signal is pending, just return */
|
414 | 831b7825 | ths | signal_pending = 0;
|
415 | 831b7825 | ths | return;
|
416 | 831b7825 | ths | handle_signal:
|
417 | 831b7825 | ths | #ifdef DEBUG_SIGNAL
|
418 | 831b7825 | ths | fprintf(stderr, "qemu: process signal %d\n", sig);
|
419 | 831b7825 | ths | #endif
|
420 | 831b7825 | ths | /* dequeue signal */
|
421 | 831b7825 | ths | q = k->first; |
422 | 831b7825 | ths | k->first = q->next; |
423 | 831b7825 | ths | if (!k->first)
|
424 | 831b7825 | ths | k->pending = 0;
|
425 | 831b7825 | ths | |
426 | 831b7825 | ths | sig = gdb_handlesig (cpu_env, sig); |
427 | 831b7825 | ths | if (!sig) {
|
428 | 831b7825 | ths | fprintf (stderr, "Lost signal\n");
|
429 | 831b7825 | ths | abort(); |
430 | 831b7825 | ths | } |
431 | 831b7825 | ths | |
432 | 831b7825 | ths | handler = k->sa.sa_handler; |
433 | 831b7825 | ths | if (handler == SIG_DFL) {
|
434 | 831b7825 | ths | /* default handler : ignore some signal. The other are fatal */
|
435 | 831b7825 | ths | if (sig != SIGCHLD &&
|
436 | 831b7825 | ths | sig != SIGURG && |
437 | 831b7825 | ths | sig != SIGWINCH) { |
438 | 831b7825 | ths | force_sig(sig); |
439 | 831b7825 | ths | } |
440 | 831b7825 | ths | } else if (handler == SIG_IGN) { |
441 | 831b7825 | ths | /* ignore sig */
|
442 | 831b7825 | ths | } else if (handler == SIG_ERR) { |
443 | 831b7825 | ths | force_sig(sig); |
444 | 831b7825 | ths | } else {
|
445 | 831b7825 | ths | |
446 | 831b7825 | ths | setup_frame(sig, k, 0, cpu_env);
|
447 | 831b7825 | ths | if (k->sa.sa_flags & SA_RESETHAND)
|
448 | 831b7825 | ths | k->sa.sa_handler = SIG_DFL; |
449 | 831b7825 | ths | } |
450 | 831b7825 | ths | if (q != &k->info)
|
451 | 831b7825 | ths | free_sigqueue(q); |
452 | 831b7825 | ths | } |