root / linux-user / signal.c @ ecd78a0a
History | View | Annotate | Download (48.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 | 3ef693a0 | bellard | #include "qemu.h" |
30 | 66fb9763 | bellard | |
31 | 66fb9763 | bellard | //#define DEBUG_SIGNAL
|
32 | 66fb9763 | bellard | |
33 | 66fb9763 | bellard | #define MAX_SIGQUEUE_SIZE 1024 |
34 | 66fb9763 | bellard | |
35 | 66fb9763 | bellard | struct sigqueue {
|
36 | 66fb9763 | bellard | struct sigqueue *next;
|
37 | 9de5e440 | bellard | target_siginfo_t info; |
38 | 66fb9763 | bellard | }; |
39 | 31e31b8a | bellard | |
40 | 31e31b8a | bellard | struct emulated_sigaction {
|
41 | 31e31b8a | bellard | struct target_sigaction sa;
|
42 | 66fb9763 | bellard | int pending; /* true if signal is pending */ |
43 | 66fb9763 | bellard | struct sigqueue *first;
|
44 | 66fb9763 | bellard | struct sigqueue info; /* in order to always have memory for the |
45 | 66fb9763 | bellard | first signal, we put it here */
|
46 | 31e31b8a | bellard | }; |
47 | 31e31b8a | bellard | |
48 | 66fb9763 | bellard | static struct emulated_sigaction sigact_table[TARGET_NSIG]; |
49 | 66fb9763 | bellard | static struct sigqueue sigqueue_table[MAX_SIGQUEUE_SIZE]; /* siginfo queue */ |
50 | 66fb9763 | bellard | static struct sigqueue *first_free; /* first free siginfo queue entry */ |
51 | 66fb9763 | bellard | static int signal_pending; /* non zero if a signal may be pending */ |
52 | 31e31b8a | bellard | |
53 | 66fb9763 | bellard | static void host_signal_handler(int host_signum, siginfo_t *info, |
54 | 66fb9763 | bellard | void *puc);
|
55 | 66fb9763 | bellard | |
56 | 9e5f5284 | bellard | static uint8_t host_to_target_signal_table[65] = { |
57 | 9e5f5284 | bellard | [SIGHUP] = TARGET_SIGHUP, |
58 | 9e5f5284 | bellard | [SIGINT] = TARGET_SIGINT, |
59 | 9e5f5284 | bellard | [SIGQUIT] = TARGET_SIGQUIT, |
60 | 9e5f5284 | bellard | [SIGILL] = TARGET_SIGILL, |
61 | 9e5f5284 | bellard | [SIGTRAP] = TARGET_SIGTRAP, |
62 | 9e5f5284 | bellard | [SIGABRT] = TARGET_SIGABRT, |
63 | 01e3b763 | bellard | /* [SIGIOT] = TARGET_SIGIOT,*/
|
64 | 9e5f5284 | bellard | [SIGBUS] = TARGET_SIGBUS, |
65 | 9e5f5284 | bellard | [SIGFPE] = TARGET_SIGFPE, |
66 | 9e5f5284 | bellard | [SIGKILL] = TARGET_SIGKILL, |
67 | 9e5f5284 | bellard | [SIGUSR1] = TARGET_SIGUSR1, |
68 | 9e5f5284 | bellard | [SIGSEGV] = TARGET_SIGSEGV, |
69 | 9e5f5284 | bellard | [SIGUSR2] = TARGET_SIGUSR2, |
70 | 9e5f5284 | bellard | [SIGPIPE] = TARGET_SIGPIPE, |
71 | 9e5f5284 | bellard | [SIGALRM] = TARGET_SIGALRM, |
72 | 9e5f5284 | bellard | [SIGTERM] = TARGET_SIGTERM, |
73 | 9e5f5284 | bellard | #ifdef SIGSTKFLT
|
74 | 9e5f5284 | bellard | [SIGSTKFLT] = TARGET_SIGSTKFLT, |
75 | 9e5f5284 | bellard | #endif
|
76 | 9e5f5284 | bellard | [SIGCHLD] = TARGET_SIGCHLD, |
77 | 9e5f5284 | bellard | [SIGCONT] = TARGET_SIGCONT, |
78 | 9e5f5284 | bellard | [SIGSTOP] = TARGET_SIGSTOP, |
79 | 9e5f5284 | bellard | [SIGTSTP] = TARGET_SIGTSTP, |
80 | 9e5f5284 | bellard | [SIGTTIN] = TARGET_SIGTTIN, |
81 | 9e5f5284 | bellard | [SIGTTOU] = TARGET_SIGTTOU, |
82 | 9e5f5284 | bellard | [SIGURG] = TARGET_SIGURG, |
83 | 9e5f5284 | bellard | [SIGXCPU] = TARGET_SIGXCPU, |
84 | 9e5f5284 | bellard | [SIGXFSZ] = TARGET_SIGXFSZ, |
85 | 9e5f5284 | bellard | [SIGVTALRM] = TARGET_SIGVTALRM, |
86 | 9e5f5284 | bellard | [SIGPROF] = TARGET_SIGPROF, |
87 | 9e5f5284 | bellard | [SIGWINCH] = TARGET_SIGWINCH, |
88 | 9e5f5284 | bellard | [SIGIO] = TARGET_SIGIO, |
89 | 9e5f5284 | bellard | [SIGPWR] = TARGET_SIGPWR, |
90 | 9e5f5284 | bellard | [SIGSYS] = TARGET_SIGSYS, |
91 | 9e5f5284 | bellard | /* next signals stay the same */
|
92 | 9e5f5284 | bellard | }; |
93 | 9e5f5284 | bellard | static uint8_t target_to_host_signal_table[65]; |
94 | 9e5f5284 | bellard | |
95 | 31e31b8a | bellard | static inline int host_to_target_signal(int sig) |
96 | 31e31b8a | bellard | { |
97 | 9e5f5284 | bellard | return host_to_target_signal_table[sig];
|
98 | 31e31b8a | bellard | } |
99 | 31e31b8a | bellard | |
100 | 31e31b8a | bellard | static inline int target_to_host_signal(int sig) |
101 | 31e31b8a | bellard | { |
102 | 9e5f5284 | bellard | return target_to_host_signal_table[sig];
|
103 | 31e31b8a | bellard | } |
104 | 31e31b8a | bellard | |
105 | 9231944d | bellard | static void host_to_target_sigset_internal(target_sigset_t *d, |
106 | 9231944d | bellard | const sigset_t *s)
|
107 | 66fb9763 | bellard | { |
108 | 66fb9763 | bellard | int i;
|
109 | 9e5f5284 | bellard | unsigned long sigmask; |
110 | 9e5f5284 | bellard | uint32_t target_sigmask; |
111 | 9e5f5284 | bellard | |
112 | 9e5f5284 | bellard | sigmask = ((unsigned long *)s)[0]; |
113 | 9e5f5284 | bellard | target_sigmask = 0;
|
114 | 9e5f5284 | bellard | for(i = 0; i < 32; i++) { |
115 | 9e5f5284 | bellard | if (sigmask & (1 << i)) |
116 | 9e5f5284 | bellard | target_sigmask |= 1 << (host_to_target_signal(i + 1) - 1); |
117 | 9e5f5284 | bellard | } |
118 | 9e5f5284 | bellard | #if TARGET_LONG_BITS == 32 && HOST_LONG_BITS == 32 |
119 | 9231944d | bellard | d->sig[0] = target_sigmask;
|
120 | 9e5f5284 | bellard | for(i = 1;i < TARGET_NSIG_WORDS; i++) { |
121 | 9231944d | bellard | d->sig[i] = ((unsigned long *)s)[i]; |
122 | 66fb9763 | bellard | } |
123 | 9e5f5284 | bellard | #elif TARGET_LONG_BITS == 32 && HOST_LONG_BITS == 64 && TARGET_NSIG_WORDS == 2 |
124 | 9231944d | bellard | d->sig[0] = target_sigmask;
|
125 | 9231944d | bellard | d->sig[1] = sigmask >> 32; |
126 | 9e5f5284 | bellard | #else
|
127 | a315a145 | bellard | #warning host_to_target_sigset
|
128 | 9e5f5284 | bellard | #endif
|
129 | 66fb9763 | bellard | } |
130 | 66fb9763 | bellard | |
131 | 9231944d | bellard | void host_to_target_sigset(target_sigset_t *d, const sigset_t *s) |
132 | 9231944d | bellard | { |
133 | 9231944d | bellard | target_sigset_t d1; |
134 | 9231944d | bellard | int i;
|
135 | 9231944d | bellard | |
136 | 9231944d | bellard | host_to_target_sigset_internal(&d1, s); |
137 | 9231944d | bellard | for(i = 0;i < TARGET_NSIG_WORDS; i++) |
138 | 9231944d | bellard | __put_user(d1.sig[i], &d->sig[i]); |
139 | 9231944d | bellard | } |
140 | 9231944d | bellard | |
141 | 9231944d | bellard | void target_to_host_sigset_internal(sigset_t *d, const target_sigset_t *s) |
142 | 66fb9763 | bellard | { |
143 | 66fb9763 | bellard | int i;
|
144 | 9e5f5284 | bellard | unsigned long sigmask; |
145 | 9e5f5284 | bellard | target_ulong target_sigmask; |
146 | 9e5f5284 | bellard | |
147 | 9231944d | bellard | target_sigmask = s->sig[0];
|
148 | 9e5f5284 | bellard | sigmask = 0;
|
149 | 9e5f5284 | bellard | for(i = 0; i < 32; i++) { |
150 | 9e5f5284 | bellard | if (target_sigmask & (1 << i)) |
151 | 9e5f5284 | bellard | sigmask |= 1 << (target_to_host_signal(i + 1) - 1); |
152 | 9e5f5284 | bellard | } |
153 | 9e5f5284 | bellard | #if TARGET_LONG_BITS == 32 && HOST_LONG_BITS == 32 |
154 | 9e5f5284 | bellard | ((unsigned long *)d)[0] = sigmask; |
155 | 9e5f5284 | bellard | for(i = 1;i < TARGET_NSIG_WORDS; i++) { |
156 | 9231944d | bellard | ((unsigned long *)d)[i] = s->sig[i]; |
157 | 66fb9763 | bellard | } |
158 | 9e5f5284 | bellard | #elif TARGET_LONG_BITS == 32 && HOST_LONG_BITS == 64 && TARGET_NSIG_WORDS == 2 |
159 | 9231944d | bellard | ((unsigned long *)d)[0] = sigmask | ((unsigned long)(s->sig[1]) << 32); |
160 | 9e5f5284 | bellard | #else
|
161 | a315a145 | bellard | #warning target_to_host_sigset
|
162 | 9e5f5284 | bellard | #endif /* TARGET_LONG_BITS */ |
163 | 66fb9763 | bellard | } |
164 | 66fb9763 | bellard | |
165 | 9231944d | bellard | void target_to_host_sigset(sigset_t *d, const target_sigset_t *s) |
166 | 9231944d | bellard | { |
167 | 9231944d | bellard | target_sigset_t s1; |
168 | 9231944d | bellard | int i;
|
169 | 9231944d | bellard | |
170 | 9231944d | bellard | for(i = 0;i < TARGET_NSIG_WORDS; i++) |
171 | 9231944d | bellard | __get_user(s1.sig[i], &s->sig[i]); |
172 | 9231944d | bellard | target_to_host_sigset_internal(d, &s1); |
173 | 9231944d | bellard | } |
174 | 9231944d | bellard | |
175 | 66fb9763 | bellard | void host_to_target_old_sigset(target_ulong *old_sigset,
|
176 | 66fb9763 | bellard | const sigset_t *sigset)
|
177 | 66fb9763 | bellard | { |
178 | 9e5f5284 | bellard | target_sigset_t d; |
179 | 9e5f5284 | bellard | host_to_target_sigset(&d, sigset); |
180 | 9e5f5284 | bellard | *old_sigset = d.sig[0];
|
181 | 66fb9763 | bellard | } |
182 | 66fb9763 | bellard | |
183 | 66fb9763 | bellard | void target_to_host_old_sigset(sigset_t *sigset,
|
184 | 66fb9763 | bellard | const target_ulong *old_sigset)
|
185 | 66fb9763 | bellard | { |
186 | 9e5f5284 | bellard | target_sigset_t d; |
187 | 9e5f5284 | bellard | int i;
|
188 | 9e5f5284 | bellard | |
189 | 9e5f5284 | bellard | d.sig[0] = *old_sigset;
|
190 | 9e5f5284 | bellard | for(i = 1;i < TARGET_NSIG_WORDS; i++) |
191 | 9e5f5284 | bellard | d.sig[i] = 0;
|
192 | 9e5f5284 | bellard | target_to_host_sigset(sigset, &d); |
193 | 66fb9763 | bellard | } |
194 | 66fb9763 | bellard | |
195 | 9de5e440 | bellard | /* siginfo conversion */
|
196 | 9de5e440 | bellard | |
197 | 9de5e440 | bellard | static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo, |
198 | 9de5e440 | bellard | const siginfo_t *info)
|
199 | 66fb9763 | bellard | { |
200 | 9de5e440 | bellard | int sig;
|
201 | 9de5e440 | bellard | sig = host_to_target_signal(info->si_signo); |
202 | 9de5e440 | bellard | tinfo->si_signo = sig; |
203 | 9de5e440 | bellard | tinfo->si_errno = 0;
|
204 | 9de5e440 | bellard | tinfo->si_code = 0;
|
205 | 447db213 | bellard | if (sig == SIGILL || sig == SIGFPE || sig == SIGSEGV ||
|
206 | 447db213 | bellard | sig == SIGBUS || sig == SIGTRAP) { |
207 | 9de5e440 | bellard | /* should never come here, but who knows. The information for
|
208 | 9de5e440 | bellard | the target is irrelevant */
|
209 | 9de5e440 | bellard | tinfo->_sifields._sigfault._addr = 0;
|
210 | 9de5e440 | bellard | } else if (sig >= TARGET_SIGRTMIN) { |
211 | 9de5e440 | bellard | tinfo->_sifields._rt._pid = info->si_pid; |
212 | 9de5e440 | bellard | tinfo->_sifields._rt._uid = info->si_uid; |
213 | 9de5e440 | bellard | /* XXX: potential problem if 64 bit */
|
214 | 9de5e440 | bellard | tinfo->_sifields._rt._sigval.sival_ptr = |
215 | 9de5e440 | bellard | (target_ulong)info->si_value.sival_ptr; |
216 | 9de5e440 | bellard | } |
217 | 9de5e440 | bellard | } |
218 | 9de5e440 | bellard | |
219 | 9de5e440 | bellard | static void tswap_siginfo(target_siginfo_t *tinfo, |
220 | 9de5e440 | bellard | const target_siginfo_t *info)
|
221 | 9de5e440 | bellard | { |
222 | 9de5e440 | bellard | int sig;
|
223 | 9de5e440 | bellard | sig = info->si_signo; |
224 | 9de5e440 | bellard | tinfo->si_signo = tswap32(sig); |
225 | 66fb9763 | bellard | tinfo->si_errno = tswap32(info->si_errno); |
226 | 66fb9763 | bellard | tinfo->si_code = tswap32(info->si_code); |
227 | 447db213 | bellard | if (sig == SIGILL || sig == SIGFPE || sig == SIGSEGV ||
|
228 | 447db213 | bellard | sig == SIGBUS || sig == SIGTRAP) { |
229 | 9de5e440 | bellard | tinfo->_sifields._sigfault._addr = |
230 | 9de5e440 | bellard | tswapl(info->_sifields._sigfault._addr); |
231 | 9de5e440 | bellard | } else if (sig >= TARGET_SIGRTMIN) { |
232 | 9de5e440 | bellard | tinfo->_sifields._rt._pid = tswap32(info->_sifields._rt._pid); |
233 | 9de5e440 | bellard | tinfo->_sifields._rt._uid = tswap32(info->_sifields._rt._uid); |
234 | 9de5e440 | bellard | tinfo->_sifields._rt._sigval.sival_ptr = |
235 | 9de5e440 | bellard | tswapl(info->_sifields._rt._sigval.sival_ptr); |
236 | 9de5e440 | bellard | } |
237 | 9de5e440 | bellard | } |
238 | 9de5e440 | bellard | |
239 | 9de5e440 | bellard | |
240 | 9de5e440 | bellard | void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info) |
241 | 9de5e440 | bellard | { |
242 | 9de5e440 | bellard | host_to_target_siginfo_noswap(tinfo, info); |
243 | 9de5e440 | bellard | tswap_siginfo(tinfo, tinfo); |
244 | 66fb9763 | bellard | } |
245 | 66fb9763 | bellard | |
246 | 9de5e440 | bellard | /* XXX: we support only POSIX RT signals are used. */
|
247 | 9de5e440 | bellard | /* XXX: find a solution for 64 bit (additionnal malloced data is needed) */
|
248 | 9de5e440 | bellard | void target_to_host_siginfo(siginfo_t *info, const target_siginfo_t *tinfo) |
249 | 66fb9763 | bellard | { |
250 | 66fb9763 | bellard | info->si_signo = tswap32(tinfo->si_signo); |
251 | 66fb9763 | bellard | info->si_errno = tswap32(tinfo->si_errno); |
252 | 66fb9763 | bellard | info->si_code = tswap32(tinfo->si_code); |
253 | 9de5e440 | bellard | info->si_pid = tswap32(tinfo->_sifields._rt._pid); |
254 | 9de5e440 | bellard | info->si_uid = tswap32(tinfo->_sifields._rt._uid); |
255 | 9de5e440 | bellard | info->si_value.sival_ptr = |
256 | 9de5e440 | bellard | (void *)tswapl(tinfo->_sifields._rt._sigval.sival_ptr);
|
257 | 66fb9763 | bellard | } |
258 | 66fb9763 | bellard | |
259 | 31e31b8a | bellard | void signal_init(void) |
260 | 31e31b8a | bellard | { |
261 | 31e31b8a | bellard | struct sigaction act;
|
262 | 9e5f5284 | bellard | int i, j;
|
263 | 31e31b8a | bellard | |
264 | 9e5f5284 | bellard | /* generate signal conversion tables */
|
265 | 9e5f5284 | bellard | for(i = 1; i <= 64; i++) { |
266 | 9e5f5284 | bellard | if (host_to_target_signal_table[i] == 0) |
267 | 9e5f5284 | bellard | host_to_target_signal_table[i] = i; |
268 | 9e5f5284 | bellard | } |
269 | 9e5f5284 | bellard | for(i = 1; i <= 64; i++) { |
270 | 9e5f5284 | bellard | j = host_to_target_signal_table[i]; |
271 | 9e5f5284 | bellard | target_to_host_signal_table[j] = i; |
272 | 9e5f5284 | bellard | } |
273 | 9e5f5284 | bellard | |
274 | 9de5e440 | bellard | /* set all host signal handlers. ALL signals are blocked during
|
275 | 9de5e440 | bellard | the handlers to serialize them. */
|
276 | 9de5e440 | bellard | sigfillset(&act.sa_mask); |
277 | 31e31b8a | bellard | act.sa_flags = SA_SIGINFO; |
278 | 31e31b8a | bellard | act.sa_sigaction = host_signal_handler; |
279 | 31e31b8a | bellard | for(i = 1; i < NSIG; i++) { |
280 | c9087c2a | bellard | sigaction(i, &act, NULL);
|
281 | 31e31b8a | bellard | } |
282 | 31e31b8a | bellard | |
283 | 31e31b8a | bellard | memset(sigact_table, 0, sizeof(sigact_table)); |
284 | 66fb9763 | bellard | |
285 | 66fb9763 | bellard | first_free = &sigqueue_table[0];
|
286 | 66fb9763 | bellard | for(i = 0; i < MAX_SIGQUEUE_SIZE - 1; i++) |
287 | 66fb9763 | bellard | sigqueue_table[i].next = &sigqueue_table[i + 1];
|
288 | 66fb9763 | bellard | sigqueue_table[MAX_SIGQUEUE_SIZE - 1].next = NULL; |
289 | 66fb9763 | bellard | } |
290 | 66fb9763 | bellard | |
291 | 66fb9763 | bellard | /* signal queue handling */
|
292 | 66fb9763 | bellard | |
293 | 66fb9763 | bellard | static inline struct sigqueue *alloc_sigqueue(void) |
294 | 66fb9763 | bellard | { |
295 | 66fb9763 | bellard | struct sigqueue *q = first_free;
|
296 | 66fb9763 | bellard | if (!q)
|
297 | 66fb9763 | bellard | return NULL; |
298 | 66fb9763 | bellard | first_free = q->next; |
299 | 66fb9763 | bellard | return q;
|
300 | 31e31b8a | bellard | } |
301 | 31e31b8a | bellard | |
302 | 66fb9763 | bellard | static inline void free_sigqueue(struct sigqueue *q) |
303 | 66fb9763 | bellard | { |
304 | 66fb9763 | bellard | q->next = first_free; |
305 | 66fb9763 | bellard | first_free = q; |
306 | 66fb9763 | bellard | } |
307 | 66fb9763 | bellard | |
308 | 9de5e440 | bellard | /* abort execution with signal */
|
309 | 9de5e440 | bellard | void __attribute((noreturn)) force_sig(int sig) |
310 | 66fb9763 | bellard | { |
311 | 66fb9763 | bellard | int host_sig;
|
312 | 66fb9763 | bellard | host_sig = target_to_host_signal(sig); |
313 | bc8a22cc | bellard | fprintf(stderr, "qemu: uncaught target signal %d (%s) - exiting\n",
|
314 | 66fb9763 | bellard | sig, strsignal(host_sig)); |
315 | 9de5e440 | bellard | #if 1 |
316 | 66fb9763 | bellard | _exit(-host_sig); |
317 | 9de5e440 | bellard | #else
|
318 | 9de5e440 | bellard | { |
319 | 9de5e440 | bellard | struct sigaction act;
|
320 | 9de5e440 | bellard | sigemptyset(&act.sa_mask); |
321 | 9de5e440 | bellard | act.sa_flags = SA_SIGINFO; |
322 | 9de5e440 | bellard | act.sa_sigaction = SIG_DFL; |
323 | 9de5e440 | bellard | sigaction(SIGABRT, &act, NULL);
|
324 | 9de5e440 | bellard | abort(); |
325 | 9de5e440 | bellard | } |
326 | 9de5e440 | bellard | #endif
|
327 | 66fb9763 | bellard | } |
328 | 66fb9763 | bellard | |
329 | 9de5e440 | bellard | /* queue a signal so that it will be send to the virtual CPU as soon
|
330 | 9de5e440 | bellard | as possible */
|
331 | 9de5e440 | bellard | int queue_signal(int sig, target_siginfo_t *info) |
332 | 31e31b8a | bellard | { |
333 | 66fb9763 | bellard | struct emulated_sigaction *k;
|
334 | 9de5e440 | bellard | struct sigqueue *q, **pq;
|
335 | 66fb9763 | bellard | target_ulong handler; |
336 | 66fb9763 | bellard | |
337 | 9de5e440 | bellard | #if defined(DEBUG_SIGNAL)
|
338 | bc8a22cc | bellard | fprintf(stderr, "queue_signal: sig=%d\n",
|
339 | 9de5e440 | bellard | sig); |
340 | 66fb9763 | bellard | #endif
|
341 | 9de5e440 | bellard | k = &sigact_table[sig - 1];
|
342 | 66fb9763 | bellard | handler = k->sa._sa_handler; |
343 | 66fb9763 | bellard | if (handler == TARGET_SIG_DFL) {
|
344 | 66fb9763 | bellard | /* default handler : ignore some signal. The other are fatal */
|
345 | 66fb9763 | bellard | if (sig != TARGET_SIGCHLD &&
|
346 | 66fb9763 | bellard | sig != TARGET_SIGURG && |
347 | 66fb9763 | bellard | sig != TARGET_SIGWINCH) { |
348 | 66fb9763 | bellard | force_sig(sig); |
349 | 9de5e440 | bellard | } else {
|
350 | 9de5e440 | bellard | return 0; /* indicate ignored */ |
351 | 66fb9763 | bellard | } |
352 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_IGN) { |
353 | 66fb9763 | bellard | /* ignore signal */
|
354 | 9de5e440 | bellard | return 0; |
355 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_ERR) { |
356 | 66fb9763 | bellard | force_sig(sig); |
357 | 66fb9763 | bellard | } else {
|
358 | 9de5e440 | bellard | pq = &k->first; |
359 | 9de5e440 | bellard | if (sig < TARGET_SIGRTMIN) {
|
360 | 9de5e440 | bellard | /* if non real time signal, we queue exactly one signal */
|
361 | 9de5e440 | bellard | if (!k->pending)
|
362 | 9de5e440 | bellard | q = &k->info; |
363 | 9de5e440 | bellard | else
|
364 | 9de5e440 | bellard | return 0; |
365 | 9de5e440 | bellard | } else {
|
366 | 9de5e440 | bellard | if (!k->pending) {
|
367 | 9de5e440 | bellard | /* first signal */
|
368 | 9de5e440 | bellard | q = &k->info; |
369 | 9de5e440 | bellard | } else {
|
370 | 9de5e440 | bellard | q = alloc_sigqueue(); |
371 | 9de5e440 | bellard | if (!q)
|
372 | 9de5e440 | bellard | return -EAGAIN;
|
373 | 9de5e440 | bellard | while (*pq != NULL) |
374 | 9de5e440 | bellard | pq = &(*pq)->next; |
375 | 9de5e440 | bellard | } |
376 | 9de5e440 | bellard | } |
377 | 9de5e440 | bellard | *pq = q; |
378 | 9de5e440 | bellard | q->info = *info; |
379 | 9de5e440 | bellard | q->next = NULL;
|
380 | 9de5e440 | bellard | k->pending = 1;
|
381 | 9de5e440 | bellard | /* signal that a new signal is pending */
|
382 | 9de5e440 | bellard | signal_pending = 1;
|
383 | 9de5e440 | bellard | return 1; /* indicates that the signal was queued */ |
384 | 9de5e440 | bellard | } |
385 | 9de5e440 | bellard | } |
386 | 9de5e440 | bellard | |
387 | 9de5e440 | bellard | static void host_signal_handler(int host_signum, siginfo_t *info, |
388 | 9de5e440 | bellard | void *puc)
|
389 | 9de5e440 | bellard | { |
390 | 9de5e440 | bellard | int sig;
|
391 | 9de5e440 | bellard | target_siginfo_t tinfo; |
392 | 9de5e440 | bellard | |
393 | 9de5e440 | bellard | /* the CPU emulator uses some host signals to detect exceptions,
|
394 | 9de5e440 | bellard | we we forward to it some signals */
|
395 | 58fe2f10 | bellard | if (host_signum == SIGSEGV || host_signum == SIGBUS
|
396 | 58fe2f10 | bellard | #if defined(TARGET_I386) && defined(USE_CODE_COPY)
|
397 | 58fe2f10 | bellard | || host_signum == SIGFPE |
398 | 58fe2f10 | bellard | #endif
|
399 | 58fe2f10 | bellard | ) { |
400 | b346ff46 | bellard | if (cpu_signal_handler(host_signum, info, puc))
|
401 | 9de5e440 | bellard | return;
|
402 | 9de5e440 | bellard | } |
403 | 9de5e440 | bellard | |
404 | 9de5e440 | bellard | /* get target signal number */
|
405 | 9de5e440 | bellard | sig = host_to_target_signal(host_signum); |
406 | 9de5e440 | bellard | if (sig < 1 || sig > TARGET_NSIG) |
407 | 9de5e440 | bellard | return;
|
408 | 9de5e440 | bellard | #if defined(DEBUG_SIGNAL)
|
409 | bc8a22cc | bellard | fprintf(stderr, "qemu: got signal %d\n", sig);
|
410 | 9de5e440 | bellard | #endif
|
411 | 9de5e440 | bellard | host_to_target_siginfo_noswap(&tinfo, info); |
412 | 9de5e440 | bellard | if (queue_signal(sig, &tinfo) == 1) { |
413 | 9de5e440 | bellard | /* interrupt the virtual CPU as soon as possible */
|
414 | 68a79315 | bellard | cpu_interrupt(global_env, CPU_INTERRUPT_EXIT); |
415 | 66fb9763 | bellard | } |
416 | 66fb9763 | bellard | } |
417 | 66fb9763 | bellard | |
418 | 66fb9763 | bellard | int do_sigaction(int sig, const struct target_sigaction *act, |
419 | 66fb9763 | bellard | struct target_sigaction *oact)
|
420 | 66fb9763 | bellard | { |
421 | 66fb9763 | bellard | struct emulated_sigaction *k;
|
422 | 773b93ee | bellard | struct sigaction act1;
|
423 | 773b93ee | bellard | int host_sig;
|
424 | 66fb9763 | bellard | |
425 | 66fb9763 | bellard | if (sig < 1 || sig > TARGET_NSIG) |
426 | 66fb9763 | bellard | return -EINVAL;
|
427 | 66fb9763 | bellard | k = &sigact_table[sig - 1];
|
428 | 773b93ee | bellard | #if defined(DEBUG_SIGNAL)
|
429 | 66fb9763 | bellard | fprintf(stderr, "sigaction sig=%d act=0x%08x, oact=0x%08x\n",
|
430 | 66fb9763 | bellard | sig, (int)act, (int)oact); |
431 | 66fb9763 | bellard | #endif
|
432 | 66fb9763 | bellard | if (oact) {
|
433 | 66fb9763 | bellard | oact->_sa_handler = tswapl(k->sa._sa_handler); |
434 | 66fb9763 | bellard | oact->sa_flags = tswapl(k->sa.sa_flags); |
435 | 66fb9763 | bellard | oact->sa_restorer = tswapl(k->sa.sa_restorer); |
436 | 66fb9763 | bellard | oact->sa_mask = k->sa.sa_mask; |
437 | 66fb9763 | bellard | } |
438 | 66fb9763 | bellard | if (act) {
|
439 | 66fb9763 | bellard | k->sa._sa_handler = tswapl(act->_sa_handler); |
440 | 66fb9763 | bellard | k->sa.sa_flags = tswapl(act->sa_flags); |
441 | 66fb9763 | bellard | k->sa.sa_restorer = tswapl(act->sa_restorer); |
442 | 66fb9763 | bellard | k->sa.sa_mask = act->sa_mask; |
443 | 773b93ee | bellard | |
444 | 773b93ee | bellard | /* we update the host linux signal state */
|
445 | 773b93ee | bellard | host_sig = target_to_host_signal(sig); |
446 | 773b93ee | bellard | if (host_sig != SIGSEGV && host_sig != SIGBUS) {
|
447 | 773b93ee | bellard | sigfillset(&act1.sa_mask); |
448 | 773b93ee | bellard | act1.sa_flags = SA_SIGINFO; |
449 | 773b93ee | bellard | if (k->sa.sa_flags & TARGET_SA_RESTART)
|
450 | 773b93ee | bellard | act1.sa_flags |= SA_RESTART; |
451 | 773b93ee | bellard | /* NOTE: it is important to update the host kernel signal
|
452 | 773b93ee | bellard | ignore state to avoid getting unexpected interrupted
|
453 | 773b93ee | bellard | syscalls */
|
454 | 773b93ee | bellard | if (k->sa._sa_handler == TARGET_SIG_IGN) {
|
455 | 773b93ee | bellard | act1.sa_sigaction = (void *)SIG_IGN;
|
456 | 773b93ee | bellard | } else if (k->sa._sa_handler == TARGET_SIG_DFL) { |
457 | 773b93ee | bellard | act1.sa_sigaction = (void *)SIG_DFL;
|
458 | 773b93ee | bellard | } else {
|
459 | 773b93ee | bellard | act1.sa_sigaction = host_signal_handler; |
460 | 773b93ee | bellard | } |
461 | 773b93ee | bellard | sigaction(host_sig, &act1, NULL);
|
462 | 773b93ee | bellard | } |
463 | 66fb9763 | bellard | } |
464 | 66fb9763 | bellard | return 0; |
465 | 66fb9763 | bellard | } |
466 | 66fb9763 | bellard | |
467 | 43fff238 | bellard | #ifndef offsetof
|
468 | 43fff238 | bellard | #define offsetof(type, field) ((size_t) &((type *)0)->field) |
469 | 43fff238 | bellard | #endif
|
470 | 43fff238 | bellard | |
471 | 43fff238 | bellard | static inline int copy_siginfo_to_user(target_siginfo_t *tinfo, |
472 | 43fff238 | bellard | const target_siginfo_t *info)
|
473 | 43fff238 | bellard | { |
474 | 43fff238 | bellard | tswap_siginfo(tinfo, info); |
475 | 43fff238 | bellard | return 0; |
476 | 43fff238 | bellard | } |
477 | 43fff238 | bellard | |
478 | 66fb9763 | bellard | #ifdef TARGET_I386
|
479 | 66fb9763 | bellard | |
480 | 66fb9763 | bellard | /* from the Linux kernel */
|
481 | 66fb9763 | bellard | |
482 | 66fb9763 | bellard | struct target_fpreg {
|
483 | 66fb9763 | bellard | uint16_t significand[4];
|
484 | 66fb9763 | bellard | uint16_t exponent; |
485 | 66fb9763 | bellard | }; |
486 | 66fb9763 | bellard | |
487 | 66fb9763 | bellard | struct target_fpxreg {
|
488 | 66fb9763 | bellard | uint16_t significand[4];
|
489 | 66fb9763 | bellard | uint16_t exponent; |
490 | 66fb9763 | bellard | uint16_t padding[3];
|
491 | 66fb9763 | bellard | }; |
492 | 66fb9763 | bellard | |
493 | 66fb9763 | bellard | struct target_xmmreg {
|
494 | 66fb9763 | bellard | target_ulong element[4];
|
495 | 66fb9763 | bellard | }; |
496 | 66fb9763 | bellard | |
497 | 66fb9763 | bellard | struct target_fpstate {
|
498 | 66fb9763 | bellard | /* Regular FPU environment */
|
499 | 66fb9763 | bellard | target_ulong cw; |
500 | 66fb9763 | bellard | target_ulong sw; |
501 | 66fb9763 | bellard | target_ulong tag; |
502 | 66fb9763 | bellard | target_ulong ipoff; |
503 | 66fb9763 | bellard | target_ulong cssel; |
504 | 66fb9763 | bellard | target_ulong dataoff; |
505 | 66fb9763 | bellard | target_ulong datasel; |
506 | 66fb9763 | bellard | struct target_fpreg _st[8]; |
507 | 66fb9763 | bellard | uint16_t status; |
508 | 66fb9763 | bellard | uint16_t magic; /* 0xffff = regular FPU data only */
|
509 | 66fb9763 | bellard | |
510 | 66fb9763 | bellard | /* FXSR FPU environment */
|
511 | 66fb9763 | bellard | target_ulong _fxsr_env[6]; /* FXSR FPU env is ignored */ |
512 | 66fb9763 | bellard | target_ulong mxcsr; |
513 | 66fb9763 | bellard | target_ulong reserved; |
514 | 66fb9763 | bellard | struct target_fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */ |
515 | 66fb9763 | bellard | struct target_xmmreg _xmm[8]; |
516 | 66fb9763 | bellard | target_ulong padding[56];
|
517 | 66fb9763 | bellard | }; |
518 | 66fb9763 | bellard | |
519 | 66fb9763 | bellard | #define X86_FXSR_MAGIC 0x0000 |
520 | 66fb9763 | bellard | |
521 | 66fb9763 | bellard | struct target_sigcontext {
|
522 | 66fb9763 | bellard | uint16_t gs, __gsh; |
523 | 66fb9763 | bellard | uint16_t fs, __fsh; |
524 | 66fb9763 | bellard | uint16_t es, __esh; |
525 | 66fb9763 | bellard | uint16_t ds, __dsh; |
526 | 66fb9763 | bellard | target_ulong edi; |
527 | 66fb9763 | bellard | target_ulong esi; |
528 | 66fb9763 | bellard | target_ulong ebp; |
529 | 66fb9763 | bellard | target_ulong esp; |
530 | 66fb9763 | bellard | target_ulong ebx; |
531 | 66fb9763 | bellard | target_ulong edx; |
532 | 66fb9763 | bellard | target_ulong ecx; |
533 | 66fb9763 | bellard | target_ulong eax; |
534 | 66fb9763 | bellard | target_ulong trapno; |
535 | 66fb9763 | bellard | target_ulong err; |
536 | 66fb9763 | bellard | target_ulong eip; |
537 | 66fb9763 | bellard | uint16_t cs, __csh; |
538 | 66fb9763 | bellard | target_ulong eflags; |
539 | 66fb9763 | bellard | target_ulong esp_at_signal; |
540 | 66fb9763 | bellard | uint16_t ss, __ssh; |
541 | 66fb9763 | bellard | target_ulong fpstate; /* pointer */
|
542 | 66fb9763 | bellard | target_ulong oldmask; |
543 | 66fb9763 | bellard | target_ulong cr2; |
544 | 66fb9763 | bellard | }; |
545 | 66fb9763 | bellard | |
546 | 66fb9763 | bellard | typedef struct target_sigaltstack { |
547 | 66fb9763 | bellard | target_ulong ss_sp; |
548 | 66fb9763 | bellard | int ss_flags;
|
549 | 66fb9763 | bellard | target_ulong ss_size; |
550 | 66fb9763 | bellard | } target_stack_t; |
551 | 66fb9763 | bellard | |
552 | 66fb9763 | bellard | struct target_ucontext {
|
553 | b8076a74 | bellard | target_ulong tuc_flags; |
554 | b8076a74 | bellard | target_ulong tuc_link; |
555 | b8076a74 | bellard | target_stack_t tuc_stack; |
556 | b8076a74 | bellard | struct target_sigcontext tuc_mcontext;
|
557 | b8076a74 | bellard | target_sigset_t tuc_sigmask; /* mask last for extensibility */
|
558 | 66fb9763 | bellard | }; |
559 | 66fb9763 | bellard | |
560 | 66fb9763 | bellard | struct sigframe
|
561 | 66fb9763 | bellard | { |
562 | 66fb9763 | bellard | target_ulong pretcode; |
563 | 66fb9763 | bellard | int sig;
|
564 | 66fb9763 | bellard | struct target_sigcontext sc;
|
565 | 66fb9763 | bellard | struct target_fpstate fpstate;
|
566 | 66fb9763 | bellard | target_ulong extramask[TARGET_NSIG_WORDS-1];
|
567 | 66fb9763 | bellard | char retcode[8]; |
568 | 66fb9763 | bellard | }; |
569 | 66fb9763 | bellard | |
570 | 66fb9763 | bellard | struct rt_sigframe
|
571 | 66fb9763 | bellard | { |
572 | 66fb9763 | bellard | target_ulong pretcode; |
573 | 66fb9763 | bellard | int sig;
|
574 | 66fb9763 | bellard | target_ulong pinfo; |
575 | 66fb9763 | bellard | target_ulong puc; |
576 | 66fb9763 | bellard | struct target_siginfo info;
|
577 | 66fb9763 | bellard | struct target_ucontext uc;
|
578 | 66fb9763 | bellard | struct target_fpstate fpstate;
|
579 | 66fb9763 | bellard | char retcode[8]; |
580 | 66fb9763 | bellard | }; |
581 | 66fb9763 | bellard | |
582 | 66fb9763 | bellard | /*
|
583 | 66fb9763 | bellard | * Set up a signal frame.
|
584 | 66fb9763 | bellard | */
|
585 | 66fb9763 | bellard | |
586 | 66fb9763 | bellard | /* XXX: save x87 state */
|
587 | 66fb9763 | bellard | static int |
588 | 66fb9763 | bellard | setup_sigcontext(struct target_sigcontext *sc, struct target_fpstate *fpstate, |
589 | 66fb9763 | bellard | CPUX86State *env, unsigned long mask) |
590 | 66fb9763 | bellard | { |
591 | 66fb9763 | bellard | int err = 0; |
592 | 66fb9763 | bellard | |
593 | a52c757c | bellard | err |= __put_user(env->segs[R_GS].selector, (unsigned int *)&sc->gs); |
594 | a52c757c | bellard | err |= __put_user(env->segs[R_FS].selector, (unsigned int *)&sc->fs); |
595 | a52c757c | bellard | err |= __put_user(env->segs[R_ES].selector, (unsigned int *)&sc->es); |
596 | a52c757c | bellard | err |= __put_user(env->segs[R_DS].selector, (unsigned int *)&sc->ds); |
597 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EDI], &sc->edi); |
598 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ESI], &sc->esi); |
599 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EBP], &sc->ebp); |
600 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ESP], &sc->esp); |
601 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EBX], &sc->ebx); |
602 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EDX], &sc->edx); |
603 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ECX], &sc->ecx); |
604 | 66fb9763 | bellard | err |= __put_user(env->regs[R_EAX], &sc->eax); |
605 | 66099dd9 | bellard | err |= __put_user(env->exception_index, &sc->trapno); |
606 | 66099dd9 | bellard | err |= __put_user(env->error_code, &sc->err); |
607 | 66fb9763 | bellard | err |= __put_user(env->eip, &sc->eip); |
608 | a52c757c | bellard | err |= __put_user(env->segs[R_CS].selector, (unsigned int *)&sc->cs); |
609 | 66fb9763 | bellard | err |= __put_user(env->eflags, &sc->eflags); |
610 | 66fb9763 | bellard | err |= __put_user(env->regs[R_ESP], &sc->esp_at_signal); |
611 | a52c757c | bellard | err |= __put_user(env->segs[R_SS].selector, (unsigned int *)&sc->ss); |
612 | ed2dcdf6 | bellard | |
613 | ed2dcdf6 | bellard | cpu_x86_fsave(env, (void *)fpstate, 1); |
614 | ed2dcdf6 | bellard | fpstate->status = fpstate->sw; |
615 | ed2dcdf6 | bellard | err |= __put_user(0xffff, &fpstate->magic);
|
616 | ed2dcdf6 | bellard | err |= __put_user(fpstate, &sc->fpstate); |
617 | ed2dcdf6 | bellard | |
618 | 66fb9763 | bellard | /* non-iBCS2 extensions.. */
|
619 | 66fb9763 | bellard | err |= __put_user(mask, &sc->oldmask); |
620 | a52c757c | bellard | err |= __put_user(env->cr[2], &sc->cr2);
|
621 | 66fb9763 | bellard | return err;
|
622 | 31e31b8a | bellard | } |
623 | 31e31b8a | bellard | |
624 | 66fb9763 | bellard | /*
|
625 | 66fb9763 | bellard | * Determine which stack to use..
|
626 | 66fb9763 | bellard | */
|
627 | 31e31b8a | bellard | |
628 | 66fb9763 | bellard | static inline void * |
629 | 66fb9763 | bellard | get_sigframe(struct emulated_sigaction *ka, CPUX86State *env, size_t frame_size)
|
630 | 31e31b8a | bellard | { |
631 | 66fb9763 | bellard | unsigned long esp; |
632 | 66fb9763 | bellard | |
633 | 66fb9763 | bellard | /* Default to using normal stack */
|
634 | 66fb9763 | bellard | esp = env->regs[R_ESP]; |
635 | 66fb9763 | bellard | #if 0
|
636 | 66fb9763 | bellard | /* This is the X/Open sanctioned signal stack switching. */
|
637 | 66fb9763 | bellard | if (ka->sa.sa_flags & SA_ONSTACK) {
|
638 | 66fb9763 | bellard | if (sas_ss_flags(esp) == 0)
|
639 | 66fb9763 | bellard | esp = current->sas_ss_sp + current->sas_ss_size;
|
640 | 66fb9763 | bellard | }
|
641 | 66fb9763 | bellard | |
642 | 66fb9763 | bellard | /* This is the legacy signal stack switching. */
|
643 | a52c757c | bellard | else
|
644 | 66fb9763 | bellard | #endif
|
645 | a52c757c | bellard | if ((env->segs[R_SS].selector & 0xffff) != __USER_DS && |
646 | a52c757c | bellard | !(ka->sa.sa_flags & TARGET_SA_RESTORER) && |
647 | a52c757c | bellard | ka->sa.sa_restorer) { |
648 | a52c757c | bellard | esp = (unsigned long) ka->sa.sa_restorer; |
649 | a52c757c | bellard | } |
650 | a52c757c | bellard | return (void *)((esp - frame_size) & -8ul); |
651 | 66fb9763 | bellard | } |
652 | 66fb9763 | bellard | |
653 | 66fb9763 | bellard | static void setup_frame(int sig, struct emulated_sigaction *ka, |
654 | 66fb9763 | bellard | target_sigset_t *set, CPUX86State *env) |
655 | 66fb9763 | bellard | { |
656 | 66fb9763 | bellard | struct sigframe *frame;
|
657 | 9231944d | bellard | int i, err = 0; |
658 | 66fb9763 | bellard | |
659 | 66fb9763 | bellard | frame = get_sigframe(ka, env, sizeof(*frame));
|
660 | 66fb9763 | bellard | |
661 | 66fb9763 | bellard | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
662 | 66fb9763 | bellard | goto give_sigsegv;
|
663 | 66fb9763 | bellard | err |= __put_user((/*current->exec_domain
|
664 | 66fb9763 | bellard | && current->exec_domain->signal_invmap
|
665 | 66fb9763 | bellard | && sig < 32
|
666 | 66fb9763 | bellard | ? current->exec_domain->signal_invmap[sig]
|
667 | 66fb9763 | bellard | : */ sig),
|
668 | 66fb9763 | bellard | &frame->sig); |
669 | 66fb9763 | bellard | if (err)
|
670 | 66fb9763 | bellard | goto give_sigsegv;
|
671 | 66fb9763 | bellard | |
672 | 66fb9763 | bellard | setup_sigcontext(&frame->sc, &frame->fpstate, env, set->sig[0]);
|
673 | 66fb9763 | bellard | if (err)
|
674 | 66fb9763 | bellard | goto give_sigsegv;
|
675 | 66fb9763 | bellard | |
676 | 9231944d | bellard | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
677 | 9231944d | bellard | if (__put_user(set->sig[i], &frame->extramask[i - 1])) |
678 | 9231944d | bellard | goto give_sigsegv;
|
679 | 9231944d | bellard | } |
680 | 66fb9763 | bellard | |
681 | 66fb9763 | bellard | /* Set up to return from userspace. If provided, use a stub
|
682 | 66fb9763 | bellard | already in userspace. */
|
683 | 66fb9763 | bellard | if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
|
684 | 66fb9763 | bellard | err |= __put_user(ka->sa.sa_restorer, &frame->pretcode); |
685 | 66fb9763 | bellard | } else {
|
686 | 66fb9763 | bellard | err |= __put_user(frame->retcode, &frame->pretcode); |
687 | 66fb9763 | bellard | /* This is popl %eax ; movl $,%eax ; int $0x80 */
|
688 | 66fb9763 | bellard | err |= __put_user(0xb858, (short *)(frame->retcode+0)); |
689 | 66fb9763 | bellard | err |= __put_user(TARGET_NR_sigreturn, (int *)(frame->retcode+2)); |
690 | 66fb9763 | bellard | err |= __put_user(0x80cd, (short *)(frame->retcode+6)); |
691 | 66fb9763 | bellard | } |
692 | 66fb9763 | bellard | |
693 | 66fb9763 | bellard | if (err)
|
694 | 66fb9763 | bellard | goto give_sigsegv;
|
695 | 66fb9763 | bellard | |
696 | 66fb9763 | bellard | /* Set up registers for signal handler */
|
697 | 66fb9763 | bellard | env->regs[R_ESP] = (unsigned long) frame; |
698 | 66fb9763 | bellard | env->eip = (unsigned long) ka->sa._sa_handler; |
699 | 66fb9763 | bellard | |
700 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_DS, __USER_DS); |
701 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_ES, __USER_DS); |
702 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_SS, __USER_DS); |
703 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_CS, __USER_CS); |
704 | 66fb9763 | bellard | env->eflags &= ~TF_MASK; |
705 | 66fb9763 | bellard | |
706 | 66fb9763 | bellard | return;
|
707 | 66fb9763 | bellard | |
708 | 66fb9763 | bellard | give_sigsegv:
|
709 | 66fb9763 | bellard | if (sig == TARGET_SIGSEGV)
|
710 | 66fb9763 | bellard | ka->sa._sa_handler = TARGET_SIG_DFL; |
711 | 66fb9763 | bellard | force_sig(TARGET_SIGSEGV /* , current */);
|
712 | 66fb9763 | bellard | } |
713 | 66fb9763 | bellard | |
714 | 9de5e440 | bellard | static void setup_rt_frame(int sig, struct emulated_sigaction *ka, |
715 | 9de5e440 | bellard | target_siginfo_t *info, |
716 | 66fb9763 | bellard | target_sigset_t *set, CPUX86State *env) |
717 | 66fb9763 | bellard | { |
718 | 66fb9763 | bellard | struct rt_sigframe *frame;
|
719 | 9231944d | bellard | int i, err = 0; |
720 | 66fb9763 | bellard | |
721 | 66fb9763 | bellard | frame = get_sigframe(ka, env, sizeof(*frame));
|
722 | 66fb9763 | bellard | |
723 | 66fb9763 | bellard | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
724 | 66fb9763 | bellard | goto give_sigsegv;
|
725 | 66fb9763 | bellard | |
726 | 66fb9763 | bellard | err |= __put_user((/*current->exec_domain
|
727 | 66fb9763 | bellard | && current->exec_domain->signal_invmap
|
728 | 66fb9763 | bellard | && sig < 32
|
729 | 66fb9763 | bellard | ? current->exec_domain->signal_invmap[sig]
|
730 | 66fb9763 | bellard | : */sig),
|
731 | 66fb9763 | bellard | &frame->sig); |
732 | 66fb9763 | bellard | err |= __put_user((target_ulong)&frame->info, &frame->pinfo); |
733 | 66fb9763 | bellard | err |= __put_user((target_ulong)&frame->uc, &frame->puc); |
734 | 66fb9763 | bellard | err |= copy_siginfo_to_user(&frame->info, info); |
735 | 66fb9763 | bellard | if (err)
|
736 | 66fb9763 | bellard | goto give_sigsegv;
|
737 | 31e31b8a | bellard | |
738 | 66fb9763 | bellard | /* Create the ucontext. */
|
739 | b8076a74 | bellard | err |= __put_user(0, &frame->uc.tuc_flags);
|
740 | b8076a74 | bellard | err |= __put_user(0, &frame->uc.tuc_link);
|
741 | b8076a74 | bellard | err |= __put_user(/*current->sas_ss_sp*/ 0, |
742 | b8076a74 | bellard | &frame->uc.tuc_stack.ss_sp); |
743 | 66fb9763 | bellard | err |= __put_user(/* sas_ss_flags(regs->esp) */ 0, |
744 | b8076a74 | bellard | &frame->uc.tuc_stack.ss_flags); |
745 | b8076a74 | bellard | err |= __put_user(/* current->sas_ss_size */ 0, |
746 | b8076a74 | bellard | &frame->uc.tuc_stack.ss_size); |
747 | b8076a74 | bellard | err |= setup_sigcontext(&frame->uc.tuc_mcontext, &frame->fpstate, |
748 | 66fb9763 | bellard | env, set->sig[0]);
|
749 | 9231944d | bellard | for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
750 | b8076a74 | bellard | if (__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]))
|
751 | 9231944d | bellard | goto give_sigsegv;
|
752 | 9231944d | bellard | } |
753 | 31e31b8a | bellard | |
754 | 66fb9763 | bellard | /* Set up to return from userspace. If provided, use a stub
|
755 | 66fb9763 | bellard | already in userspace. */
|
756 | 66fb9763 | bellard | if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
|
757 | 66fb9763 | bellard | err |= __put_user(ka->sa.sa_restorer, &frame->pretcode); |
758 | 66fb9763 | bellard | } else {
|
759 | 66fb9763 | bellard | err |= __put_user(frame->retcode, &frame->pretcode); |
760 | 66fb9763 | bellard | /* This is movl $,%eax ; int $0x80 */
|
761 | 66fb9763 | bellard | err |= __put_user(0xb8, (char *)(frame->retcode+0)); |
762 | 66fb9763 | bellard | err |= __put_user(TARGET_NR_rt_sigreturn, (int *)(frame->retcode+1)); |
763 | 66fb9763 | bellard | err |= __put_user(0x80cd, (short *)(frame->retcode+5)); |
764 | 66fb9763 | bellard | } |
765 | 66fb9763 | bellard | |
766 | 66fb9763 | bellard | if (err)
|
767 | 66fb9763 | bellard | goto give_sigsegv;
|
768 | 66fb9763 | bellard | |
769 | 66fb9763 | bellard | /* Set up registers for signal handler */
|
770 | 66fb9763 | bellard | env->regs[R_ESP] = (unsigned long) frame; |
771 | 66fb9763 | bellard | env->eip = (unsigned long) ka->sa._sa_handler; |
772 | 66fb9763 | bellard | |
773 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_DS, __USER_DS); |
774 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_ES, __USER_DS); |
775 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_SS, __USER_DS); |
776 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_CS, __USER_CS); |
777 | 66fb9763 | bellard | env->eflags &= ~TF_MASK; |
778 | 66fb9763 | bellard | |
779 | 66fb9763 | bellard | return;
|
780 | 66fb9763 | bellard | |
781 | 66fb9763 | bellard | give_sigsegv:
|
782 | 66fb9763 | bellard | if (sig == TARGET_SIGSEGV)
|
783 | 66fb9763 | bellard | ka->sa._sa_handler = TARGET_SIG_DFL; |
784 | 66fb9763 | bellard | force_sig(TARGET_SIGSEGV /* , current */);
|
785 | 66fb9763 | bellard | } |
786 | 66fb9763 | bellard | |
787 | 66fb9763 | bellard | static int |
788 | 66fb9763 | bellard | restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc, int *peax) |
789 | 66fb9763 | bellard | { |
790 | 66fb9763 | bellard | unsigned int err = 0; |
791 | 66fb9763 | bellard | |
792 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_GS, lduw(&sc->gs)); |
793 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_FS, lduw(&sc->fs)); |
794 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_ES, lduw(&sc->es)); |
795 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_DS, lduw(&sc->ds)); |
796 | 66fb9763 | bellard | |
797 | 66fb9763 | bellard | env->regs[R_EDI] = ldl(&sc->edi); |
798 | 66fb9763 | bellard | env->regs[R_ESI] = ldl(&sc->esi); |
799 | 66fb9763 | bellard | env->regs[R_EBP] = ldl(&sc->ebp); |
800 | 66fb9763 | bellard | env->regs[R_ESP] = ldl(&sc->esp); |
801 | 66fb9763 | bellard | env->regs[R_EBX] = ldl(&sc->ebx); |
802 | 66fb9763 | bellard | env->regs[R_EDX] = ldl(&sc->edx); |
803 | 66fb9763 | bellard | env->regs[R_ECX] = ldl(&sc->ecx); |
804 | 66fb9763 | bellard | env->eip = ldl(&sc->eip); |
805 | 66fb9763 | bellard | |
806 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_CS, lduw(&sc->cs) | 3);
|
807 | 66fb9763 | bellard | cpu_x86_load_seg(env, R_SS, lduw(&sc->ss) | 3);
|
808 | 66fb9763 | bellard | |
809 | 66fb9763 | bellard | { |
810 | 66fb9763 | bellard | unsigned int tmpflags; |
811 | 66fb9763 | bellard | tmpflags = ldl(&sc->eflags); |
812 | 66fb9763 | bellard | env->eflags = (env->eflags & ~0x40DD5) | (tmpflags & 0x40DD5); |
813 | 66fb9763 | bellard | // regs->orig_eax = -1; /* disable syscall checks */
|
814 | 66fb9763 | bellard | } |
815 | 66fb9763 | bellard | |
816 | 66fb9763 | bellard | { |
817 | 66fb9763 | bellard | struct _fpstate * buf;
|
818 | ed2dcdf6 | bellard | buf = (void *)ldl(&sc->fpstate);
|
819 | 66fb9763 | bellard | if (buf) {
|
820 | ed2dcdf6 | bellard | #if 0
|
821 | 66fb9763 | bellard | if (verify_area(VERIFY_READ, buf, sizeof(*buf)))
|
822 | 66fb9763 | bellard | goto badframe;
|
823 | ed2dcdf6 | bellard | #endif
|
824 | ed2dcdf6 | bellard | cpu_x86_frstor(env, (void *)buf, 1); |
825 | 66fb9763 | bellard | } |
826 | 66fb9763 | bellard | } |
827 | ed2dcdf6 | bellard | |
828 | 66fb9763 | bellard | *peax = ldl(&sc->eax); |
829 | 66fb9763 | bellard | return err;
|
830 | 66fb9763 | bellard | #if 0
|
831 | 66fb9763 | bellard | badframe:
|
832 | 66fb9763 | bellard | return 1;
|
833 | 66fb9763 | bellard | #endif
|
834 | 66fb9763 | bellard | } |
835 | 66fb9763 | bellard | |
836 | 66fb9763 | bellard | long do_sigreturn(CPUX86State *env)
|
837 | 66fb9763 | bellard | { |
838 | 66fb9763 | bellard | struct sigframe *frame = (struct sigframe *)(env->regs[R_ESP] - 8); |
839 | 66fb9763 | bellard | target_sigset_t target_set; |
840 | 66fb9763 | bellard | sigset_t set; |
841 | 66fb9763 | bellard | int eax, i;
|
842 | 66fb9763 | bellard | |
843 | 447db213 | bellard | #if defined(DEBUG_SIGNAL)
|
844 | 447db213 | bellard | fprintf(stderr, "do_sigreturn\n");
|
845 | 447db213 | bellard | #endif
|
846 | 66fb9763 | bellard | /* set blocked signals */
|
847 | 9231944d | bellard | if (__get_user(target_set.sig[0], &frame->sc.oldmask)) |
848 | 9231944d | bellard | goto badframe;
|
849 | 9231944d | bellard | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
850 | 9231944d | bellard | if (__get_user(target_set.sig[i], &frame->extramask[i - 1])) |
851 | 9231944d | bellard | goto badframe;
|
852 | 9231944d | bellard | } |
853 | 66fb9763 | bellard | |
854 | 9231944d | bellard | target_to_host_sigset_internal(&set, &target_set); |
855 | 66fb9763 | bellard | sigprocmask(SIG_SETMASK, &set, NULL);
|
856 | 66fb9763 | bellard | |
857 | 66fb9763 | bellard | /* restore registers */
|
858 | 66fb9763 | bellard | if (restore_sigcontext(env, &frame->sc, &eax))
|
859 | 66fb9763 | bellard | goto badframe;
|
860 | 66fb9763 | bellard | return eax;
|
861 | 66fb9763 | bellard | |
862 | 66fb9763 | bellard | badframe:
|
863 | 66fb9763 | bellard | force_sig(TARGET_SIGSEGV); |
864 | 66fb9763 | bellard | return 0; |
865 | 66fb9763 | bellard | } |
866 | 66fb9763 | bellard | |
867 | 66fb9763 | bellard | long do_rt_sigreturn(CPUX86State *env)
|
868 | 66fb9763 | bellard | { |
869 | 66fb9763 | bellard | struct rt_sigframe *frame = (struct rt_sigframe *)(env->regs[R_ESP] - 4); |
870 | 66fb9763 | bellard | sigset_t set; |
871 | 66fb9763 | bellard | // stack_t st;
|
872 | 66fb9763 | bellard | int eax;
|
873 | 66fb9763 | bellard | |
874 | 66fb9763 | bellard | #if 0
|
875 | 66fb9763 | bellard | if (verify_area(VERIFY_READ, frame, sizeof(*frame)))
|
876 | 66fb9763 | bellard | goto badframe;
|
877 | 66fb9763 | bellard | #endif
|
878 | b8076a74 | bellard | target_to_host_sigset(&set, &frame->uc.tuc_sigmask); |
879 | 66fb9763 | bellard | sigprocmask(SIG_SETMASK, &set, NULL);
|
880 | 66fb9763 | bellard | |
881 | b8076a74 | bellard | if (restore_sigcontext(env, &frame->uc.tuc_mcontext, &eax))
|
882 | 66fb9763 | bellard | goto badframe;
|
883 | 66fb9763 | bellard | |
884 | 66fb9763 | bellard | #if 0
|
885 | b8076a74 | bellard | if (__copy_from_user(&st, &frame->uc.tuc_stack, sizeof(st)))
|
886 | 66fb9763 | bellard | goto badframe;
|
887 | 66fb9763 | bellard | /* It is more difficult to avoid calling this function than to
|
888 | 66fb9763 | bellard | call it and ignore errors. */
|
889 | 66fb9763 | bellard | do_sigaltstack(&st, NULL, regs->esp);
|
890 | 66fb9763 | bellard | #endif
|
891 | 66fb9763 | bellard | return eax;
|
892 | 66fb9763 | bellard | |
893 | 66fb9763 | bellard | badframe:
|
894 | 66fb9763 | bellard | force_sig(TARGET_SIGSEGV); |
895 | 66fb9763 | bellard | return 0; |
896 | 66fb9763 | bellard | } |
897 | 66fb9763 | bellard | |
898 | 43fff238 | bellard | #elif defined(TARGET_ARM)
|
899 | 43fff238 | bellard | |
900 | 43fff238 | bellard | struct target_sigcontext {
|
901 | 43fff238 | bellard | target_ulong trap_no; |
902 | 43fff238 | bellard | target_ulong error_code; |
903 | 43fff238 | bellard | target_ulong oldmask; |
904 | 43fff238 | bellard | target_ulong arm_r0; |
905 | 43fff238 | bellard | target_ulong arm_r1; |
906 | 43fff238 | bellard | target_ulong arm_r2; |
907 | 43fff238 | bellard | target_ulong arm_r3; |
908 | 43fff238 | bellard | target_ulong arm_r4; |
909 | 43fff238 | bellard | target_ulong arm_r5; |
910 | 43fff238 | bellard | target_ulong arm_r6; |
911 | 43fff238 | bellard | target_ulong arm_r7; |
912 | 43fff238 | bellard | target_ulong arm_r8; |
913 | 43fff238 | bellard | target_ulong arm_r9; |
914 | 43fff238 | bellard | target_ulong arm_r10; |
915 | 43fff238 | bellard | target_ulong arm_fp; |
916 | 43fff238 | bellard | target_ulong arm_ip; |
917 | 43fff238 | bellard | target_ulong arm_sp; |
918 | 43fff238 | bellard | target_ulong arm_lr; |
919 | 43fff238 | bellard | target_ulong arm_pc; |
920 | 43fff238 | bellard | target_ulong arm_cpsr; |
921 | 43fff238 | bellard | target_ulong fault_address; |
922 | 43fff238 | bellard | }; |
923 | 43fff238 | bellard | |
924 | 43fff238 | bellard | typedef struct target_sigaltstack { |
925 | 43fff238 | bellard | target_ulong ss_sp; |
926 | 43fff238 | bellard | int ss_flags;
|
927 | 43fff238 | bellard | target_ulong ss_size; |
928 | 43fff238 | bellard | } target_stack_t; |
929 | 43fff238 | bellard | |
930 | 43fff238 | bellard | struct target_ucontext {
|
931 | b8076a74 | bellard | target_ulong tuc_flags; |
932 | b8076a74 | bellard | target_ulong tuc_link; |
933 | b8076a74 | bellard | target_stack_t tuc_stack; |
934 | b8076a74 | bellard | struct target_sigcontext tuc_mcontext;
|
935 | b8076a74 | bellard | target_sigset_t tuc_sigmask; /* mask last for extensibility */
|
936 | 43fff238 | bellard | }; |
937 | 43fff238 | bellard | |
938 | 43fff238 | bellard | struct sigframe
|
939 | 43fff238 | bellard | { |
940 | 43fff238 | bellard | struct target_sigcontext sc;
|
941 | 43fff238 | bellard | target_ulong extramask[TARGET_NSIG_WORDS-1];
|
942 | 43fff238 | bellard | target_ulong retcode; |
943 | 43fff238 | bellard | }; |
944 | 43fff238 | bellard | |
945 | 43fff238 | bellard | struct rt_sigframe
|
946 | 43fff238 | bellard | { |
947 | 43fff238 | bellard | struct target_siginfo *pinfo;
|
948 | 43fff238 | bellard | void *puc;
|
949 | 43fff238 | bellard | struct target_siginfo info;
|
950 | 43fff238 | bellard | struct target_ucontext uc;
|
951 | 43fff238 | bellard | target_ulong retcode; |
952 | 43fff238 | bellard | }; |
953 | 43fff238 | bellard | |
954 | 43fff238 | bellard | #define TARGET_CONFIG_CPU_32 1 |
955 | 43fff238 | bellard | |
956 | 43fff238 | bellard | /*
|
957 | 43fff238 | bellard | * For ARM syscalls, we encode the syscall number into the instruction.
|
958 | 43fff238 | bellard | */
|
959 | 43fff238 | bellard | #define SWI_SYS_SIGRETURN (0xef000000|(TARGET_NR_sigreturn + ARM_SYSCALL_BASE)) |
960 | 43fff238 | bellard | #define SWI_SYS_RT_SIGRETURN (0xef000000|(TARGET_NR_rt_sigreturn + ARM_SYSCALL_BASE)) |
961 | 43fff238 | bellard | |
962 | 43fff238 | bellard | /*
|
963 | 43fff238 | bellard | * For Thumb syscalls, we pass the syscall number via r7. We therefore
|
964 | 43fff238 | bellard | * need two 16-bit instructions.
|
965 | 43fff238 | bellard | */
|
966 | 43fff238 | bellard | #define SWI_THUMB_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_sigreturn)) |
967 | 43fff238 | bellard | #define SWI_THUMB_RT_SIGRETURN (0xdf00 << 16 | 0x2700 | (TARGET_NR_rt_sigreturn)) |
968 | 43fff238 | bellard | |
969 | 43fff238 | bellard | static const target_ulong retcodes[4] = { |
970 | 43fff238 | bellard | SWI_SYS_SIGRETURN, SWI_THUMB_SIGRETURN, |
971 | 43fff238 | bellard | SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN |
972 | 43fff238 | bellard | }; |
973 | 43fff238 | bellard | |
974 | 43fff238 | bellard | |
975 | 43fff238 | bellard | #define __put_user_error(x,p,e) __put_user(x, p)
|
976 | 43fff238 | bellard | #define __get_user_error(x,p,e) __get_user(x, p)
|
977 | 43fff238 | bellard | |
978 | 43fff238 | bellard | static inline int valid_user_regs(CPUState *regs) |
979 | 43fff238 | bellard | { |
980 | 43fff238 | bellard | return 1; |
981 | 43fff238 | bellard | } |
982 | 43fff238 | bellard | |
983 | 43fff238 | bellard | static int |
984 | 43fff238 | bellard | setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/ |
985 | 43fff238 | bellard | CPUState *env, unsigned long mask) |
986 | 43fff238 | bellard | { |
987 | 43fff238 | bellard | int err = 0; |
988 | 43fff238 | bellard | |
989 | 43fff238 | bellard | __put_user_error(env->regs[0], &sc->arm_r0, err);
|
990 | 43fff238 | bellard | __put_user_error(env->regs[1], &sc->arm_r1, err);
|
991 | 43fff238 | bellard | __put_user_error(env->regs[2], &sc->arm_r2, err);
|
992 | 43fff238 | bellard | __put_user_error(env->regs[3], &sc->arm_r3, err);
|
993 | 43fff238 | bellard | __put_user_error(env->regs[4], &sc->arm_r4, err);
|
994 | 43fff238 | bellard | __put_user_error(env->regs[5], &sc->arm_r5, err);
|
995 | 43fff238 | bellard | __put_user_error(env->regs[6], &sc->arm_r6, err);
|
996 | 43fff238 | bellard | __put_user_error(env->regs[7], &sc->arm_r7, err);
|
997 | 43fff238 | bellard | __put_user_error(env->regs[8], &sc->arm_r8, err);
|
998 | 43fff238 | bellard | __put_user_error(env->regs[9], &sc->arm_r9, err);
|
999 | 43fff238 | bellard | __put_user_error(env->regs[10], &sc->arm_r10, err);
|
1000 | 43fff238 | bellard | __put_user_error(env->regs[11], &sc->arm_fp, err);
|
1001 | 43fff238 | bellard | __put_user_error(env->regs[12], &sc->arm_ip, err);
|
1002 | 43fff238 | bellard | __put_user_error(env->regs[13], &sc->arm_sp, err);
|
1003 | 43fff238 | bellard | __put_user_error(env->regs[14], &sc->arm_lr, err);
|
1004 | 43fff238 | bellard | __put_user_error(env->regs[15], &sc->arm_pc, err);
|
1005 | 43fff238 | bellard | #ifdef TARGET_CONFIG_CPU_32
|
1006 | b5ff1b31 | bellard | __put_user_error(cpsr_read(env), &sc->arm_cpsr, err); |
1007 | 43fff238 | bellard | #endif
|
1008 | 43fff238 | bellard | |
1009 | 43fff238 | bellard | __put_user_error(/* current->thread.trap_no */ 0, &sc->trap_no, err); |
1010 | 43fff238 | bellard | __put_user_error(/* current->thread.error_code */ 0, &sc->error_code, err); |
1011 | 43fff238 | bellard | __put_user_error(/* current->thread.address */ 0, &sc->fault_address, err); |
1012 | 43fff238 | bellard | __put_user_error(mask, &sc->oldmask, err); |
1013 | 43fff238 | bellard | |
1014 | 43fff238 | bellard | return err;
|
1015 | 43fff238 | bellard | } |
1016 | 43fff238 | bellard | |
1017 | 43fff238 | bellard | static inline void * |
1018 | 43fff238 | bellard | get_sigframe(struct emulated_sigaction *ka, CPUState *regs, int framesize) |
1019 | 43fff238 | bellard | { |
1020 | 43fff238 | bellard | unsigned long sp = regs->regs[13]; |
1021 | 43fff238 | bellard | |
1022 | 43fff238 | bellard | #if 0
|
1023 | 43fff238 | bellard | /*
|
1024 | 43fff238 | bellard | * This is the X/Open sanctioned signal stack switching.
|
1025 | 43fff238 | bellard | */
|
1026 | 43fff238 | bellard | if ((ka->sa.sa_flags & SA_ONSTACK) && !sas_ss_flags(sp))
|
1027 | 43fff238 | bellard | sp = current->sas_ss_sp + current->sas_ss_size;
|
1028 | 43fff238 | bellard | #endif
|
1029 | 43fff238 | bellard | /*
|
1030 | 43fff238 | bellard | * ATPCS B01 mandates 8-byte alignment
|
1031 | 43fff238 | bellard | */
|
1032 | 43fff238 | bellard | return (void *)((sp - framesize) & ~7); |
1033 | 43fff238 | bellard | } |
1034 | 43fff238 | bellard | |
1035 | 43fff238 | bellard | static int |
1036 | 43fff238 | bellard | setup_return(CPUState *env, struct emulated_sigaction *ka,
|
1037 | 43fff238 | bellard | target_ulong *rc, void *frame, int usig) |
1038 | 43fff238 | bellard | { |
1039 | 43fff238 | bellard | target_ulong handler = (target_ulong)ka->sa._sa_handler; |
1040 | 43fff238 | bellard | target_ulong retcode; |
1041 | 43fff238 | bellard | int thumb = 0; |
1042 | 43fff238 | bellard | #if defined(TARGET_CONFIG_CPU_32)
|
1043 | b5ff1b31 | bellard | #if 0
|
1044 | 43fff238 | bellard | target_ulong cpsr = env->cpsr;
|
1045 | 43fff238 | bellard | |
1046 | 43fff238 | bellard | /*
|
1047 | 43fff238 | bellard | * Maybe we need to deliver a 32-bit signal to a 26-bit task.
|
1048 | 43fff238 | bellard | */
|
1049 | 43fff238 | bellard | if (ka->sa.sa_flags & SA_THIRTYTWO)
|
1050 | 43fff238 | bellard | cpsr = (cpsr & ~MODE_MASK) | USR_MODE;
|
1051 | 43fff238 | bellard | |
1052 | 43fff238 | bellard | #ifdef CONFIG_ARM_THUMB
|
1053 | 43fff238 | bellard | if (elf_hwcap & HWCAP_THUMB) {
|
1054 | 43fff238 | bellard | /*
|
1055 | 43fff238 | bellard | * The LSB of the handler determines if we're going to
|
1056 | 43fff238 | bellard | * be using THUMB or ARM mode for this signal handler.
|
1057 | 43fff238 | bellard | */
|
1058 | 43fff238 | bellard | thumb = handler & 1;
|
1059 | 43fff238 | bellard | |
1060 | 43fff238 | bellard | if (thumb)
|
1061 | 43fff238 | bellard | cpsr |= T_BIT;
|
1062 | 43fff238 | bellard | else
|
1063 | 43fff238 | bellard | cpsr &= ~T_BIT;
|
1064 | 43fff238 | bellard | }
|
1065 | 43fff238 | bellard | #endif
|
1066 | 43fff238 | bellard | #endif
|
1067 | 43fff238 | bellard | #endif /* TARGET_CONFIG_CPU_32 */ |
1068 | 43fff238 | bellard | |
1069 | 43fff238 | bellard | if (ka->sa.sa_flags & TARGET_SA_RESTORER) {
|
1070 | 43fff238 | bellard | retcode = (target_ulong)ka->sa.sa_restorer; |
1071 | 43fff238 | bellard | } else {
|
1072 | 43fff238 | bellard | unsigned int idx = thumb; |
1073 | 43fff238 | bellard | |
1074 | 43fff238 | bellard | if (ka->sa.sa_flags & TARGET_SA_SIGINFO)
|
1075 | 43fff238 | bellard | idx += 2;
|
1076 | 43fff238 | bellard | |
1077 | 43fff238 | bellard | if (__put_user(retcodes[idx], rc))
|
1078 | 43fff238 | bellard | return 1; |
1079 | 43fff238 | bellard | #if 0
|
1080 | 43fff238 | bellard | flush_icache_range((target_ulong)rc,
|
1081 | 43fff238 | bellard | (target_ulong)(rc + 1));
|
1082 | 43fff238 | bellard | #endif
|
1083 | 43fff238 | bellard | retcode = ((target_ulong)rc) + thumb; |
1084 | 43fff238 | bellard | } |
1085 | 43fff238 | bellard | |
1086 | 43fff238 | bellard | env->regs[0] = usig;
|
1087 | 43fff238 | bellard | env->regs[13] = (target_ulong)frame;
|
1088 | 43fff238 | bellard | env->regs[14] = retcode;
|
1089 | 43fff238 | bellard | env->regs[15] = handler & (thumb ? ~1 : ~3); |
1090 | 43fff238 | bellard | |
1091 | b5ff1b31 | bellard | #if 0
|
1092 | 43fff238 | bellard | #ifdef TARGET_CONFIG_CPU_32
|
1093 | 43fff238 | bellard | env->cpsr = cpsr;
|
1094 | 43fff238 | bellard | #endif
|
1095 | b5ff1b31 | bellard | #endif
|
1096 | 43fff238 | bellard | |
1097 | 43fff238 | bellard | return 0; |
1098 | 43fff238 | bellard | } |
1099 | 43fff238 | bellard | |
1100 | 43fff238 | bellard | static void setup_frame(int usig, struct emulated_sigaction *ka, |
1101 | 43fff238 | bellard | target_sigset_t *set, CPUState *regs) |
1102 | 43fff238 | bellard | { |
1103 | 43fff238 | bellard | struct sigframe *frame = get_sigframe(ka, regs, sizeof(*frame)); |
1104 | 9231944d | bellard | int i, err = 0; |
1105 | 43fff238 | bellard | |
1106 | 43fff238 | bellard | err |= setup_sigcontext(&frame->sc, /*&frame->fpstate,*/ regs, set->sig[0]); |
1107 | 43fff238 | bellard | |
1108 | 9231944d | bellard | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
1109 | 9231944d | bellard | if (__put_user(set->sig[i], &frame->extramask[i - 1])) |
1110 | 9231944d | bellard | return;
|
1111 | 43fff238 | bellard | } |
1112 | 43fff238 | bellard | |
1113 | 43fff238 | bellard | if (err == 0) |
1114 | 43fff238 | bellard | err = setup_return(regs, ka, &frame->retcode, frame, usig); |
1115 | 43fff238 | bellard | // return err;
|
1116 | 43fff238 | bellard | } |
1117 | 43fff238 | bellard | |
1118 | 43fff238 | bellard | static void setup_rt_frame(int usig, struct emulated_sigaction *ka, |
1119 | 43fff238 | bellard | target_siginfo_t *info, |
1120 | 43fff238 | bellard | target_sigset_t *set, CPUState *env) |
1121 | 43fff238 | bellard | { |
1122 | 43fff238 | bellard | struct rt_sigframe *frame = get_sigframe(ka, env, sizeof(*frame)); |
1123 | 9231944d | bellard | int i, err = 0; |
1124 | 43fff238 | bellard | |
1125 | 43fff238 | bellard | if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame))) |
1126 | edf779ff | bellard | return /* 1 */; |
1127 | edf779ff | bellard | |
1128 | 43fff238 | bellard | __put_user_error(&frame->info, (target_ulong *)&frame->pinfo, err); |
1129 | 43fff238 | bellard | __put_user_error(&frame->uc, (target_ulong *)&frame->puc, err); |
1130 | 43fff238 | bellard | err |= copy_siginfo_to_user(&frame->info, info); |
1131 | 43fff238 | bellard | |
1132 | 43fff238 | bellard | /* Clear all the bits of the ucontext we don't use. */
|
1133 | 43fff238 | bellard | err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));
|
1134 | 43fff238 | bellard | |
1135 | b8076a74 | bellard | err |= setup_sigcontext(&frame->uc.tuc_mcontext, /*&frame->fpstate,*/
|
1136 | 43fff238 | bellard | env, set->sig[0]);
|
1137 | 9231944d | bellard | for(i = 0; i < TARGET_NSIG_WORDS; i++) { |
1138 | b8076a74 | bellard | if (__put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]))
|
1139 | 9231944d | bellard | return;
|
1140 | 9231944d | bellard | } |
1141 | 43fff238 | bellard | |
1142 | 43fff238 | bellard | if (err == 0) |
1143 | 43fff238 | bellard | err = setup_return(env, ka, &frame->retcode, frame, usig); |
1144 | 43fff238 | bellard | |
1145 | 43fff238 | bellard | if (err == 0) { |
1146 | 43fff238 | bellard | /*
|
1147 | 43fff238 | bellard | * For realtime signals we must also set the second and third
|
1148 | 43fff238 | bellard | * arguments for the signal handler.
|
1149 | 43fff238 | bellard | * -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
|
1150 | 43fff238 | bellard | */
|
1151 | 43fff238 | bellard | env->regs[1] = (target_ulong)frame->pinfo;
|
1152 | 43fff238 | bellard | env->regs[2] = (target_ulong)frame->puc;
|
1153 | 43fff238 | bellard | } |
1154 | 43fff238 | bellard | |
1155 | 43fff238 | bellard | // return err;
|
1156 | 43fff238 | bellard | } |
1157 | 43fff238 | bellard | |
1158 | 43fff238 | bellard | static int |
1159 | 43fff238 | bellard | restore_sigcontext(CPUState *env, struct target_sigcontext *sc)
|
1160 | 43fff238 | bellard | { |
1161 | 43fff238 | bellard | int err = 0; |
1162 | b5ff1b31 | bellard | uint32_t cpsr; |
1163 | 43fff238 | bellard | |
1164 | 43fff238 | bellard | __get_user_error(env->regs[0], &sc->arm_r0, err);
|
1165 | 43fff238 | bellard | __get_user_error(env->regs[1], &sc->arm_r1, err);
|
1166 | 43fff238 | bellard | __get_user_error(env->regs[2], &sc->arm_r2, err);
|
1167 | 43fff238 | bellard | __get_user_error(env->regs[3], &sc->arm_r3, err);
|
1168 | 43fff238 | bellard | __get_user_error(env->regs[4], &sc->arm_r4, err);
|
1169 | 43fff238 | bellard | __get_user_error(env->regs[5], &sc->arm_r5, err);
|
1170 | 43fff238 | bellard | __get_user_error(env->regs[6], &sc->arm_r6, err);
|
1171 | 43fff238 | bellard | __get_user_error(env->regs[7], &sc->arm_r7, err);
|
1172 | 43fff238 | bellard | __get_user_error(env->regs[8], &sc->arm_r8, err);
|
1173 | 43fff238 | bellard | __get_user_error(env->regs[9], &sc->arm_r9, err);
|
1174 | 43fff238 | bellard | __get_user_error(env->regs[10], &sc->arm_r10, err);
|
1175 | 43fff238 | bellard | __get_user_error(env->regs[11], &sc->arm_fp, err);
|
1176 | 43fff238 | bellard | __get_user_error(env->regs[12], &sc->arm_ip, err);
|
1177 | 43fff238 | bellard | __get_user_error(env->regs[13], &sc->arm_sp, err);
|
1178 | 43fff238 | bellard | __get_user_error(env->regs[14], &sc->arm_lr, err);
|
1179 | 43fff238 | bellard | __get_user_error(env->regs[15], &sc->arm_pc, err);
|
1180 | 43fff238 | bellard | #ifdef TARGET_CONFIG_CPU_32
|
1181 | b5ff1b31 | bellard | __get_user_error(cpsr, &sc->arm_cpsr, err); |
1182 | b5ff1b31 | bellard | cpsr_write(env, cpsr, 0xffffffff);
|
1183 | 43fff238 | bellard | #endif
|
1184 | 43fff238 | bellard | |
1185 | 43fff238 | bellard | err |= !valid_user_regs(env); |
1186 | 43fff238 | bellard | |
1187 | 43fff238 | bellard | return err;
|
1188 | 43fff238 | bellard | } |
1189 | 43fff238 | bellard | |
1190 | 43fff238 | bellard | long do_sigreturn(CPUState *env)
|
1191 | 43fff238 | bellard | { |
1192 | 43fff238 | bellard | struct sigframe *frame;
|
1193 | 43fff238 | bellard | target_sigset_t set; |
1194 | 43fff238 | bellard | sigset_t host_set; |
1195 | 9231944d | bellard | int i;
|
1196 | 43fff238 | bellard | |
1197 | 43fff238 | bellard | /*
|
1198 | 43fff238 | bellard | * Since we stacked the signal on a 64-bit boundary,
|
1199 | 43fff238 | bellard | * then 'sp' should be word aligned here. If it's
|
1200 | 43fff238 | bellard | * not, then the user is trying to mess with us.
|
1201 | 43fff238 | bellard | */
|
1202 | 43fff238 | bellard | if (env->regs[13] & 7) |
1203 | 43fff238 | bellard | goto badframe;
|
1204 | 43fff238 | bellard | |
1205 | 43fff238 | bellard | frame = (struct sigframe *)env->regs[13]; |
1206 | 43fff238 | bellard | |
1207 | 43fff238 | bellard | #if 0
|
1208 | 43fff238 | bellard | if (verify_area(VERIFY_READ, frame, sizeof (*frame)))
|
1209 | 43fff238 | bellard | goto badframe;
|
1210 | 43fff238 | bellard | #endif
|
1211 | 9231944d | bellard | if (__get_user(set.sig[0], &frame->sc.oldmask)) |
1212 | 9231944d | bellard | goto badframe;
|
1213 | 9231944d | bellard | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
1214 | 9231944d | bellard | if (__get_user(set.sig[i], &frame->extramask[i - 1])) |
1215 | 9231944d | bellard | goto badframe;
|
1216 | 9231944d | bellard | } |
1217 | 43fff238 | bellard | |
1218 | 9231944d | bellard | target_to_host_sigset_internal(&host_set, &set); |
1219 | 43fff238 | bellard | sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1220 | 43fff238 | bellard | |
1221 | 43fff238 | bellard | if (restore_sigcontext(env, &frame->sc))
|
1222 | 43fff238 | bellard | goto badframe;
|
1223 | 43fff238 | bellard | |
1224 | 43fff238 | bellard | #if 0
|
1225 | 43fff238 | bellard | /* Send SIGTRAP if we're single-stepping */
|
1226 | 43fff238 | bellard | if (ptrace_cancel_bpt(current))
|
1227 | 43fff238 | bellard | send_sig(SIGTRAP, current, 1);
|
1228 | 43fff238 | bellard | #endif
|
1229 | 43fff238 | bellard | return env->regs[0]; |
1230 | 43fff238 | bellard | |
1231 | 43fff238 | bellard | badframe:
|
1232 | 43fff238 | bellard | force_sig(SIGSEGV /* , current */);
|
1233 | 43fff238 | bellard | return 0; |
1234 | 43fff238 | bellard | } |
1235 | 43fff238 | bellard | |
1236 | 43fff238 | bellard | long do_rt_sigreturn(CPUState *env)
|
1237 | 43fff238 | bellard | { |
1238 | 43fff238 | bellard | struct rt_sigframe *frame;
|
1239 | 43fff238 | bellard | sigset_t host_set; |
1240 | 43fff238 | bellard | |
1241 | 43fff238 | bellard | /*
|
1242 | 43fff238 | bellard | * Since we stacked the signal on a 64-bit boundary,
|
1243 | 43fff238 | bellard | * then 'sp' should be word aligned here. If it's
|
1244 | 43fff238 | bellard | * not, then the user is trying to mess with us.
|
1245 | 43fff238 | bellard | */
|
1246 | 43fff238 | bellard | if (env->regs[13] & 7) |
1247 | 43fff238 | bellard | goto badframe;
|
1248 | 43fff238 | bellard | |
1249 | 43fff238 | bellard | frame = (struct rt_sigframe *)env->regs[13]; |
1250 | 43fff238 | bellard | |
1251 | 43fff238 | bellard | #if 0
|
1252 | 43fff238 | bellard | if (verify_area(VERIFY_READ, frame, sizeof (*frame)))
|
1253 | 43fff238 | bellard | goto badframe;
|
1254 | 43fff238 | bellard | #endif
|
1255 | b8076a74 | bellard | target_to_host_sigset(&host_set, &frame->uc.tuc_sigmask); |
1256 | 43fff238 | bellard | sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1257 | 43fff238 | bellard | |
1258 | b8076a74 | bellard | if (restore_sigcontext(env, &frame->uc.tuc_mcontext))
|
1259 | 43fff238 | bellard | goto badframe;
|
1260 | 43fff238 | bellard | |
1261 | 43fff238 | bellard | #if 0
|
1262 | 43fff238 | bellard | /* Send SIGTRAP if we're single-stepping */
|
1263 | 43fff238 | bellard | if (ptrace_cancel_bpt(current))
|
1264 | 43fff238 | bellard | send_sig(SIGTRAP, current, 1);
|
1265 | 43fff238 | bellard | #endif
|
1266 | 43fff238 | bellard | return env->regs[0]; |
1267 | 43fff238 | bellard | |
1268 | 43fff238 | bellard | badframe:
|
1269 | 43fff238 | bellard | force_sig(SIGSEGV /* , current */);
|
1270 | 43fff238 | bellard | return 0; |
1271 | 43fff238 | bellard | } |
1272 | 43fff238 | bellard | |
1273 | 6d5e216d | bellard | #elif defined(TARGET_SPARC)
|
1274 | 80a9d035 | bellard | |
1275 | 6d5e216d | bellard | #define __SUNOS_MAXWIN 31 |
1276 | 6d5e216d | bellard | |
1277 | 6d5e216d | bellard | /* This is what SunOS does, so shall I. */
|
1278 | 6d5e216d | bellard | struct target_sigcontext {
|
1279 | 6d5e216d | bellard | target_ulong sigc_onstack; /* state to restore */
|
1280 | 6d5e216d | bellard | |
1281 | 6d5e216d | bellard | target_ulong sigc_mask; /* sigmask to restore */
|
1282 | 6d5e216d | bellard | target_ulong sigc_sp; /* stack pointer */
|
1283 | 6d5e216d | bellard | target_ulong sigc_pc; /* program counter */
|
1284 | 6d5e216d | bellard | target_ulong sigc_npc; /* next program counter */
|
1285 | 6d5e216d | bellard | target_ulong sigc_psr; /* for condition codes etc */
|
1286 | 6d5e216d | bellard | target_ulong sigc_g1; /* User uses these two registers */
|
1287 | 6d5e216d | bellard | target_ulong sigc_o0; /* within the trampoline code. */
|
1288 | 6d5e216d | bellard | |
1289 | 6d5e216d | bellard | /* Now comes information regarding the users window set
|
1290 | 6d5e216d | bellard | * at the time of the signal.
|
1291 | 6d5e216d | bellard | */
|
1292 | 6d5e216d | bellard | target_ulong sigc_oswins; /* outstanding windows */
|
1293 | 6d5e216d | bellard | |
1294 | 6d5e216d | bellard | /* stack ptrs for each regwin buf */
|
1295 | 6d5e216d | bellard | char *sigc_spbuf[__SUNOS_MAXWIN];
|
1296 | 6d5e216d | bellard | |
1297 | 6d5e216d | bellard | /* Windows to restore after signal */
|
1298 | 6d5e216d | bellard | struct {
|
1299 | 6d5e216d | bellard | target_ulong locals[8];
|
1300 | 6d5e216d | bellard | target_ulong ins[8];
|
1301 | 6d5e216d | bellard | } sigc_wbuf[__SUNOS_MAXWIN]; |
1302 | 6d5e216d | bellard | }; |
1303 | 6d5e216d | bellard | /* A Sparc stack frame */
|
1304 | 6d5e216d | bellard | struct sparc_stackf {
|
1305 | 6d5e216d | bellard | target_ulong locals[8];
|
1306 | 6d5e216d | bellard | target_ulong ins[6];
|
1307 | 6d5e216d | bellard | struct sparc_stackf *fp;
|
1308 | 6d5e216d | bellard | target_ulong callers_pc; |
1309 | 6d5e216d | bellard | char *structptr;
|
1310 | 6d5e216d | bellard | target_ulong xargs[6];
|
1311 | 6d5e216d | bellard | target_ulong xxargs[1];
|
1312 | 6d5e216d | bellard | }; |
1313 | 6d5e216d | bellard | |
1314 | 6d5e216d | bellard | typedef struct { |
1315 | 6d5e216d | bellard | struct {
|
1316 | 6d5e216d | bellard | target_ulong psr; |
1317 | 6d5e216d | bellard | target_ulong pc; |
1318 | 6d5e216d | bellard | target_ulong npc; |
1319 | 6d5e216d | bellard | target_ulong y; |
1320 | 6d5e216d | bellard | target_ulong u_regs[16]; /* globals and ins */ |
1321 | 6d5e216d | bellard | } si_regs; |
1322 | 6d5e216d | bellard | int si_mask;
|
1323 | 6d5e216d | bellard | } __siginfo_t; |
1324 | 6d5e216d | bellard | |
1325 | 6d5e216d | bellard | typedef struct { |
1326 | 6d5e216d | bellard | unsigned long si_float_regs [32]; |
1327 | 6d5e216d | bellard | unsigned long si_fsr; |
1328 | 6d5e216d | bellard | unsigned long si_fpqdepth; |
1329 | 6d5e216d | bellard | struct {
|
1330 | 6d5e216d | bellard | unsigned long *insn_addr; |
1331 | 6d5e216d | bellard | unsigned long insn; |
1332 | 6d5e216d | bellard | } si_fpqueue [16];
|
1333 | 6d5e216d | bellard | } __siginfo_fpu_t; |
1334 | 6d5e216d | bellard | |
1335 | 6d5e216d | bellard | |
1336 | 6d5e216d | bellard | struct target_signal_frame {
|
1337 | 6d5e216d | bellard | struct sparc_stackf ss;
|
1338 | 6d5e216d | bellard | __siginfo_t info; |
1339 | 6d5e216d | bellard | __siginfo_fpu_t *fpu_save; |
1340 | 6d5e216d | bellard | target_ulong insns[2] __attribute__ ((aligned (8))); |
1341 | 6d5e216d | bellard | target_ulong extramask[TARGET_NSIG_WORDS - 1];
|
1342 | 6d5e216d | bellard | target_ulong extra_size; /* Should be 0 */
|
1343 | 6d5e216d | bellard | __siginfo_fpu_t fpu_state; |
1344 | 6d5e216d | bellard | }; |
1345 | 6d5e216d | bellard | struct target_rt_signal_frame {
|
1346 | 6d5e216d | bellard | struct sparc_stackf ss;
|
1347 | 6d5e216d | bellard | siginfo_t info; |
1348 | 6d5e216d | bellard | target_ulong regs[20];
|
1349 | 6d5e216d | bellard | sigset_t mask; |
1350 | 6d5e216d | bellard | __siginfo_fpu_t *fpu_save; |
1351 | 6d5e216d | bellard | unsigned int insns[2]; |
1352 | 6d5e216d | bellard | stack_t stack; |
1353 | 6d5e216d | bellard | unsigned int extra_size; /* Should be 0 */ |
1354 | 6d5e216d | bellard | __siginfo_fpu_t fpu_state; |
1355 | 6d5e216d | bellard | }; |
1356 | 6d5e216d | bellard | |
1357 | e80cfcfc | bellard | #define UREG_O0 16 |
1358 | e80cfcfc | bellard | #define UREG_O6 22 |
1359 | e80cfcfc | bellard | #define UREG_I0 0 |
1360 | e80cfcfc | bellard | #define UREG_I1 1 |
1361 | e80cfcfc | bellard | #define UREG_I2 2 |
1362 | e80cfcfc | bellard | #define UREG_I6 6 |
1363 | e80cfcfc | bellard | #define UREG_I7 7 |
1364 | e80cfcfc | bellard | #define UREG_L0 8 |
1365 | 6d5e216d | bellard | #define UREG_FP UREG_I6
|
1366 | 6d5e216d | bellard | #define UREG_SP UREG_O6
|
1367 | 6d5e216d | bellard | |
1368 | 6d5e216d | bellard | static inline void *get_sigframe(struct emulated_sigaction *sa, CPUState *env, unsigned long framesize) |
1369 | 6d5e216d | bellard | { |
1370 | 6d5e216d | bellard | unsigned long sp; |
1371 | 6d5e216d | bellard | |
1372 | 6d5e216d | bellard | sp = env->regwptr[UREG_FP]; |
1373 | 6d5e216d | bellard | #if 0
|
1374 | 6d5e216d | bellard | |
1375 | 6d5e216d | bellard | /* This is the X/Open sanctioned signal stack switching. */
|
1376 | 6d5e216d | bellard | if (sa->sa_flags & TARGET_SA_ONSTACK) {
|
1377 | 6d5e216d | bellard | if (!on_sig_stack(sp) && !((current->sas_ss_sp + current->sas_ss_size) & 7))
|
1378 | 6d5e216d | bellard | sp = current->sas_ss_sp + current->sas_ss_size;
|
1379 | 6d5e216d | bellard | }
|
1380 | 6d5e216d | bellard | #endif
|
1381 | 6d5e216d | bellard | return (void *)(sp - framesize); |
1382 | 6d5e216d | bellard | } |
1383 | 6d5e216d | bellard | |
1384 | 6d5e216d | bellard | static int |
1385 | 6d5e216d | bellard | setup___siginfo(__siginfo_t *si, CPUState *env, target_ulong mask) |
1386 | 6d5e216d | bellard | { |
1387 | 6d5e216d | bellard | int err = 0, i; |
1388 | 6d5e216d | bellard | |
1389 | 6d5e216d | bellard | err |= __put_user(env->psr, &si->si_regs.psr); |
1390 | 6d5e216d | bellard | err |= __put_user(env->pc, &si->si_regs.pc); |
1391 | 6d5e216d | bellard | err |= __put_user(env->npc, &si->si_regs.npc); |
1392 | 6d5e216d | bellard | err |= __put_user(env->y, &si->si_regs.y); |
1393 | a315a145 | bellard | for (i=0; i < 8; i++) { |
1394 | 6d5e216d | bellard | err |= __put_user(env->gregs[i], &si->si_regs.u_regs[i]); |
1395 | 6d5e216d | bellard | } |
1396 | a315a145 | bellard | for (i=0; i < 8; i++) { |
1397 | e80cfcfc | bellard | err |= __put_user(env->regwptr[UREG_I0 + i], &si->si_regs.u_regs[i+8]);
|
1398 | 6d5e216d | bellard | } |
1399 | 6d5e216d | bellard | err |= __put_user(mask, &si->si_mask); |
1400 | 6d5e216d | bellard | return err;
|
1401 | 6d5e216d | bellard | } |
1402 | e80cfcfc | bellard | |
1403 | 80a9d035 | bellard | #if 0
|
1404 | 6d5e216d | bellard | static int
|
1405 | 6d5e216d | bellard | setup_sigcontext(struct target_sigcontext *sc, /*struct _fpstate *fpstate,*/
|
1406 | 6d5e216d | bellard | CPUState *env, unsigned long mask)
|
1407 | 6d5e216d | bellard | {
|
1408 | 6d5e216d | bellard | int err = 0;
|
1409 | 6d5e216d | bellard | |
1410 | 6d5e216d | bellard | err |= __put_user(mask, &sc->sigc_mask);
|
1411 | 6d5e216d | bellard | err |= __put_user(env->regwptr[UREG_SP], &sc->sigc_sp);
|
1412 | 6d5e216d | bellard | err |= __put_user(env->pc, &sc->sigc_pc);
|
1413 | 6d5e216d | bellard | err |= __put_user(env->npc, &sc->sigc_npc);
|
1414 | 6d5e216d | bellard | err |= __put_user(env->psr, &sc->sigc_psr);
|
1415 | 6d5e216d | bellard | err |= __put_user(env->gregs[1], &sc->sigc_g1);
|
1416 | 6d5e216d | bellard | err |= __put_user(env->regwptr[UREG_O0], &sc->sigc_o0);
|
1417 | 6d5e216d | bellard | |
1418 | 6d5e216d | bellard | return err;
|
1419 | 6d5e216d | bellard | }
|
1420 | 80a9d035 | bellard | #endif
|
1421 | 6d5e216d | bellard | #define NF_ALIGNEDSZ (((sizeof(struct target_signal_frame) + 7) & (~7))) |
1422 | 6d5e216d | bellard | |
1423 | 6d5e216d | bellard | static void setup_frame(int sig, struct emulated_sigaction *ka, |
1424 | 6d5e216d | bellard | target_sigset_t *set, CPUState *env) |
1425 | 6d5e216d | bellard | { |
1426 | 6d5e216d | bellard | struct target_signal_frame *sf;
|
1427 | 6d5e216d | bellard | int sigframe_size, err, i;
|
1428 | 6d5e216d | bellard | |
1429 | 6d5e216d | bellard | /* 1. Make sure everything is clean */
|
1430 | 6d5e216d | bellard | //synchronize_user_stack();
|
1431 | 6d5e216d | bellard | |
1432 | 6d5e216d | bellard | sigframe_size = NF_ALIGNEDSZ; |
1433 | 6d5e216d | bellard | |
1434 | 6d5e216d | bellard | sf = (struct target_signal_frame *)
|
1435 | 6d5e216d | bellard | get_sigframe(ka, env, sigframe_size); |
1436 | 6d5e216d | bellard | |
1437 | e80cfcfc | bellard | //fprintf(stderr, "sf: %x pc %x fp %x sp %x\n", sf, env->pc, env->regwptr[UREG_FP], env->regwptr[UREG_SP]);
|
1438 | 6d5e216d | bellard | #if 0
|
1439 | 6d5e216d | bellard | if (invalid_frame_pointer(sf, sigframe_size))
|
1440 | 6d5e216d | bellard | goto sigill_and_return;
|
1441 | 6d5e216d | bellard | #endif
|
1442 | 6d5e216d | bellard | /* 2. Save the current process state */
|
1443 | 6d5e216d | bellard | err = setup___siginfo(&sf->info, env, set->sig[0]);
|
1444 | 6d5e216d | bellard | err |= __put_user(0, &sf->extra_size);
|
1445 | 6d5e216d | bellard | |
1446 | 6d5e216d | bellard | //err |= save_fpu_state(regs, &sf->fpu_state);
|
1447 | 6d5e216d | bellard | //err |= __put_user(&sf->fpu_state, &sf->fpu_save);
|
1448 | 6d5e216d | bellard | |
1449 | 6d5e216d | bellard | err |= __put_user(set->sig[0], &sf->info.si_mask);
|
1450 | 6d5e216d | bellard | for (i = 0; i < TARGET_NSIG_WORDS - 1; i++) { |
1451 | 6d5e216d | bellard | err |= __put_user(set->sig[i + 1], &sf->extramask[i]);
|
1452 | 6d5e216d | bellard | } |
1453 | 6d5e216d | bellard | |
1454 | a315a145 | bellard | for (i = 0; i < 8; i++) { |
1455 | e80cfcfc | bellard | err |= __put_user(env->regwptr[i + UREG_L0], &sf->ss.locals[i]); |
1456 | 6d5e216d | bellard | } |
1457 | a315a145 | bellard | for (i = 0; i < 8; i++) { |
1458 | e80cfcfc | bellard | err |= __put_user(env->regwptr[i + UREG_I0], &sf->ss.ins[i]); |
1459 | 6d5e216d | bellard | } |
1460 | 6d5e216d | bellard | if (err)
|
1461 | 6d5e216d | bellard | goto sigsegv;
|
1462 | 6d5e216d | bellard | |
1463 | 6d5e216d | bellard | /* 3. signal handler back-trampoline and parameters */
|
1464 | 6d5e216d | bellard | env->regwptr[UREG_FP] = (target_ulong) sf; |
1465 | 6d5e216d | bellard | env->regwptr[UREG_I0] = sig; |
1466 | 6d5e216d | bellard | env->regwptr[UREG_I1] = (target_ulong) &sf->info; |
1467 | 6d5e216d | bellard | env->regwptr[UREG_I2] = (target_ulong) &sf->info; |
1468 | 6d5e216d | bellard | |
1469 | 6d5e216d | bellard | /* 4. signal handler */
|
1470 | 6d5e216d | bellard | env->pc = (unsigned long) ka->sa._sa_handler; |
1471 | 6d5e216d | bellard | env->npc = (env->pc + 4);
|
1472 | 6d5e216d | bellard | /* 5. return to kernel instructions */
|
1473 | 6d5e216d | bellard | if (ka->sa.sa_restorer)
|
1474 | 6d5e216d | bellard | env->regwptr[UREG_I7] = (unsigned long)ka->sa.sa_restorer; |
1475 | 6d5e216d | bellard | else {
|
1476 | 6d5e216d | bellard | env->regwptr[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2); |
1477 | 6d5e216d | bellard | |
1478 | 6d5e216d | bellard | /* mov __NR_sigreturn, %g1 */
|
1479 | 6d5e216d | bellard | err |= __put_user(0x821020d8, &sf->insns[0]); |
1480 | 6d5e216d | bellard | |
1481 | 6d5e216d | bellard | /* t 0x10 */
|
1482 | 6d5e216d | bellard | err |= __put_user(0x91d02010, &sf->insns[1]); |
1483 | 6d5e216d | bellard | if (err)
|
1484 | 6d5e216d | bellard | goto sigsegv;
|
1485 | 6d5e216d | bellard | |
1486 | 6d5e216d | bellard | /* Flush instruction space. */
|
1487 | 6d5e216d | bellard | //flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
|
1488 | 80a9d035 | bellard | // tb_flush(env);
|
1489 | 6d5e216d | bellard | } |
1490 | 6d5e216d | bellard | return;
|
1491 | 6d5e216d | bellard | |
1492 | 80a9d035 | bellard | //sigill_and_return:
|
1493 | 6d5e216d | bellard | force_sig(TARGET_SIGILL); |
1494 | 6d5e216d | bellard | sigsegv:
|
1495 | e80cfcfc | bellard | //fprintf(stderr, "force_sig\n");
|
1496 | 6d5e216d | bellard | force_sig(TARGET_SIGSEGV); |
1497 | 6d5e216d | bellard | } |
1498 | 6d5e216d | bellard | static inline int |
1499 | 6d5e216d | bellard | restore_fpu_state(CPUState *env, __siginfo_fpu_t *fpu) |
1500 | 6d5e216d | bellard | { |
1501 | 6d5e216d | bellard | int err;
|
1502 | 6d5e216d | bellard | #if 0
|
1503 | 6d5e216d | bellard | #ifdef CONFIG_SMP
|
1504 | 6d5e216d | bellard | if (current->flags & PF_USEDFPU)
|
1505 | 6d5e216d | bellard | regs->psr &= ~PSR_EF;
|
1506 | 6d5e216d | bellard | #else
|
1507 | 6d5e216d | bellard | if (current == last_task_used_math) {
|
1508 | 6d5e216d | bellard | last_task_used_math = 0;
|
1509 | 6d5e216d | bellard | regs->psr &= ~PSR_EF; |
1510 | 6d5e216d | bellard | } |
1511 | 6d5e216d | bellard | #endif
|
1512 | 6d5e216d | bellard | current->used_math = 1;
|
1513 | 6d5e216d | bellard | current->flags &= ~PF_USEDFPU; |
1514 | 6d5e216d | bellard | #endif
|
1515 | 6d5e216d | bellard | #if 0
|
1516 | 6d5e216d | bellard | if (verify_area (VERIFY_READ, fpu, sizeof(*fpu)))
|
1517 | 6d5e216d | bellard | return -EFAULT;
|
1518 | 6d5e216d | bellard | #endif
|
1519 | 6d5e216d | bellard | |
1520 | 6d5e216d | bellard | err = __copy_from_user(&env->fpr[0], &fpu->si_float_regs[0], |
1521 | 6d5e216d | bellard | (sizeof(unsigned long) * 32)); |
1522 | 6d5e216d | bellard | err |= __get_user(env->fsr, &fpu->si_fsr); |
1523 | 6d5e216d | bellard | #if 0
|
1524 | 6d5e216d | bellard | err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
|
1525 | 6d5e216d | bellard | if (current->thread.fpqdepth != 0)
|
1526 | 6d5e216d | bellard | err |= __copy_from_user(¤t->thread.fpqueue[0],
|
1527 | 6d5e216d | bellard | &fpu->si_fpqueue[0],
|
1528 | 6d5e216d | bellard | ((sizeof(unsigned long) +
|
1529 | 6d5e216d | bellard | (sizeof(unsigned long *)))*16));
|
1530 | 6d5e216d | bellard | #endif
|
1531 | 6d5e216d | bellard | return err;
|
1532 | 6d5e216d | bellard | } |
1533 | 6d5e216d | bellard | |
1534 | 6d5e216d | bellard | |
1535 | 6d5e216d | bellard | static void setup_rt_frame(int sig, struct emulated_sigaction *ka, |
1536 | 6d5e216d | bellard | target_siginfo_t *info, |
1537 | 6d5e216d | bellard | target_sigset_t *set, CPUState *env) |
1538 | 6d5e216d | bellard | { |
1539 | 6d5e216d | bellard | fprintf(stderr, "setup_rt_frame: not implemented\n");
|
1540 | 6d5e216d | bellard | } |
1541 | 6d5e216d | bellard | |
1542 | 6d5e216d | bellard | long do_sigreturn(CPUState *env)
|
1543 | 6d5e216d | bellard | { |
1544 | 6d5e216d | bellard | struct target_signal_frame *sf;
|
1545 | e80cfcfc | bellard | uint32_t up_psr, pc, npc; |
1546 | 6d5e216d | bellard | target_sigset_t set; |
1547 | e80cfcfc | bellard | sigset_t host_set; |
1548 | 80a9d035 | bellard | target_ulong fpu_save; |
1549 | e80cfcfc | bellard | int err, i;
|
1550 | 6d5e216d | bellard | |
1551 | e80cfcfc | bellard | sf = (struct target_signal_frame *) env->regwptr[UREG_FP];
|
1552 | 80a9d035 | bellard | #if 0
|
1553 | e80cfcfc | bellard | fprintf(stderr, "sigreturn\n");
|
1554 | e80cfcfc | bellard | fprintf(stderr, "sf: %x pc %x fp %x sp %x\n", sf, env->pc, env->regwptr[UREG_FP], env->regwptr[UREG_SP]);
|
1555 | 80a9d035 | bellard | #endif
|
1556 | e80cfcfc | bellard | //cpu_dump_state(env, stderr, fprintf, 0);
|
1557 | 6d5e216d | bellard | |
1558 | 6d5e216d | bellard | /* 1. Make sure we are not getting garbage from the user */
|
1559 | 6d5e216d | bellard | #if 0
|
1560 | 6d5e216d | bellard | if (verify_area (VERIFY_READ, sf, sizeof (*sf)))
|
1561 | 6d5e216d | bellard | goto segv_and_exit;
|
1562 | 6d5e216d | bellard | #endif
|
1563 | 6d5e216d | bellard | |
1564 | 6d5e216d | bellard | if (((uint) sf) & 3) |
1565 | 6d5e216d | bellard | goto segv_and_exit;
|
1566 | 6d5e216d | bellard | |
1567 | 6d5e216d | bellard | err = __get_user(pc, &sf->info.si_regs.pc); |
1568 | 6d5e216d | bellard | err |= __get_user(npc, &sf->info.si_regs.npc); |
1569 | 6d5e216d | bellard | |
1570 | 6d5e216d | bellard | if ((pc | npc) & 3) |
1571 | 6d5e216d | bellard | goto segv_and_exit;
|
1572 | 6d5e216d | bellard | |
1573 | 6d5e216d | bellard | /* 2. Restore the state */
|
1574 | e80cfcfc | bellard | err |= __get_user(up_psr, &sf->info.si_regs.psr); |
1575 | e80cfcfc | bellard | |
1576 | 6d5e216d | bellard | /* User can only change condition codes and FPU enabling in %psr. */
|
1577 | a315a145 | bellard | env->psr = (up_psr & (PSR_ICC /* | PSR_EF */))
|
1578 | a315a145 | bellard | | (env->psr & ~(PSR_ICC /* | PSR_EF */));
|
1579 | a315a145 | bellard | |
1580 | a315a145 | bellard | env->pc = pc; |
1581 | a315a145 | bellard | env->npc = npc; |
1582 | e80cfcfc | bellard | err |= __get_user(env->y, &sf->info.si_regs.y); |
1583 | a315a145 | bellard | for (i=0; i < 8; i++) { |
1584 | e80cfcfc | bellard | err |= __get_user(env->gregs[i], &sf->info.si_regs.u_regs[i]); |
1585 | e80cfcfc | bellard | } |
1586 | a315a145 | bellard | for (i=0; i < 8; i++) { |
1587 | e80cfcfc | bellard | err |= __get_user(env->regwptr[i + UREG_I0], &sf->info.si_regs.u_regs[i+8]);
|
1588 | e80cfcfc | bellard | } |
1589 | 6d5e216d | bellard | |
1590 | 80a9d035 | bellard | err |= __get_user(fpu_save, (target_ulong *)&sf->fpu_save); |
1591 | 6d5e216d | bellard | |
1592 | e80cfcfc | bellard | //if (fpu_save)
|
1593 | e80cfcfc | bellard | // err |= restore_fpu_state(env, fpu_save);
|
1594 | 6d5e216d | bellard | |
1595 | 6d5e216d | bellard | /* This is pretty much atomic, no amount locking would prevent
|
1596 | 6d5e216d | bellard | * the races which exist anyways.
|
1597 | 6d5e216d | bellard | */
|
1598 | 6d5e216d | bellard | err |= __get_user(set.sig[0], &sf->info.si_mask);
|
1599 | e80cfcfc | bellard | for(i = 1; i < TARGET_NSIG_WORDS; i++) { |
1600 | e80cfcfc | bellard | err |= (__get_user(set.sig[i], &sf->extramask[i - 1]));
|
1601 | e80cfcfc | bellard | } |
1602 | e80cfcfc | bellard | |
1603 | e80cfcfc | bellard | target_to_host_sigset_internal(&host_set, &set); |
1604 | e80cfcfc | bellard | sigprocmask(SIG_SETMASK, &host_set, NULL);
|
1605 | 6d5e216d | bellard | |
1606 | 6d5e216d | bellard | if (err)
|
1607 | 6d5e216d | bellard | goto segv_and_exit;
|
1608 | 6d5e216d | bellard | |
1609 | 6d5e216d | bellard | return env->regwptr[0]; |
1610 | 6d5e216d | bellard | |
1611 | 6d5e216d | bellard | segv_and_exit:
|
1612 | 6d5e216d | bellard | force_sig(TARGET_SIGSEGV); |
1613 | 6d5e216d | bellard | } |
1614 | 6d5e216d | bellard | |
1615 | 6d5e216d | bellard | long do_rt_sigreturn(CPUState *env)
|
1616 | 6d5e216d | bellard | { |
1617 | 6d5e216d | bellard | fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
1618 | 6d5e216d | bellard | return -ENOSYS;
|
1619 | 6d5e216d | bellard | } |
1620 | 6d5e216d | bellard | |
1621 | 6d5e216d | bellard | |
1622 | b346ff46 | bellard | #else
|
1623 | b346ff46 | bellard | |
1624 | b346ff46 | bellard | static void setup_frame(int sig, struct emulated_sigaction *ka, |
1625 | b346ff46 | bellard | target_sigset_t *set, CPUState *env) |
1626 | b346ff46 | bellard | { |
1627 | b346ff46 | bellard | fprintf(stderr, "setup_frame: not implemented\n");
|
1628 | b346ff46 | bellard | } |
1629 | b346ff46 | bellard | |
1630 | b346ff46 | bellard | static void setup_rt_frame(int sig, struct emulated_sigaction *ka, |
1631 | b346ff46 | bellard | target_siginfo_t *info, |
1632 | b346ff46 | bellard | target_sigset_t *set, CPUState *env) |
1633 | b346ff46 | bellard | { |
1634 | b346ff46 | bellard | fprintf(stderr, "setup_rt_frame: not implemented\n");
|
1635 | b346ff46 | bellard | } |
1636 | b346ff46 | bellard | |
1637 | b346ff46 | bellard | long do_sigreturn(CPUState *env)
|
1638 | b346ff46 | bellard | { |
1639 | b346ff46 | bellard | fprintf(stderr, "do_sigreturn: not implemented\n");
|
1640 | b346ff46 | bellard | return -ENOSYS;
|
1641 | b346ff46 | bellard | } |
1642 | b346ff46 | bellard | |
1643 | b346ff46 | bellard | long do_rt_sigreturn(CPUState *env)
|
1644 | b346ff46 | bellard | { |
1645 | b346ff46 | bellard | fprintf(stderr, "do_rt_sigreturn: not implemented\n");
|
1646 | b346ff46 | bellard | return -ENOSYS;
|
1647 | b346ff46 | bellard | } |
1648 | b346ff46 | bellard | |
1649 | 66fb9763 | bellard | #endif
|
1650 | 66fb9763 | bellard | |
1651 | 66fb9763 | bellard | void process_pending_signals(void *cpu_env) |
1652 | 66fb9763 | bellard | { |
1653 | 66fb9763 | bellard | int sig;
|
1654 | 66fb9763 | bellard | target_ulong handler; |
1655 | 9de5e440 | bellard | sigset_t set, old_set; |
1656 | 9de5e440 | bellard | target_sigset_t target_old_set; |
1657 | 66fb9763 | bellard | struct emulated_sigaction *k;
|
1658 | 66fb9763 | bellard | struct sigqueue *q;
|
1659 | 66fb9763 | bellard | |
1660 | 31e31b8a | bellard | if (!signal_pending)
|
1661 | 31e31b8a | bellard | return;
|
1662 | 31e31b8a | bellard | |
1663 | 66fb9763 | bellard | k = sigact_table; |
1664 | 66fb9763 | bellard | for(sig = 1; sig <= TARGET_NSIG; sig++) { |
1665 | 66fb9763 | bellard | if (k->pending)
|
1666 | 31e31b8a | bellard | goto handle_signal;
|
1667 | 66fb9763 | bellard | k++; |
1668 | 31e31b8a | bellard | } |
1669 | 31e31b8a | bellard | /* if no signal is pending, just return */
|
1670 | 31e31b8a | bellard | signal_pending = 0;
|
1671 | 31e31b8a | bellard | return;
|
1672 | 66fb9763 | bellard | |
1673 | 31e31b8a | bellard | handle_signal:
|
1674 | 66fb9763 | bellard | #ifdef DEBUG_SIGNAL
|
1675 | bc8a22cc | bellard | fprintf(stderr, "qemu: process signal %d\n", sig);
|
1676 | 66fb9763 | bellard | #endif
|
1677 | 66fb9763 | bellard | /* dequeue signal */
|
1678 | 66fb9763 | bellard | q = k->first; |
1679 | 66fb9763 | bellard | k->first = q->next; |
1680 | 66fb9763 | bellard | if (!k->first)
|
1681 | 66fb9763 | bellard | k->pending = 0;
|
1682 | 1fddef4b | bellard | |
1683 | 1fddef4b | bellard | sig = gdb_handlesig (cpu_env, sig); |
1684 | 1fddef4b | bellard | if (!sig) {
|
1685 | 1fddef4b | bellard | fprintf (stderr, "Lost signal\n");
|
1686 | 1fddef4b | bellard | abort(); |
1687 | 1fddef4b | bellard | } |
1688 | 66fb9763 | bellard | |
1689 | 66fb9763 | bellard | handler = k->sa._sa_handler; |
1690 | 66fb9763 | bellard | if (handler == TARGET_SIG_DFL) {
|
1691 | 66fb9763 | bellard | /* default handler : ignore some signal. The other are fatal */
|
1692 | 66fb9763 | bellard | if (sig != TARGET_SIGCHLD &&
|
1693 | 66fb9763 | bellard | sig != TARGET_SIGURG && |
1694 | 66fb9763 | bellard | sig != TARGET_SIGWINCH) { |
1695 | 66fb9763 | bellard | force_sig(sig); |
1696 | 66fb9763 | bellard | } |
1697 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_IGN) { |
1698 | 66fb9763 | bellard | /* ignore sig */
|
1699 | 66fb9763 | bellard | } else if (handler == TARGET_SIG_ERR) { |
1700 | 66fb9763 | bellard | force_sig(sig); |
1701 | 66fb9763 | bellard | } else {
|
1702 | 9de5e440 | bellard | /* compute the blocked signals during the handler execution */
|
1703 | 9de5e440 | bellard | target_to_host_sigset(&set, &k->sa.sa_mask); |
1704 | 9de5e440 | bellard | /* SA_NODEFER indicates that the current signal should not be
|
1705 | 9de5e440 | bellard | blocked during the handler */
|
1706 | 9de5e440 | bellard | if (!(k->sa.sa_flags & TARGET_SA_NODEFER))
|
1707 | 9de5e440 | bellard | sigaddset(&set, target_to_host_signal(sig)); |
1708 | 9de5e440 | bellard | |
1709 | 9de5e440 | bellard | /* block signals in the handler using Linux */
|
1710 | 9de5e440 | bellard | sigprocmask(SIG_BLOCK, &set, &old_set); |
1711 | 9de5e440 | bellard | /* save the previous blocked signal state to restore it at the
|
1712 | 9de5e440 | bellard | end of the signal execution (see do_sigreturn) */
|
1713 | 9231944d | bellard | host_to_target_sigset_internal(&target_old_set, &old_set); |
1714 | 9de5e440 | bellard | |
1715 | bc8a22cc | bellard | /* if the CPU is in VM86 mode, we restore the 32 bit values */
|
1716 | bc8a22cc | bellard | #ifdef TARGET_I386
|
1717 | bc8a22cc | bellard | { |
1718 | bc8a22cc | bellard | CPUX86State *env = cpu_env; |
1719 | bc8a22cc | bellard | if (env->eflags & VM_MASK)
|
1720 | bc8a22cc | bellard | save_v86_state(env); |
1721 | bc8a22cc | bellard | } |
1722 | bc8a22cc | bellard | #endif
|
1723 | 9de5e440 | bellard | /* prepare the stack frame of the virtual CPU */
|
1724 | 66fb9763 | bellard | if (k->sa.sa_flags & TARGET_SA_SIGINFO)
|
1725 | 9de5e440 | bellard | setup_rt_frame(sig, k, &q->info, &target_old_set, cpu_env); |
1726 | 66fb9763 | bellard | else
|
1727 | 9de5e440 | bellard | setup_frame(sig, k, &target_old_set, cpu_env); |
1728 | 66fb9763 | bellard | if (k->sa.sa_flags & TARGET_SA_RESETHAND)
|
1729 | 66fb9763 | bellard | k->sa._sa_handler = TARGET_SIG_DFL; |
1730 | 31e31b8a | bellard | } |
1731 | 66fb9763 | bellard | if (q != &k->info)
|
1732 | 66fb9763 | bellard | free_sigqueue(q); |
1733 | 66fb9763 | bellard | } |
1734 | 31e31b8a | bellard |