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 const SO_RCVTIMEO_OLD: c_int = 20; 44 const SO_SNDTIMEO_OLD: c_int = 21; 45 pub const SO_SECURITY_AUTHENTICATION: c_int = 22; 46 pub const SO_SECURITY_ENCRYPTION_TRANSPORT: c_int = 23; 47 pub const SO_SECURITY_ENCRYPTION_NETWORK: c_int = 24; 48 pub const SO_BINDTODEVICE: c_int = 25; 49 pub const SO_ATTACH_FILTER: c_int = 26; 50 pub const SO_DETACH_FILTER: c_int = 27; 51 pub const SO_GET_FILTER: c_int = SO_ATTACH_FILTER; 52 pub const SO_PEERNAME: c_int = 28; 53 const SO_TIMESTAMP_OLD: c_int = 29; 54 const SO_TIMESTAMPNS_OLD: c_int = 35; 55 const SO_TIMESTAMPING_OLD: c_int = 37; 56 57 cfg_if! { 58 if #[cfg(all( 59 linux_time_bits64, 60 any(target_arch = "arm", target_arch = "x86"), 61 not(any(target_env = "musl", target_env = "ohos")) 62 ))] { 63 pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_NEW; 64 pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_NEW; 65 pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_NEW; 66 pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_NEW; 67 pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_NEW; 68 } else if #[cfg(all( 69 linux_time_bits64, 70 any(target_arch = "arm", target_arch = "x86"), 71 any(target_env = "musl", target_env = "ohos") 72 ))] { 73 pub const SO_TIMESTAMP: c_int = 63; 74 pub const SO_TIMESTAMPNS: c_int = 64; 75 pub const SO_TIMESTAMPING: c_int = 65; 76 pub const SO_RCVTIMEO: c_int = 66; 77 pub const SO_SNDTIMEO: c_int = 67; 78 } else { 79 pub const SO_TIMESTAMP: c_int = SO_TIMESTAMP_OLD; 80 pub const SO_TIMESTAMPNS: c_int = SO_TIMESTAMPNS_OLD; 81 pub const SO_TIMESTAMPING: c_int = SO_TIMESTAMPING_OLD; 82 pub const SO_RCVTIMEO: c_int = SO_RCVTIMEO_OLD; 83 pub const SO_SNDTIMEO: c_int = SO_SNDTIMEO_OLD; 84 } 85 } 86 87 pub const SO_ACCEPTCONN: c_int = 30; 88 pub const SO_PEERSEC: c_int = 31; 89 pub const SO_SNDBUFFORCE: c_int = 32; 90 pub const SO_RCVBUFFORCE: c_int = 33; 91 pub const SO_PASSSEC: c_int = 34; 92 pub const SO_MARK: c_int = 36; 93 pub const SO_PROTOCOL: c_int = 38; 94 pub const SO_DOMAIN: c_int = 39; 95 pub const SO_RXQ_OVFL: c_int = 40; 96 pub const SO_WIFI_STATUS: c_int = 41; 97 pub const SCM_WIFI_STATUS: c_int = SO_WIFI_STATUS; 98 pub const SO_PEEK_OFF: c_int = 42; 99 pub const SO_NOFCS: c_int = 43; 100 pub const SO_LOCK_FILTER: c_int = 44; 101 pub const SO_SELECT_ERR_QUEUE: c_int = 45; 102 pub const SO_BUSY_POLL: c_int = 46; 103 pub const SO_MAX_PACING_RATE: c_int = 47; 104 pub const SO_BPF_EXTENSIONS: c_int = 48; 105 pub const SO_INCOMING_CPU: c_int = 49; 106 pub const SO_ATTACH_BPF: c_int = 50; 107 pub const SO_DETACH_BPF: c_int = SO_DETACH_FILTER; 108 pub const SO_ATTACH_REUSEPORT_CBPF: c_int = 51; 109 pub const SO_ATTACH_REUSEPORT_EBPF: c_int = 52; 110 pub const SO_CNX_ADVICE: c_int = 53; 111 pub const SCM_TIMESTAMPING_OPT_STATS: c_int = 54; 112 pub const SO_MEMINFO: c_int = 55; 113 pub const SO_INCOMING_NAPI_ID: c_int = 56; 114 pub const SO_COOKIE: c_int = 57; 115 pub const SCM_TIMESTAMPING_PKTINFO: c_int = 58; 116 pub const SO_PEERGROUPS: c_int = 59; 117 pub const SO_ZEROCOPY: c_int = 60; 118 pub const SO_TXTIME: c_int = 61; 119 pub const SCM_TXTIME: c_int = SO_TXTIME; 120 pub const SO_BINDTOIFINDEX: c_int = 62; 121 cfg_if! { 122 // Some of these platforms in CI already have these constants. 123 // But they may still not have those _OLD ones. 124 if #[cfg(all( 125 any( 126 target_arch = "x86", 127 target_arch = "x86_64", 128 target_arch = "arm", 129 target_arch = "aarch64", 130 target_arch = "csky", 131 target_arch = "loongarch64" 132 ), 133 // FIXME(musl): 134 // Musl hardcodes the SO_* constants instead 135 // of inheriting them from the kernel headers. 136 // For new constants you might need consider updating 137 // musl in the CI as well. 138 not(any(target_env = "musl", target_env = "ohos")) 139 ))] { 140 pub const SO_TIMESTAMP_NEW: c_int = 63; 141 pub const SO_TIMESTAMPNS_NEW: c_int = 64; 142 pub const SO_TIMESTAMPING_NEW: c_int = 65; 143 pub const SO_RCVTIMEO_NEW: c_int = 66; 144 pub const SO_SNDTIMEO_NEW: c_int = 67; 145 pub const SO_DETACH_REUSEPORT_BPF: c_int = 68; 146 } 147 } 148 pub const SO_PREFER_BUSY_POLL: c_int = 69; 149 pub const SO_BUSY_POLL_BUDGET: c_int = 70; 150 pub const SO_NETNS_COOKIE: c_int = 71; 151 pub const SO_BUF_LOCK: c_int = 72; 152 pub const SO_RESERVE_MEM: c_int = 73; 153 pub const SO_TXREHASH: c_int = 74; 154 pub const SO_RCVMARK: c_int = 75; 155 pub const SO_PASSPIDFD: c_int = 76; 156 pub const SO_PEERPIDFD: c_int = 77; 157 pub const SO_DEVMEM_LINEAR: c_int = 78; 158 pub const SO_DEVMEM_DMABUF: c_int = 79; 159 pub const SO_DEVMEM_DONTNEED: c_int = 80; 160 161 cfg_if! { 162 if #[cfg(any( 163 target_arch = "x86", 164 target_arch = "x86_64", 165 target_arch = "arm", 166 target_arch = "aarch64", 167 target_arch = "riscv64", 168 target_arch = "s390x", 169 target_arch = "csky", 170 target_arch = "loongarch64" 171 ))] { 172 pub const FICLONE: c_ulong = 0x40049409; 173 pub const FICLONERANGE: c_ulong = 0x4020940D; 174 } 175 } 176 177 // Defined in unix/linux_like/mod.rs 178 // pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; 179 pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS; 180 pub const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING; 181 182 pub const SCM_DEVMEM_LINEAR: c_int = SO_DEVMEM_LINEAR; 183 pub const SCM_DEVMEM_DMABUF: c_int = SO_DEVMEM_DMABUF; 184 185 // Ioctl Constants 186 187 pub const TCGETS: Ioctl = 0x5401; 188 pub const TCSETS: Ioctl = 0x5402; 189 pub const TCSETSW: Ioctl = 0x5403; 190 pub const TCSETSF: Ioctl = 0x5404; 191 pub const TCGETA: Ioctl = 0x5405; 192 pub const TCSETA: Ioctl = 0x5406; 193 pub const TCSETAW: Ioctl = 0x5407; 194 pub const TCSETAF: Ioctl = 0x5408; 195 pub const TCSBRK: Ioctl = 0x5409; 196 pub const TCXONC: Ioctl = 0x540A; 197 pub const TCFLSH: Ioctl = 0x540B; 198 pub const TIOCEXCL: Ioctl = 0x540C; 199 pub const TIOCNXCL: Ioctl = 0x540D; 200 pub const TIOCSCTTY: Ioctl = 0x540E; 201 pub const TIOCGPGRP: Ioctl = 0x540F; 202 pub const TIOCSPGRP: Ioctl = 0x5410; 203 pub const TIOCOUTQ: Ioctl = 0x5411; 204 pub const TIOCSTI: Ioctl = 0x5412; 205 pub const TIOCGWINSZ: Ioctl = 0x5413; 206 pub const TIOCSWINSZ: Ioctl = 0x5414; 207 pub const TIOCMGET: Ioctl = 0x5415; 208 pub const TIOCMBIS: Ioctl = 0x5416; 209 pub const TIOCMBIC: Ioctl = 0x5417; 210 pub const TIOCMSET: Ioctl = 0x5418; 211 pub const TIOCGSOFTCAR: Ioctl = 0x5419; 212 pub const TIOCSSOFTCAR: Ioctl = 0x541A; 213 pub const FIONREAD: Ioctl = 0x541B; 214 pub const TIOCINQ: Ioctl = FIONREAD; 215 pub const TIOCLINUX: Ioctl = 0x541C; 216 pub const TIOCCONS: Ioctl = 0x541D; 217 pub const TIOCGSERIAL: Ioctl = 0x541E; 218 pub const TIOCSSERIAL: Ioctl = 0x541F; 219 pub const TIOCPKT: Ioctl = 0x5420; 220 pub const FIONBIO: Ioctl = 0x5421; 221 pub const TIOCNOTTY: Ioctl = 0x5422; 222 pub const TIOCSETD: Ioctl = 0x5423; 223 pub const TIOCGETD: Ioctl = 0x5424; 224 pub const TCSBRKP: Ioctl = 0x5425; 225 pub const TIOCSBRK: Ioctl = 0x5427; 226 pub const TIOCCBRK: Ioctl = 0x5428; 227 pub const TIOCGSID: Ioctl = 0x5429; 228 pub const TCGETS2: Ioctl = 0x802c542a; 229 pub const TCSETS2: Ioctl = 0x402c542b; 230 pub const TCSETSW2: Ioctl = 0x402c542c; 231 pub const TCSETSF2: Ioctl = 0x402c542d; 232 pub const TIOCGRS485: Ioctl = 0x542E; 233 pub const TIOCSRS485: Ioctl = 0x542F; 234 pub const TIOCGPTN: Ioctl = 0x80045430; 235 pub const TIOCSPTLCK: Ioctl = 0x40045431; 236 pub const TIOCGDEV: Ioctl = 0x80045432; 237 pub const TCGETX: Ioctl = 0x5432; 238 pub const TCSETX: Ioctl = 0x5433; 239 pub const TCSETXF: Ioctl = 0x5434; 240 pub const TCSETXW: Ioctl = 0x5435; 241 pub const TIOCSIG: Ioctl = 0x40045436; 242 pub const TIOCVHANGUP: Ioctl = 0x5437; 243 pub const TIOCGPKT: Ioctl = 0x80045438; 244 pub const TIOCGPTLCK: Ioctl = 0x80045439; 245 pub const TIOCGEXCL: Ioctl = 0x80045440; 246 pub const TIOCGPTPEER: Ioctl = 0x5441; 247 // pub const TIOCGISO7816: Ioctl = 0x80285442; 248 // pub const TIOCSISO7816: Ioctl = 0xc0285443; 249 pub const FIONCLEX: Ioctl = 0x5450; 250 pub const FIOCLEX: Ioctl = 0x5451; 251 pub const FIOASYNC: Ioctl = 0x5452; 252 pub const TIOCSERCONFIG: Ioctl = 0x5453; 253 pub const TIOCSERGWILD: Ioctl = 0x5454; 254 pub const TIOCSERSWILD: Ioctl = 0x5455; 255 pub const TIOCGLCKTRMIOS: Ioctl = 0x5456; 256 pub const TIOCSLCKTRMIOS: Ioctl = 0x5457; 257 pub const TIOCSERGSTRUCT: Ioctl = 0x5458; 258 pub const TIOCSERGETLSR: Ioctl = 0x5459; 259 pub const TIOCSERGETMULTI: Ioctl = 0x545A; 260 pub const TIOCSERSETMULTI: Ioctl = 0x545B; 261 pub const TIOCMIWAIT: Ioctl = 0x545C; 262 pub const TIOCGICOUNT: Ioctl = 0x545D; 263 pub const BLKIOMIN: Ioctl = 0x1278; 264 pub const BLKIOOPT: Ioctl = 0x1279; 265 pub const BLKSSZGET: Ioctl = 0x1268; 266 pub const BLKPBSZGET: Ioctl = 0x127B; 267 // linux/if_tun.h 268 pub const TUNSETNOCSUM: Ioctl = 0x400454c8; 269 pub const TUNSETDEBUG: Ioctl = 0x400454c9; 270 pub const TUNSETIFF: Ioctl = 0x400454ca; 271 pub const TUNSETPERSIST: Ioctl = 0x400454cb; 272 pub const TUNSETOWNER: Ioctl = 0x400454cc; 273 pub const TUNSETLINK: Ioctl = 0x400454cd; 274 pub const TUNSETGROUP: Ioctl = 0x400454ce; 275 pub const TUNGETFEATURES: Ioctl = 0x800454cf; 276 pub const TUNSETOFFLOAD: Ioctl = 0x400454d0; 277 pub const TUNSETTXFILTER: Ioctl = 0x400454d1; 278 pub const TUNGETIFF: Ioctl = 0x800454d2; 279 pub const TUNGETSNDBUF: Ioctl = 0x800454d3; 280 pub const TUNSETSNDBUF: Ioctl = 0x400454d4; 281 pub const TUNGETVNETHDRSZ: Ioctl = 0x800454d7; 282 pub const TUNSETVNETHDRSZ: Ioctl = 0x400454d8; 283 pub const TUNSETQUEUE: Ioctl = 0x400454d9; 284 pub const TUNSETIFINDEX: Ioctl = 0x400454da; 285 pub const TUNSETVNETLE: Ioctl = 0x400454dc; 286 pub const TUNGETVNETLE: Ioctl = 0x800454dd; 287 /* The TUNSETVNETBE and TUNGETVNETBE ioctls are for cross-endian support on 288 * little-endian hosts. Not all kernel configurations support them, but all 289 * configurations that support SET also support GET. 290 */ 291 pub const TUNSETVNETBE: Ioctl = 0x400454de; 292 pub const TUNGETVNETBE: Ioctl = 0x800454df; 293 pub const TUNSETSTEERINGEBPF: Ioctl = 0x800454e0; 294 pub const TUNSETFILTEREBPF: Ioctl = 0x800454e1; 295 296 cfg_if! { 297 // Those type are constructed using the _IOC macro 298 // DD-SS_SSSS_SSSS_SSSS-TTTT_TTTT-NNNN_NNNN 299 // where D stands for direction (either None (00), Read (01) or Write (11)) 300 // where S stands for size (int, long, struct...) 301 // where T stands for type ('f','v','X'...) 302 // where N stands for NR (NumbeR) 303 if #[cfg(any( 304 target_arch = "x86", 305 target_arch = "arm", 306 target_arch = "csky" 307 ))] { 308 pub const FS_IOC_GETFLAGS: Ioctl = 0x80046601; 309 pub const FS_IOC_SETFLAGS: Ioctl = 0x40046602; 310 pub const FS_IOC_GETVERSION: Ioctl = 0x80047601; 311 pub const FS_IOC_SETVERSION: Ioctl = 0x40047602; 312 pub const FS_IOC32_GETFLAGS: Ioctl = 0x80046601; 313 pub const FS_IOC32_SETFLAGS: Ioctl = 0x40046602; 314 pub const FS_IOC32_GETVERSION: Ioctl = 0x80047601; 315 pub const FS_IOC32_SETVERSION: Ioctl = 0x40047602; 316 pub const TUNATTACHFILTER: Ioctl = 0x400854d5; 317 pub const TUNDETACHFILTER: Ioctl = 0x400854d6; 318 pub const TUNGETFILTER: Ioctl = 0x800854db; 319 } else if #[cfg(any( 320 target_arch = "x86_64", 321 target_arch = "riscv64", 322 target_arch = "aarch64", 323 target_arch = "s390x", 324 target_arch = "loongarch64", 325 target_arch = "wasm32" 326 ))] { 327 pub const FS_IOC_GETFLAGS: Ioctl = 0x80086601; 328 pub const FS_IOC_SETFLAGS: Ioctl = 0x40086602; 329 pub const FS_IOC_GETVERSION: Ioctl = 0x80087601; 330 pub const FS_IOC_SETVERSION: Ioctl = 0x40087602; 331 pub const FS_IOC32_GETFLAGS: Ioctl = 0x80046601; 332 pub const FS_IOC32_SETFLAGS: Ioctl = 0x40046602; 333 pub const FS_IOC32_GETVERSION: Ioctl = 0x80047601; 334 pub const FS_IOC32_SETVERSION: Ioctl = 0x40047602; 335 pub const TUNATTACHFILTER: Ioctl = 0x401054d5; 336 pub const TUNDETACHFILTER: Ioctl = 0x401054d6; 337 pub const TUNGETFILTER: Ioctl = 0x801054db; 338 } 339 } 340 341 cfg_if! { 342 if #[cfg(any(target_arch = "arm", target_arch = "s390x"))] { 343 pub const FIOQSIZE: Ioctl = 0x545E; 344 } else { 345 pub const FIOQSIZE: Ioctl = 0x5460; 346 } 347 } 348 349 pub const TIOCM_LE: c_int = 0x001; 350 pub const TIOCM_DTR: c_int = 0x002; 351 pub const TIOCM_RTS: c_int = 0x004; 352 pub const TIOCM_ST: c_int = 0x008; 353 pub const TIOCM_SR: c_int = 0x010; 354 pub const TIOCM_CTS: c_int = 0x020; 355 pub const TIOCM_CAR: c_int = 0x040; 356 pub const TIOCM_CD: c_int = TIOCM_CAR; 357 pub const TIOCM_RNG: c_int = 0x080; 358 pub const TIOCM_RI: c_int = TIOCM_RNG; 359 pub const TIOCM_DSR: c_int = 0x100; 360 361 pub const BOTHER: crate::speed_t = 0o010000; 362 pub const IBSHIFT: crate::tcflag_t = 16; 363 364 // RLIMIT Constants 365 366 cfg_if! { 367 if #[cfg(any(target_env = "gnu", target_env = "uclibc"))] { 368 pub const RLIMIT_CPU: crate::__rlimit_resource_t = 0; 369 pub const RLIMIT_FSIZE: crate::__rlimit_resource_t = 1; 370 pub const RLIMIT_DATA: crate::__rlimit_resource_t = 2; 371 pub const RLIMIT_STACK: crate::__rlimit_resource_t = 3; 372 pub const RLIMIT_CORE: crate::__rlimit_resource_t = 4; 373 pub const RLIMIT_RSS: crate::__rlimit_resource_t = 5; 374 pub const RLIMIT_NPROC: crate::__rlimit_resource_t = 6; 375 pub const RLIMIT_NOFILE: crate::__rlimit_resource_t = 7; 376 pub const RLIMIT_MEMLOCK: crate::__rlimit_resource_t = 8; 377 pub const RLIMIT_AS: crate::__rlimit_resource_t = 9; 378 pub const RLIMIT_LOCKS: crate::__rlimit_resource_t = 10; 379 pub const RLIMIT_SIGPENDING: crate::__rlimit_resource_t = 11; 380 pub const RLIMIT_MSGQUEUE: crate::__rlimit_resource_t = 12; 381 pub const RLIMIT_NICE: crate::__rlimit_resource_t = 13; 382 pub const RLIMIT_RTPRIO: crate::__rlimit_resource_t = 14; 383 pub const RLIMIT_RTTIME: crate::__rlimit_resource_t = 15; 384 #[allow(deprecated)] 385 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] 386 pub const RLIMIT_NLIMITS: crate::__rlimit_resource_t = RLIM_NLIMITS; 387 } else if #[cfg(any(target_env = "musl", target_env = "ohos"))] { 388 pub const RLIMIT_CPU: c_int = 0; 389 pub const RLIMIT_FSIZE: c_int = 1; 390 pub const RLIMIT_DATA: c_int = 2; 391 pub const RLIMIT_STACK: c_int = 3; 392 pub const RLIMIT_CORE: c_int = 4; 393 pub const RLIMIT_RSS: c_int = 5; 394 pub const RLIMIT_NPROC: c_int = 6; 395 pub const RLIMIT_NOFILE: c_int = 7; 396 pub const RLIMIT_MEMLOCK: c_int = 8; 397 pub const RLIMIT_AS: c_int = 9; 398 pub const RLIMIT_LOCKS: c_int = 10; 399 pub const RLIMIT_SIGPENDING: c_int = 11; 400 pub const RLIMIT_MSGQUEUE: c_int = 12; 401 pub const RLIMIT_NICE: c_int = 13; 402 pub const RLIMIT_RTPRIO: c_int = 14; 403 pub const RLIMIT_RTTIME: c_int = 15; 404 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] 405 #[cfg(not(target_arch = "loongarch64"))] 406 pub const RLIM_NLIMITS: c_int = 15; 407 #[cfg(target_arch = "loongarch64")] 408 pub const RLIM_NLIMITS: c_int = 16; 409 #[allow(deprecated)] 410 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] 411 pub const RLIMIT_NLIMITS: c_int = RLIM_NLIMITS; 412 } 413 } 414 415 cfg_if! { 416 if #[cfg(target_env = "gnu")] { 417 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] 418 pub const RLIM_NLIMITS: crate::__rlimit_resource_t = 16; 419 } else if #[cfg(target_env = "uclibc")] { 420 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] 421 pub const RLIM_NLIMITS: crate::__rlimit_resource_t = 15; 422 } 423 } 424 425 pub const RLIM_INFINITY: crate::rlim_t = !0; 426