1//! Adapt the Linux API to resemble a POSIX-style libc API.
2//!
3//! The linux_raw backend doesn't use actual libc; this just defines certain
4//! types that are convenient to have defined.
5
6#![allow(unused_imports)]
7#![allow(non_camel_case_types)]
8
9pub(crate) type size_t = usize;
10pub(crate) use linux_raw_sys::ctypes::*;
11pub(crate) use linux_raw_sys::errno::EINVAL;
12pub(crate) use linux_raw_sys::ioctl::{FIONBIO, FIONREAD};
13// Import the kernel's `uid_t` and `gid_t` if they're 32-bit.
14#[cfg(not(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86")))]
15pub(crate) use linux_raw_sys::general::{__kernel_gid_t as gid_t, __kernel_uid_t as uid_t};
16pub(crate) use linux_raw_sys::general::{
17 __kernel_pid_t as pid_t, __kernel_time64_t as time_t, __kernel_timespec as timespec, iovec,
18 O_CLOEXEC, O_NOCTTY, O_NONBLOCK, O_RDWR,
19};
20
21#[cfg(feature = "event")]
22#[cfg(test)]
23pub(crate) use linux_raw_sys::general::epoll_event;
24
25#[cfg(any(
26 feature = "fs",
27 all(
28 not(feature = "use-libc-auxv"),
29 not(feature = "use-explicitly-provided-auxv"),
30 any(
31 feature = "param",
32 feature = "process",
33 feature = "runtime",
34 feature = "time",
35 target_arch = "x86",
36 )
37 )
38))]
39pub(crate) use linux_raw_sys::general::{
40 AT_FDCWD, NFS_SUPER_MAGIC, O_LARGEFILE, PROC_SUPER_MAGIC, UTIME_NOW, UTIME_OMIT, XATTR_CREATE,
41 XATTR_REPLACE,
42};
43
44pub(crate) use linux_raw_sys::ioctl::{BLKPBSZGET, BLKSSZGET, FICLONE};
45
46#[cfg(feature = "io_uring")]
47pub(crate) use linux_raw_sys::{general::open_how, io_uring::*};
48
49#[cfg(feature = "net")]
50pub(crate) use linux_raw_sys::{
51 cmsg_macros::*,
52 general::{O_CLOEXEC as SOCK_CLOEXEC, O_NONBLOCK as SOCK_NONBLOCK},
53 if_ether::*,
54 net::{
55 linger, msghdr, sockaddr, sockaddr_in, sockaddr_in6, sockaddr_un, socklen_t, AF_DECnet,
56 __kernel_sa_family_t as sa_family_t, __kernel_sockaddr_storage as sockaddr_storage,
57 cmsghdr, in6_addr, in_addr, ip_mreq, ip_mreq_source, ip_mreqn, ipv6_mreq, AF_APPLETALK,
58 AF_ASH, AF_ATMPVC, AF_ATMSVC, AF_AX25, AF_BLUETOOTH, AF_BRIDGE, AF_CAN, AF_ECONET,
59 AF_IEEE802154, AF_INET, AF_INET6, AF_IPX, AF_IRDA, AF_ISDN, AF_IUCV, AF_KEY, AF_LLC,
60 AF_NETBEUI, AF_NETLINK, AF_NETROM, AF_PACKET, AF_PHONET, AF_PPPOX, AF_RDS, AF_ROSE,
61 AF_RXRPC, AF_SECURITY, AF_SNA, AF_TIPC, AF_UNIX, AF_UNSPEC, AF_WANPIPE, AF_X25,
62 IP6T_SO_ORIGINAL_DST, IPPROTO_FRAGMENT, IPPROTO_ICMPV6, IPPROTO_MH, IPPROTO_ROUTING,
63 IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP, IPV6_FREEBIND, IPV6_MULTICAST_HOPS,
64 IPV6_MULTICAST_LOOP, IPV6_RECVTCLASS, IPV6_TCLASS, IPV6_UNICAST_HOPS, IPV6_V6ONLY,
65 IP_ADD_MEMBERSHIP, IP_ADD_SOURCE_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_DROP_SOURCE_MEMBERSHIP,
66 IP_FREEBIND, IP_MULTICAST_LOOP, IP_MULTICAST_TTL, IP_RECVTOS, IP_TOS, IP_TTL,
67 MSG_CMSG_CLOEXEC, MSG_CONFIRM, MSG_DONTROUTE, MSG_DONTWAIT, MSG_EOR, MSG_ERRQUEUE,
68 MSG_MORE, MSG_NOSIGNAL, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, SCM_CREDENTIALS,
69 SCM_RIGHTS, SHUT_RD, SHUT_RDWR, SHUT_WR, SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET,
70 SOCK_STREAM, SOL_SOCKET, SO_ACCEPTCONN, SO_BROADCAST, SO_COOKIE, SO_DOMAIN, SO_ERROR,
71 SO_INCOMING_CPU, SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_ORIGINAL_DST, SO_PASSCRED,
72 SO_PROTOCOL, SO_RCVBUF, SO_RCVTIMEO_NEW, SO_RCVTIMEO_NEW as SO_RCVTIMEO, SO_RCVTIMEO_OLD,
73 SO_REUSEADDR, SO_REUSEPORT, SO_SNDBUF, SO_SNDTIMEO_NEW, SO_SNDTIMEO_NEW as SO_SNDTIMEO,
74 SO_SNDTIMEO_OLD, SO_TYPE, TCP_CONGESTION, TCP_CORK, TCP_KEEPCNT, TCP_KEEPIDLE,
75 TCP_KEEPINTVL, TCP_NODELAY, TCP_QUICKACK, TCP_THIN_LINEAR_TIMEOUTS, TCP_USER_TIMEOUT,
76 },
77 netlink::*,
78};
79
80// Cast away bindgen's `enum` type to make these consistent with the other
81// `setsockopt`/`getsockopt` level values.
82#[cfg(feature = "net")]
83pub(crate) const IPPROTO_IP: u32 = linux_raw_sys::net::IPPROTO_IP as _;
84#[cfg(feature = "net")]
85pub(crate) const IPPROTO_ICMP: u32 = linux_raw_sys::net::IPPROTO_ICMP as _;
86#[cfg(feature = "net")]
87pub(crate) const IPPROTO_IGMP: u32 = linux_raw_sys::net::IPPROTO_IGMP as _;
88#[cfg(feature = "net")]
89pub(crate) const IPPROTO_IPIP: u32 = linux_raw_sys::net::IPPROTO_IPIP as _;
90#[cfg(feature = "net")]
91pub(crate) const IPPROTO_TCP: u32 = linux_raw_sys::net::IPPROTO_TCP as _;
92#[cfg(feature = "net")]
93pub(crate) const IPPROTO_EGP: u32 = linux_raw_sys::net::IPPROTO_EGP as _;
94#[cfg(feature = "net")]
95pub(crate) const IPPROTO_PUP: u32 = linux_raw_sys::net::IPPROTO_PUP as _;
96#[cfg(feature = "net")]
97pub(crate) const IPPROTO_UDP: u32 = linux_raw_sys::net::IPPROTO_UDP as _;
98#[cfg(feature = "net")]
99pub(crate) const IPPROTO_IDP: u32 = linux_raw_sys::net::IPPROTO_IDP as _;
100#[cfg(feature = "net")]
101pub(crate) const IPPROTO_TP: u32 = linux_raw_sys::net::IPPROTO_TP as _;
102#[cfg(feature = "net")]
103pub(crate) const IPPROTO_DCCP: u32 = linux_raw_sys::net::IPPROTO_DCCP as _;
104#[cfg(feature = "net")]
105pub(crate) const IPPROTO_IPV6: u32 = linux_raw_sys::net::IPPROTO_IPV6 as _;
106#[cfg(feature = "net")]
107pub(crate) const IPPROTO_RSVP: u32 = linux_raw_sys::net::IPPROTO_RSVP as _;
108#[cfg(feature = "net")]
109pub(crate) const IPPROTO_GRE: u32 = linux_raw_sys::net::IPPROTO_GRE as _;
110#[cfg(feature = "net")]
111pub(crate) const IPPROTO_ESP: u32 = linux_raw_sys::net::IPPROTO_ESP as _;
112#[cfg(feature = "net")]
113pub(crate) const IPPROTO_AH: u32 = linux_raw_sys::net::IPPROTO_AH as _;
114#[cfg(feature = "net")]
115pub(crate) const IPPROTO_MTP: u32 = linux_raw_sys::net::IPPROTO_MTP as _;
116#[cfg(feature = "net")]
117pub(crate) const IPPROTO_BEETPH: u32 = linux_raw_sys::net::IPPROTO_BEETPH as _;
118#[cfg(feature = "net")]
119pub(crate) const IPPROTO_ENCAP: u32 = linux_raw_sys::net::IPPROTO_ENCAP as _;
120#[cfg(feature = "net")]
121pub(crate) const IPPROTO_PIM: u32 = linux_raw_sys::net::IPPROTO_PIM as _;
122#[cfg(feature = "net")]
123pub(crate) const IPPROTO_COMP: u32 = linux_raw_sys::net::IPPROTO_COMP as _;
124#[cfg(feature = "net")]
125pub(crate) const IPPROTO_SCTP: u32 = linux_raw_sys::net::IPPROTO_SCTP as _;
126#[cfg(feature = "net")]
127pub(crate) const IPPROTO_UDPLITE: u32 = linux_raw_sys::net::IPPROTO_UDPLITE as _;
128#[cfg(feature = "net")]
129pub(crate) const IPPROTO_MPLS: u32 = linux_raw_sys::net::IPPROTO_MPLS as _;
130#[cfg(feature = "net")]
131pub(crate) const IPPROTO_ETHERNET: u32 = linux_raw_sys::net::IPPROTO_ETHERNET as _;
132#[cfg(feature = "net")]
133pub(crate) const IPPROTO_RAW: u32 = linux_raw_sys::net::IPPROTO_RAW as _;
134#[cfg(feature = "net")]
135pub(crate) const IPPROTO_MPTCP: u32 = linux_raw_sys::net::IPPROTO_MPTCP as _;
136
137#[cfg(any(feature = "process", feature = "runtime"))]
138pub(crate) use linux_raw_sys::general::siginfo_t;
139
140#[cfg(any(feature = "process", feature = "runtime"))]
141pub(crate) const EXIT_SUCCESS: c_int = 0;
142#[cfg(any(feature = "process", feature = "runtime"))]
143pub(crate) const EXIT_FAILURE: c_int = 1;
144#[cfg(feature = "process")]
145pub(crate) const EXIT_SIGNALED_SIGABRT: c_int = 128 + linux_raw_sys::general::SIGABRT as c_int;
146#[cfg(feature = "runtime")]
147pub(crate) const CLONE_CHILD_SETTID: c_int = linux_raw_sys::general::CLONE_CHILD_SETTID as c_int;
148
149#[cfg(feature = "process")]
150pub(crate) use linux_raw_sys::{
151 general::{
152 CLD_CONTINUED, CLD_DUMPED, CLD_EXITED, CLD_KILLED, CLD_STOPPED, CLD_TRAPPED,
153 O_NONBLOCK as PIDFD_NONBLOCK, P_ALL, P_PGID, P_PID, P_PIDFD,
154 },
155 ioctl::TIOCSCTTY,
156};
157
158#[cfg(feature = "pty")]
159pub(crate) use linux_raw_sys::ioctl::TIOCGPTPEER;
160
161#[cfg(feature = "termios")]
162pub(crate) use linux_raw_sys::{
163 general::{
164 cc_t, speed_t, tcflag_t, termios, termios2, winsize, B0, B1000000, B110, B115200, B1152000,
165 B1200, B134, B150, B1500000, B1800, B19200, B200, B2000000, B230400, B2400, B2500000, B300,
166 B3000000, B3500000, B38400, B4000000, B460800, B4800, B50, B500000, B57600, B576000, B600,
167 B75, B921600, B9600, BOTHER, BRKINT, BS0, BS1, BSDLY, CBAUD, CBAUDEX, CIBAUD, CLOCAL,
168 CMSPAR, CR0, CR1, CR2, CR3, CRDLY, CREAD, CRTSCTS, CS5, CS6, CS7, CS8, CSIZE, CSTOPB, ECHO,
169 ECHOCTL, ECHOE, ECHOK, ECHOKE, ECHONL, ECHOPRT, EXTA, EXTB, EXTPROC, FF0, FF1, FFDLY,
170 FLUSHO, HUPCL, IBSHIFT, ICANON, ICRNL, IEXTEN, IGNBRK, IGNCR, IGNPAR, IMAXBEL, INLCR,
171 INPCK, ISIG, ISTRIP, IUCLC, IUTF8, IXANY, IXOFF, IXON, NCCS, NL0, NL1, NLDLY, NOFLSH,
172 OCRNL, OFDEL, OFILL, OLCUC, ONLCR, ONLRET, ONOCR, OPOST, PARENB, PARMRK, PARODD, PENDIN,
173 TAB0, TAB1, TAB2, TAB3, TABDLY, TCIFLUSH, TCIOFF, TCIOFLUSH, TCION, TCOFLUSH, TCOOFF,
174 TCOON, TCSADRAIN, TCSAFLUSH, TCSANOW, TOSTOP, VDISCARD, VEOF, VEOL, VEOL2, VERASE, VINTR,
175 VKILL, VLNEXT, VMIN, VQUIT, VREPRINT, VSTART, VSTOP, VSUSP, VSWTC, VT0, VT1, VTDLY, VTIME,
176 VWERASE, XCASE, XTABS,
177 },
178 ioctl::{TCGETS2, TCSETS2, TCSETSF2, TCSETSW2, TIOCEXCL, TIOCNXCL},
179};
180
181// On MIPS, `TCSANOW` et al have `TCSETS` added to them, so we need it to
182// subtract it out.
183#[cfg(all(
184 feature = "termios",
185 any(
186 target_arch = "mips",
187 target_arch = "mips32r6",
188 target_arch = "mips64",
189 target_arch = "mips64r6"
190 )
191))]
192pub(crate) use linux_raw_sys::ioctl::TCSETS;
193
194// Define our own `uid_t` and `gid_t` if the kernel's versions are not 32-bit.
195#[cfg(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86"))]
196pub(crate) type uid_t = u32;
197#[cfg(any(target_arch = "arm", target_arch = "sparc", target_arch = "x86"))]
198pub(crate) type gid_t = u32;
199
200// Bindgen infers `u32` for many of these macro types which meant to be
201// used with `c_int` in the C APIs, so cast them to `c_int`.
202
203// Convert the signal constants from `u32` to `c_int`.
204pub(crate) const SIGHUP: c_int = linux_raw_sys::general::SIGHUP as _;
205pub(crate) const SIGINT: c_int = linux_raw_sys::general::SIGINT as _;
206pub(crate) const SIGQUIT: c_int = linux_raw_sys::general::SIGQUIT as _;
207pub(crate) const SIGILL: c_int = linux_raw_sys::general::SIGILL as _;
208pub(crate) const SIGTRAP: c_int = linux_raw_sys::general::SIGTRAP as _;
209pub(crate) const SIGABRT: c_int = linux_raw_sys::general::SIGABRT as _;
210pub(crate) const SIGBUS: c_int = linux_raw_sys::general::SIGBUS as _;
211pub(crate) const SIGFPE: c_int = linux_raw_sys::general::SIGFPE as _;
212pub(crate) const SIGKILL: c_int = linux_raw_sys::general::SIGKILL as _;
213pub(crate) const SIGUSR1: c_int = linux_raw_sys::general::SIGUSR1 as _;
214pub(crate) const SIGSEGV: c_int = linux_raw_sys::general::SIGSEGV as _;
215pub(crate) const SIGUSR2: c_int = linux_raw_sys::general::SIGUSR2 as _;
216pub(crate) const SIGPIPE: c_int = linux_raw_sys::general::SIGPIPE as _;
217pub(crate) const SIGALRM: c_int = linux_raw_sys::general::SIGALRM as _;
218pub(crate) const SIGTERM: c_int = linux_raw_sys::general::SIGTERM as _;
219#[cfg(not(any(
220 target_arch = "mips",
221 target_arch = "mips32r6",
222 target_arch = "mips64",
223 target_arch = "mips64r6",
224 target_arch = "sparc",
225 target_arch = "sparc64"
226)))]
227pub(crate) const SIGSTKFLT: c_int = linux_raw_sys::general::SIGSTKFLT as _;
228pub(crate) const SIGCHLD: c_int = linux_raw_sys::general::SIGCHLD as _;
229pub(crate) const SIGCONT: c_int = linux_raw_sys::general::SIGCONT as _;
230pub(crate) const SIGSTOP: c_int = linux_raw_sys::general::SIGSTOP as _;
231pub(crate) const SIGTSTP: c_int = linux_raw_sys::general::SIGTSTP as _;
232pub(crate) const SIGTTIN: c_int = linux_raw_sys::general::SIGTTIN as _;
233pub(crate) const SIGTTOU: c_int = linux_raw_sys::general::SIGTTOU as _;
234pub(crate) const SIGURG: c_int = linux_raw_sys::general::SIGURG as _;
235pub(crate) const SIGXCPU: c_int = linux_raw_sys::general::SIGXCPU as _;
236pub(crate) const SIGXFSZ: c_int = linux_raw_sys::general::SIGXFSZ as _;
237pub(crate) const SIGVTALRM: c_int = linux_raw_sys::general::SIGVTALRM as _;
238pub(crate) const SIGPROF: c_int = linux_raw_sys::general::SIGPROF as _;
239pub(crate) const SIGWINCH: c_int = linux_raw_sys::general::SIGWINCH as _;
240pub(crate) const SIGIO: c_int = linux_raw_sys::general::SIGIO as _;
241pub(crate) const SIGPWR: c_int = linux_raw_sys::general::SIGPWR as _;
242pub(crate) const SIGSYS: c_int = linux_raw_sys::general::SIGSYS as _;
243#[cfg(any(
244 target_arch = "mips",
245 target_arch = "mips32r6",
246 target_arch = "mips64",
247 target_arch = "mips64r6",
248 target_arch = "sparc",
249 target_arch = "sparc64"
250))]
251pub(crate) const SIGEMT: c_int = linux_raw_sys::general::SIGEMT as _;
252
253#[cfg(feature = "stdio")]
254pub(crate) const STDIN_FILENO: c_int = linux_raw_sys::general::STDIN_FILENO as _;
255#[cfg(feature = "stdio")]
256pub(crate) const STDOUT_FILENO: c_int = linux_raw_sys::general::STDOUT_FILENO as _;
257#[cfg(feature = "stdio")]
258pub(crate) const STDERR_FILENO: c_int = linux_raw_sys::general::STDERR_FILENO as _;
259
260pub(crate) const PIPE_BUF: usize = linux_raw_sys::general::PIPE_BUF as _;
261
262pub(crate) const CLOCK_MONOTONIC: c_int = linux_raw_sys::general::CLOCK_MONOTONIC as _;
263pub(crate) const CLOCK_REALTIME: c_int = linux_raw_sys::general::CLOCK_REALTIME as _;
264pub(crate) const CLOCK_MONOTONIC_RAW: c_int = linux_raw_sys::general::CLOCK_MONOTONIC_RAW as _;
265pub(crate) const CLOCK_MONOTONIC_COARSE: c_int =
266 linux_raw_sys::general::CLOCK_MONOTONIC_COARSE as _;
267pub(crate) const CLOCK_REALTIME_COARSE: c_int = linux_raw_sys::general::CLOCK_REALTIME_COARSE as _;
268pub(crate) const CLOCK_THREAD_CPUTIME_ID: c_int =
269 linux_raw_sys::general::CLOCK_THREAD_CPUTIME_ID as _;
270pub(crate) const CLOCK_PROCESS_CPUTIME_ID: c_int =
271 linux_raw_sys::general::CLOCK_PROCESS_CPUTIME_ID as _;
272#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))]
273pub(crate) const CLOCK_BOOTTIME: c_int = linux_raw_sys::general::CLOCK_BOOTTIME as _;
274#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))]
275pub(crate) const CLOCK_BOOTTIME_ALARM: c_int = linux_raw_sys::general::CLOCK_BOOTTIME_ALARM as _;
276#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))]
277pub(crate) const CLOCK_TAI: c_int = linux_raw_sys::general::CLOCK_TAI as _;
278#[cfg(any(feature = "thread", feature = "time", target_arch = "x86"))]
279pub(crate) const CLOCK_REALTIME_ALARM: c_int = linux_raw_sys::general::CLOCK_REALTIME_ALARM as _;
280
281#[cfg(feature = "system")]
282mod reboot_symbols {
283 use super::c_int;
284
285 pub(crate) const LINUX_REBOOT_MAGIC1: c_int = linux_raw_sys::general::LINUX_REBOOT_MAGIC1 as _;
286 pub(crate) const LINUX_REBOOT_MAGIC2: c_int = linux_raw_sys::general::LINUX_REBOOT_MAGIC2 as _;
287
288 pub(crate) const LINUX_REBOOT_CMD_RESTART: c_int =
289 linux_raw_sys::general::LINUX_REBOOT_CMD_RESTART as _;
290 pub(crate) const LINUX_REBOOT_CMD_HALT: c_int =
291 linux_raw_sys::general::LINUX_REBOOT_CMD_HALT as _;
292 pub(crate) const LINUX_REBOOT_CMD_CAD_ON: c_int =
293 linux_raw_sys::general::LINUX_REBOOT_CMD_CAD_ON as _;
294 pub(crate) const LINUX_REBOOT_CMD_CAD_OFF: c_int =
295 linux_raw_sys::general::LINUX_REBOOT_CMD_CAD_OFF as _;
296 pub(crate) const LINUX_REBOOT_CMD_POWER_OFF: c_int =
297 linux_raw_sys::general::LINUX_REBOOT_CMD_POWER_OFF as _;
298 pub(crate) const LINUX_REBOOT_CMD_SW_SUSPEND: c_int =
299 linux_raw_sys::general::LINUX_REBOOT_CMD_SW_SUSPEND as _;
300 pub(crate) const LINUX_REBOOT_CMD_KEXEC: c_int =
301 linux_raw_sys::general::LINUX_REBOOT_CMD_KEXEC as _;
302}
303#[cfg(feature = "system")]
304pub(crate) use reboot_symbols::*;
305