root / linux-user / signal.c @ facc68be
History | View | Annotate | Download (38.1 kB)
1 | 31e31b8a | bellard | /*
|
---|---|---|---|
2 | 66fb9763 | bellard | * Emulation of Linux signals
|
3 | 31e31b8a | bellard | *
|
4 | 31e31b8a | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 31e31b8a | bellard | *
|
6 | 31e31b8a | bellard | * This program is free software; you can redistribute it and/or modify
|
7 | 31e31b8a | bellard | * it under the terms of the GNU General Public License as published by
|
8 | 31e31b8a | bellard | * the Free Software Foundation; either version 2 of the License, or
|
9 | 31e31b8a | bellard | * (at your option) any later version.
|
10 | 31e31b8a | bellard | *
|
11 | 31e31b8a | bellard | * This program is distributed in the hope that it will be useful,
|
12 | 31e31b8a | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 31e31b8a | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 31e31b8a | bellard | * GNU General Public License for more details.
|
15 | 31e31b8a | bellard | *
|
16 | 31e31b8a | bellard | * You should have received a copy of the GNU General Public License
|
17 | 31e31b8a | bellard | * along with this program; if not, write to the Free Software
|
18 | 31e31b8a | bellard | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 | 31e31b8a | bellard | */
|
20 | 31e31b8a | bellard | #include <stdlib.h> |
21 | 31e31b8a | bellard | #include <stdio.h> |
22 | 66fb9763 | bellard | #include <string.h> |
23 | 31e31b8a | bellard | #include <stdarg.h> |
24 | 2677e107 | bellard | #include <unistd.h> |
25 | 31e31b8a | bellard | #include <signal.h> |
26 | 66fb9763 | bellard | #include <errno.h> |
27 | 31e31b8a | bellard | #include <sys/ucontext.h> |
28 | 31e31b8a | bellard | |
29 | 0d330196 | bellard | #ifdef __ia64__
|
30 | 0d330196 | bellard | #undef uc_mcontext
|
31 | 0d330196 | bellard | #undef uc_sigmask
|
32 | 0d330196 | bellard | #undef uc_stack
|
33 | 0d330196 | bellard | #undef uc_link
|
34 | 0d330196 | bellard | #endif
|
35 | 0d330196 | bellard | |
36 | 3ef693a0 | bellard | #include "qemu.h" |
37 | 66fb9763 | bellard | |
38 | 66fb9763 | bellard | //#define DEBUG_SIGNAL
|
39 | 66fb9763 | bellard | |
40 | 66fb9763 | bellard | #define MAX_SIGQUEUE_SIZE 1024 |
41 | 66fb9763 | bellard | |
42 | 66fb9763 | bellard | struct sigqueue {
|
43 | 66fb9763 | bellard | struct sigqueue *next;
|
44 | 9de5e440 | bellard | target_siginfo_t info; |
45 | 66fb9763 | bellard | }; |
46 | 31e31b8a | bellard | |
47 | 31e31b8a | bellard | struct emulated_sigaction {
|
48 | 31e31b8a | bellard | struct target_sigaction sa;
|
49 | 66fb9763 | bellard | int pending; /* true if signal is pending */ |
50 | 66fb9763 | bellard | struct sigqueue *first;
|
51 | 66fb9763 | bellard | struct sigqueue info; /* in order to always have memory for the |
52 | 66fb9763 | bellard | first signal, we put it here */
|
53 | 31e31b8a | bellard | }; |
54 | 31e31b8a | bellard | |
55 | 66fb9763 | bellard | static struct emulated_sigaction sigact_table[TARGET_NSIG]; |
56 | 66fb9763 | bellard | static struct sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE]; /* siginfo queue */ |
57 | 66fb9763 | bellard | static struct sigqueue *first_free; /* first free siginfo queue entry */ |
58 | 66fb9763 | bellard | static int signal_pending; /* non zero if a signal may be pending */ |
59 | 31e31b8a | bellard | |
60 | 66fb9763 | bellard | static void host_signal_handler(int host_signum, siginfo_t *info, |
61 | 66fb9763 | bellard | void *puc);
|
62 | 66fb9763 | bellard | |
63 | 9e5f5284 | bellard | static uint8_t host_to_target_signal_table[65] = { |
64 | 9e5f5284 | bellard | [SIGHUP] = TARGET_SIGHUP, |
65 | 9e5f5284 | bellard | [SIGINT] = TARGET_SIGINT, |
66 | 9e5f5284 | bellard | [SIGQUIT] = TARGET_SIGQUIT, |
67 | 9e5f5284 | bellard | [SIGILL] = TARGET_SIGILL, |
68 | 9e5f5284 | bellard | [SIGTRAP] = TARGET_SIGTRAP, |
69 | 9e5f5284 | bellard | [SIGABRT] = TARGET_SIGABRT, |
70 | 9e5f5284 | bellard | [SIGIOT] = TARGET_SIGIOT, |
71 | 9e5f5284 | bellard | [SIGBUS] = TARGET_SIGBUS, |
72 | 9e5f5284 | bellard | [SIGFPE] = TARGET_SIGFPE, |
73 | 9e5f5284 | bellard | [SIGKILL] = TARGET_SIGKILL, |
74 | 9e5f5284 | bellard | [SIGUSR1] = TARGET_SIGUSR1, |
75 | 9e5f5284 | bellard | [SIGSEGV] = TARGET_SIGSEGV, |
76 | 9e5f5284 | bellard | [SIGUSR2] = TARGET_SIGUSR2, |
77 | 9e5f5284 | bellard | [SIGPIPE] = TARGET_SIGPIPE, |
78 | 9e5f5284 | bellard | [SIGALRM] = TARGET_SIGALRM, |
79 | 9e5f5284 | bellard | [SIGTERM] = TARGET_SIGTERM, |
80 | 9e5f5284 | bellard | #ifdef SIGSTKFLT
|
81 | 9e5f5284 | bellard | [SIGSTKFLT] = TARGET_SIGSTKFLT, |
82 | 9e5f5284 | bellard | #endif
|
83 | 9e5f5284 | bellard | [SIGCHLD] = TARGET_SIGCHLD, |
84 | 9e5f5284 | bellard | [SIGCONT] = TARGET_SIGCONT, |
85 | 9e5f5284 | bellard | [SIGSTOP] = TARGET_SIGSTOP, |
86 | 9e5f5284 | bellard | [SIGTSTP] = TARGET_SIGTSTP, |
87 | 9e5f5284 | bellard | [SIGTTIN] = TARGET_SIGTTIN, |
88 | 9e5f5284 | bellard | [SIGTTOU] = TARGET_SIGTTOU, |
89 | 9e5f5284 | bellard | [SIGURG] = TARGET_SIGURG, |
90 | 9e5f5284 | bellard | [SIGXCPU] = TARGET_SIGXCPU, |
91 | 9e5f5284 | bellard | [SIGXFSZ] = TARGET_SIGXFSZ, |
92 | 9e5f5284 | bellard | [SIGVTALRM] = TARGET_SIGVTALRM, |
93 | 9e5f5284 | bellard | [SIGPROF] = TARGET_SIGPROF, |
94 | 9e5f5284 | bellard | [SIGWINCH] = TARGET_SIGWINCH, |
95 | 9e5f5284 | bellard | [SIGIO] = TARGET_SIGIO, |
96 | 9e5f5284 | bellard | [SIGPWR] = TARGET_SIGPWR, |
97 | 9e5f5284 | bellard | [SIGSYS] = TARGET_SIGSYS, |
98 | 9e5f5284 | bellard | /* next signals stay the same */
|
99 | 9e5f5284 | bellard | }; |
100 | 9e5f5284 | bellard | static uint8_t target_to_host_signal_table[65]; |
101 | 9e5f5284 | bellard | |
102 | 31e31b8a | bellard | static inline int host_to_target_signal(int sig) |
103 | 31e31b8a | bellard | { |
104 | 9e5f5284 | bellard | return host_to_target_signal_table[sig];
|
105 | 31e31b8a | bellard | } |
106 | 31e31b8a | bellard | |
107 | 31e31b8a | bellard | static inline int target_to_host_signal(int sig) |
108 | 31e31b8a | bellard | { |
109 | 9e5f5284 | bellard | return target_to_host_signal_table[sig];
|
110 | 31e31b8a | bellard | } |
111 | 31e31b8a | bellard | |
112 | 9e5f5284 | bellard | void host_to_target_sigset(target_sigset_t *d, const sigset_t *s) |
113 | 66fb9763 | bellard | { |
114 | 66fb9763 | bellard | int i;
|
115 | 9e5f5284 | bellard | unsigned long sigmask; |
116 | 9e5f5284 | bellard | uint32_t target_sigmask; |
117 | 9e5f5284 | bellard | |
118 | 9e5f5284 | bellard | sigmask = ((unsigned long *)s)[0]; |
119 | 9e5f5284 | bellard | target_sigmask = 0;
|
120 | 9e5f5284 | bellard | for(i = 0; i < 32; i++) { |
121 | 9e5f5284 | bellard | if (sigmask & (1 << i)) |
122 | 9e5f5284 | bellard | target_sigmask |= 1 << (host_to_target_signal(i + 1) - 1); |
123 | 9e5f5284 | bellard | } |
124 | 9e5f5284 | bellard | #if TARGET_LONG_BITS == 32 && HOST_LONG_BITS == 32 |
125 | 9e5f5284 | bellard | d->sig[0] = tswapl(target_sigmask);
|
126 | 9e5f5284 | bellard | for(i = 1;i < TARGET_NSIG_WORDS; i++) { |
127 | 66fb9763 | bellard | d->sig[i] = tswapl(((unsigned long *)s)[i]); |
128 | 66fb9763 | bellard | } |
129 | 9e5f5284 | bellard | #elif TARGET_LONG_BITS == 32 && HOST_LONG_BITS == 64 && TARGET_NSIG_WORDS == 2 |
130 | 9e5f5284 | bellard | d->sig[0] = tswapl(target_sigmask);
|
131 | 9e5f5284 | bellard | d->sig[1] = tswapl(sigmask >> 32); |
132 | 9e5f5284 | bellard | #else
|
133 | 9e5f5284 | bellard | #error host_to_target_sigset
|
134 | 9e5f5284 | bellard | #endif
|
135 | 66fb9763 | bellard | } |
136 | 66fb9763 | bellard | |
137 | 9e5f5284 | bellard | void target_to_host_sigset(sigset_t *d, const target_sigset_t *s) |
138 | 66fb9763 | bellard | { |
139 | 66fb9763 | bellard | int i;
|
140 | 9e5f5284 | bellard | unsigned long sigmask; |
141 | 9e5f5284 | bellard | target_ulong target_sigmask; |
142 | 9e5f5284 | bellard | |
143 | 9e5f5284 | bellard | target_sigmask = tswapl(s->sig[0]);
|
144 | 9e5f5284 | bellard | sigmask = 0;
|
145 | 9e5f5284 | bellard | for(i = 0; i < 32; i++) { |
146 | 9e5f5284 | bellard | if (target_sigmask & (1 << i)) |
147 | 9e5f5284 | bellard | sigmask |= 1 << (target_to_host_signal(i + 1) - 1); |
148 | 9e5f5284 | bellard | } |
149 | 9e5f5284 | bellard | #if TARGET_LONG_BITS == 32 && HOST_LONG_BITS == 32 |
150 | 9e5f5284 | bellard | ((unsigned long *)d)[0] = sigmask; |
151 | 9e5f5284 | bellard | for(i = 1;i < TARGET_NSIG_WORDS; i++) { |
152 | 66fb9763 | bellard | ((unsigned long *)d)[i] = tswapl(s->sig[i]); |
153 | 66fb9763 | bellard | } |
154 | 9e5f5284 | bellard | #elif TARGET_LONG_BITS == 32 && HOST_LONG_BITS == 64 && TARGET_NSIG_WORDS == 2 |
155 | 9dfa5b42 | bellard | ((unsigned long *)d)[0] = sigmask | ((unsigned long)tswapl(s->sig[1]) << 32); |
156 | 9e5f5284 | bellard | #else
|
157 | 9e5f5284 | bellard | #error target_to_host_sigset
|
158 | 9e5f5284 | bellard | #endif /* TARGET_LONG_BITS */ |
159 | 66fb9763 | bellard | } |
160 | 66fb9763 | bellard | |
161 | 66fb9763 | bellard | void host_to_target_old_sigset(target_ulong *old_sigset,
|
162 | 66fb9763 | bellard | const sigset_t *sigset)
|
163 | 66fb9763 | bellard | { |
164 | 9e5f5284 | bellard | target_sigset_t d; |
165 | 9e5f5284 | bellard | host_to_target_sigset(&d, sigset); |
166 | 9e5f5284 | bellard | *old_sigset = d.sig[0];
|
167 | 66fb9763 | bellard | } |
168 | 66fb9763 | bellard | |
169 | 66fb9763 | bellard | void target_to_host_old_sigset(sigset_t *sigset,
|
170 | 66fb9763 | bellard | const target_ulong *old_sigset)
|
171 | 66fb9763 | bellard | { |
172 | 9e5f5284 | bellard | target_sigset_t d; |
173 | 9e5f5284 | bellard | int i;
|
174 | 9e5f5284 | bellard | |
175 | 9e5f5284 | bellard | d.sig[0] = *old_sigset;
|
176 | 9e5f5284 | bellard | for(i = 1;i < TARGET_NSIG_WORDS; i++) |
177 | 9e5f5284 | bellard | d.sig[i] = 0;
|
178 | 9e5f5284 | bellard | target_to_host_sigset(sigset, &d); |
179 | 66fb9763 | bellard | } |
180 | 66fb9763 | bellard | |
181 | 9de5e440 | bellard | /* siginfo conversion */
|
182 | 9de5e440 | bellard | |
183 | 9de5e440 | bellard | static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo, |
184 | 9de5e440 | bellard | const siginfo_t *info)
|
185 | 66fb9763 | bellard | { |
186 | 9de5e440 | bellard | int sig;
|
187 | 9de5e440 | bellard | sig = host_to_target_signal(info->si_signo); |
188 | 9de5e440 | bellard | tinfo->si_signo = sig; |
189 | 9de5e440 | bellard | tinfo->si_errno = 0;
|
190 | 9de5e440 | bellard | tinfo->si_code = 0;
|
191 | 447db213 | bellard | if (sig == SIGILL || sig == SIGFPE || sig == SIGSEGV ||
|
192 | 447db213 | bellard | sig == SIGBUS || sig == SIGTRAP) { |
193 | 9de5e440 | bellard | /* should never come here, but who knows. The information for
|
194 | 9de5e440 | bellard | the target is irrelevant */
|
195 | 9de5e440 | bellard | tinfo->_sifields._sigfault._addr = 0;
|
196 | 9de5e440 | bellard | } else if (sig >= TARGET_SIGRTMIN) { |
197 | 9de5e440 | bellard | tinfo->_sifields._rt._pid = info->si_pid; |
198 | 9de5e440 | bellard | tinfo->_sifields._rt._uid = info->si_uid; |
199 | 9de5e440 | bellard | /* XXX: potential problem if 64 bit */
|
200 | 9de5e440 | bellard | tinfo->_sifields._rt._sigval.sival_ptr = |
201 | 9de5e440 | bellard | (target_ulong)info->si_value.sival_ptr; |
202 | 9de5e440 | bellard | } |
203 | 9de5e440 | bellard | } |
204 | 9de5e440 | bellard | |
205 | 9de5e440 | bellard | static void tswap_siginfo(target_siginfo_t *tinfo, |
206 | 9de5e440 | bellard | const target_siginfo_t *info)
|
207 | 9de5e440 | bellard | { |
208 | 9de5e440 | bellard | int sig;
|
209 | 9de5e440 | bellard | sig = info->si_signo; |
210 | 9de5e440 | bellard | tinfo->si_signo = tswap32(sig); |
211 | 66fb9763 | bellard | tinfo->si_errno = tswap32(info->si_errno); |
212 | 66fb9763 | bellard | tinfo->si_code = tswap32(info->si_code); |
213 | 447db213 | bellard | if (sig == SIGILL || sig == SIGFPE || sig == SIGSEGV ||
|
214 | 447db213 | bellard | sig == SIGBUS || sig == SIGTRAP) { |
215 | 9de5e440 | bellard | tinfo->_sifields._sigfault._addr = |
216 | 9de5e440 | bellard | tswapl(info->_sifields._sigfault._addr); |
217 | 9de5e440 | bellard | } else if (sig >= TARGET_SIGRTMIN) { |
218 | 9de5e440 | bellard | tinfo->_sifields._rt._pid = tswap32(info->_sifields._rt._pid); |
219 | 9de5e440 | bellard | tinfo->_sifields._rt._uid = tswap32(info->_sifields._rt._uid); |
220 | 9de5e440 | bellard | tinfo->_sifields._rt._sigval.sival_ptr = |
221 | 9de5e440 | bellard | tswapl(info->_sifields._rt._sigval.sival_ptr); |
222 | 9de5e440 | bellard | } |
223 | 9de5e440 | bellard | } |
224 | 9de5e440 | bellard | |
225 | 9de5e440 | bellard | |
226 | 9de5e440 | bellard | void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info) |
227 | 9de5e440 | bellard | { |
228 | 9de5e440 | bellard | host_to_target_siginfo_noswap(tinfo, info); |
229 | 9de5e440 | bellard | tswap_siginfo(tinfo, tinfo); |
230 | 66fb9763 | bellard | } |
231 | 66fb9763 | bellard | |
232 | 9de5e440 | bellard | /* XXX: we support only POSIX RT signals are used. */
|
233 | 9de5e440 | bellard | /* XXX: find a solution for 64 bit (additionnal malloced data is needed) */
|
234 | 9de5e440 | bellard | void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo) |
235 | 66fb9763 | bellard | { |
236 | 66fb9763 | bellard | info->si_signo = tswap32(tinfo->si_signo); |
237 | 66fb9763 | bellard | info->si_errno = tswap32(tinfo->si_errno); |
238 | 66fb9763 | bellard | info->si_code = tswap32(tinfo->si_code); |
239 | 9de5e440 | bellard | info->si_pid = tswap32(tinfo->_sifields._rt._pid); |
240 | 9de5e440 | bellard | info->si_uid = tswap32(tinfo->_sifields._rt._uid); |
241 | 9de5e440 | bellard | info->si_value.sival_ptr = |
242 | 9de5e440 | bellard | (void *)tswapl(tinfo->_sifields._rt._sigval.sival_ptr);
|
243 | 66fb9763 | bellard | } |
244 | 66fb9763 | bellard | |
245 | 31e31b8a | bellard | void signal_init(void) |
246 | 31e31b8a | bellard | { |
247 | 31e31b8a | bellard | struct sigaction act;
|
248 | 9e5f5284 | bellard | int i, j;
|
249 | 31e31b8a | bellard | |
250 | 9e5f5284 | bellard | /* generate signal conversion tables */
|
251 | 9e5f5284 | bellard | for(i = 1; i <= 64; i++) { |
252 | 9e5f5284 | bellard | if (host_to_target_signal_table[i] == 0) |
253 | 9e5f5284 | bellard | host_to_target_signal_table[i] = i; |
254 | 9e5f5284 | bellard | } |
255 | 9e5f5284 | bellard | for(i = 1; i <= 64; i++) { |
256 | 9e5f5284 | bellard | j = host_to_target_signal_table[i]; |
257 | 9e5f5284 | bellard | target_to_host_signal_table[j] = i; |
258 | 9e5f5284 | bellard | } |
259 | 9e5f5284 | bellard | |
260 | 9de5e440 | bellard | /* set all host signal handlers. ALL signals are blocked during
|
261 | 9de5e440 | bellard | the handlers to serialize them. */
|
262 | 9de5e440 | bellard | sigfillset(&act.sa_mask); |
263 | 31e31b8a | bellard | act.sa_flags = SA_SIGINFO; |
264 | 31e31b8a | bellard | act.sa_sigaction = host_signal_handler; |
265 | 31e31b8a | bellard | for(i = 1; i < NSIG; i++) { |
266 | c9087c2a | bellard | sigaction(i, &act, NULL);
|
267 | 31e31b8a | bellard | } |
268 | 31e31b8a | bellard | |
269 | 31e31b8a | bellard | memset(sigact_table, 0, sizeof(sigact_table)); |
270 | 66fb9763 | bellard | |
271 | 66fb9763 | bellard | first_free = &sigqueue_table[0];
|
272 | 66fb9763 | bellard | for(i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) |
273 | 66fb9763 | bellard | sigqueue_table[i].next = &sigqueue_table[i + 1];
|
274 | 66fb9763 | bellard | sigqueue_table[MAX_SIGQUEUE_SIZE - 1].next = NULL; |
275 | 66fb9763 | bellard | } |
276 | 66fb9763 | bellard | |
277 | 66fb9763 | bellard | /* signal queue handling */
|
278 | 66fb9763 | bellard | |
279 | 66fb9763 | bellard | static inline struct sigqueue *alloc_sigqueue(void) |
280 | 66fb9763 | bellard | { |
281 | 66fb9763 | bellard | struct sigqueue *q = first_free;
|
282 | 66fb9763 | bellard | if (!q)
|
283 | 66fb9763 | bellard | return NULL; |
284 | 66fb9763 | bellard | first_free = q->next; |
285 | 66fb9763 | bellard | return q;
|
286 | 31e31b8a | bellard | } |
287 | 31e31b8a | bellard | |
288 | 66fb9763 | bellard | static inline void free_sigqueue(struct sigqueue *q) |
289 | 66fb9763 | bellard | { |
290 | 66fb9763 | bellard | q->next = first_free; |
291 | 66fb9763 | bellard | first_free = q; |
292 | 66fb9763 | bellard | } |
293 | 66fb9763 | bellard | |
294 | 9de5e440 | bellard | /* abort execution with signal */
|
295 | 9de5e440 | bellard | void __attribute((noreturn)) force_sig(int sig) |
296 | 66fb9763 | bellard | { |
297 | 66fb9763 | bellard | int host_sig;
|
298 | 66fb9763 | bellard | host_sig = target_to_host_signal(sig); |
299 | bc8a22cc | bellard | fprintf(stderr, "qemu: uncaught target signal %d (%s) - exiting\n",
|
300 | 66fb9763 | bellard | sig, strsignal(host_sig)); |
301 | 9de5e440 | bellard | #if 1 |
302 | 66fb9763 | bellard | _exit(-host_sig); |
303 | 9de5e440 | bellard | #else
|
304 | 9de5e440 | bellard | { |
305 | 9de5e440 | bellard | struct sigaction act;
|
306 | 9de5e440 | bellard | sigemptyset(&act.sa_mask); |
307 | 9de5e440 | bellard | act.sa_flags = SA_SIGINFO; |
308 | 9de5e440 | bellard | act.sa_sigaction = SIG_DFL; |
309 | 9de5e440 | bellard | sigaction(SIGABRT, &act, NULL);
|
310 | 9de5e440 | bellard | abort(); |
311 | 9de5e440 | bellard | } |
312 | 9de5e440 | bellard | #endif
|
313 | 66fb9763 | bellard | } |
314 | 66fb9763 | bellard | |
315 | 9de5e440 | bellard | /* queue a signal so that it will be send to the virtual CPU as soon
|
316 | 9de5e440 | bellard | as possible */
|
317 | 9de5e440 | bellard | int queue_signal(int sig, target_siginfo_t *info) |
318 | 31e31b8a | bellard | { |
319 | 66fb9763 | bellard | struct emulated_sigaction *k;
|
320 | 9de5e440 | bellard | struct sigqueue *q, **pq;
|
321 | 66fb9763 | bellard | target_ulong handler; |
322 | 66fb9763 | bellard | |
323 | 9de5e440 | bellard | #if defined(DEBUG_SIGNAL)
|
324 | bc8a22cc | bellard | fprintf(stderr, "queue_signal: sig=%d\n",
|
325 | 9de5e440 | bellard | sig); |
326 | 66fb9763 | bellard | #endif
|
327 | 9de5e440 | bellard | k = &sigact_table[sig - 1];
|
328 | 66fb9763 | bellard | handler = k->sa._sa_handler; |
329 | 66fb9763 | bellard | if (handler == TARGET_SIG_DFL) {
|
330 | 66fb9763 | bellard | /* default handler : ignore some signal. The other are fatal */
|
331 | 66fb9763 | bellard | if (sig != TARGET_SIGCHLD &&
|
332 | 66fb9763 | bellard | sig != TARGET_SIGURG && |
333 | 66fb9763 | bellard | sig != TARGET_SIGWINCH) { |
334 | 66fb9763 | bellard | force_sig(sig); |
335 | 9de5e440 | bellard | } else {
|
336 | 9de5e440 | bellard | return 0; /* indicate ignored */ |
337 | 66fb9763 | bellard | } |
338 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_IGN) { |
339 | 66fb9763 | bellard | /* ignore signal */
|
340 | 9de5e440 | bellard | return 0; |
341 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_ERR) { |
342 | 66fb9763 | bellard | force_sig(sig); |
343 | 66fb9763 | bellard | } else {
|
344 | 9de5e440 | bellard | pq = &k->first; |
345 | 9de5e440 | bellard | if (sig < TARGET_SIGRTMIN) {
|
346 | 9de5e440 | bellard | /* if non real time signal, we queue exactly one signal */
|
347 | 9de5e440 | bellard | if (!k->pending)
|
348 | 9de5e440 | bellard | q = &k->info; |
349 | 9de5e440 | bellard | else
|
350 | 9de5e440 | bellard | return 0; |
351 | 9de5e440 | bellard | } else {
|
352 | 9de5e440 | bellard | if (!k->pending) {
|
353 | 9de5e440 | bellard | /* first signal */
|
354 | 9de5e440 | bellard | q = &k->info; |
355 | 9de5e440 | bellard | } else {
|
356 | 9de5e440 | bellard | q = alloc_sigqueue(); |
357 | 9de5e440 | bellard | if (!q)
|
358 | 9de5e440 | bellard | return -EAGAIN;
|
359 | 9de5e440 | bellard | while (*pq != NULL) |
360 | 9de5e440 | bellard | pq = &(*pq)->next; |
361 | 9de5e440 | bellard | } |
362 | 9de5e440 | bellard | } |
363 | 9de5e440 | bellard | *pq = q; |
364 | 9de5e440 | bellard | q->info = *info; |
365 | 9de5e440 | bellard | q->next = NULL;
|
366 | 9de5e440 | bellard | k->pending = 1;
|
367 | 9de5e440 | bellard | /* signal that a new signal is pending */
|
368 | 9de5e440 | bellard | signal_pending = 1;
|
369 | 9de5e440 | bellard | return 1; /* indicates that the signal was queued */ |
370 | 9de5e440 | bellard | } |
371 | 9de5e440 | bellard | } |
372 | 9de5e440 | bellard | |
373 | 9de5e440 | bellard | #if defined(DEBUG_SIGNAL)
|
374 | 9de5e440 | bellard | #ifdef __i386__
|
375 | 9de5e440 | bellard | static void dump_regs(struct ucontext *uc) |
376 | 9de5e440 | bellard | { |
377 | 9de5e440 | bellard | fprintf(stderr, |
378 | 9de5e440 | bellard | "EAX=%08x EBX=%08x ECX=%08x EDX=%08x\n"
|
379 | 9de5e440 | bellard | "ESI=%08x EDI=%08x EBP=%08x ESP=%08x\n"
|
380 | 9de5e440 | bellard | "EFL=%08x EIP=%08x\n",
|
381 | 9de5e440 | bellard | uc->uc_mcontext.gregs[EAX], |
382 | 9de5e440 | bellard | uc->uc_mcontext.gregs[EBX], |
383 | 9de5e440 | bellard | uc->uc_mcontext.gregs[ECX], |
384 | 9de5e440 | bellard | uc->uc_mcontext.gregs[EDX], |
385 | 9de5e440 | bellard | uc->uc_mcontext.gregs[ESI], |
386 | 9de5e440 | bellard | uc->uc_mcontext.gregs[EDI], |
387 | 9de5e440 | bellard | uc->uc_mcontext.gregs[EBP], |
388 | 9de5e440 | bellard | uc->uc_mcontext.gregs[ESP], |
389 | 9de5e440 | bellard | uc->uc_mcontext.gregs[EFL], |
390 | 9de5e440 | bellard | uc->uc_mcontext.gregs[EIP]); |
391 | 9de5e440 | bellard | } |
392 | 9de5e440 | bellard | #else
|
393 | 9de5e440 | bellard | static void dump_regs(struct ucontext *uc) |
394 | 9de5e440 | bellard | { |
395 | 9de5e440 | bellard | } |
396 | 9de5e440 | bellard | #endif
|
397 | 9de5e440 | bellard | |
398 | 9de5e440 | bellard | #endif
|
399 | 9de5e440 | bellard | |
400 | 9de5e440 | bellard | static void host_signal_handler(int host_signum, siginfo_t *info, |
401 | 9de5e440 | bellard | void *puc)
|
402 | 9de5e440 | bellard | { |
403 | 9de5e440 | bellard | int sig;
|
404 | 9de5e440 | bellard | target_siginfo_t tinfo; |
405 | 9de5e440 | bellard | |
406 | 9de5e440 | bellard | /* the CPU emulator uses some host signals to detect exceptions,
|
407 | 9de5e440 | bellard | we we forward to it some signals */
|
408 | 9de5e440 | bellard | if (host_signum == SIGSEGV || host_signum == SIGBUS) {
|
409 | b346ff46 | bellard | if (cpu_signal_handler(host_signum, info, puc))
|
410 | 9de5e440 | bellard | return;
|
411 | 9de5e440 | bellard | } |
412 | 9de5e440 | bellard | |
413 | 9de5e440 | bellard | /* get target signal number */
|
414 | 9de5e440 | bellard | sig = host_to_target_signal(host_signum); |
415 | 9de5e440 | bellard | if (sig < 1 || sig > TARGET_NSIG) |
416 | 9de5e440 | bellard | return;
|
417 | 9de5e440 | bellard | #if defined(DEBUG_SIGNAL)
|
418 | bc8a22cc | bellard | fprintf(stderr, "qemu: got signal %d\n", sig);
|
419 | 9de5e440 | bellard | dump_regs(puc); |
420 | 9de5e440 | bellard | #endif
|
421 | 9de5e440 | bellard | host_to_target_siginfo_noswap(&tinfo, info); |
422 | 9de5e440 | bellard | if (queue_signal(sig, &tinfo) == 1) { |
423 | 9de5e440 | bellard | /* interrupt the virtual CPU as soon as possible */
|
424 | 68a79315 | bellard | cpu_interrupt(global_env, CPU_INTERRUPT_EXIT); |
425 | 66fb9763 | bellard | } |
426 | 66fb9763 | bellard | } |
427 | 66fb9763 | bellard | |
428 | 66fb9763 | bellard | int do_sigaction(int sig, const struct target_sigaction *act, |
429 | 66fb9763 | bellard | struct target_sigaction *oact)
|
430 | 66fb9763 | bellard | { |
431 | 66fb9763 | bellard | struct emulated_sigaction *k;
|
432 | 66fb9763 | bellard | |
433 | 66fb9763 | bellard | if (sig < 1 || sig > TARGET_NSIG) |
434 | 66fb9763 | bellard | return -EINVAL;
|
435 | 66fb9763 | bellard | k = &sigact_table[sig - 1];
|
436 | 66fb9763 | bellard | #if defined(DEBUG_SIGNAL) && 0 |
437 | 66fb9763 | bellard | fprintf(stderr, "sigaction sig=%d act=0x%08x, oact=0x%08x\n",
|
438 | 66fb9763 | bellard | sig, (int)act, (int)oact); |
439 | 66fb9763 | bellard | #endif
|
440 | 66fb9763 | bellard | if (oact) {
|
441 | 66fb9763 | bellard | oact->_sa_handler = tswapl(k->sa._sa_handler); |
442 | 66fb9763 | bellard | oact->sa_flags = tswapl(k->sa.sa_flags); |
443 | 66fb9763 | bellard | oact->sa_restorer = tswapl(k->sa.sa_restorer); |
444 | 66fb9763 | bellard | oact->sa_mask = k->sa.sa_mask; |
445 | 66fb9763 | bellard | } |
446 | 66fb9763 | bellard | if (act) {
|
447 | 66fb9763 | bellard | k->sa._sa_handler = tswapl(act->_sa_handler); |
448 | 66fb9763 | bellard | k->sa.sa_flags = tswapl(act->sa_flags); |
449 | 66fb9763 | bellard | k->sa.sa_restorer = tswapl(act->sa_restorer); |
450 | 66fb9763 | bellard | k->sa.sa_mask = act->sa_mask; |
451 | 66fb9763 | bellard | } |
452 | 66fb9763 | bellard | return 0; |
453 | 66fb9763 | bellard | } |
454 | 66fb9763 | bellard | |
455 | 43fff238 | bellard | #define __put_user(x,ptr)\
|
456 | 43fff238 | bellard | ({\ |
457 | 43fff238 | bellard | int size = sizeof(*ptr);\ |
458 | 43fff238 | bellard | switch(size) {\
|
459 | 43fff238 | bellard | case 1:\ |
460 | 43fff238 | bellard | stb(ptr, (typeof(*ptr))(x));\ |
461 | 43fff238 | bellard | break;\
|
462 | 43fff238 | bellard | case 2:\ |
463 | 43fff238 | bellard | stw(ptr, (typeof(*ptr))(x));\ |
464 | 43fff238 | bellard | break;\
|
465 | 43fff238 | bellard | case 4:\ |
466 | 43fff238 | bellard | stl(ptr, (typeof(*ptr))(x));\ |
467 | 43fff238 | bellard | break;\
|
468 | 43fff238 | bellard | case 8:\ |
469 | 43fff238 | bellard | stq(ptr, (typeof(*ptr))(x));\ |
470 | 43fff238 | bellard | break;\
|
471 | 43fff238 | bellard | default:\
|
472 | 43fff238 | bellard | abort();\ |
473 | 43fff238 | bellard | }\ |
474 | 43fff238 | bellard | 0;\
|
475 | 43fff238 | bellard | }) |
476 | 43fff238 | bellard | |
477 | 43fff238 | bellard | #define __get_user(x, ptr) \
|
478 | 43fff238 | bellard | ({\ |
479 | 43fff238 | bellard | int size = sizeof(*ptr);\ |
480 | 43fff238 | bellard | switch(size) {\
|
481 | 43fff238 | bellard | case 1:\ |
482 | 43fff238 | bellard | x = (typeof(*ptr))ldub(ptr);\ |
483 | 43fff238 | bellard | break;\
|
484 | 43fff238 | bellard | case 2:\ |
485 | 43fff238 | bellard | x = (typeof(*ptr))lduw(ptr);\ |
486 | 43fff238 | bellard | break;\
|
487 | 43fff238 | bellard | case 4:\ |
488 | 43fff238 | bellard | x = (typeof(*ptr))ldl(ptr);\ |
489 | 43fff238 | bellard | break;\
|
490 | 43fff238 | bellard | case 8:\ |
491 | 43fff238 | bellard | x = (typeof(*ptr))ldq(ptr);\ |
492 | 43fff238 | bellard | break;\
|
493 | 43fff238 | bellard | default:\
|
494 | 43fff238 | bellard | abort();\ |
495 | 43fff238 | bellard | }\ |
496 | 43fff238 | bellard | 0;\
|
497 | 43fff238 | bellard | }) |
498 | 43fff238 | bellard | |
499 | 43fff238 | bellard | |
500 | 43fff238 | bellard | #define __copy_to_user(dst, src, size)\
|
501 | 43fff238 | bellard | ({\ |
502 | 43fff238 | bellard | memcpy(dst, src, size);\ |
503 | 43fff238 | bellard | 0;\
|
504 | 43fff238 | bellard | }) |
505 | 43fff238 | bellard | |
506 | 43fff238 | bellard | #define __copy_from_user(dst, src, size)\
|
507 | 43fff238 | bellard | ({\ |
508 | 43fff238 | bellard | memcpy(dst, src, size);\ |
509 | 43fff238 | bellard | 0;\
|
510 | 43fff238 | bellard | }) |
511 | 43fff238 | bellard | |
512 | 43fff238 | bellard | #define __clear_user(dst, size)\
|
513 | 43fff238 | bellard | ({\ |
514 | 43fff238 | bellard | memset(dst, 0, size);\
|
515 | 43fff238 | bellard | 0;\
|
516 | 43fff238 | bellard | }) |
517 | 43fff238 | bellard | |
518 | 43fff238 | bellard | #ifndef offsetof
|
519 | 43fff238 | bellard | #define offsetof(type, field) ((size_t) &((type *)0)->field) |
520 | 43fff238 | bellard | #endif
|
521 | 43fff238 | bellard | |
522 | 43fff238 | bellard | static inline int copy_siginfo_to_user(target_siginfo_t *tinfo, |
523 | 43fff238 | bellard | const target_siginfo_t *info)
|
524 | 43fff238 | bellard | { |
525 | 43fff238 | bellard | tswap_siginfo(tinfo, info); |
526 | 43fff238 | bellard | return 0; |
527 | 43fff238 | bellard | } |
528 | 43fff238 | bellard | |
529 | 66fb9763 | bellard | #ifdef TARGET_I386
|
530 | 66fb9763 | bellard | |
531 | 66fb9763 | bellard | /* from the Linux kernel */
|
532 | 66fb9763 | bellard | |
533 | 66fb9763 | bellard | struct target_fpreg {
|
534 | 66fb9763 | bellard | uint16_t significand[4];
|
535 | 66fb9763 | bellard | uint16_t exponent; |
536 | 66fb9763 | bellard | }; |
537 | 66fb9763 | bellard | |
538 | 66fb9763 | bellard | struct target_fpxreg {
|
539 | 66fb9763 | bellard | uint16_t significand[4];
|
540 | 66fb9763 | bellard | uint16_t exponent; |
541 | 66fb9763 | bellard | uint16_t padding[3];
|
542 | 66fb9763 | bellard | }; |
543 | 66fb9763 | bellard | |
544 | 66fb9763 | bellard | struct target_xmmreg {
|
545 | 66fb9763 | bellard | target_ulong element[4];
|
546 | 66fb9763 | bellard | }; |
547 | 66fb9763 | bellard | |
548 | 66fb9763 | bellard | struct target_fpstate {
|
549 | 66fb9763 | bellard | /* Regular FPU environment */
|
550 | 66fb9763 | bellard | target_ulong cw; |
551 | 66fb9763 | bellard | target_ulong sw; |
552 | 66fb9763 | bellard | target_ulong tag; |
553 | 66fb9763 | bellard | target_ulong ipoff; |
554 | 66fb9763 | bellard | target_ulong cssel; |
555 | 66fb9763 | bellard | target_ulong dataoff; |
556 | 66fb9763 | bellard | target_ulong datasel; |
557 | 66fb9763 | bellard | struct target_fpreg _st[8]; |
558 | 66fb9763 | bellard | uint16_t status; |
559 | 66fb9763 | bellard | uint16_t magic; /* 0xffff = regular FPU data only */
|
560 | 66fb9763 | bellard | |
561 | 66fb9763 | bellard | /* FXSR FPU environment */
|
562 | 66fb9763 | bellard | target_ulong _fxsr_env[6]; /* FXSR FPU env is ignored */ |
563 | 66fb9763 | bellard | target_ulong mxcsr; |
564 | 66fb9763 | bellard | target_ulong reserved; |
565 | 66fb9763 | bellard | struct target_fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */ |
566 | 66fb9763 | bellard | struct target_xmmreg _xmm[8]; |
567 | 66fb9763 | bellard | target_ulong padding[56];
|
568 | 66fb9763 | bellard | }; |
569 | 66fb9763 | bellard | |
570 | 66fb9763 | bellard | #define X86_FXSR_MAGIC 0x0000 |
571 | 66fb9763 | bellard | |
572 | 66fb9763 | bellard | struct target_sigcontext {
|
573 | 66fb9763 | bellard | uint16_t gs, __gsh; |
574 | 66fb9763 | bellard | uint16_t fs, __fsh; |
575 | 66fb9763 | bellard | uint16_t es, __esh; |
576 | 66fb9763 | bellard | uint16_t ds, __dsh; |
577 | 66fb9763 | bellard | target_ulong edi; |
578 | 66fb9763 | bellard | target_ulong esi; |
579 | 66fb9763 | bellard | target_ulong ebp; |
580 | 66fb9763 | bellard | target_ulong esp; |
581 | 66fb9763 | bellard | target_ulong ebx; |
582 | 66fb9763 | bellard | target_ulong edx; |
583 | 66fb9763 | bellard | target_ulong ecx; |
584 | 66fb9763 | bellard | target_ulong eax; |
585 | 66fb9763 | bellard | target_ulong trapno; |
586 | 66fb9763 | bellard | target_ulong err; |
587 | 66fb9763 | bellard | target_ulong eip; |
588 | 66fb9763 | bellard | uint16_t cs, __csh; |
589 | 66fb9763 | bellard | target_ulong eflags; |
590 | 66fb9763 | bellard | target_ulong esp_at_signal; |
591 | 66fb9763 | bellard | uint16_t ss, __ssh; |
592 | 66fb9763 | bellard | target_ulong fpstate; /* pointer */
|
593 | 66fb9763 | bellard | target_ulong oldmask; |
594 | 66fb9763 | bellard | target_ulong cr2; |
595 | 66fb9763 | bellard | }; |
596 | 66fb9763 | bellard | |
597 | 66fb9763 | bellard | typedef struct target_sigaltstack { |
598 | 66fb9763 | bellard | target_ulong ss_sp; |
599 | 66fb9763 | bellard | int ss_flags;
|
600 | 66fb9763 | bellard | target_ulong ss_size; |
601 | 66fb9763 | bellard | } target_stack_t; |
602 | 66fb9763 | bellard | |
603 | 66fb9763 | bellard | struct target_ucontext {
|
604 | 66fb9763 | bellard | target_ulong uc_flags; |
605 | 66fb9763 | bellard | target_ulong uc_link; |
606 | 66fb9763 | bellard | target_stack_t uc_stack; |
607 | 66fb9763 | bellard | struct target_sigcontext uc_mcontext;
|
608 | 66fb9763 | bellard | target_sigset_t uc_sigmask; /* mask last for extensibility */
|
609 | 66fb9763 | bellard | }; |
610 | 66fb9763 | bellard | |
611 | 66fb9763 | bellard | struct sigframe
|
612 | 66fb9763 | bellard | { |
613 | 66fb9763 | bellard | target_ulong pretcode; |
614 | 66fb9763 | bellard | int sig;
|
615 | 66fb9763 | bellard | struct target_sigcontext sc;
|
616 | 66fb9763 | bellard | struct target_fpstate fpstate;
|
617 | 66fb9763 | bellard | target_ulong extramask[TARGET_NSIG_WORDS-1];
|
618 | 66fb9763 | bellard | char retcode[8]; |
619 | 66fb9763 | bellard | }; |
620 | 66fb9763 | bellard | |
621 | 66fb9763 | bellard | struct rt_sigframe
|
622 | 66fb9763 | bellard | { |
623 | 66fb9763 | bellard | target_ulong pretcode; |
624 | 66fb9763 | bellard | int sig;
|
625 | 66fb9763 | bellard | target_ulong pinfo; |
626 | 66fb9763 | bellard | target_ulong puc; |
627 | 66fb9763 | bellard | struct target_siginfo info;
|
628 | 66fb9763 | bellard | struct target_ucontext uc;
|
629 | 66fb9763 | bellard | struct target_fpstate fpstate;
|
630 | 66fb9763 | bellard | char retcode[8]; |
631 | 66fb9763 | bellard | }; |
632 | 66fb9763 | bellard | |
633 | 66fb9763 | bellard | /*
|
634 | 66fb9763 | bellard | * Set up a signal frame.
|
635 | 66fb9763 | bellard | */
|
636 | 66fb9763 | bellard | |
637 | 66fb9763 | bellard | /* XXX: save x87 state */
|
638 | 66fb9763 | bellard | static int |
639 | 66fb9763 | bellard | setup_sigcontext(struct target_sigcontext *sc, struct target_fpstate *fpstate, |
640 | 66fb9763 | bellard | CPUX86State *env, unsigned long mask) |
641 | 66fb9763 | bellard | { |
642 | 66fb9763 | bellard | int err = 0; |
643 | 66fb9763 | bellard | |
644 | a52c757c | bellard | err |= __put_user(env->segs[R_GS].selector, (unsigned int *)&sc->gs); |
645 | a52c757c | bellard | err |= __put_user(env->segs[R_FS].selector, (unsigned int *)&sc->fs); |
646 | a52c757c | bellard | err |= __put_user(env->segs[R_ES].selector, (unsigned int *)&sc->es); |
647 | a52c757c | bellard | err |= __put_user(env->segs[R_DS].selector, (unsigned int *)&sc->ds); |
648 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EDI], &sc->edi); |
649 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ESI], &sc->esi); |
650 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EBP], &sc->ebp); |
651 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ESP], &sc->esp); |
652 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EBX], &sc->ebx); |
653 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EDX], &sc->edx); |
654 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ECX], &sc->ecx); |
655 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EAX], &sc->eax); |
656 | 66099dd9 | bellard | err |= __put_user(env->exception_index, &sc->trapno); |
657 | 66099dd9 | bellard | err |= __put_user(env->error_code, &sc->err); |
658 | 66fb9763 | bellard | err |= __put_user(env->eip, &sc->eip); |
659 | a52c757c | bellard | err |= __put_user(env->segs[R_CS].selector, (unsigned int *)&sc->cs); |
660 | 66fb9763 | bellard | err |= __put_user(env->eflags, &sc->eflags); |
661 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ESP], &sc->esp_at_signal); |
662 | a52c757c | bellard | err |= __put_user(env->segs[R_SS].selector, (unsigned int *)&sc->ss); |
663 | ed2dcdf6 | bellard | |
664 | ed2dcdf6 | bellard | cpu_x86_fsave(env, (void *)fpstate, 1); |
665 | ed2dcdf6 | bellard | fpstate->status = fpstate->sw; |
666 | ed2dcdf6 | bellard | err |= __put_user(0xffff, &fpstate->magic);
|
667 | ed2dcdf6 | bellard | err |= __put_user(fpstate, &sc->fpstate); |
668 | ed2dcdf6 | bellard | |
669 | 66fb9763 | bellard | /* non-iBCS2 extensions.. */
|
670 | 66fb9763 | bellard | err |= __put_user(mask, &sc->oldmask); |
671 | a52c757c | bellard | err |= __put_user(env->cr[2], &sc->cr2);
|
672 | 66fb9763 | bellard | return err;
|
673 | 31e31b8a | bellard | } |
674 | 31e31b8a | bellard | |
675 | 66fb9763 | bellard | /*
|
676 | 66fb9763 | bellard | * Determine which stack to use..
|
677 | 66fb9763 | bellard | */
|
678 | 31e31b8a | bellard | |
679 | 66fb9763 | bellard | static inline void * |
680 | 66fb9763 | bellard | get_sigframe(struct emulated_sigaction *ka, CPUX86State *env, size_t frame_size)
|
681 | 31e31b8a | bellard | { |
682 | 66fb9763 | bellard | unsigned long esp; |
683 | 66fb9763 | bellard | |
684 | 66fb9763 | bellard | /* Default to using normal stack */
|
685 | 66fb9763 | bellard | esp = env->regs[R_ESP]; |
686 | 66fb9763 | bellard | #if 0
|
687 | 66fb9763 | bellard | /* This is the X/Open sanctioned signal stack switching. */
|
688 | 66fb9763 | bellard | if (ka->sa.sa_flags & SA_ONSTACK) {
|
689 | 66fb9763 | bellard | if (sas_ss_flags(esp) == 0)
|
690 | 66fb9763 | bellard | esp = current->sas_ss_sp + current->sas_ss_size;
|
691 | 66fb9763 | bellard | }
|
692 | 66fb9763 | bellard | |
693 | 66fb9763 | bellard | /* This is the legacy signal stack switching. */
|
694 | a52c757c | bellard | else
|
695 | 66fb9763 | bellard | #endif
|
696 | a52c757c | bellard | if ((env->segs[R_SS].selector & 0xffff) != __USER_DS && |
697 | a52c757c | bellard | !(ka->sa.sa_flags & TARGET_SA_RESTORER) && |
698 | a52c757c | bellard | ka->sa.sa_restorer) { |
699 | a52c757c | bellard | esp = (unsigned long) ka->sa.sa_restorer; |
700 | a52c757c | bellard | } |
701 | a52c757c | bellard | return (void *)((esp - frame_size) & -8ul); |
702 | 66fb9763 | bellard | } |
703 | 66fb9763 | bellard | |
704 | 66fb9763 | bellard | static void setup_frame(int sig, struct emulated_sigaction *ka, |
705 | 66fb9763 | bellard | target_sigset_t *set, CPUX86State *env) |
706 | 66fb9763 | bellard | { |
707 | 66fb9763 | bellard | struct sigframe *frame;
|
708 | 66fb9763 | bellard | int err = 0; |
709 | 66fb9763 | bellard | |
710 | 66fb9763 | bellard | frame = get_sigframe(ka, env, sizeof(*frame));
|
711 | 66fb9763 | bellard | |
712 | 66fb9763 | bellard | #if 0
|
713 | 66fb9763 | bellard | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
|
714 | 66fb9763 | bellard | goto give_sigsegv;
|
715 | 66fb9763 | bellard | #endif
|
716 | 66fb9763 | bellard | err |= __put_user((/*current->exec_domain
|
717 | 66fb9763 | bellard | && current->exec_domain->signal_invmap
|
718 | 66fb9763 | bellard | && sig < 32
|
719 | 66fb9763 | bellard | ? current->exec_domain->signal_invmap[sig]
|
720 | 66fb9763 | bellard | : */ sig),
|
721 | 66fb9763 | bellard | &frame->sig); |
722 | 66fb9763 | bellard | if (err)
|
723 | 66fb9763 | bellard | goto give_sigsegv;
|
724 | 66fb9763 | bellard | |
725 | 66fb9763 | bellard | setup_sigcontext(&frame->sc, &frame->fpstate, env, set->sig[0]);
|
726 | 66fb9763 | bellard | if (err)
|
727 | 66fb9763 | bellard | goto give_sigsegv;
|
728 | 66fb9763 | bellard | |
729 | 66fb9763 | bellard | if (TARGET_NSIG_WORDS > 1) { |
730 | 66fb9763 | bellard | err |= __copy_to_user(frame->extramask, &set->sig[1],
|
731 | 66fb9763 | bellard | sizeof(frame->extramask));
|
732 | 66fb9763 | bellard | } |
733 | 66fb9763 | bellard | if (err)
|
734 | 66fb9763 | bellard | goto give_sigsegv;
|
735 | 66fb9763 | bellard | |
736 | 66fb9763 | bellard | /* Set up to return from userspace. If provided, use a stub
|
737 | 66fb9763 | bellard | already in userspace. */
|
738 | 66fb9763 | bellard | if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
|
739 | 66fb9763 | bellard | err |= __put_user(ka->sa.sa_restorer, &frame->pretcode); |
740 | 66fb9763 | bellard | } else {
|
741 | 66fb9763 | bellard | err |= __put_user(frame->retcode, &frame->pretcode); |
742 | 66fb9763 | bellard | /* This is popl %eax ; movl $,%eax ; int $0x80 */
|
743 | 66fb9763 | bellard | err |= __put_user(0xb858, (short *)(frame->retcode+0)); |
744 | 66fb9763 | bellard | err |= __put_user(TARGET_NR_sigreturn, (int *)(frame->retcode+2)); |
745 | 66fb9763 | bellard | err |= __put_user(0x80cd, (short *)(frame->retcode+6)); |
746 | 66fb9763 | bellard | } |
747 | 66fb9763 | bellard | |
748 | 66fb9763 | bellard | if (err)
|
749 | 66fb9763 | bellard | goto give_sigsegv;
|
750 | 66fb9763 | bellard | |
751 | 66fb9763 | bellard | /* Set up registers for signal handler */
|
752 | 66fb9763 | bellard | env->regs[R_ESP] = (unsigned long) frame; |
753 | 66fb9763 | bellard | env->eip = (unsigned long) ka->sa._sa_handler; |
754 | 66fb9763 | bellard | |
755 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_DS, __USER_DS); |
756 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_ES, __USER_DS); |
757 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_SS, __USER_DS); |
758 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_CS, __USER_CS); |
759 | 66fb9763 | bellard | env->eflags &= ~TF_MASK; |
760 | 66fb9763 | bellard | |
761 | 66fb9763 | bellard | return;
|
762 | 66fb9763 | bellard | |
763 | 66fb9763 | bellard | give_sigsegv:
|
764 | 66fb9763 | bellard | if (sig == TARGET_SIGSEGV)
|
765 | 66fb9763 | bellard | ka->sa._sa_handler = TARGET_SIG_DFL; |
766 | 66fb9763 | bellard | force_sig(TARGET_SIGSEGV /* , current */);
|
767 | 66fb9763 | bellard | } |
768 | 66fb9763 | bellard | |
769 | 9de5e440 | bellard | static void setup_rt_frame(int sig, struct emulated_sigaction *ka, |
770 | 9de5e440 | bellard | target_siginfo_t *info, |
771 | 66fb9763 | bellard | target_sigset_t *set, CPUX86State *env) |
772 | 66fb9763 | bellard | { |
773 | 66fb9763 | bellard | struct rt_sigframe *frame;
|
774 | 66fb9763 | bellard | int err = 0; |
775 | 66fb9763 | bellard | |
776 | 66fb9763 | bellard | frame = get_sigframe(ka, env, sizeof(*frame));
|
777 | 66fb9763 | bellard | |
778 | 66fb9763 | bellard | #if 0
|
779 | 66fb9763 | bellard | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
|
780 | 66fb9763 | bellard | goto give_sigsegv;
|
781 | 66fb9763 | bellard | #endif
|
782 | 66fb9763 | bellard | |
783 | 66fb9763 | bellard | err |= __put_user((/*current->exec_domain
|
784 | 66fb9763 | bellard | && current->exec_domain->signal_invmap
|
785 | 66fb9763 | bellard | && sig < 32
|
786 | 66fb9763 | bellard | ? current->exec_domain->signal_invmap[sig]
|
787 | 66fb9763 | bellard | : */sig),
|
788 | 66fb9763 | bellard | &frame->sig); |
789 | 66fb9763 | bellard | err |= __put_user((target_ulong)&frame->info, &frame->pinfo); |
790 | 66fb9763 | bellard | err |= __put_user((target_ulong)&frame->uc, &frame->puc); |
791 | 66fb9763 | bellard | err |= copy_siginfo_to_user(&frame->info, info); |
792 | 66fb9763 | bellard | if (err)
|
793 | 66fb9763 | bellard | goto give_sigsegv;
|
794 | 31e31b8a | bellard | |
795 | 66fb9763 | bellard | /* Create the ucontext. */
|
796 | 66fb9763 | bellard | err |= __put_user(0, &frame->uc.uc_flags);
|
797 | 66fb9763 | bellard | err |= __put_user(0, &frame->uc.uc_link);
|
798 | 66fb9763 | bellard | err |= __put_user(/*current->sas_ss_sp*/ 0, &frame->uc.uc_stack.ss_sp); |
799 | 66fb9763 | bellard | err |= __put_user(/* sas_ss_flags(regs->esp) */ 0, |
800 | 66fb9763 | bellard | &frame->uc.uc_stack.ss_flags); |
801 | 66fb9763 | bellard | err |= __put_user(/* current->sas_ss_size */ 0, &frame->uc.uc_stack.ss_size); |
802 | 66fb9763 | bellard | err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->fpstate, |
803 | 66fb9763 | bellard | env, set->sig[0]);
|
804 | 66fb9763 | bellard | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
|
805 | 66fb9763 | bellard | if (err)
|
806 | 66fb9763 | bellard | goto give_sigsegv;
|
807 | 31e31b8a | bellard | |
808 | 66fb9763 | bellard | /* Set up to return from userspace. If provided, use a stub
|
809 | 66fb9763 | bellard | already in userspace. */
|
810 | 66fb9763 | bellard | if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
|
811 | 66fb9763 | bellard | err |= __put_user(ka->sa.sa_restorer, &frame->pretcode); |
812 | 66fb9763 | bellard | } else {
|
813 | 66fb9763 | bellard | err |= __put_user(frame->retcode, &frame->pretcode); |
814 | 66fb9763 | bellard | /* This is movl $,%eax ; int $0x80 */
|
815 | 66fb9763 | bellard | err |= __put_user(0xb8, (char *)(frame->retcode+0)); |
816 | 66fb9763 | bellard | err |= __put_user(TARGET_NR_rt_sigreturn, (int *)(frame->retcode+1)); |
817 | 66fb9763 | bellard | err |= __put_user(0x80cd, (short *)(frame->retcode+5)); |
818 | 66fb9763 | bellard | } |
819 | 66fb9763 | bellard | |
820 | 66fb9763 | bellard | if (err)
|
821 | 66fb9763 | bellard | goto give_sigsegv;
|
822 | 66fb9763 | bellard | |
823 | 66fb9763 | bellard | /* Set up registers for signal handler */
|
824 | 66fb9763 | bellard | env->regs[R_ESP] = (unsigned long) frame; |
825 | 66fb9763 | bellard | env->eip = (unsigned long) ka->sa._sa_handler; |
826 | 66fb9763 | bellard | |
827 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_DS, __USER_DS); |
828 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_ES, __USER_DS); |
829 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_SS, __USER_DS); |
830 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_CS, __USER_CS); |
831 | 66fb9763 | bellard | env->eflags &= ~TF_MASK; |
832 | 66fb9763 | bellard | |
833 | 66fb9763 | bellard | return;
|
834 | 66fb9763 | bellard | |
835 | 66fb9763 | bellard | give_sigsegv:
|
836 | 66fb9763 | bellard | if (sig == TARGET_SIGSEGV)
|
837 | 66fb9763 | bellard | ka->sa._sa_handler = TARGET_SIG_DFL; |
838 | 66fb9763 | bellard | force_sig(TARGET_SIGSEGV /* , current */);
|
839 | 66fb9763 | bellard | } |
840 | 66fb9763 | bellard | |
841 | 66fb9763 | bellard | static int |
842 | 66fb9763 | bellard | restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc, int *peax) |
843 | 66fb9763 | bellard | { |
844 | 66fb9763 | bellard | unsigned int err = 0; |
845 | 66fb9763 | bellard | |
846 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_GS, lduw(&sc->gs)); |
847 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_FS, lduw(&sc->fs)); |
848 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_ES, lduw(&sc->es)); |
849 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_DS, lduw(&sc->ds)); |
850 | 66fb9763 | bellard | |
851 | 66fb9763 | bellard | env->regs[R_EDI] = ldl(&sc->edi); |
852 | 66fb9763 | bellard | env->regs[R_ESI] = ldl(&sc->esi); |
853 | 66fb9763 | bellard | env->regs[R_EBP] = ldl(&sc->ebp); |
854 | 66fb9763 | bellard | env->regs[R_ESP] = ldl(&sc->esp); |
855 | 66fb9763 | bellard | env->regs[R_EBX] = ldl(&sc->ebx); |
856 | 66fb9763 | bellard | env->regs[R_EDX] = ldl(&sc->edx); |
857 | 66fb9763 | bellard | env->regs[R_ECX] = ldl(&sc->ecx); |
858 | 66fb9763 | bellard | env->eip = ldl(&sc->eip); |
859 | 66fb9763 | bellard | |
860 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_CS, lduw(&sc->cs) | 3);
|
861 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_SS, lduw(&sc->ss) | 3);
|
862 | 66fb9763 | bellard | |
863 | 66fb9763 | bellard | { |
864 | 66fb9763 | bellard | unsigned int tmpflags; |
865 | 66fb9763 | bellard | tmpflags = ldl(&sc->eflags); |
866 | 66fb9763 | bellard | env->eflags = (env->eflags & ~0x40DD5) | (tmpflags & 0x40DD5); |
867 | 66fb9763 | bellard | // regs->orig_eax = -1; /* disable syscall checks */
|
868 | 66fb9763 | bellard | } |
869 | 66fb9763 | bellard | |
870 | 66fb9763 | bellard | { |
871 | 66fb9763 | bellard | struct _fpstate * buf;
|
872 | ed2dcdf6 | bellard | buf = (void *)ldl(&sc->fpstate);
|
873 | 66fb9763 | bellard | if (buf) {
|
874 | ed2dcdf6 | bellard | #if 0
|
875 | 66fb9763 | bellard | if (verify_area(VERIFY_READ, buf, sizeof(*buf)))
|
876 | 66fb9763 | bellard | goto badframe;
|
877 | ed2dcdf6 | bellard | #endif
|
878 | ed2dcdf6 | bellard | cpu_x86_frstor(env, (void *)buf, 1); |
879 | 66fb9763 | bellard | } |
880 | 66fb9763 | bellard | } |
881 | ed2dcdf6 | bellard | |
882 | 66fb9763 | bellard | *peax = ldl(&sc->eax); |
883 | 66fb9763 | bellard | return err;
|
884 | 66fb9763 | bellard | #if 0
|
885 | 66fb9763 | bellard | badframe:
|
886 | 66fb9763 | bellard | return 1;
|
887 | 66fb9763 | bellard | #endif
|
888 | 66fb9763 | bellard | } |
889 | 66fb9763 | bellard | |
890 | 66fb9763 | bellard | long do_sigreturn(CPUX86State *env)
|
891 | 66fb9763 | bellard | { |
892 | 66fb9763 | bellard | struct sigframe *frame = (struct sigframe *)(env->regs[R_ESP] - 8); |
893 | 66fb9763 | bellard | target_sigset_t target_set; |
894 | 66fb9763 | bellard | sigset_t set; |
895 | 66fb9763 | bellard | int eax, i;
|
896 | 66fb9763 | bellard | |
897 | 447db213 | bellard | #if defined(DEBUG_SIGNAL)
|
898 | 447db213 | bellard | fprintf(stderr, "do_sigreturn\n");
|
899 | 447db213 | bellard | #endif
|
900 | 66fb9763 | bellard | /* set blocked signals */
|
901 | 66fb9763 | bellard | target_set.sig[0] = frame->sc.oldmask;
|
902 | 66fb9763 | bellard | for(i = 1; i < TARGET_NSIG_WORDS; i++) |
903 | 66fb9763 | bellard | target_set.sig[i] = frame->extramask[i - 1];
|
904 | 66fb9763 | bellard | |
905 | 66fb9763 | bellard | target_to_host_sigset(&set, &target_set); |
906 | 66fb9763 | bellard | sigprocmask(SIG_SETMASK, &set, NULL);
|
907 | 66fb9763 | bellard | |
908 | 66fb9763 | bellard | /* restore registers */
|
909 | 66fb9763 | bellard | if (restore_sigcontext(env, &frame->sc, &eax))
|
910 | 66fb9763 | bellard | goto badframe;
|
911 | 66fb9763 | bellard | return eax;
|
912 | 66fb9763 | bellard | |
913 | 66fb9763 | bellard | badframe:
|
914 | 66fb9763 | bellard | force_sig(TARGET_SIGSEGV); |
915 | 66fb9763 | bellard | return 0; |
916 | 66fb9763 | bellard | } |
917 | 66fb9763 | bellard | |
918 | 66fb9763 | bellard | long do_rt_sigreturn(CPUX86State *env)
|
919 | 66fb9763 | bellard | { |
920 | 66fb9763 | bellard | struct rt_sigframe *frame = (struct rt_sigframe *)(env->regs[R_ESP] - 4); |
921 | 66fb9763 | bellard | target_sigset_t target_set; |
922 | 66fb9763 | bellard | sigset_t set; |
923 | 66fb9763 | bellard | // stack_t st;
|
924 | 66fb9763 | bellard | int eax;
|
925 | 66fb9763 | bellard | |
926 | 66fb9763 | bellard | #if 0
|
927 | 66fb9763 | bellard | if (verify_area(VERIFY_READ, frame, sizeof(*frame)))
|
928 | 66fb9763 | bellard | goto badframe;
|
929 | 66fb9763 | bellard | #endif
|
930 | 66fb9763 | bellard | memcpy(&target_set, &frame->uc.uc_sigmask, sizeof(target_sigset_t));
|
931 | 66fb9763 | bellard | |
932 | 66fb9763 | bellard | target_to_host_sigset(&set, &target_set); |
933 | 66fb9763 | bellard | sigprocmask(SIG_SETMASK, &set, NULL);
|
934 | 66fb9763 | bellard | |
935 | 66fb9763 | bellard | if (restore_sigcontext(env, &frame->uc.uc_mcontext, &eax))
|
936 | 66fb9763 | bellard | goto badframe;
|
937 | 66fb9763 | bellard | |
938 | 66fb9763 | bellard | #if 0
|
939 | 66fb9763 | bellard | if (__copy_from_user(&st, &frame->uc.uc_stack, sizeof(st)))
|
940 | 66fb9763 | bellard | goto badframe;
|
941 | 66fb9763 | bellard | /* It is more difficult to avoid calling this function than to
|
942 | 66fb9763 | bellard | call it and ignore errors. */
|
943 | 66fb9763 | bellard | do_sigaltstack(&st, NULL, regs->esp);
|
944 | 66fb9763 | bellard | #endif
|
945 | 66fb9763 | bellard | return eax;
|
946 | 66fb9763 | bellard | |
947 | 66fb9763 | bellard | badframe:
|
948 | 66fb9763 | bellard | force_sig(TARGET_SIGSEGV); |
949 | 66fb9763 | bellard | return 0; |
950 | 66fb9763 | bellard | } |
951 | 66fb9763 | bellard | |
952 | 43fff238 | bellard | #elif defined(TARGET_ARM)
|
953 | 43fff238 | bellard | |
954 | 43fff238 | bellard | struct target_sigcontext {
|
955 | 43fff238 | bellard | target_ulong trap_no; |
956 | 43fff238 | bellard | target_ulong error_code; |
957 | 43fff238 | bellard | target_ulong oldmask; |
958 | 43fff238 | bellard | target_ulong arm_r0; |
959 | 43fff238 | bellard | target_ulong arm_r1; |
960 | 43fff238 | bellard | target_ulong arm_r2; |
961 | 43fff238 | bellard | target_ulong arm_r3; |
962 | 43fff238 | bellard | target_ulong arm_r4; |
963 | 43fff238 | bellard | target_ulong arm_r5; |
964 | 43fff238 | bellard | target_ulong arm_r6; |
965 | 43fff238 | bellard | target_ulong arm_r7; |
966 | 43fff238 | bellard | target_ulong arm_r8; |
967 | 43fff238 | bellard | target_ulong arm_r9; |
968 | 43fff238 | bellard | target_ulong arm_r10; |
969 | 43fff238 | bellard | target_ulong arm_fp; |
970 | 43fff238 | bellard | target_ulong arm_ip; |
971 | 43fff238 | bellard | target_ulong arm_sp; |
972 | 43fff238 | bellard | target_ulong arm_lr; |
973 | 43fff238 | bellard | target_ulong arm_pc; |
974 | 43fff238 | bellard | target_ulong arm_cpsr; |
975 | 43fff238 | bellard | target_ulong fault_address; |
976 | 43fff238 | bellard | }; |
977 | 43fff238 | bellard | |
978 | 43fff238 | bellard | typedef struct target_sigaltstack { |
979 | 43fff238 | bellard | target_ulong ss_sp; |
980 | 43fff238 | bellard | int ss_flags;
|
981 | 43fff238 | bellard | target_ulong ss_size; |
982 | 43fff238 | bellard | } target_stack_t; |
983 | 43fff238 | bellard | |
984 | 43fff238 | bellard | struct target_ucontext {
|
985 | 43fff238 | bellard | target_ulong uc_flags; |
986 | 43fff238 | bellard | target_ulong uc_link; |
987 | 43fff238 | bellard | target_stack_t uc_stack; |
988 | 43fff238 | bellard | struct target_sigcontext uc_mcontext;
|
989 | 43fff238 | bellard | target_sigset_t uc_sigmask; /* mask last for extensibility */
|
990 | 43fff238 | bellard | }; |
991 | 43fff238 | bellard | |
992 | 43fff238 | bellard | struct sigframe
|
993 | 43fff238 | bellard | { |
994 | 43fff238 | bellard | struct target_sigcontext sc;
|
995 | 43fff238 | bellard | target_ulong extramask[TARGET_NSIG_WORDS-1];
|
996 | 43fff238 | bellard | target_ulong retcode; |
997 | 43fff238 | bellard | }; |
998 | 43fff238 | bellard | |
999 | 43fff238 | bellard | struct rt_sigframe
|
1000 | 43fff238 | bellard | { |
1001 | 43fff238 | bellard | struct target_siginfo *pinfo;
|
1002 | 43fff238 | bellard | void *puc;
|
1003 | 43fff238 | bellard | struct target_siginfo info;
|
1004 | 43fff238 | bellard | struct target_ucontext uc;
|
1005 | 43fff238 | bellard | target_ulong retcode; |
1006 | 43fff238 | bellard | }; |
1007 | 43fff238 | bellard | |
1008 | 43fff238 | bellard | #define TARGET_CONFIG_CPU_32 1 |
1009 | 43fff238 | bellard | |
1010 | 43fff238 | bellard | /*
|
1011 | 43fff238 | bellard | * For ARM syscalls, we encode the syscall number into the instruction.
|
1012 | 43fff238 | bellard | */
|
1013 | 43fff238 | bellard | #define SWI_SYS_SIGRETURN (0xef000000|(TARGET_NR_sigreturn + ARM_SYSCALL_BASE)) |
1014 | 43fff238 | bellard | #define SWI_SYS_RT_SIGRETURN (0xef000000|(TARGET_NR_rt_sigreturn + ARM_SYSCALL_BASE)) |
1015 | 43fff238 | bellard | |
1016 | 43fff238 | bellard | /*
|
1017 | 43fff238 | bellard | * For Thumb syscalls, we pass the syscall number via r7. We therefore
|
1018 | 43fff238 | bellard | * need two 16-bit instructions.
|
1019 | 43fff238 | bellard | */
|
1020 | 43fff238 | bellard | #define SWI_THUMB_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_sigreturn)) |
1021 | 43fff238 | bellard | #define SWI_THUMB_RT_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_rt_sigreturn)) |
1022 | 43fff238 | bellard | |
1023 | 43fff238 | bellard | static const target_ulong retcodes[4] = { |
1024 | 43fff238 | bellard | SWI_SYS_SIGRETURN, SWI_THUMB_SIGRETURN, |
1025 | 43fff238 | bellard | SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN |
1026 | 43fff238 | bellard | }; |
1027 | 43fff238 | bellard | |
1028 | 43fff238 | bellard | |
1029 | 43fff238 | bellard | #define __put_user_error(x,p,e) __put_user(x, p)
|
1030 | 43fff238 | bellard | #define __get_user_error(x,p,e) __get_user(x, p)
|
1031 | 43fff238 | bellard | |
1032 | 43fff238 | bellard | static inline int valid_user_regs(CPUState *regs) |
1033 | 43fff238 | bellard | { |
1034 | 43fff238 | bellard | return 1; |
1035 | 43fff238 | bellard | } |
1036 | 43fff238 | bellard | |
1037 | 43fff238 | bellard | static int |
1038 | 43fff238 | bellard | setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/ |
1039 | 43fff238 | bellard | CPUState *env, unsigned long mask) |
1040 | 43fff238 | bellard | { |
1041 | 43fff238 | bellard | int err = 0; |
1042 | 43fff238 | bellard | |
1043 | 43fff238 | bellard | __put_user_error(env->regs[0], &sc->arm_r0, err);
|
1044 | 43fff238 | bellard | __put_user_error(env->regs[1], &sc->arm_r1, err);
|
1045 | 43fff238 | bellard | __put_user_error(env->regs[2], &sc->arm_r2, err);
|
1046 | 43fff238 | bellard | __put_user_error(env->regs[3], &sc->arm_r3, err);
|
1047 | 43fff238 | bellard | __put_user_error(env->regs[4], &sc->arm_r4, err);
|
1048 | 43fff238 | bellard | __put_user_error(env->regs[5], &sc->arm_r5, err);
|
1049 | 43fff238 | bellard | __put_user_error(env->regs[6], &sc->arm_r6, err);
|
1050 | 43fff238 | bellard | __put_user_error(env->regs[7], &sc->arm_r7, err);
|
1051 | 43fff238 | bellard | __put_user_error(env->regs[8], &sc->arm_r8, err);
|
1052 | 43fff238 | bellard | __put_user_error(env->regs[9], &sc->arm_r9, err);
|
1053 | 43fff238 | bellard | __put_user_error(env->regs[10], &sc->arm_r10, err);
|
1054 | 43fff238 | bellard | __put_user_error(env->regs[11], &sc->arm_fp, err);
|
1055 | 43fff238 | bellard | __put_user_error(env->regs[12], &sc->arm_ip, err);
|
1056 | 43fff238 | bellard | __put_user_error(env->regs[13], &sc->arm_sp, err);
|
1057 | 43fff238 | bellard | __put_user_error(env->regs[14], &sc->arm_lr, err);
|
1058 | 43fff238 | bellard | __put_user_error(env->regs[15], &sc->arm_pc, err);
|
1059 | 43fff238 | bellard | #ifdef TARGET_CONFIG_CPU_32
|
1060 | 43fff238 | bellard | __put_user_error(env->cpsr, &sc->arm_cpsr, err); |
1061 | 43fff238 | bellard | #endif
|
1062 | 43fff238 | bellard | |
1063 | 43fff238 | bellard | __put_user_error(/* current->thread.trap_no */ 0, &sc->trap_no, err); |
1064 | 43fff238 | bellard | __put_user_error(/* current->thread.error_code */ 0, &sc->error_code, err); |
1065 | 43fff238 | bellard | __put_user_error(/* current->thread.address */ 0, &sc->fault_address, err); |
1066 | 43fff238 | bellard | __put_user_error(mask, &sc->oldmask, err); |
1067 | 43fff238 | bellard | |
1068 | 43fff238 | bellard | return err;
|
1069 | 43fff238 | bellard | } |
1070 | 43fff238 | bellard | |
1071 | 43fff238 | bellard | static inline void * |
1072 | 43fff238 | bellard | get_sigframe(struct emulated_sigaction *ka, CPUState *regs, int framesize) |
1073 | 43fff238 | bellard | { |
1074 | 43fff238 | bellard | unsigned long sp = regs->regs[13]; |
1075 | 43fff238 | bellard | |
1076 | 43fff238 | bellard | #if 0
|
1077 | 43fff238 | bellard | /*
|
1078 | 43fff238 | bellard | * This is the X/Open sanctioned signal stack switching.
|
1079 | 43fff238 | bellard | */
|
1080 | 43fff238 | bellard | if ((ka->sa.sa_flags & SA_ONSTACK) && !sas_ss_flags(sp))
|
1081 | 43fff238 | bellard | sp = current->sas_ss_sp + current->sas_ss_size;
|
1082 | 43fff238 | bellard | #endif
|
1083 | 43fff238 | bellard | /*
|
1084 | 43fff238 | bellard | * ATPCS B01 mandates 8-byte alignment
|
1085 | 43fff238 | bellard | */
|
1086 | 43fff238 | bellard | return (void *)((sp - framesize) & ~7); |
1087 | 43fff238 | bellard | } |
1088 | 43fff238 | bellard | |
1089 | 43fff238 | bellard | static int |
1090 | 43fff238 | bellard | setup_return(CPUState *env, struct emulated_sigaction *ka,
|
1091 | 43fff238 | bellard | target_ulong *rc, void *frame, int usig) |
1092 | 43fff238 | bellard | { |
1093 | 43fff238 | bellard | target_ulong handler = (target_ulong)ka->sa._sa_handler; |
1094 | 43fff238 | bellard | target_ulong retcode; |
1095 | 43fff238 | bellard | int thumb = 0; |
1096 | 43fff238 | bellard | #if defined(TARGET_CONFIG_CPU_32)
|
1097 | 43fff238 | bellard | target_ulong cpsr = env->cpsr; |
1098 | 43fff238 | bellard | |
1099 | 43fff238 | bellard | #if 0
|
1100 | 43fff238 | bellard | /*
|
1101 | 43fff238 | bellard | * Maybe we need to deliver a 32-bit signal to a 26-bit task.
|
1102 | 43fff238 | bellard | */
|
1103 | 43fff238 | bellard | if (ka->sa.sa_flags & SA_THIRTYTWO)
|
1104 | 43fff238 | bellard | cpsr = (cpsr & ~MODE_MASK) | USR_MODE;
|
1105 | 43fff238 | bellard | |
1106 | 43fff238 | bellard | #ifdef CONFIG_ARM_THUMB
|
1107 | 43fff238 | bellard | if (elf_hwcap & HWCAP_THUMB) {
|
1108 | 43fff238 | bellard | /*
|
1109 | 43fff238 | bellard | * The LSB of the handler determines if we're going to
|
1110 | 43fff238 | bellard | * be using THUMB or ARM mode for this signal handler.
|
1111 | 43fff238 | bellard | */
|
1112 | 43fff238 | bellard | thumb = handler & 1;
|
1113 | 43fff238 | bellard | |
1114 | 43fff238 | bellard | if (thumb)
|
1115 | 43fff238 | bellard | cpsr |= T_BIT;
|
1116 | 43fff238 | bellard | else
|
1117 | 43fff238 | bellard | cpsr &= ~T_BIT;
|
1118 | 43fff238 | bellard | }
|
1119 | 43fff238 | bellard | #endif
|
1120 | 43fff238 | bellard | #endif
|
1121 | 43fff238 | bellard | #endif /* TARGET_CONFIG_CPU_32 */ |
1122 | 43fff238 | bellard | |
1123 | 43fff238 | bellard | if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
|
1124 | 43fff238 | bellard | retcode = (target_ulong)ka->sa.sa_restorer; |
1125 | 43fff238 | bellard | } else {
|
1126 | 43fff238 | bellard | unsigned int idx = thumb; |
1127 | 43fff238 | bellard | |
1128 | 43fff238 | bellard | if (ka->sa.sa_flags & TARGET_SA_SIGINFO)
|
1129 | 43fff238 | bellard | idx += 2;
|
1130 | 43fff238 | bellard | |
1131 | 43fff238 | bellard | if (__put_user(retcodes[idx], rc))
|
1132 | 43fff238 | bellard | return 1; |
1133 | 43fff238 | bellard | #if 0
|
1134 | 43fff238 | bellard | flush_icache_range((target_ulong)rc,
|
1135 | 43fff238 | bellard | (target_ulong)(rc + 1));
|
1136 | 43fff238 | bellard | #endif
|
1137 | 43fff238 | bellard | retcode = ((target_ulong)rc) + thumb; |
1138 | 43fff238 | bellard | } |
1139 | 43fff238 | bellard | |
1140 | 43fff238 | bellard | env->regs[0] = usig;
|
1141 | 43fff238 | bellard | env->regs[13] = (target_ulong)frame;
|
1142 | 43fff238 | bellard | env->regs[14] = retcode;
|
1143 | 43fff238 | bellard | env->regs[15] = handler & (thumb ? ~1 : ~3); |
1144 | 43fff238 | bellard | |
1145 | 43fff238 | bellard | #ifdef TARGET_CONFIG_CPU_32
|
1146 | 43fff238 | bellard | env->cpsr = cpsr; |
1147 | 43fff238 | bellard | #endif
|
1148 | 43fff238 | bellard | |
1149 | 43fff238 | bellard | return 0; |
1150 | 43fff238 | bellard | } |
1151 | 43fff238 | bellard | |
1152 | 43fff238 | bellard | static void setup_frame(int usig, struct emulated_sigaction *ka, |
1153 | 43fff238 | bellard | target_sigset_t *set, CPUState *regs) |
1154 | 43fff238 | bellard | { |
1155 | 43fff238 | bellard | struct sigframe *frame = get_sigframe(ka, regs, sizeof(*frame)); |
1156 | 43fff238 | bellard | int err = 0; |
1157 | 43fff238 | bellard | |
1158 | 43fff238 | bellard | err |= setup_sigcontext(&frame->sc, /*&frame->fpstate,*/ regs, set->sig[0]); |
1159 | 43fff238 | bellard | |
1160 | 43fff238 | bellard | if (TARGET_NSIG_WORDS > 1) { |
1161 | 43fff238 | bellard | err |= __copy_to_user(frame->extramask, &set->sig[1],
|
1162 | 43fff238 | bellard | sizeof(frame->extramask));
|
1163 | 43fff238 | bellard | } |
1164 | 43fff238 | bellard | |
1165 | 43fff238 | bellard | if (err == 0) |
1166 | 43fff238 | bellard | err = setup_return(regs, ka, &frame->retcode, frame, usig); |
1167 | 43fff238 | bellard | // return err;
|
1168 | 43fff238 | bellard | } |
1169 | 43fff238 | bellard | |
1170 | 43fff238 | bellard | static void setup_rt_frame(int usig, struct emulated_sigaction *ka, |
1171 | 43fff238 | bellard | target_siginfo_t *info, |
1172 | 43fff238 | bellard | target_sigset_t *set, CPUState *env) |
1173 | 43fff238 | bellard | { |
1174 | 43fff238 | bellard | struct rt_sigframe *frame = get_sigframe(ka, env, sizeof(*frame)); |
1175 | 43fff238 | bellard | int err = 0; |
1176 | 43fff238 | bellard | |
1177 | 43fff238 | bellard | #if 0
|
1178 | 43fff238 | bellard | if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
|
1179 | 43fff238 | bellard | return 1;
|
1180 | 43fff238 | bellard | #endif
|
1181 | 43fff238 | bellard | __put_user_error(&frame->info, (target_ulong *)&frame->pinfo, err); |
1182 | 43fff238 | bellard | __put_user_error(&frame->uc, (target_ulong *)&frame->puc, err); |
1183 | 43fff238 | bellard | err |= copy_siginfo_to_user(&frame->info, info); |
1184 | 43fff238 | bellard | |
1185 | 43fff238 | bellard | /* Clear all the bits of the ucontext we don't use. */
|
1186 | 43fff238 | bellard | err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));
|
1187 | 43fff238 | bellard | |
1188 | 43fff238 | bellard | err |= setup_sigcontext(&frame->uc.uc_mcontext, /*&frame->fpstate,*/
|
1189 | 43fff238 | bellard | env, set->sig[0]);
|
1190 | 43fff238 | bellard | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
|
1191 | 43fff238 | bellard | |
1192 | 43fff238 | bellard | if (err == 0) |
1193 | 43fff238 | bellard | err = setup_return(env, ka, &frame->retcode, frame, usig); |
1194 | 43fff238 | bellard | |
1195 | 43fff238 | bellard | if (err == 0) { |
1196 | 43fff238 | bellard | /*
|
1197 | 43fff238 | bellard | * For realtime signals we must also set the second and third
|
1198 | 43fff238 | bellard | * arguments for the signal handler.
|
1199 | 43fff238 | bellard | * -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
|
1200 | 43fff238 | bellard | */
|
1201 | 43fff238 | bellard | env->regs[1] = (target_ulong)frame->pinfo;
|
1202 | 43fff238 | bellard | env->regs[2] = (target_ulong)frame->puc;
|
1203 | 43fff238 | bellard | } |
1204 | 43fff238 | bellard | |
1205 | 43fff238 | bellard | // return err;
|
1206 | 43fff238 | bellard | } |
1207 | 43fff238 | bellard | |
1208 | 43fff238 | bellard | static int |
1209 | 43fff238 | bellard | restore_sigcontext(CPUState *env, struct target_sigcontext *sc)
|
1210 | 43fff238 | bellard | { |
1211 | 43fff238 | bellard | int err = 0; |
1212 | 43fff238 | bellard | |
1213 | 43fff238 | bellard | __get_user_error(env->regs[0], &sc->arm_r0, err);
|
1214 | 43fff238 | bellard | __get_user_error(env->regs[1], &sc->arm_r1, err);
|
1215 | 43fff238 | bellard | __get_user_error(env->regs[2], &sc->arm_r2, err);
|
1216 | 43fff238 | bellard | __get_user_error(env->regs[3], &sc->arm_r3, err);
|
1217 | 43fff238 | bellard | __get_user_error(env->regs[4], &sc->arm_r4, err);
|
1218 | 43fff238 | bellard | __get_user_error(env->regs[5], &sc->arm_r5, err);
|
1219 | 43fff238 | bellard | __get_user_error(env->regs[6], &sc->arm_r6, err);
|
1220 | 43fff238 | bellard | __get_user_error(env->regs[7], &sc->arm_r7, err);
|
1221 | 43fff238 | bellard | __get_user_error(env->regs[8], &sc->arm_r8, err);
|
1222 | 43fff238 | bellard | __get_user_error(env->regs[9], &sc->arm_r9, err);
|
1223 | 43fff238 | bellard | __get_user_error(env->regs[10], &sc->arm_r10, err);
|
1224 | 43fff238 | bellard | __get_user_error(env->regs[11], &sc->arm_fp, err);
|
1225 | 43fff238 | bellard | __get_user_error(env->regs[12], &sc->arm_ip, err);
|
1226 | 43fff238 | bellard | __get_user_error(env->regs[13], &sc->arm_sp, err);
|
1227 | 43fff238 | bellard | __get_user_error(env->regs[14], &sc->arm_lr, err);
|
1228 | 43fff238 | bellard | __get_user_error(env->regs[15], &sc->arm_pc, err);
|
1229 | 43fff238 | bellard | #ifdef TARGET_CONFIG_CPU_32
|
1230 | 43fff238 | bellard | __get_user_error(env->cpsr, &sc->arm_cpsr, err); |
1231 | 43fff238 | bellard | #endif
|
1232 | 43fff238 | bellard | |
1233 | 43fff238 | bellard | err |= !valid_user_regs(env); |
1234 | 43fff238 | bellard | |
1235 | 43fff238 | bellard | return err;
|
1236 | 43fff238 | bellard | } |
1237 | 43fff238 | bellard | |
1238 | 43fff238 | bellard | long do_sigreturn(CPUState *env)
|
1239 | 43fff238 | bellard | { |
1240 | 43fff238 | bellard | struct sigframe *frame;
|
1241 | 43fff238 | bellard | target_sigset_t set; |
1242 | 43fff238 | bellard | sigset_t host_set; |
1243 | 43fff238 | bellard | |
1244 | 43fff238 | bellard | /*
|
1245 | 43fff238 | bellard | * Since we stacked the signal on a 64-bit boundary,
|
1246 | 43fff238 | bellard | * then 'sp' should be word aligned here. If it's
|
1247 | 43fff238 | bellard | * not, then the user is trying to mess with us.
|
1248 | 43fff238 | bellard | */
|
1249 | 43fff238 | bellard | if (env->regs[13] & 7) |
1250 | 43fff238 | bellard | goto badframe;
|
1251 | 43fff238 | bellard | |
1252 | 43fff238 | bellard | frame = (struct sigframe *)env->regs[13]; |
1253 | 43fff238 | bellard | |
1254 | 43fff238 | bellard | #if 0
|
1255 | 43fff238 | bellard | if (verify_area(VERIFY_READ, frame, sizeof (*frame)))
|
1256 | 43fff238 | bellard | goto badframe;
|
1257 | 43fff238 | bellard | #endif
|
1258 | 43fff238 | bellard | if (__get_user(set.sig[0], &frame->sc.oldmask) |
1259 | 43fff238 | bellard | || (TARGET_NSIG_WORDS > 1
|
1260 | 43fff238 | bellard | && __copy_from_user(&set.sig[1], &frame->extramask,
|
1261 | 43fff238 | bellard | sizeof(frame->extramask))))
|
1262 | 43fff238 | bellard | goto badframe;
|
1263 | 43fff238 | bellard | |
1264 | 43fff238 | bellard | target_to_host_sigset(&host_set, &set); |
1265 | 43fff238 | bellard | sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1266 | 43fff238 | bellard | |
1267 | 43fff238 | bellard | if (restore_sigcontext(env, &frame->sc))
|
1268 | 43fff238 | bellard | goto badframe;
|
1269 | 43fff238 | bellard | |
1270 | 43fff238 | bellard | #if 0
|
1271 | 43fff238 | bellard | /* Send SIGTRAP if we're single-stepping */
|
1272 | 43fff238 | bellard | if (ptrace_cancel_bpt(current))
|
1273 | 43fff238 | bellard | send_sig(SIGTRAP, current, 1);
|
1274 | 43fff238 | bellard | #endif
|
1275 | 43fff238 | bellard | return env->regs[0]; |
1276 | 43fff238 | bellard | |
1277 | 43fff238 | bellard | badframe:
|
1278 | 43fff238 | bellard | force_sig(SIGSEGV /* , current */);
|
1279 | 43fff238 | bellard | return 0; |
1280 | 43fff238 | bellard | } |
1281 | 43fff238 | bellard | |
1282 | 43fff238 | bellard | long do_rt_sigreturn(CPUState *env)
|
1283 | 43fff238 | bellard | { |
1284 | 43fff238 | bellard | struct rt_sigframe *frame;
|
1285 | 43fff238 | bellard | target_sigset_t set; |
1286 | 43fff238 | bellard | sigset_t host_set; |
1287 | 43fff238 | bellard | |
1288 | 43fff238 | bellard | /*
|
1289 | 43fff238 | bellard | * Since we stacked the signal on a 64-bit boundary,
|
1290 | 43fff238 | bellard | * then 'sp' should be word aligned here. If it's
|
1291 | 43fff238 | bellard | * not, then the user is trying to mess with us.
|
1292 | 43fff238 | bellard | */
|
1293 | 43fff238 | bellard | if (env->regs[13] & 7) |
1294 | 43fff238 | bellard | goto badframe;
|
1295 | 43fff238 | bellard | |
1296 | 43fff238 | bellard | frame = (struct rt_sigframe *)env->regs[13]; |
1297 | 43fff238 | bellard | |
1298 | 43fff238 | bellard | #if 0
|
1299 | 43fff238 | bellard | if (verify_area(VERIFY_READ, frame, sizeof (*frame)))
|
1300 | 43fff238 | bellard | goto badframe;
|
1301 | 43fff238 | bellard | #endif
|
1302 | 43fff238 | bellard | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
1303 | 43fff238 | bellard | goto badframe;
|
1304 | 43fff238 | bellard | |
1305 | 43fff238 | bellard | target_to_host_sigset(&host_set, &set); |
1306 | 43fff238 | bellard | sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1307 | 43fff238 | bellard | |
1308 | 43fff238 | bellard | if (restore_sigcontext(env, &frame->uc.uc_mcontext))
|
1309 | 43fff238 | bellard | goto badframe;
|
1310 | 43fff238 | bellard | |
1311 | 43fff238 | bellard | #if 0
|
1312 | 43fff238 | bellard | /* Send SIGTRAP if we're single-stepping */
|
1313 | 43fff238 | bellard | if (ptrace_cancel_bpt(current))
|
1314 | 43fff238 | bellard | send_sig(SIGTRAP, current, 1);
|
1315 | 43fff238 | bellard | #endif
|
1316 | 43fff238 | bellard | return env->regs[0]; |
1317 | 43fff238 | bellard | |
1318 | 43fff238 | bellard | badframe:
|
1319 | 43fff238 | bellard | force_sig(SIGSEGV /* , current */);
|
1320 | 43fff238 | bellard | return 0; |
1321 | 43fff238 | bellard | } |
1322 | 43fff238 | bellard | |
1323 | b346ff46 | bellard | #else
|
1324 | b346ff46 | bellard | |
1325 | b346ff46 | bellard | static void setup_frame(int sig, struct emulated_sigaction *ka, |
1326 | b346ff46 | bellard | target_sigset_t *set, CPUState *env) |
1327 | b346ff46 | bellard | { |
1328 | b346ff46 | bellard | fprintf(stderr, "setup_frame: not implemented\n");
|
1329 | b346ff46 | bellard | } |
1330 | b346ff46 | bellard | |
1331 | b346ff46 | bellard | static void setup_rt_frame(int sig, struct emulated_sigaction *ka, |
1332 | b346ff46 | bellard | target_siginfo_t *info, |
1333 | b346ff46 | bellard | target_sigset_t *set, CPUState *env) |
1334 | b346ff46 | bellard | { |
1335 | b346ff46 | bellard | fprintf(stderr, "setup_rt_frame: not implemented\n");
|
1336 | b346ff46 | bellard | } |
1337 | b346ff46 | bellard | |
1338 | b346ff46 | bellard | long do_sigreturn(CPUState *env)
|
1339 | b346ff46 | bellard | { |
1340 | b346ff46 | bellard | fprintf(stderr, "do_sigreturn: not implemented\n");
|
1341 | b346ff46 | bellard | return -ENOSYS;
|
1342 | b346ff46 | bellard | } |
1343 | b346ff46 | bellard | |
1344 | b346ff46 | bellard | long do_rt_sigreturn(CPUState *env)
|
1345 | b346ff46 | bellard | { |
1346 | b346ff46 | bellard | fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
1347 | b346ff46 | bellard | return -ENOSYS;
|
1348 | b346ff46 | bellard | } |
1349 | b346ff46 | bellard | |
1350 | 66fb9763 | bellard | #endif
|
1351 | 66fb9763 | bellard | |
1352 | 66fb9763 | bellard | void process_pending_signals(void *cpu_env) |
1353 | 66fb9763 | bellard | { |
1354 | 66fb9763 | bellard | int sig;
|
1355 | 66fb9763 | bellard | target_ulong handler; |
1356 | 9de5e440 | bellard | sigset_t set, old_set; |
1357 | 9de5e440 | bellard | target_sigset_t target_old_set; |
1358 | 66fb9763 | bellard | struct emulated_sigaction *k;
|
1359 | 66fb9763 | bellard | struct sigqueue *q;
|
1360 | 66fb9763 | bellard | |
1361 | 31e31b8a | bellard | if (!signal_pending)
|
1362 | 31e31b8a | bellard | return;
|
1363 | 31e31b8a | bellard | |
1364 | 66fb9763 | bellard | k = sigact_table; |
1365 | 66fb9763 | bellard | for(sig = 1; sig <= TARGET_NSIG; sig++) { |
1366 | 66fb9763 | bellard | if (k->pending)
|
1367 | 31e31b8a | bellard | goto handle_signal;
|
1368 | 66fb9763 | bellard | k++; |
1369 | 31e31b8a | bellard | } |
1370 | 31e31b8a | bellard | /* if no signal is pending, just return */
|
1371 | 31e31b8a | bellard | signal_pending = 0;
|
1372 | 31e31b8a | bellard | return;
|
1373 | 66fb9763 | bellard | |
1374 | 31e31b8a | bellard | handle_signal:
|
1375 | 66fb9763 | bellard | #ifdef DEBUG_SIGNAL
|
1376 | bc8a22cc | bellard | fprintf(stderr, "qemu: process signal %d\n", sig);
|
1377 | 66fb9763 | bellard | #endif
|
1378 | 66fb9763 | bellard | /* dequeue signal */
|
1379 | 66fb9763 | bellard | q = k->first; |
1380 | 66fb9763 | bellard | k->first = q->next; |
1381 | 66fb9763 | bellard | if (!k->first)
|
1382 | 66fb9763 | bellard | k->pending = 0;
|
1383 | 66fb9763 | bellard | |
1384 | 66fb9763 | bellard | handler = k->sa._sa_handler; |
1385 | 66fb9763 | bellard | if (handler == TARGET_SIG_DFL) {
|
1386 | 66fb9763 | bellard | /* default handler : ignore some signal. The other are fatal */
|
1387 | 66fb9763 | bellard | if (sig != TARGET_SIGCHLD &&
|
1388 | 66fb9763 | bellard | sig != TARGET_SIGURG && |
1389 | 66fb9763 | bellard | sig != TARGET_SIGWINCH) { |
1390 | 66fb9763 | bellard | force_sig(sig); |
1391 | 66fb9763 | bellard | } |
1392 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_IGN) { |
1393 | 66fb9763 | bellard | /* ignore sig */
|
1394 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_ERR) { |
1395 | 66fb9763 | bellard | force_sig(sig); |
1396 | 66fb9763 | bellard | } else {
|
1397 | 9de5e440 | bellard | /* compute the blocked signals during the handler execution */
|
1398 | 9de5e440 | bellard | target_to_host_sigset(&set, &k->sa.sa_mask); |
1399 | 9de5e440 | bellard | /* SA_NODEFER indicates that the current signal should not be
|
1400 | 9de5e440 | bellard | blocked during the handler */
|
1401 | 9de5e440 | bellard | if (!(k->sa.sa_flags & TARGET_SA_NODEFER))
|
1402 | 9de5e440 | bellard | sigaddset(&set, target_to_host_signal(sig)); |
1403 | 9de5e440 | bellard | |
1404 | 9de5e440 | bellard | /* block signals in the handler using Linux */
|
1405 | 9de5e440 | bellard | sigprocmask(SIG_BLOCK, &set, &old_set); |
1406 | 9de5e440 | bellard | /* save the previous blocked signal state to restore it at the
|
1407 | 9de5e440 | bellard | end of the signal execution (see do_sigreturn) */
|
1408 | 9de5e440 | bellard | host_to_target_sigset(&target_old_set, &old_set); |
1409 | 9de5e440 | bellard | |
1410 | bc8a22cc | bellard | /* if the CPU is in VM86 mode, we restore the 32 bit values */
|
1411 | bc8a22cc | bellard | #ifdef TARGET_I386
|
1412 | bc8a22cc | bellard | { |
1413 | bc8a22cc | bellard | CPUX86State *env = cpu_env; |
1414 | bc8a22cc | bellard | if (env->eflags & VM_MASK)
|
1415 | bc8a22cc | bellard | save_v86_state(env); |
1416 | bc8a22cc | bellard | } |
1417 | bc8a22cc | bellard | #endif
|
1418 | 9de5e440 | bellard | /* prepare the stack frame of the virtual CPU */
|
1419 | 66fb9763 | bellard | if (k->sa.sa_flags & TARGET_SA_SIGINFO)
|
1420 | 9de5e440 | bellard | setup_rt_frame(sig, k, &q->info, &target_old_set, cpu_env); |
1421 | 66fb9763 | bellard | else
|
1422 | 9de5e440 | bellard | setup_frame(sig, k, &target_old_set, cpu_env); |
1423 | 66fb9763 | bellard | if (k->sa.sa_flags & TARGET_SA_RESETHAND)
|
1424 | 66fb9763 | bellard | k->sa._sa_handler = TARGET_SIG_DFL; |
1425 | 31e31b8a | bellard | } |
1426 | 66fb9763 | bellard | if (q != &k->info)
|
1427 | 66fb9763 | bellard | free_sigqueue(q); |
1428 | 66fb9763 | bellard | } |
1429 | 31e31b8a | bellard |