227 |
227 |
{
|
228 |
228 |
}
|
229 |
229 |
|
|
230 |
/* If we have signalfd, we mask out the signals we want to handle and then
|
|
231 |
* use signalfd to listen for them. We rely on whatever the current signal
|
|
232 |
* handler is to dispatch the signals when we receive them.
|
|
233 |
*/
|
|
234 |
static void sigfd_handler(void *opaque)
|
|
235 |
{
|
|
236 |
int fd = (unsigned long) opaque;
|
|
237 |
struct qemu_signalfd_siginfo info;
|
|
238 |
struct sigaction action;
|
|
239 |
ssize_t len;
|
|
240 |
|
|
241 |
while (1) {
|
|
242 |
do {
|
|
243 |
len = read(fd, &info, sizeof(info));
|
|
244 |
} while (len == -1 && errno == EINTR);
|
|
245 |
|
|
246 |
if (len == -1 && errno == EAGAIN) {
|
|
247 |
break;
|
|
248 |
}
|
|
249 |
|
|
250 |
if (len != sizeof(info)) {
|
|
251 |
printf("read from sigfd returned %zd: %m\n", len);
|
|
252 |
return;
|
|
253 |
}
|
|
254 |
|
|
255 |
sigaction(info.ssi_signo, NULL, &action);
|
|
256 |
if ((action.sa_flags & SA_SIGINFO) && action.sa_sigaction) {
|
|
257 |
action.sa_sigaction(info.ssi_signo,
|
|
258 |
(siginfo_t *)&info, NULL);
|
|
259 |
} else if (action.sa_handler) {
|
|
260 |
action.sa_handler(info.ssi_signo);
|
|
261 |
}
|
|
262 |
}
|
|
263 |
}
|
|
264 |
|
|
265 |
static int qemu_signalfd_init(sigset_t mask)
|
|
266 |
{
|
|
267 |
int sigfd;
|
|
268 |
|
|
269 |
sigfd = qemu_signalfd(&mask);
|
|
270 |
if (sigfd == -1) {
|
|
271 |
fprintf(stderr, "failed to create signalfd\n");
|
|
272 |
return -errno;
|
|
273 |
}
|
|
274 |
|
|
275 |
fcntl_setfl(sigfd, O_NONBLOCK);
|
|
276 |
|
|
277 |
qemu_set_fd_handler2(sigfd, NULL, sigfd_handler, NULL,
|
|
278 |
(void *)(unsigned long) sigfd);
|
|
279 |
|
|
280 |
return 0;
|
|
281 |
}
|
|
282 |
|
230 |
283 |
static void sigbus_reraise(void);
|
231 |
284 |
|
232 |
285 |
static void qemu_kvm_eat_signals(CPUState *env)
|
... | ... | |
330 |
383 |
|
331 |
384 |
int qemu_init_main_loop(void)
|
332 |
385 |
{
|
|
386 |
#ifndef _WIN32
|
|
387 |
sigset_t blocked_signals;
|
|
388 |
int ret;
|
|
389 |
|
|
390 |
sigemptyset(&blocked_signals);
|
|
391 |
|
|
392 |
ret = qemu_signalfd_init(blocked_signals);
|
|
393 |
if (ret) {
|
|
394 |
return ret;
|
|
395 |
}
|
|
396 |
#endif
|
333 |
397 |
cpu_set_debug_excp_handler(cpu_debug_handler);
|
334 |
398 |
|
335 |
399 |
return qemu_event_init();
|
... | ... | |
426 |
490 |
static QemuCond qemu_pause_cond;
|
427 |
491 |
static QemuCond qemu_work_cond;
|
428 |
492 |
|
429 |
|
/* If we have signalfd, we mask out the signals we want to handle and then
|
430 |
|
* use signalfd to listen for them. We rely on whatever the current signal
|
431 |
|
* handler is to dispatch the signals when we receive them.
|
432 |
|
*/
|
433 |
|
static void sigfd_handler(void *opaque)
|
434 |
|
{
|
435 |
|
int fd = (unsigned long) opaque;
|
436 |
|
struct qemu_signalfd_siginfo info;
|
437 |
|
struct sigaction action;
|
438 |
|
ssize_t len;
|
439 |
|
|
440 |
|
while (1) {
|
441 |
|
do {
|
442 |
|
len = read(fd, &info, sizeof(info));
|
443 |
|
} while (len == -1 && errno == EINTR);
|
444 |
|
|
445 |
|
if (len == -1 && errno == EAGAIN) {
|
446 |
|
break;
|
447 |
|
}
|
448 |
|
|
449 |
|
if (len != sizeof(info)) {
|
450 |
|
printf("read from sigfd returned %zd: %m\n", len);
|
451 |
|
return;
|
452 |
|
}
|
453 |
|
|
454 |
|
sigaction(info.ssi_signo, NULL, &action);
|
455 |
|
if ((action.sa_flags & SA_SIGINFO) && action.sa_sigaction) {
|
456 |
|
action.sa_sigaction(info.ssi_signo,
|
457 |
|
(siginfo_t *)&info, NULL);
|
458 |
|
} else if (action.sa_handler) {
|
459 |
|
action.sa_handler(info.ssi_signo);
|
460 |
|
}
|
461 |
|
}
|
462 |
|
}
|
463 |
|
|
464 |
493 |
static void cpu_signal(int sig)
|
465 |
494 |
{
|
466 |
495 |
if (cpu_single_env) {
|
... | ... | |
532 |
561 |
return set;
|
533 |
562 |
}
|
534 |
563 |
|
535 |
|
static int qemu_signalfd_init(sigset_t mask)
|
536 |
|
{
|
537 |
|
int sigfd;
|
538 |
|
|
539 |
|
sigfd = qemu_signalfd(&mask);
|
540 |
|
if (sigfd == -1) {
|
541 |
|
fprintf(stderr, "failed to create signalfd\n");
|
542 |
|
return -errno;
|
543 |
|
}
|
544 |
|
|
545 |
|
fcntl_setfl(sigfd, O_NONBLOCK);
|
546 |
|
|
547 |
|
qemu_set_fd_handler2(sigfd, NULL, sigfd_handler, NULL,
|
548 |
|
(void *)(unsigned long) sigfd);
|
549 |
|
|
550 |
|
return 0;
|
551 |
|
}
|
552 |
|
|
553 |
564 |
int qemu_init_main_loop(void)
|
554 |
565 |
{
|
555 |
566 |
int ret;
|