2 * signalfd/eventfd compatibility
4 * Copyright IBM, Corp. 2008
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu-common.h"
19 #include <sys/syscall.h>
22 struct sigfd_compat_info
28 static void *sigwait_compat(void *opaque)
30 struct sigfd_compat_info *info = opaque;
34 pthread_sigmask(SIG_BLOCK, &all, NULL);
40 err = sigwait(&info->mask, &sig);
48 struct qemu_signalfd_siginfo buffer;
51 memset(&buffer, 0, sizeof(buffer));
52 buffer.ssi_signo = sig;
54 while (offset < sizeof(buffer)) {
57 len = write(info->fd, (char *)&buffer + offset,
58 sizeof(buffer) - offset);
59 if (len == -1 && errno == EINTR)
72 static int qemu_signalfd_compat(const sigset_t *mask)
76 struct sigfd_compat_info *info;
79 info = malloc(sizeof(*info));
85 if (pipe(fds) == -1) {
90 qemu_set_cloexec(fds[0]);
91 qemu_set_cloexec(fds[1]);
93 memcpy(&info->mask, mask, sizeof(*mask));
96 pthread_attr_init(&attr);
97 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
99 pthread_create(&tid, &attr, sigwait_compat, info);
101 pthread_attr_destroy(&attr);
106 int qemu_signalfd(const sigset_t *mask)
108 #if defined(CONFIG_SIGNALFD)
111 ret = syscall(SYS_signalfd, -1, mask, _NSIG / 8);
113 qemu_set_cloexec(ret);
118 return qemu_signalfd_compat(mask);
121 bool qemu_signalfd_available(void)
123 #ifdef CONFIG_SIGNALFD
129 fd = syscall(SYS_signalfd, -1, &mask, _NSIG / 8);
130 ok = (errno != ENOSYS);