2 * signalfd/eventfd compatibility
4 * Copyright IBM, Corp. 2008
7 * Anthony Liguori <aliguori@us.ibm.com>
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 memcpy(&info
->mask
, mask
, sizeof(*mask
));
91 pthread_attr_init(&attr
);
92 pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
94 pthread_create(&tid
, &attr
, sigwait_compat
, info
);
96 pthread_attr_destroy(&attr
);
101 int qemu_signalfd(const sigset_t
*mask
)
103 #if defined(CONFIG_SIGNALFD)
106 ret
= syscall(SYS_signalfd
, -1, mask
, _NSIG
/ 8);
111 return qemu_signalfd_compat(mask
);
114 int qemu_eventfd(int *fds
)
116 #if defined(CONFIG_EVENTFD)
119 ret
= syscall(SYS_eventfd
, 0);
122 if ((fds
[1] = dup(ret
)) == -1) {