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