root / darwin-user / signal.c @ 36bb244b
History | View | Annotate | Download (12.3 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 | 831b7825 | ths | * along with this program; if not, write to the Free Software
|
18 | 831b7825 | ths | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 | 831b7825 | ths | */
|
20 | 831b7825 | ths | #include <stdlib.h> |
21 | 831b7825 | ths | #include <stdio.h> |
22 | 831b7825 | ths | #include <string.h> |
23 | 831b7825 | ths | #include <stdarg.h> |
24 | 831b7825 | ths | #include <unistd.h> |
25 | 831b7825 | ths | #include <signal.h> |
26 | 831b7825 | ths | #include <errno.h> |
27 | 831b7825 | ths | #include <sys/ucontext.h> |
28 | 831b7825 | ths | |
29 | 831b7825 | ths | #ifdef __ia64__
|
30 | 831b7825 | ths | #undef uc_mcontext
|
31 | 831b7825 | ths | #undef uc_sigmask
|
32 | 831b7825 | ths | #undef uc_stack
|
33 | 831b7825 | ths | #undef uc_link
|
34 | 831b7825 | ths | #endif
|
35 | 831b7825 | ths | |
36 | 831b7825 | ths | #include <signal.h> |
37 | 831b7825 | ths | |
38 | 831b7825 | ths | #include "qemu.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 | 831b7825 | ths | 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 | 831b7825 | ths | void __attribute((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 | 831b7825 | ths | if (host_signum == SIGSEGV || host_signum == SIGBUS
|
202 | 831b7825 | ths | #if defined(TARGET_I386) && defined(USE_CODE_COPY)
|
203 | 831b7825 | ths | || host_signum == SIGFPE |
204 | 831b7825 | ths | #endif
|
205 | 831b7825 | ths | ) { |
206 | 831b7825 | ths | if (cpu_signal_handler(host_signum, (void*)info, puc)) |
207 | 831b7825 | ths | return;
|
208 | 831b7825 | ths | } |
209 | 831b7825 | ths | |
210 | 831b7825 | ths | /* get target signal number */
|
211 | 831b7825 | ths | sig = host_to_target_signal(host_signum); |
212 | 831b7825 | ths | if (sig < 1 || sig > NSIG) |
213 | 831b7825 | ths | return;
|
214 | 831b7825 | ths | |
215 | 831b7825 | ths | #if defined(DEBUG_SIGNAL)
|
216 | 831b7825 | ths | fprintf(stderr, "qemu: got signal %d\n", sig);
|
217 | 831b7825 | ths | #endif
|
218 | 831b7825 | ths | if (queue_signal(sig, &tinfo) == 1) { |
219 | 831b7825 | ths | /* interrupt the virtual CPU as soon as possible */
|
220 | 831b7825 | ths | cpu_interrupt(global_env, CPU_INTERRUPT_EXIT); |
221 | 831b7825 | ths | } |
222 | 831b7825 | ths | } |
223 | 831b7825 | ths | |
224 | 831b7825 | ths | int do_sigaltstack(const struct sigaltstack *ss, struct sigaltstack *oss) |
225 | 831b7825 | ths | { |
226 | 831b7825 | ths | /* XXX: test errors */
|
227 | 831b7825 | ths | if(oss)
|
228 | 831b7825 | ths | { |
229 | 831b7825 | ths | oss->ss_sp = tswap32(target_sigaltstack_used.ss_sp); |
230 | 831b7825 | ths | oss->ss_size = tswap32(target_sigaltstack_used.ss_size); |
231 | 831b7825 | ths | oss->ss_flags = tswap32(target_sigaltstack_used.ss_flags); |
232 | 831b7825 | ths | } |
233 | 831b7825 | ths | if(ss)
|
234 | 831b7825 | ths | { |
235 | 831b7825 | ths | target_sigaltstack_used.ss_sp = tswap32(ss->ss_sp); |
236 | 831b7825 | ths | target_sigaltstack_used.ss_size = tswap32(ss->ss_size); |
237 | 831b7825 | ths | target_sigaltstack_used.ss_flags = tswap32(ss->ss_flags); |
238 | 831b7825 | ths | } |
239 | 831b7825 | ths | return 0; |
240 | 831b7825 | ths | } |
241 | 831b7825 | ths | |
242 | 831b7825 | ths | int do_sigaction(int sig, const struct sigaction *act, |
243 | 831b7825 | ths | struct sigaction *oact)
|
244 | 831b7825 | ths | { |
245 | 831b7825 | ths | struct emulated_sigaction *k;
|
246 | 831b7825 | ths | struct sigaction act1;
|
247 | 831b7825 | ths | int host_sig;
|
248 | 831b7825 | ths | |
249 | 831b7825 | ths | if (sig < 1 || sig > NSIG) |
250 | 831b7825 | ths | return -EINVAL;
|
251 | 831b7825 | ths | |
252 | 831b7825 | ths | k = &sigact_table[sig - 1];
|
253 | 831b7825 | ths | #if defined(DEBUG_SIGNAL)
|
254 | 831b7825 | ths | fprintf(stderr, "sigaction 1 sig=%d act=0x%08x, oact=0x%08x\n",
|
255 | 831b7825 | ths | sig, (int)act, (int)oact); |
256 | 831b7825 | ths | #endif
|
257 | 831b7825 | ths | if (oact) {
|
258 | 831b7825 | ths | #if defined(DEBUG_SIGNAL)
|
259 | 831b7825 | ths | fprintf(stderr, "sigaction 1 sig=%d act=0x%08x, oact=0x%08x\n",
|
260 | 831b7825 | ths | sig, (int)act, (int)oact); |
261 | 831b7825 | ths | #endif
|
262 | 831b7825 | ths | |
263 | 831b7825 | ths | oact->sa_handler = tswapl(k->sa.sa_handler); |
264 | 831b7825 | ths | oact->sa_flags = tswapl(k->sa.sa_flags); |
265 | 831b7825 | ths | oact->sa_mask = tswapl(k->sa.sa_mask); |
266 | 831b7825 | ths | } |
267 | 831b7825 | ths | if (act) {
|
268 | 831b7825 | ths | #if defined(DEBUG_SIGNAL)
|
269 | 831b7825 | ths | fprintf(stderr, "sigaction handler 0x%x flag 0x%x mask 0x%x\n",
|
270 | 831b7825 | ths | act->sa_handler, act->sa_flags, act->sa_mask); |
271 | 831b7825 | ths | #endif
|
272 | 831b7825 | ths | |
273 | 831b7825 | ths | k->sa.sa_handler = tswapl(act->sa_handler); |
274 | 831b7825 | ths | k->sa.sa_flags = tswapl(act->sa_flags); |
275 | 831b7825 | ths | k->sa.sa_mask = tswapl(act->sa_mask); |
276 | 831b7825 | ths | /* we update the host signal state */
|
277 | 831b7825 | ths | host_sig = target_to_host_signal(sig); |
278 | 831b7825 | ths | if (host_sig != SIGSEGV && host_sig != SIGBUS) {
|
279 | 831b7825 | ths | #if defined(DEBUG_SIGNAL)
|
280 | 831b7825 | ths | fprintf(stderr, "sigaction handler going to call sigaction\n",
|
281 | 831b7825 | ths | act->sa_handler, act->sa_flags, act->sa_mask); |
282 | 831b7825 | ths | #endif
|
283 | 831b7825 | ths | |
284 | 831b7825 | ths | sigfillset(&act1.sa_mask); |
285 | 831b7825 | ths | act1.sa_flags = SA_SIGINFO; |
286 | 831b7825 | ths | if (k->sa.sa_flags & SA_RESTART)
|
287 | 831b7825 | ths | act1.sa_flags |= SA_RESTART; |
288 | 831b7825 | ths | /* NOTE: it is important to update the host kernel signal
|
289 | 831b7825 | ths | ignore state to avoid getting unexpected interrupted
|
290 | 831b7825 | ths | syscalls */
|
291 | 831b7825 | ths | if (k->sa.sa_handler == SIG_IGN) {
|
292 | 831b7825 | ths | act1.sa_sigaction = (void *)SIG_IGN;
|
293 | 831b7825 | ths | } else if (k->sa.sa_handler == SIG_DFL) { |
294 | 831b7825 | ths | act1.sa_sigaction = (void *)SIG_DFL;
|
295 | 831b7825 | ths | } else {
|
296 | 831b7825 | ths | act1.sa_sigaction = host_signal_handler; |
297 | 831b7825 | ths | } |
298 | 831b7825 | ths | sigaction(host_sig, &act1, NULL);
|
299 | 831b7825 | ths | } |
300 | 831b7825 | ths | } |
301 | 831b7825 | ths | return 0; |
302 | 831b7825 | ths | } |
303 | 831b7825 | ths | |
304 | 831b7825 | ths | |
305 | 831b7825 | ths | #ifdef TARGET_I386
|
306 | 831b7825 | ths | |
307 | 831b7825 | ths | static inline void * |
308 | 831b7825 | ths | get_sigframe(struct emulated_sigaction *ka, CPUX86State *env, size_t frame_size)
|
309 | 831b7825 | ths | { |
310 | 831b7825 | ths | /* XXX Fix that */
|
311 | 831b7825 | ths | if(target_sigaltstack_used.ss_flags & SA_DISABLE)
|
312 | 831b7825 | ths | { |
313 | 831b7825 | ths | int esp;
|
314 | 831b7825 | ths | /* Default to using normal stack */
|
315 | 831b7825 | ths | esp = env->regs[R_ESP]; |
316 | 831b7825 | ths | |
317 | 831b7825 | ths | return (void *)((esp - frame_size) & -8ul); |
318 | 831b7825 | ths | } |
319 | 831b7825 | ths | else
|
320 | 831b7825 | ths | { |
321 | 831b7825 | ths | return target_sigaltstack_used.ss_sp;
|
322 | 831b7825 | ths | } |
323 | 831b7825 | ths | } |
324 | 831b7825 | ths | |
325 | 831b7825 | ths | static void setup_frame(int sig, struct emulated_sigaction *ka, |
326 | 831b7825 | ths | void *set, CPUState *env)
|
327 | 831b7825 | ths | { |
328 | 831b7825 | ths | void *frame;
|
329 | 831b7825 | ths | int i, err = 0; |
330 | 831b7825 | ths | |
331 | 831b7825 | ths | fprintf(stderr, "setup_frame %d\n", sig);
|
332 | 831b7825 | ths | frame = get_sigframe(ka, env, sizeof(*frame));
|
333 | 831b7825 | ths | |
334 | 831b7825 | ths | /* Set up registers for signal handler */
|
335 | 831b7825 | ths | env->regs[R_ESP] = (unsigned long) frame; |
336 | 831b7825 | ths | env->eip = (unsigned long) ka->sa.sa_handler; |
337 | 831b7825 | ths | |
338 | 831b7825 | ths | env->eflags &= ~TF_MASK; |
339 | 831b7825 | ths | |
340 | 831b7825 | ths | return;
|
341 | 831b7825 | ths | |
342 | 831b7825 | ths | give_sigsegv:
|
343 | 831b7825 | ths | if (sig == SIGSEGV)
|
344 | 831b7825 | ths | ka->sa.sa_handler = SIG_DFL; |
345 | 831b7825 | ths | force_sig(SIGSEGV /* , current */);
|
346 | 831b7825 | ths | } |
347 | 831b7825 | ths | |
348 | 831b7825 | ths | long do_sigreturn(CPUState *env, int num) |
349 | 831b7825 | ths | { |
350 | 831b7825 | ths | int i = 0; |
351 | 831b7825 | ths | struct target_sigcontext *scp = get_int_arg(&i, env);
|
352 | 831b7825 | ths | /* XXX Get current signal number */
|
353 | 831b7825 | ths | /* XXX Adjust accordin to sc_onstack, sc_mask */
|
354 | 831b7825 | ths | if(tswapl(scp->sc_onstack) & 0x1) |
355 | 831b7825 | ths | target_sigaltstack_used.ss_flags |= ~SA_DISABLE; |
356 | 831b7825 | ths | else
|
357 | 831b7825 | ths | target_sigaltstack_used.ss_flags &= SA_DISABLE; |
358 | 831b7825 | ths | int set = tswapl(scp->sc_eax);
|
359 | 831b7825 | ths | sigprocmask(SIG_SETMASK, &set, NULL);
|
360 | 831b7825 | ths | |
361 | 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));
|
362 | 831b7825 | ths | fprintf(stderr, "ECX:%x EDX:%x EDI:%x\n", scp->sc_ecx, tswapl(scp->sc_edx), tswapl(scp->sc_edi));
|
363 | 831b7825 | ths | fprintf(stderr, "EIP:%x\n", tswapl(scp->sc_eip));
|
364 | 831b7825 | ths | |
365 | 831b7825 | ths | env->regs[R_EAX] = tswapl(scp->sc_eax); |
366 | 831b7825 | ths | env->regs[R_EBX] = tswapl(scp->sc_ebx); |
367 | 831b7825 | ths | env->regs[R_ECX] = tswapl(scp->sc_ecx); |
368 | 831b7825 | ths | env->regs[R_EDX] = tswapl(scp->sc_edx); |
369 | 831b7825 | ths | env->regs[R_EDI] = tswapl(scp->sc_edi); |
370 | 831b7825 | ths | env->regs[R_ESI] = tswapl(scp->sc_esi); |
371 | 831b7825 | ths | env->regs[R_EBP] = tswapl(scp->sc_ebp); |
372 | 831b7825 | ths | env->regs[R_ESP] = tswapl(scp->sc_esp); |
373 | 831b7825 | ths | env->segs[R_SS].selector = (void*)tswapl(scp->sc_ss);
|
374 | 831b7825 | ths | env->eflags = tswapl(scp->sc_eflags); |
375 | 831b7825 | ths | env->eip = tswapl(scp->sc_eip); |
376 | 831b7825 | ths | env->segs[R_CS].selector = (void*)tswapl(scp->sc_cs);
|
377 | 831b7825 | ths | env->segs[R_DS].selector = (void*)tswapl(scp->sc_ds);
|
378 | 831b7825 | ths | env->segs[R_ES].selector = (void*)tswapl(scp->sc_es);
|
379 | 831b7825 | ths | env->segs[R_FS].selector = (void*)tswapl(scp->sc_fs);
|
380 | 831b7825 | ths | env->segs[R_GS].selector = (void*)tswapl(scp->sc_gs);
|
381 | 831b7825 | ths | |
382 | 831b7825 | ths | /* Again, because our caller's caller will reset EAX */
|
383 | 831b7825 | ths | return env->regs[R_EAX];
|
384 | 831b7825 | ths | } |
385 | 831b7825 | ths | |
386 | 831b7825 | ths | #else
|
387 | 831b7825 | ths | |
388 | 831b7825 | ths | static void setup_frame(int sig, struct emulated_sigaction *ka, |
389 | 831b7825 | ths | void *set, CPUState *env)
|
390 | 831b7825 | ths | { |
391 | 831b7825 | ths | fprintf(stderr, "setup_frame: not implemented\n");
|
392 | 831b7825 | ths | } |
393 | 831b7825 | ths | |
394 | 831b7825 | ths | long do_sigreturn(CPUState *env, int num) |
395 | 831b7825 | ths | { |
396 | 831b7825 | ths | int i = 0; |
397 | 831b7825 | ths | struct target_sigcontext *scp = get_int_arg(&i, env);
|
398 | 831b7825 | ths | fprintf(stderr, "do_sigreturn: not implemented\n");
|
399 | 831b7825 | ths | return -ENOSYS;
|
400 | 831b7825 | ths | } |
401 | 831b7825 | ths | |
402 | 831b7825 | ths | #endif
|
403 | 831b7825 | ths | |
404 | 831b7825 | ths | void process_pending_signals(void *cpu_env) |
405 | 831b7825 | ths | { |
406 | 831b7825 | ths | struct emulated_sigaction *k;
|
407 | 831b7825 | ths | struct sigqueue *q;
|
408 | 831b7825 | ths | target_ulong handler; |
409 | 831b7825 | ths | int sig;
|
410 | 831b7825 | ths | |
411 | 831b7825 | ths | if (!signal_pending)
|
412 | 831b7825 | ths | return;
|
413 | 831b7825 | ths | |
414 | 831b7825 | ths | k = sigact_table; |
415 | 831b7825 | ths | |
416 | 831b7825 | ths | for(sig = 1; sig <= NSIG; sig++) { |
417 | 831b7825 | ths | if (k->pending)
|
418 | 831b7825 | ths | goto handle_signal;
|
419 | 831b7825 | ths | k++; |
420 | 831b7825 | ths | } |
421 | 831b7825 | ths | |
422 | 831b7825 | ths | /* if no signal is pending, just return */
|
423 | 831b7825 | ths | signal_pending = 0;
|
424 | 831b7825 | ths | return;
|
425 | 831b7825 | ths | handle_signal:
|
426 | 831b7825 | ths | #ifdef DEBUG_SIGNAL
|
427 | 831b7825 | ths | fprintf(stderr, "qemu: process signal %d\n", sig);
|
428 | 831b7825 | ths | #endif
|
429 | 831b7825 | ths | /* dequeue signal */
|
430 | 831b7825 | ths | q = k->first; |
431 | 831b7825 | ths | k->first = q->next; |
432 | 831b7825 | ths | if (!k->first)
|
433 | 831b7825 | ths | k->pending = 0;
|
434 | 831b7825 | ths | |
435 | 831b7825 | ths | sig = gdb_handlesig (cpu_env, sig); |
436 | 831b7825 | ths | if (!sig) {
|
437 | 831b7825 | ths | fprintf (stderr, "Lost signal\n");
|
438 | 831b7825 | ths | abort(); |
439 | 831b7825 | ths | } |
440 | 831b7825 | ths | |
441 | 831b7825 | ths | handler = k->sa.sa_handler; |
442 | 831b7825 | ths | if (handler == SIG_DFL) {
|
443 | 831b7825 | ths | /* default handler : ignore some signal. The other are fatal */
|
444 | 831b7825 | ths | if (sig != SIGCHLD &&
|
445 | 831b7825 | ths | sig != SIGURG && |
446 | 831b7825 | ths | sig != SIGWINCH) { |
447 | 831b7825 | ths | force_sig(sig); |
448 | 831b7825 | ths | } |
449 | 831b7825 | ths | } else if (handler == SIG_IGN) { |
450 | 831b7825 | ths | /* ignore sig */
|
451 | 831b7825 | ths | } else if (handler == SIG_ERR) { |
452 | 831b7825 | ths | force_sig(sig); |
453 | 831b7825 | ths | } else {
|
454 | 831b7825 | ths | |
455 | 831b7825 | ths | setup_frame(sig, k, 0, cpu_env);
|
456 | 831b7825 | ths | if (k->sa.sa_flags & SA_RESETHAND)
|
457 | 831b7825 | ths | k->sa.sa_handler = SIG_DFL; |
458 | 831b7825 | ths | } |
459 | 831b7825 | ths | if (q != &k->info)
|
460 | 831b7825 | ths | free_sigqueue(q); |
461 | 831b7825 | ths | } |
462 | 831b7825 | ths |