mirror of https://github.com/xqemu/xqemu.git
cpus: remove ugly cast on sigbus_handler
The cast is there because sigbus_handler is invoked via sigfd_handler. But it feels just wrong to use struct qemu_signalfd_siginfo in the prototype of a function that is passed to sigaction. Instead, do a simple-minded conversion of qemu_signalfd_siginfo to siginfo_t. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
30f3dda24b
commit
d98d407234
12
cpus.c
12
cpus.c
|
@ -51,10 +51,6 @@
|
||||||
#include "hw/nmi.h"
|
#include "hw/nmi.h"
|
||||||
#include "sysemu/replay.h"
|
#include "sysemu/replay.h"
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#include "qemu/compatfd.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_LINUX
|
#ifdef CONFIG_LINUX
|
||||||
|
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
|
@ -924,11 +920,9 @@ static void sigbus_reraise(void)
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo,
|
static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx)
|
||||||
void *ctx)
|
|
||||||
{
|
{
|
||||||
if (kvm_on_sigbus(siginfo->ssi_code,
|
if (kvm_on_sigbus(siginfo->si_code, siginfo->si_addr)) {
|
||||||
(void *)(intptr_t)siginfo->ssi_addr)) {
|
|
||||||
sigbus_reraise();
|
sigbus_reraise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -939,7 +933,7 @@ static void qemu_init_sigbus(void)
|
||||||
|
|
||||||
memset(&action, 0, sizeof(action));
|
memset(&action, 0, sizeof(action));
|
||||||
action.sa_flags = SA_SIGINFO;
|
action.sa_flags = SA_SIGINFO;
|
||||||
action.sa_sigaction = (void (*)(int, siginfo_t*, void*))sigbus_handler;
|
action.sa_sigaction = sigbus_handler;
|
||||||
sigaction(SIGBUS, &action, NULL);
|
sigaction(SIGBUS, &action, NULL);
|
||||||
|
|
||||||
prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0);
|
prctl(PR_MCE_KILL, PR_MCE_KILL_SET, PR_MCE_KILL_EARLY, 0, 0);
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
* signalfd/eventfd compatibility
|
|
||||||
*
|
|
||||||
* Copyright IBM, Corp. 2008
|
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Anthony Liguori <aliguori@us.ibm.com>
|
|
||||||
*
|
|
||||||
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
||||||
* the COPYING file in the top-level directory.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef QEMU_COMPATFD_H
|
|
||||||
#define QEMU_COMPATFD_H
|
|
||||||
|
|
||||||
|
|
||||||
struct qemu_signalfd_siginfo {
|
|
||||||
uint32_t ssi_signo; /* Signal number */
|
|
||||||
int32_t ssi_errno; /* Error number (unused) */
|
|
||||||
int32_t ssi_code; /* Signal code */
|
|
||||||
uint32_t ssi_pid; /* PID of sender */
|
|
||||||
uint32_t ssi_uid; /* Real UID of sender */
|
|
||||||
int32_t ssi_fd; /* File descriptor (SIGIO) */
|
|
||||||
uint32_t ssi_tid; /* Kernel timer ID (POSIX timers) */
|
|
||||||
uint32_t ssi_band; /* Band event (SIGIO) */
|
|
||||||
uint32_t ssi_overrun; /* POSIX timer overrun count */
|
|
||||||
uint32_t ssi_trapno; /* Trap number that caused signal */
|
|
||||||
int32_t ssi_status; /* Exit status or signal (SIGCHLD) */
|
|
||||||
int32_t ssi_int; /* Integer sent by sigqueue(2) */
|
|
||||||
uint64_t ssi_ptr; /* Pointer sent by sigqueue(2) */
|
|
||||||
uint64_t ssi_utime; /* User CPU time consumed (SIGCHLD) */
|
|
||||||
uint64_t ssi_stime; /* System CPU time consumed (SIGCHLD) */
|
|
||||||
uint64_t ssi_addr; /* Address that generated signal
|
|
||||||
(for hardware-generated signals) */
|
|
||||||
uint8_t pad[48]; /* Pad size to 128 bytes (allow for
|
|
||||||
additional fields in the future) */
|
|
||||||
};
|
|
||||||
|
|
||||||
int qemu_signalfd(const sigset_t *mask);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -297,6 +297,34 @@ void qemu_anon_ram_free(void *ptr, size_t size);
|
||||||
# define QEMU_VMALLOC_ALIGN getpagesize()
|
# define QEMU_VMALLOC_ALIGN getpagesize()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_POSIX
|
||||||
|
struct qemu_signalfd_siginfo {
|
||||||
|
uint32_t ssi_signo; /* Signal number */
|
||||||
|
int32_t ssi_errno; /* Error number (unused) */
|
||||||
|
int32_t ssi_code; /* Signal code */
|
||||||
|
uint32_t ssi_pid; /* PID of sender */
|
||||||
|
uint32_t ssi_uid; /* Real UID of sender */
|
||||||
|
int32_t ssi_fd; /* File descriptor (SIGIO) */
|
||||||
|
uint32_t ssi_tid; /* Kernel timer ID (POSIX timers) */
|
||||||
|
uint32_t ssi_band; /* Band event (SIGIO) */
|
||||||
|
uint32_t ssi_overrun; /* POSIX timer overrun count */
|
||||||
|
uint32_t ssi_trapno; /* Trap number that caused signal */
|
||||||
|
int32_t ssi_status; /* Exit status or signal (SIGCHLD) */
|
||||||
|
int32_t ssi_int; /* Integer sent by sigqueue(2) */
|
||||||
|
uint64_t ssi_ptr; /* Pointer sent by sigqueue(2) */
|
||||||
|
uint64_t ssi_utime; /* User CPU time consumed (SIGCHLD) */
|
||||||
|
uint64_t ssi_stime; /* System CPU time consumed (SIGCHLD) */
|
||||||
|
uint64_t ssi_addr; /* Address that generated signal
|
||||||
|
(for hardware-generated signals) */
|
||||||
|
uint8_t pad[48]; /* Pad size to 128 bytes (allow for
|
||||||
|
additional fields in the future) */
|
||||||
|
};
|
||||||
|
|
||||||
|
int qemu_signalfd(const sigset_t *mask);
|
||||||
|
void sigaction_invoke(struct sigaction *action,
|
||||||
|
struct qemu_signalfd_siginfo *info);
|
||||||
|
#endif
|
||||||
|
|
||||||
int qemu_madvise(void *addr, size_t len, int advice);
|
int qemu_madvise(void *addr, size_t len, int advice);
|
||||||
|
|
||||||
int qemu_open(const char *name, int flags, ...);
|
int qemu_open(const char *name, int flags, ...);
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "qemu-common.h"
|
#include "qemu-common.h"
|
||||||
#include "qemu/compatfd.h"
|
|
||||||
#include "qemu/thread.h"
|
#include "qemu/thread.h"
|
||||||
|
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
|
|
|
@ -34,8 +34,6 @@
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
|
||||||
#include "qemu/compatfd.h"
|
|
||||||
|
|
||||||
/* If we have signalfd, we mask out the signals we want to handle and then
|
/* If we have signalfd, we mask out the signals we want to handle and then
|
||||||
* use signalfd to listen for them. We rely on whatever the current signal
|
* use signalfd to listen for them. We rely on whatever the current signal
|
||||||
* handler is to dispatch the signals when we receive them.
|
* handler is to dispatch the signals when we receive them.
|
||||||
|
@ -63,8 +61,7 @@ static void sigfd_handler(void *opaque)
|
||||||
|
|
||||||
sigaction(info.ssi_signo, NULL, &action);
|
sigaction(info.ssi_signo, NULL, &action);
|
||||||
if ((action.sa_flags & SA_SIGINFO) && action.sa_sigaction) {
|
if ((action.sa_flags & SA_SIGINFO) && action.sa_sigaction) {
|
||||||
action.sa_sigaction(info.ssi_signo,
|
sigaction_invoke(&action, &info);
|
||||||
(siginfo_t *)&info, NULL);
|
|
||||||
} else if (action.sa_handler) {
|
} else if (action.sa_handler) {
|
||||||
action.sa_handler(info.ssi_signo);
|
action.sa_handler(info.ssi_signo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -603,3 +603,36 @@ void qemu_free_stack(void *stack, size_t sz)
|
||||||
|
|
||||||
munmap(stack, sz);
|
munmap(stack, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sigaction_invoke(struct sigaction *action,
|
||||||
|
struct qemu_signalfd_siginfo *info)
|
||||||
|
{
|
||||||
|
siginfo_t si = { 0 };
|
||||||
|
si.si_signo = info->ssi_signo;
|
||||||
|
si.si_errno = info->ssi_errno;
|
||||||
|
si.si_code = info->ssi_code;
|
||||||
|
|
||||||
|
/* Convert the minimal set of fields defined by POSIX.
|
||||||
|
* Positive si_code values are reserved for kernel-generated
|
||||||
|
* signals, where the valid siginfo fields are determined by
|
||||||
|
* the signal number. But according to POSIX, it is unspecified
|
||||||
|
* whether SI_USER and SI_QUEUE have values less than or equal to
|
||||||
|
* zero.
|
||||||
|
*/
|
||||||
|
if (info->ssi_code == SI_USER || info->ssi_code == SI_QUEUE ||
|
||||||
|
info->ssi_code <= 0) {
|
||||||
|
/* SIGTERM, etc. */
|
||||||
|
si.si_pid = info->ssi_pid;
|
||||||
|
si.si_uid = info->ssi_uid;
|
||||||
|
} else if (info->ssi_signo == SIGILL || info->ssi_signo == SIGFPE ||
|
||||||
|
info->ssi_signo == SIGSEGV || info->ssi_signo == SIGBUS) {
|
||||||
|
si.si_addr = (void *)(uintptr_t)info->ssi_addr;
|
||||||
|
} else if (info->ssi_signo == SIGCHLD) {
|
||||||
|
si.si_pid = info->ssi_pid;
|
||||||
|
si.si_status = info->ssi_status;
|
||||||
|
si.si_uid = info->ssi_uid;
|
||||||
|
} else if (info->ssi_signo == SIGIO) {
|
||||||
|
si.si_band = info->ssi_band;
|
||||||
|
}
|
||||||
|
action->sa_sigaction(info->ssi_signo, &si, NULL);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue