1 use crate::prelude::*; 2 use crate::{Ioctl, _IOR, _IOW}; 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 pub const FICLONE: Ioctl = _IOW::<c_int>(0x94, 9) as Ioctl; 162 pub const FICLONERANGE: Ioctl = _IOW::<crate::file_clone_range>(0x94, 13) as Ioctl; 163 164 // Defined in unix/linux_like/mod.rs 165 // pub const SCM_TIMESTAMP: c_int = SO_TIMESTAMP; 166 pub const SCM_TIMESTAMPNS: c_int = SO_TIMESTAMPNS; 167 pub const SCM_TIMESTAMPING: c_int = SO_TIMESTAMPING; 168 169 pub const SCM_DEVMEM_LINEAR: c_int = SO_DEVMEM_LINEAR; 170 pub const SCM_DEVMEM_DMABUF: c_int = SO_DEVMEM_DMABUF; 171 172 // Ioctl Constants 173 174 pub const TCGETS: Ioctl = 0x5401; 175 pub const TCSETS: Ioctl = 0x5402; 176 pub const TCSETSW: Ioctl = 0x5403; 177 pub const TCSETSF: Ioctl = 0x5404; 178 pub const TCGETA: Ioctl = 0x5405; 179 pub const TCSETA: Ioctl = 0x5406; 180 pub const TCSETAW: Ioctl = 0x5407; 181 pub const TCSETAF: Ioctl = 0x5408; 182 pub const TCSBRK: Ioctl = 0x5409; 183 pub const TCXONC: Ioctl = 0x540A; 184 pub const TCFLSH: Ioctl = 0x540B; 185 pub const TIOCEXCL: Ioctl = 0x540C; 186 pub const TIOCNXCL: Ioctl = 0x540D; 187 pub const TIOCSCTTY: Ioctl = 0x540E; 188 pub const TIOCGPGRP: Ioctl = 0x540F; 189 pub const TIOCSPGRP: Ioctl = 0x5410; 190 pub const TIOCOUTQ: Ioctl = 0x5411; 191 pub const TIOCSTI: Ioctl = 0x5412; 192 pub const TIOCGWINSZ: Ioctl = 0x5413; 193 pub const TIOCSWINSZ: Ioctl = 0x5414; 194 pub const TIOCMGET: Ioctl = 0x5415; 195 pub const TIOCMBIS: Ioctl = 0x5416; 196 pub const TIOCMBIC: Ioctl = 0x5417; 197 pub const TIOCMSET: Ioctl = 0x5418; 198 pub const TIOCGSOFTCAR: Ioctl = 0x5419; 199 pub const TIOCSSOFTCAR: Ioctl = 0x541A; 200 pub const FIONREAD: Ioctl = 0x541B; 201 pub const TIOCINQ: Ioctl = FIONREAD; 202 pub const TIOCLINUX: Ioctl = 0x541C; 203 pub const TIOCCONS: Ioctl = 0x541D; 204 pub const TIOCGSERIAL: Ioctl = 0x541E; 205 pub const TIOCSSERIAL: Ioctl = 0x541F; 206 pub const TIOCPKT: Ioctl = 0x5420; 207 pub const FIONBIO: Ioctl = 0x5421; 208 pub const TIOCNOTTY: Ioctl = 0x5422; 209 pub const TIOCSETD: Ioctl = 0x5423; 210 pub const TIOCGETD: Ioctl = 0x5424; 211 pub const TCSBRKP: Ioctl = 0x5425; 212 pub const TIOCSBRK: Ioctl = 0x5427; 213 pub const TIOCCBRK: Ioctl = 0x5428; 214 pub const TIOCGSID: Ioctl = 0x5429; 215 pub const TCGETS2: Ioctl = 0x802c542a; 216 pub const TCSETS2: Ioctl = 0x402c542b; 217 pub const TCSETSW2: Ioctl = 0x402c542c; 218 pub const TCSETSF2: Ioctl = 0x402c542d; 219 pub const TIOCGRS485: Ioctl = 0x542E; 220 pub const TIOCSRS485: Ioctl = 0x542F; 221 pub const TIOCGPTN: Ioctl = 0x80045430; 222 pub const TIOCSPTLCK: Ioctl = 0x40045431; 223 pub const TIOCGDEV: Ioctl = 0x80045432; 224 pub const TCGETX: Ioctl = 0x5432; 225 pub const TCSETX: Ioctl = 0x5433; 226 pub const TCSETXF: Ioctl = 0x5434; 227 pub const TCSETXW: Ioctl = 0x5435; 228 pub const TIOCSIG: Ioctl = 0x40045436; 229 pub const TIOCVHANGUP: Ioctl = 0x5437; 230 pub const TIOCGPKT: Ioctl = 0x80045438; 231 pub const TIOCGPTLCK: Ioctl = 0x80045439; 232 pub const TIOCGEXCL: Ioctl = 0x80045440; 233 pub const TIOCGPTPEER: Ioctl = 0x5441; 234 // pub const TIOCGISO7816: Ioctl = 0x80285442; 235 // pub const TIOCSISO7816: Ioctl = 0xc0285443; 236 pub const FIONCLEX: Ioctl = 0x5450; 237 pub const FIOCLEX: Ioctl = 0x5451; 238 pub const FIOASYNC: Ioctl = 0x5452; 239 pub const TIOCSERCONFIG: Ioctl = 0x5453; 240 pub const TIOCSERGWILD: Ioctl = 0x5454; 241 pub const TIOCSERSWILD: Ioctl = 0x5455; 242 pub const TIOCGLCKTRMIOS: Ioctl = 0x5456; 243 pub const TIOCSLCKTRMIOS: Ioctl = 0x5457; 244 pub const TIOCSERGSTRUCT: Ioctl = 0x5458; 245 pub const TIOCSERGETLSR: Ioctl = 0x5459; 246 pub const TIOCSERGETMULTI: Ioctl = 0x545A; 247 pub const TIOCSERSETMULTI: Ioctl = 0x545B; 248 pub const TIOCMIWAIT: Ioctl = 0x545C; 249 pub const TIOCGICOUNT: Ioctl = 0x545D; 250 pub const BLKIOMIN: Ioctl = 0x1278; 251 pub const BLKIOOPT: Ioctl = 0x1279; 252 pub const BLKSSZGET: Ioctl = 0x1268; 253 pub const BLKPBSZGET: Ioctl = 0x127B; 254 // linux/if_tun.h 255 pub const TUNSETNOCSUM: Ioctl = 0x400454c8; 256 pub const TUNSETDEBUG: Ioctl = 0x400454c9; 257 pub const TUNSETIFF: Ioctl = 0x400454ca; 258 pub const TUNSETPERSIST: Ioctl = 0x400454cb; 259 pub const TUNSETOWNER: Ioctl = 0x400454cc; 260 pub const TUNSETLINK: Ioctl = 0x400454cd; 261 pub const TUNSETGROUP: Ioctl = 0x400454ce; 262 pub const TUNGETFEATURES: Ioctl = 0x800454cf; 263 pub const TUNSETOFFLOAD: Ioctl = 0x400454d0; 264 pub const TUNSETTXFILTER: Ioctl = 0x400454d1; 265 pub const TUNGETIFF: Ioctl = 0x800454d2; 266 pub const TUNGETSNDBUF: Ioctl = 0x800454d3; 267 pub const TUNSETSNDBUF: Ioctl = 0x400454d4; 268 pub const TUNGETVNETHDRSZ: Ioctl = 0x800454d7; 269 pub const TUNSETVNETHDRSZ: Ioctl = 0x400454d8; 270 pub const TUNSETQUEUE: Ioctl = 0x400454d9; 271 pub const TUNSETIFINDEX: Ioctl = 0x400454da; 272 pub const TUNSETVNETLE: Ioctl = 0x400454dc; 273 pub const TUNGETVNETLE: Ioctl = 0x800454dd; 274 /* The TUNSETVNETBE and TUNGETVNETBE ioctls are for cross-endian support on 275 * little-endian hosts. Not all kernel configurations support them, but all 276 * configurations that support SET also support GET. 277 */ 278 pub const TUNSETVNETBE: Ioctl = 0x400454de; 279 pub const TUNGETVNETBE: Ioctl = 0x800454df; 280 pub const TUNSETSTEERINGEBPF: Ioctl = 0x800454e0; 281 pub const TUNSETFILTEREBPF: Ioctl = 0x800454e1; 282 283 pub const FS_IOC_GETFLAGS: Ioctl = _IOR::<c_long>('f' as u32, 1) as Ioctl; 284 pub const FS_IOC_SETFLAGS: Ioctl = _IOW::<c_long>('f' as u32, 2) as Ioctl; 285 pub const FS_IOC_GETVERSION: Ioctl = _IOR::<c_long>('v' as u32, 1) as Ioctl; 286 pub const FS_IOC_SETVERSION: Ioctl = _IOW::<c_long>('v' as u32, 2) as Ioctl; 287 pub const FS_IOC32_GETFLAGS: Ioctl = _IOR::<c_int>('f' as u32, 1) as Ioctl; 288 pub const FS_IOC32_SETFLAGS: Ioctl = _IOW::<c_int>('f' as u32, 2) as Ioctl; 289 pub const FS_IOC32_GETVERSION: Ioctl = _IOR::<c_int>('v' as u32, 1) as Ioctl; 290 pub const FS_IOC32_SETVERSION: Ioctl = _IOW::<c_int>('v' as u32, 2) as Ioctl; 291 292 pub const TUNATTACHFILTER: Ioctl = _IOW::<crate::sock_fprog>('T' as u32, 213) as Ioctl; 293 pub const TUNDETACHFILTER: Ioctl = _IOW::<crate::sock_fprog>('T' as u32, 214) as Ioctl; 294 pub const TUNGETFILTER: Ioctl = _IOR::<crate::sock_fprog>('T' as u32, 219) as Ioctl; 295 296 cfg_if! { 297 if #[cfg(any(target_arch = "arm", target_arch = "s390x"))] { 298 pub const FIOQSIZE: Ioctl = 0x545E; 299 } else { 300 pub const FIOQSIZE: Ioctl = 0x5460; 301 } 302 } 303 304 pub const TIOCM_LE: c_int = 0x001; 305 pub const TIOCM_DTR: c_int = 0x002; 306 pub const TIOCM_RTS: c_int = 0x004; 307 pub const TIOCM_ST: c_int = 0x008; 308 pub const TIOCM_SR: c_int = 0x010; 309 pub const TIOCM_CTS: c_int = 0x020; 310 pub const TIOCM_CAR: c_int = 0x040; 311 pub const TIOCM_CD: c_int = TIOCM_CAR; 312 pub const TIOCM_RNG: c_int = 0x080; 313 pub const TIOCM_RI: c_int = TIOCM_RNG; 314 pub const TIOCM_DSR: c_int = 0x100; 315 316 pub const BOTHER: crate::speed_t = 0o010000; 317 pub const IBSHIFT: crate::tcflag_t = 16; 318 319 // RLIMIT Constants 320 321 cfg_if! { 322 if #[cfg(any(target_env = "gnu", target_env = "uclibc"))] { 323 pub const RLIMIT_CPU: crate::__rlimit_resource_t = 0; 324 pub const RLIMIT_FSIZE: crate::__rlimit_resource_t = 1; 325 pub const RLIMIT_DATA: crate::__rlimit_resource_t = 2; 326 pub const RLIMIT_STACK: crate::__rlimit_resource_t = 3; 327 pub const RLIMIT_CORE: crate::__rlimit_resource_t = 4; 328 pub const RLIMIT_RSS: crate::__rlimit_resource_t = 5; 329 pub const RLIMIT_NPROC: crate::__rlimit_resource_t = 6; 330 pub const RLIMIT_NOFILE: crate::__rlimit_resource_t = 7; 331 pub const RLIMIT_MEMLOCK: crate::__rlimit_resource_t = 8; 332 pub const RLIMIT_AS: crate::__rlimit_resource_t = 9; 333 pub const RLIMIT_LOCKS: crate::__rlimit_resource_t = 10; 334 pub const RLIMIT_SIGPENDING: crate::__rlimit_resource_t = 11; 335 pub const RLIMIT_MSGQUEUE: crate::__rlimit_resource_t = 12; 336 pub const RLIMIT_NICE: crate::__rlimit_resource_t = 13; 337 pub const RLIMIT_RTPRIO: crate::__rlimit_resource_t = 14; 338 pub const RLIMIT_RTTIME: crate::__rlimit_resource_t = 15; 339 #[allow(deprecated)] 340 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] 341 pub const RLIMIT_NLIMITS: crate::__rlimit_resource_t = RLIM_NLIMITS; 342 } else if #[cfg(any(target_env = "musl", target_env = "ohos"))] { 343 pub const RLIMIT_CPU: c_int = 0; 344 pub const RLIMIT_FSIZE: c_int = 1; 345 pub const RLIMIT_DATA: c_int = 2; 346 pub const RLIMIT_STACK: c_int = 3; 347 pub const RLIMIT_CORE: c_int = 4; 348 pub const RLIMIT_RSS: c_int = 5; 349 pub const RLIMIT_NPROC: c_int = 6; 350 pub const RLIMIT_NOFILE: c_int = 7; 351 pub const RLIMIT_MEMLOCK: c_int = 8; 352 pub const RLIMIT_AS: c_int = 9; 353 pub const RLIMIT_LOCKS: c_int = 10; 354 pub const RLIMIT_SIGPENDING: c_int = 11; 355 pub const RLIMIT_MSGQUEUE: c_int = 12; 356 pub const RLIMIT_NICE: c_int = 13; 357 pub const RLIMIT_RTPRIO: c_int = 14; 358 pub const RLIMIT_RTTIME: c_int = 15; 359 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] 360 #[cfg(not(target_arch = "loongarch64"))] 361 pub const RLIM_NLIMITS: c_int = 15; 362 #[cfg(target_arch = "loongarch64")] 363 pub const RLIM_NLIMITS: c_int = 16; 364 #[allow(deprecated)] 365 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] 366 pub const RLIMIT_NLIMITS: c_int = RLIM_NLIMITS; 367 } 368 } 369 370 cfg_if! { 371 if #[cfg(target_env = "gnu")] { 372 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] 373 pub const RLIM_NLIMITS: crate::__rlimit_resource_t = 16; 374 } else if #[cfg(target_env = "uclibc")] { 375 #[deprecated(since = "0.2.64", note = "Not stable across OS versions")] 376 pub const RLIM_NLIMITS: crate::__rlimit_resource_t = 15; 377 } 378 } 379 380 pub const RLIM_INFINITY: crate::rlim_t = !0; 381