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;
33 sigprocmask(SIG_BLOCK, &all, NULL);
38 err = sigwaitinfo(&info->mask, &siginfo);
39 if (err == -1 && errno == EINTR) {
48 memcpy(buffer, &err, sizeof(err));
49 while (offset < sizeof(buffer)) {
52 len = write(info->fd, buffer + offset,
53 sizeof(buffer) - offset);
54 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);