Rename to libusb-1.0
[platform/upstream/libusb.git] / libusb / signalfd.h
1 /*
2  * signalfd header
3  * Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
4  *
5  * Based on glibc header
6  * Copyright (C) 2007 Free Software Foundation, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 #ifndef __LIBUSB_SIGNALFD_H__
24 #define __LIBUSB_SIGNALFD_H__
25
26 /* FIXME: in future, remove this and unconditionally use glibc directly when
27  * glibc-2.8 is widespread */
28
29 #include <signal.h>
30 #include <stdint.h>
31
32 #ifdef __i386__
33 #define __NR_signalfd 321
34 #elif defined(__x86_64__)
35 #define __NR_signalfd 282
36 #else
37 #error "signalfd unsupported on this architecture"
38 #endif
39
40 /* signalfd() implementation was added as of glibc-2.7 */
41 #if __GLIBC_PREREQ(2, 7)
42 int signalfd(int fd, const sigset_t *mask, int flags);
43 #else
44 #include <sys/syscall.h>
45
46 #define SIZEOF_SIG (_NSIG / 8)
47 #define SIZEOF_SIGSET (SIZEOF_SIG > sizeof(sigset_t) ? sizeof(sigset_t): SIZEOF_SIG)
48
49 static inline int signalfd(int fd, const sigset_t *mask, int flags)
50 {
51         return syscall(__NR_signalfd, fd, mask, SIZEOF_SIGSET);
52 }
53 #endif
54
55 struct signalfd_siginfo {
56         uint32_t ssi_signo;
57         int32_t ssi_errno;
58         int32_t ssi_code;
59         uint32_t ssi_pid;
60         uint32_t ssi_uid;
61         int32_t ssi_fd;
62         uint32_t ssi_tid;
63         uint32_t ssi_band;
64         uint32_t ssi_overrun;
65         uint32_t ssi_trapno;
66         int32_t ssi_status;
67         int32_t ssi_int;
68         uint64_t ssi_ptr;
69         uint64_t ssi_utime;
70         uint64_t ssi_stime;
71         uint64_t ssi_addr;
72         uint8_t __pad[48];
73 };
74
75 #endif
76