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.
14 #include "qemu-common.h"
17 #include <sys/syscall.h>
20 struct sigfd_compat_info
26 static void *sigwait_compat(void *opaque)
28 struct sigfd_compat_info *info = opaque;
32 pthread_sigmask(SIG_BLOCK, &all, NULL);
38 err = sigwait(&info->mask, &sig);
46 struct qemu_signalfd_siginfo buffer;
49 memset(&buffer, 0, sizeof(buffer));
50 buffer.ssi_signo = sig;
52 while (offset < sizeof(buffer)) {
55 len = write(info->fd, (char *)&buffer + offset,
56 sizeof(buffer) - offset);
57 if (len == -1 && errno == EINTR)
70 static int qemu_signalfd_compat(const sigset_t *mask)
74 struct sigfd_compat_info *info;
77 info = malloc(sizeof(*info));
83 if (pipe(fds) == -1) {
88 qemu_set_cloexec(fds[0]);
89 qemu_set_cloexec(fds[1]);
91 memcpy(&info->mask, mask, sizeof(*mask));
94 pthread_attr_init(&attr);
95 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
97 pthread_create(&tid, &attr, sigwait_compat, info);
99 pthread_attr_destroy(&attr);
104 int qemu_signalfd(const sigset_t *mask)
106 #if defined(CONFIG_SIGNALFD)
109 ret = syscall(SYS_signalfd, -1, mask, _NSIG / 8);
111 qemu_set_cloexec(ret);
116 return qemu_signalfd_compat(mask);
119 bool qemu_signalfd_available(void)
121 #ifdef CONFIG_SIGNALFD
123 syscall(SYS_signalfd, -1, NULL, _NSIG / 8);
124 return errno != ENOSYS;