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
;
31 sigprocmask(SIG_BLOCK
, &info
->mask
, NULL
);
36 err
= sigwaitinfo(&info
->mask
, &siginfo
);
37 if (err
== -1 && errno
== EINTR
)
44 memcpy(buffer
, &err
, sizeof(err
));
45 while (offset
< sizeof(buffer
)) {
48 len
= write(info
->fd
, buffer
+ offset
,
49 sizeof(buffer
) - offset
);
50 if (len
== -1 && errno
== EINTR
)
66 static int kvm_signalfd_compat(const sigset_t
*mask
)
70 struct sigfd_compat_info
*info
;
73 info
= malloc(sizeof(*info
));
79 if (pipe(fds
) == -1) {
84 memcpy(&info
->mask
, mask
, sizeof(*mask
));
87 pthread_attr_init(&attr
);
88 pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
90 pthread_create(&tid
, &attr
, sigwait_compat
, info
);
92 pthread_attr_destroy(&attr
);
97 int kvm_signalfd(const sigset_t
*mask
)
99 #if defined(SYS_signalfd)
102 ret
= syscall(SYS_signalfd
, -1, mask
, _NSIG
/ 8);
103 if (!(ret
== -1 && errno
== ENOSYS
))
107 return kvm_signalfd_compat(mask
);
110 int kvm_eventfd(int *fds
)
112 #if defined(SYS_eventfd)
115 ret
= syscall(SYS_eventfd
, 0);
117 fds
[0] = fds
[1] = ret
;
119 } else if (!(ret
== -1 && errno
== ENOSYS
))