1 use crate::prelude::*;
2 use crate::Ioctl;
3 
4 s! {
5     pub struct termios2 {
6         pub c_iflag: crate::tcflag_t,
7         pub c_oflag: crate::tcflag_t,
8         pub c_cflag: crate::tcflag_t,
9         pub c_lflag: crate::tcflag_t,
10         pub c_line: crate::cc_t,
11         pub c_cc: [crate::cc_t; 19],
12         pub c_ispeed: crate::speed_t,
13         pub c_ospeed: crate::speed_t,
14     }
15 }
16 
17 // include/uapi/asm-generic/socket.h
18 // arch/alpha/include/uapi/asm/socket.h
19 // tools/include/uapi/asm-generic/socket.h
20 // arch/mips/include/uapi/asm/socket.h
21 pub const SOL_SOCKET: c_int = 1;
22 
23 // Defined in unix/linux_like/mod.rs
24 // pub const SO_DEBUG: c_int = 1;
25 pub const SO_REUSEADDR: c_int = 2;
26 pub const SO_TYPE: c_int = 3;
27 pub const SO_ERROR: c_int = 4;
28 pub const SO_DONTROUTE: c_int = 5;
29 pub const SO_BROADCAST: c_int = 6;
30 pub const SO_SNDBUF: c_int = 7;
31 pub const SO_RCVBUF: c_int = 8;
32 pub const SO_KEEPALIVE: c_int = 9;
33 pub const SO_OOBINLINE: c_int = 10;
34 pub const SO_NO_CHECK: c_int = 11;
35 pub const SO_PRIORITY: c_int = 12;
36 pub const SO_LINGER: c_int = 13;
37 pub const SO_BSDCOMPAT: c_int = 14;
38 pub const SO_REUSEPORT: c_int = 15;
39 pub const SO_PASSCRED: c_int = 16;
40 pub const SO_PEERCRED: c_int = 17;
41 pub const SO_RCVLOWAT: c_int = 18;
42 pub const SO_SNDLOWAT: c_int = 19;
43 pub const SO_SECURITY_AUTHENTICATION: c_int = 22;
44 pub const SO_SECURITY_ENCRYPTION_TRANSPORT: c_int = 23;
45 pub const SO_SECURITY_ENCRYPTION_NETWORK: c_int = 24;
46 pub const SO_BINDTODEVICE: c_int = 25;
47 pub const SO_ATTACH_FILTER: c_int = 26;
48 pub const SO_DETACH_FILTER: c_int = 27;
49 pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER;
50 pub const SO_PEERNAME: c_int = 28;
51 
52 cfg_if! {
53     if #[cfg(all(
54         linux_time_bits64,
55         any(target_arch = "arm", target_arch = "x86"),
56         not(any(target_env = "musl", target_env = "ohos"))
57     ))] {
58         pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW;
59         pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW;
60         pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW;
61         pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_NEW;
62         pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_NEW;
63     } else if #[cfg(all(
64         linux_time_bits64,
65         any(target_arch = "arm", target_arch = "x86"),
66         any(target_env = "musl", target_env = "ohos")
67     ))] {
68         pub const SO_TIMESTAMP: c_int = 63;
69         pub const SO_TIMESTAMPNS: c_int = 64;
70         pub const SO_TIMESTAMPING: c_int = 65;
71         pub const SO_RCVTIMEO: c_int = 66;
72         pub const SO_SNDTIMEO: c_int = 67;
73     } else {
74         const SO_TIMESTAMP_OLD: c_int = 29;
75         const SO_TIMESTAMPNS_OLD: c_int = 35;
76         const SO_TIMESTAMPING_OLD: c_int = 37;
77         const SO_RCVTIMEO_OLD: c_int = 20;
78         const SO_SNDTIMEO_OLD: c_int = 21;
79 
80         pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD;
81         pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD;
82         pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD;
83         pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD;
84         pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD;
85     }
86 }
87 
88 pub const SO_ACCEPTCONN: c_int = 30;
89 pub const SO_PEERSEC: c_int = 31;
90 pub const SO_SNDBUFFORCE: c_int = 32;
91 pub const SO_RCVBUFFORCE: c_int = 33;
92 pub const SO_PASSSEC: c_int = 34;
93 pub const SO_MARK: c_int = 36;
94 pub const SO_PROTOCOL: c_int = 38;
95 pub const SO_DOMAIN: c_int = 39;
96 pub const SO_RXQ_OVFL: c_int = 40;
97 pub const SO_WIFI_STATUS: c_int = 41;
98 pub const SCM_WIFI_STATUS: c_int = SO_WIFI_STATUS;
99 pub const SO_PEEK_OFF: c_int = 42;
100 pub const SO_NOFCS: c_int = 43;
101 pub const SO_LOCK_FILTER: c_int = 44;
102 pub const SO_SELECT_ERR_QUEUE: c_int = 45;
103 pub const SO_BUSY_POLL: c_int = 46;
104 pub const SO_MAX_PACING_RATE: c_int = 47;
105 pub const SO_BPF_EXTENSIONS: c_int = 48;
106 pub const SO_INCOMING_CPU: c_int = 49;
107 pub const SO_ATTACH_BPF: c_int = 50;
108 pub const SO_DETACH_BPF: c_int = SO_DETACH_FILTER;
109 pub const SO_ATTACH_REUSEPORT_CBPF: c_int = 51;
110 pub const SO_ATTACH_REUSEPORT_EBPF: c_int = 52;
111 pub const SO_CNX_ADVICE: c_int = 53;
112 pub const SCM_TIMESTAMPING_OPT_STATS: c_int = 54;
113 pub const SO_MEMINFO: c_int = 55;
114 pub const SO_INCOMING_NAPI_ID: c_int = 56;
115 pub const SO_COOKIE: c_int = 57;
116 pub const SCM_TIMESTAMPING_PKTINFO: c_int = 58;
117 pub const SO_PEERGROUPS: c_int = 59;
118 pub const SO_ZEROCOPY: c_int = 60;
119 pub const SO_TXTIME: c_int = 61;
120 pub const SCM_TXTIME: c_int = SO_TXTIME;
121 pub const SO_BINDTOIFINDEX: c_int = 62;
122 cfg_if! {
123     // Some of these platforms in CI already have these constants.
124     // But they may still not have those _OLD ones.
125     if #[cfg(all(
126         any(
127             target_arch = "x86",
128             target_arch = "x86_64",
129             target_arch = "arm",
130             target_arch = "aarch64",
131             target_arch = "csky",
132             target_arch = "loongarch64"
133         ),
134         // FIXME(musl):
135         // Musl hardcodes the SO_* constants instead
136         // of inheriting them from the kernel headers.
137         // For new constants you might need consider updating
138         // musl in the CI as well.
139         not(any(target_env = "musl", target_env = "ohos"))
140     ))] {
141         pub const SO_TIMESTAMP_NEW: c_int = 63;
142         pub const SO_TIMESTAMPNS_NEW: c_int = 64;
143         pub const SO_TIMESTAMPING_NEW: c_int = 65;
144         pub const SO_RCVTIMEO_NEW: c_int = 66;
145         pub const SO_SNDTIMEO_NEW: c_int = 67;
146         pub const SO_DETACH_REUSEPORT_BPF: c_int = 68;
147     }
148 }
149 pub const SO_PREFER_BUSY_POLL: c_int = 69;
150 pub const SO_BUSY_POLL_BUDGET: c_int = 70;
151 pub const SO_NETNS_COOKIE: c_int = 71;
152 pub const SO_BUF_LOCK: c_int = 72;
153 pub const SO_RESERVE_MEM: c_int = 73;
154 pub const SO_TXREHASH: c_int = 74;
155 pub const SO_RCVMARK: c_int = 75;
156 pub const SO_PASSPIDFD: c_int = 76;
157 pub const SO_PEERPIDFD: c_int = 77;
158 pub const SO_DEVMEM_LINEAR: c_int = 78;
159 pub const SO_DEVMEM_DMABUF: c_int = 79;
160 pub const SO_DEVMEM_DONTNEED: c_int = 80;
161 
162 // Defined in unix/linux_like/mod.rs
163 // pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP;
164 pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS;
165 pub const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING;
166 
167 pub const SCM_DEVMEM_LINEAR: c_int = SO_DEVMEM_LINEAR;
168 pub const SCM_DEVMEM_DMABUF: c_int = SO_DEVMEM_DMABUF;
169 
170 // Ioctl Constants
171 
172 pub const TCGETS: Ioctl = 0x5401;
173 pub const TCSETS: Ioctl = 0x5402;
174 pub const TCSETSW: Ioctl = 0x5403;
175 pub const TCSETSF: Ioctl = 0x5404;
176 pub const TCGETA: Ioctl = 0x5405;
177 pub const TCSETA: Ioctl = 0x5406;
178 pub const TCSETAW: Ioctl = 0x5407;
179 pub const TCSETAF: Ioctl = 0x5408;
180 pub const TCSBRK: Ioctl = 0x5409;
181 pub const TCXONC: Ioctl = 0x540A;
182 pub const TCFLSH: Ioctl = 0x540B;
183 pub const TIOCEXCL: Ioctl = 0x540C;
184 pub const TIOCNXCL: Ioctl = 0x540D;
185 pub const TIOCSCTTY: Ioctl = 0x540E;
186 pub const TIOCGPGRP: Ioctl = 0x540F;
187 pub const TIOCSPGRP: Ioctl = 0x5410;
188 pub const TIOCOUTQ: Ioctl = 0x5411;
189 pub const TIOCSTI: Ioctl = 0x5412;
190 pub const TIOCGWINSZ: Ioctl = 0x5413;
191 pub const TIOCSWINSZ: Ioctl = 0x5414;
192 pub const TIOCMGET: Ioctl = 0x5415;
193 pub const TIOCMBIS: Ioctl = 0x5416;
194 pub const TIOCMBIC: Ioctl = 0x5417;
195 pub const TIOCMSET: Ioctl = 0x5418;
196 pub const TIOCGSOFTCAR: Ioctl = 0x5419;
197 pub const TIOCSSOFTCAR: Ioctl = 0x541A;
198 pub const FIONREAD: Ioctl = 0x541B;
199 pub const TIOCINQ: Ioctl = FIONREAD;
200 pub const TIOCLINUX: Ioctl = 0x541C;
201 pub const TIOCCONS: Ioctl = 0x541D;
202 pub const TIOCGSERIAL: Ioctl = 0x541E;
203 pub const TIOCSSERIAL: Ioctl = 0x541F;
204 pub const TIOCPKT: Ioctl = 0x5420;
205 pub const FIONBIO: Ioctl = 0x5421;
206 pub const TIOCNOTTY: Ioctl = 0x5422;
207 pub const TIOCSETD: Ioctl = 0x5423;
208 pub const TIOCGETD: Ioctl = 0x5424;
209 pub const TCSBRKP: Ioctl = 0x5425;
210 pub const TIOCSBRK: Ioctl = 0x5427;
211 pub const TIOCCBRK: Ioctl = 0x5428;
212 pub const TIOCGSID: Ioctl = 0x5429;
213 pub const TCGETS2: Ioctl = 0x802c542a;
214 pub const TCSETS2: Ioctl = 0x402c542b;
215 pub const TCSETSW2: Ioctl = 0x402c542c;
216 pub const TCSETSF2: Ioctl = 0x402c542d;
217 pub const TIOCGRS485: Ioctl = 0x542E;
218 pub const TIOCSRS485: Ioctl = 0x542F;
219 pub const TIOCGPTN: Ioctl = 0x80045430;
220 pub const TIOCSPTLCK: Ioctl = 0x40045431;
221 pub const TIOCGDEV: Ioctl = 0x80045432;
222 pub const TCGETX: Ioctl = 0x5432;
223 pub const TCSETX: Ioctl = 0x5433;
224 pub const TCSETXF: Ioctl = 0x5434;
225 pub const TCSETXW: Ioctl = 0x5435;
226 pub const TIOCSIG: Ioctl = 0x40045436;
227 pub const TIOCVHANGUP: Ioctl = 0x5437;
228 pub const TIOCGPKT: Ioctl = 0x80045438;
229 pub const TIOCGPTLCK: Ioctl = 0x80045439;
230 pub const TIOCGEXCL: Ioctl = 0x80045440;
231 pub const TIOCGPTPEER: Ioctl = 0x5441;
232 // pub const TIOCGISO7816: Ioctl = 0x80285442;
233 // pub const TIOCSISO7816: Ioctl = 0xc0285443;
234 pub const FIONCLEX: Ioctl = 0x5450;
235 pub const FIOCLEX: Ioctl = 0x5451;
236 pub const FIOASYNC: Ioctl = 0x5452;
237 pub const TIOCSERCONFIG: Ioctl = 0x5453;
238 pub const TIOCSERGWILD: Ioctl = 0x5454;
239 pub const TIOCSERSWILD: Ioctl = 0x5455;
240 pub const TIOCGLCKTRMIOS: Ioctl = 0x5456;
241 pub const TIOCSLCKTRMIOS: Ioctl = 0x5457;
242 pub const TIOCSERGSTRUCT: Ioctl = 0x5458;
243 pub const TIOCSERGETLSR: Ioctl = 0x5459;
244 pub const TIOCSERGETMULTI: Ioctl = 0x545A;
245 pub const TIOCSERSETMULTI: Ioctl = 0x545B;
246 pub const TIOCMIWAIT: Ioctl = 0x545C;
247 pub const TIOCGICOUNT: Ioctl = 0x545D;
248 pub const BLKIOMIN: Ioctl = 0x1278;
249 pub const BLKIOOPT: Ioctl = 0x1279;
250 pub const BLKSSZGET: Ioctl = 0x1268;
251 pub const BLKPBSZGET: Ioctl = 0x127B;
252 
253 cfg_if! {
254     if #[cfg(any(target_arch = "arm", target_arch = "s390x"))] {
255         pub const FIOQSIZE: Ioctl = 0x545E;
256     } else {
257         pub const FIOQSIZE: Ioctl = 0x5460;
258     }
259 }
260 
261 pub const TIOCM_LE: c_int = 0x001;
262 pub const TIOCM_DTR: c_int = 0x002;
263 pub const TIOCM_RTS: c_int = 0x004;
264 pub const TIOCM_ST: c_int = 0x008;
265 pub const TIOCM_SR: c_int = 0x010;
266 pub const TIOCM_CTS: c_int = 0x020;
267 pub const TIOCM_CAR: c_int = 0x040;
268 pub const TIOCM_CD: c_int = TIOCM_CAR;
269 pub const TIOCM_RNG: c_int = 0x080;
270 pub const TIOCM_RI: c_int = TIOCM_RNG;
271 pub const TIOCM_DSR: c_int = 0x100;
272 
273 pub const BOTHER: crate::speed_t = 0o010000;
274 pub const IBSHIFT: crate::tcflag_t = 16;
275 
276 // RLIMIT Constants
277 
278 cfg_if! {
279     if #[cfg(any(target_env = "gnu", target_env = "uclibc"))] {
280         pub const RLIMIT_CPU: crate::__rlimit_resource_t = 0;
281         pub const RLIMIT_FSIZE: crate::__rlimit_resource_t = 1;
282         pub const RLIMIT_DATA: crate::__rlimit_resource_t = 2;
283         pub const RLIMIT_STACK: crate::__rlimit_resource_t = 3;
284         pub const RLIMIT_CORE: crate::__rlimit_resource_t = 4;
285         pub const RLIMIT_RSS: crate::__rlimit_resource_t = 5;
286         pub const RLIMIT_NPROC: crate::__rlimit_resource_t = 6;
287         pub const RLIMIT_NOFILE: crate::__rlimit_resource_t = 7;
288         pub const RLIMIT_MEMLOCK: crate::__rlimit_resource_t = 8;
289         pub const RLIMIT_AS: crate::__rlimit_resource_t = 9;
290         pub const RLIMIT_LOCKS: crate::__rlimit_resource_t = 10;
291         pub const RLIMIT_SIGPENDING: crate::__rlimit_resource_t = 11;
292         pub const RLIMIT_MSGQUEUE: crate::__rlimit_resource_t = 12;
293         pub const RLIMIT_NICE: crate::__rlimit_resource_t = 13;
294         pub const RLIMIT_RTPRIO: crate::__rlimit_resource_t = 14;
295         pub const RLIMIT_RTTIME: crate::__rlimit_resource_t = 15;
296         #[allow(deprecated)]
297         #[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
298         pub const RLIMIT_NLIMITS: crate::__rlimit_resource_t = RLIM_NLIMITS;
299     } else if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
300         pub const RLIMIT_CPU: c_int = 0;
301         pub const RLIMIT_FSIZE: c_int = 1;
302         pub const RLIMIT_DATA: c_int = 2;
303         pub const RLIMIT_STACK: c_int = 3;
304         pub const RLIMIT_CORE: c_int = 4;
305         pub const RLIMIT_RSS: c_int = 5;
306         pub const RLIMIT_NPROC: c_int = 6;
307         pub const RLIMIT_NOFILE: c_int = 7;
308         pub const RLIMIT_MEMLOCK: c_int = 8;
309         pub const RLIMIT_AS: c_int = 9;
310         pub const RLIMIT_LOCKS: c_int = 10;
311         pub const RLIMIT_SIGPENDING: c_int = 11;
312         pub const RLIMIT_MSGQUEUE: c_int = 12;
313         pub const RLIMIT_NICE: c_int = 13;
314         pub const RLIMIT_RTPRIO: c_int = 14;
315         pub const RLIMIT_RTTIME: c_int = 15;
316         #[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
317         pub const RLIM_NLIMITS: c_int = 16;
318         #[allow(deprecated)]
319         #[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
320         pub const RLIMIT_NLIMITS: c_int = RLIM_NLIMITS;
321     }
322 }
323 
324 cfg_if! {
325     if #[cfg(target_env = "gnu")] {
326         #[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
327         pub const RLIM_NLIMITS: crate::__rlimit_resource_t = 16;
328     } else if #[cfg(target_env = "uclibc")] {
329         #[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
330         pub const RLIM_NLIMITS: crate::__rlimit_resource_t = 15;
331     }
332 }
333 
334 pub const RLIM_INFINITY: crate::rlim_t = !0;
335