aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / libc / src / unix / bsd / mod.rs
| 1 | use crate::prelude::*; |
| 2 | |
| 3 | pub type off_t = i64; |
| 4 | pub type useconds_t = u32; |
| 5 | pub type blkcnt_t = i64; |
| 6 | pub type socklen_t = u32; |
| 7 | pub type sa_family_t = u8; |
| 8 | pub type pthread_t = crate::uintptr_t; |
| 9 | pub type nfds_t = c_uint; |
| 10 | #[cfg(target_os = "dragonfly")] |
| 11 | pub type regoff_t = c_int; |
| 12 | #[cfg(not(target_os = "dragonfly"))] |
| 13 | pub type regoff_t = off_t; |
| 14 | |
| 15 | s! { |
| 16 | pub struct sockaddr { |
| 17 | pub sa_len: u8, |
| 18 | pub sa_family: sa_family_t, |
| 19 | pub sa_data: [c_char; 14], |
| 20 | } |
| 21 | |
| 22 | pub struct sockaddr_in6 { |
| 23 | pub sin6_len: u8, |
| 24 | pub sin6_family: sa_family_t, |
| 25 | pub sin6_port: crate::in_port_t, |
| 26 | pub sin6_flowinfo: u32, |
| 27 | pub sin6_addr: crate::in6_addr, |
| 28 | pub sin6_scope_id: u32, |
| 29 | } |
| 30 | |
| 31 | pub struct passwd { |
| 32 | pub pw_name: *mut c_char, |
| 33 | pub pw_passwd: *mut c_char, |
| 34 | pub pw_uid: crate::uid_t, |
| 35 | pub pw_gid: crate::gid_t, |
| 36 | pub pw_change: crate::time_t, |
| 37 | pub pw_class: *mut c_char, |
| 38 | pub pw_gecos: *mut c_char, |
| 39 | pub pw_dir: *mut c_char, |
| 40 | pub pw_shell: *mut c_char, |
| 41 | pub pw_expire: crate::time_t, |
| 42 | |
| 43 | #[cfg(not(any( |
| 44 | target_os = "macos", |
| 45 | target_os = "ios", |
| 46 | target_os = "tvos", |
| 47 | target_os = "watchos", |
| 48 | target_os = "visionos", |
| 49 | target_os = "netbsd", |
| 50 | target_os = "openbsd" |
| 51 | )))] |
| 52 | pub pw_fields: c_int, |
| 53 | } |
| 54 | |
| 55 | pub struct ifaddrs { |
| 56 | pub ifa_next: *mut ifaddrs, |
| 57 | pub ifa_name: *mut c_char, |
| 58 | pub ifa_flags: c_uint, |
| 59 | pub ifa_addr: *mut crate::sockaddr, |
| 60 | pub ifa_netmask: *mut crate::sockaddr, |
| 61 | pub ifa_dstaddr: *mut crate::sockaddr, |
| 62 | pub ifa_data: *mut c_void, |
| 63 | #[cfg(any(target_os = "dragonfly", target_os = "netbsd"))] |
| 64 | pub ifa_addrflags: c_uint, |
| 65 | } |
| 66 | |
| 67 | pub struct fd_set { |
| 68 | #[cfg(all( |
| 69 | target_pointer_width = "64", |
| 70 | any(target_os = "freebsd", target_os = "dragonfly") |
| 71 | ))] |
| 72 | fds_bits: [i64; FD_SETSIZE as usize / 64], |
| 73 | #[cfg(not(all( |
| 74 | target_pointer_width = "64", |
| 75 | any(target_os = "freebsd", target_os = "dragonfly") |
| 76 | )))] |
| 77 | fds_bits: [i32; FD_SETSIZE as usize / 32], |
| 78 | } |
| 79 | |
| 80 | pub struct msghdr { |
| 81 | pub msg_name: *mut c_void, |
| 82 | pub msg_namelen: crate::socklen_t, |
| 83 | pub msg_iov: *mut crate::iovec, |
| 84 | pub msg_iovlen: c_int, |
| 85 | pub msg_control: *mut c_void, |
| 86 | pub msg_controllen: crate::socklen_t, |
| 87 | pub msg_flags: c_int, |
| 88 | } |
| 89 | |
| 90 | pub struct cmsghdr { |
| 91 | pub cmsg_len: crate::socklen_t, |
| 92 | pub cmsg_level: c_int, |
| 93 | pub cmsg_type: c_int, |
| 94 | } |
| 95 | |
| 96 | pub struct fsid_t { |
| 97 | __fsid_val: [i32; 2], |
| 98 | } |
| 99 | |
| 100 | pub struct if_nameindex { |
| 101 | pub if_index: c_uint, |
| 102 | pub if_name: *mut c_char, |
| 103 | } |
| 104 | |
| 105 | pub struct regex_t { |
| 106 | __re_magic: c_int, |
| 107 | __re_nsub: size_t, |
| 108 | __re_endp: *const c_char, |
| 109 | __re_g: *mut c_void, |
| 110 | } |
| 111 | |
| 112 | pub struct regmatch_t { |
| 113 | pub rm_so: regoff_t, |
| 114 | pub rm_eo: regoff_t, |
| 115 | } |
| 116 | |
| 117 | pub struct option { |
| 118 | pub name: *const c_char, |
| 119 | pub has_arg: c_int, |
| 120 | pub flag: *mut c_int, |
| 121 | pub val: c_int, |
| 122 | } |
| 123 | pub struct sockaddr_un { |
| 124 | pub sun_len: u8, |
| 125 | pub sun_family: sa_family_t, |
| 126 | pub sun_path: [c_char; 104], |
| 127 | } |
| 128 | |
| 129 | pub struct utsname { |
| 130 | #[cfg(not(target_os = "dragonfly"))] |
| 131 | pub sysname: [c_char; 256], |
| 132 | #[cfg(target_os = "dragonfly")] |
| 133 | pub sysname: [c_char; 32], |
| 134 | #[cfg(not(target_os = "dragonfly"))] |
| 135 | pub nodename: [c_char; 256], |
| 136 | #[cfg(target_os = "dragonfly")] |
| 137 | pub nodename: [c_char; 32], |
| 138 | #[cfg(not(target_os = "dragonfly"))] |
| 139 | pub release: [c_char; 256], |
| 140 | #[cfg(target_os = "dragonfly")] |
| 141 | pub release: [c_char; 32], |
| 142 | #[cfg(not(target_os = "dragonfly"))] |
| 143 | pub version: [c_char; 256], |
| 144 | #[cfg(target_os = "dragonfly")] |
| 145 | pub version: [c_char; 32], |
| 146 | #[cfg(not(target_os = "dragonfly"))] |
| 147 | pub machine: [c_char; 256], |
| 148 | #[cfg(target_os = "dragonfly")] |
| 149 | pub machine: [c_char; 32], |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | pub const LC_ALL: c_int = 0; |
| 154 | pub const LC_COLLATE: c_int = 1; |
| 155 | pub const LC_CTYPE: c_int = 2; |
| 156 | pub const LC_MONETARY: c_int = 3; |
| 157 | pub const LC_NUMERIC: c_int = 4; |
| 158 | pub const LC_TIME: c_int = 5; |
| 159 | pub const LC_MESSAGES: c_int = 6; |
| 160 | |
| 161 | pub const FIOCLEX: c_ulong = 0x20006601; |
| 162 | pub const FIONCLEX: c_ulong = 0x20006602; |
| 163 | pub const FIONREAD: c_ulong = 0x4004667f; |
| 164 | pub const FIONBIO: c_ulong = 0x8004667e; |
| 165 | pub const FIOASYNC: c_ulong = 0x8004667d; |
| 166 | pub const FIOSETOWN: c_ulong = 0x8004667c; |
| 167 | pub const FIOGETOWN: c_ulong = 0x4004667b; |
| 168 | |
| 169 | /// Constants may change across releases. See the [usage guidelines](crate#usage-guidelines) |
| 170 | /// for details. |
| 171 | pub const PATH_MAX: c_int = 1024; |
| 172 | |
| 173 | pub const MAXPATHLEN: c_int = PATH_MAX; |
| 174 | |
| 175 | pub const IOV_MAX: c_int = 1024; |
| 176 | |
| 177 | pub const SA_ONSTACK: c_int = 0x0001; |
| 178 | pub const SA_SIGINFO: c_int = 0x0040; |
| 179 | pub const SA_RESTART: c_int = 0x0002; |
| 180 | pub const SA_RESETHAND: c_int = 0x0004; |
| 181 | pub const SA_NOCLDSTOP: c_int = 0x0008; |
| 182 | pub const SA_NODEFER: c_int = 0x0010; |
| 183 | pub const SA_NOCLDWAIT: c_int = 0x0020; |
| 184 | |
| 185 | pub const SS_ONSTACK: c_int = 1; |
| 186 | pub const SS_DISABLE: c_int = 4; |
| 187 | |
| 188 | pub const SIGCHLD: c_int = 20; |
| 189 | pub const SIGBUS: c_int = 10; |
| 190 | pub const SIGUSR1: c_int = 30; |
| 191 | pub const SIGUSR2: c_int = 31; |
| 192 | pub const SIGCONT: c_int = 19; |
| 193 | pub const SIGSTOP: c_int = 17; |
| 194 | pub const SIGTSTP: c_int = 18; |
| 195 | pub const SIGURG: c_int = 16; |
| 196 | pub const SIGIO: c_int = 23; |
| 197 | pub const SIGSYS: c_int = 12; |
| 198 | pub const SIGTTIN: c_int = 21; |
| 199 | pub const SIGTTOU: c_int = 22; |
| 200 | pub const SIGXCPU: c_int = 24; |
| 201 | pub const SIGXFSZ: c_int = 25; |
| 202 | pub const SIGVTALRM: c_int = 26; |
| 203 | pub const SIGPROF: c_int = 27; |
| 204 | pub const SIGWINCH: c_int = 28; |
| 205 | pub const SIGINFO: c_int = 29; |
| 206 | |
| 207 | pub const SIG_SETMASK: c_int = 3; |
| 208 | pub const SIG_BLOCK: c_int = 0x1; |
| 209 | pub const SIG_UNBLOCK: c_int = 0x2; |
| 210 | |
| 211 | pub const IP_TOS: c_int = 3; |
| 212 | pub const IP_MULTICAST_IF: c_int = 9; |
| 213 | pub const IP_MULTICAST_TTL: c_int = 10; |
| 214 | pub const IP_MULTICAST_LOOP: c_int = 11; |
| 215 | |
| 216 | pub const IPV6_UNICAST_HOPS: c_int = 4; |
| 217 | pub const IPV6_MULTICAST_IF: c_int = 9; |
| 218 | pub const IPV6_MULTICAST_HOPS: c_int = 10; |
| 219 | pub const IPV6_MULTICAST_LOOP: c_int = 11; |
| 220 | pub const IPV6_V6ONLY: c_int = 27; |
| 221 | pub const IPV6_DONTFRAG: c_int = 62; |
| 222 | |
| 223 | pub const IPTOS_ECN_NOTECT: u8 = 0x00; |
| 224 | pub const IPTOS_ECN_MASK: u8 = 0x03; |
| 225 | pub const IPTOS_ECN_ECT1: u8 = 0x01; |
| 226 | pub const IPTOS_ECN_ECT0: u8 = 0x02; |
| 227 | pub const IPTOS_ECN_CE: u8 = 0x03; |
| 228 | |
| 229 | pub const ST_RDONLY: c_ulong = 1; |
| 230 | |
| 231 | pub const SCM_RIGHTS: c_int = 0x01; |
| 232 | |
| 233 | pub const NCCS: usize = 20; |
| 234 | |
| 235 | pub const O_ACCMODE: c_int = 0x3; |
| 236 | pub const O_RDONLY: c_int = 0; |
| 237 | pub const O_WRONLY: c_int = 1; |
| 238 | pub const O_RDWR: c_int = 2; |
| 239 | pub const O_APPEND: c_int = 8; |
| 240 | pub const O_CREAT: c_int = 512; |
| 241 | pub const O_TRUNC: c_int = 1024; |
| 242 | pub const O_EXCL: c_int = 2048; |
| 243 | pub const O_ASYNC: c_int = 0x40; |
| 244 | pub const O_SYNC: c_int = 0x80; |
| 245 | pub const O_NONBLOCK: c_int = 0x4; |
| 246 | pub const O_NOFOLLOW: c_int = 0x100; |
| 247 | pub const O_SHLOCK: c_int = 0x10; |
| 248 | pub const O_EXLOCK: c_int = 0x20; |
| 249 | pub const O_FSYNC: c_int = O_SYNC; |
| 250 | pub const O_NDELAY: c_int = O_NONBLOCK; |
| 251 | |
| 252 | pub const F_GETOWN: c_int = 5; |
| 253 | pub const F_SETOWN: c_int = 6; |
| 254 | |
| 255 | pub const F_RDLCK: c_short = 1; |
| 256 | pub const F_UNLCK: c_short = 2; |
| 257 | pub const F_WRLCK: c_short = 3; |
| 258 | |
| 259 | pub const MNT_RDONLY: c_int = 0x00000001; |
| 260 | pub const MNT_SYNCHRONOUS: c_int = 0x00000002; |
| 261 | pub const MNT_NOEXEC: c_int = 0x00000004; |
| 262 | pub const MNT_NOSUID: c_int = 0x00000008; |
| 263 | pub const MNT_ASYNC: c_int = 0x00000040; |
| 264 | pub const MNT_EXPORTED: c_int = 0x00000100; |
| 265 | pub const MNT_UPDATE: c_int = 0x00010000; |
| 266 | pub const MNT_RELOAD: c_int = 0x00040000; |
| 267 | pub const MNT_FORCE: c_int = 0x00080000; |
| 268 | |
| 269 | pub const Q_SYNC: c_int = 0x600; |
| 270 | pub const Q_QUOTAON: c_int = 0x100; |
| 271 | pub const Q_QUOTAOFF: c_int = 0x200; |
| 272 | |
| 273 | pub const TCIOFF: c_int = 3; |
| 274 | pub const TCION: c_int = 4; |
| 275 | pub const TCOOFF: c_int = 1; |
| 276 | pub const TCOON: c_int = 2; |
| 277 | pub const TCIFLUSH: c_int = 1; |
| 278 | pub const TCOFLUSH: c_int = 2; |
| 279 | pub const TCIOFLUSH: c_int = 3; |
| 280 | pub const TCSANOW: c_int = 0; |
| 281 | pub const TCSADRAIN: c_int = 1; |
| 282 | pub const TCSAFLUSH: c_int = 2; |
| 283 | pub const VEOF: usize = 0; |
| 284 | pub const VEOL: usize = 1; |
| 285 | pub const VEOL2: usize = 2; |
| 286 | pub const VERASE: usize = 3; |
| 287 | pub const VWERASE: usize = 4; |
| 288 | pub const VKILL: usize = 5; |
| 289 | pub const VREPRINT: usize = 6; |
| 290 | pub const VINTR: usize = 8; |
| 291 | pub const VQUIT: usize = 9; |
| 292 | pub const VSUSP: usize = 10; |
| 293 | pub const VDSUSP: usize = 11; |
| 294 | pub const VSTART: usize = 12; |
| 295 | pub const VSTOP: usize = 13; |
| 296 | pub const VLNEXT: usize = 14; |
| 297 | pub const VDISCARD: usize = 15; |
| 298 | pub const VMIN: usize = 16; |
| 299 | pub const VTIME: usize = 17; |
| 300 | pub const VSTATUS: usize = 18; |
| 301 | pub const _POSIX_VDISABLE: crate::cc_t = 0xff; |
| 302 | pub const IGNBRK: crate::tcflag_t = 0x00000001; |
| 303 | pub const BRKINT: crate::tcflag_t = 0x00000002; |
| 304 | pub const IGNPAR: crate::tcflag_t = 0x00000004; |
| 305 | pub const PARMRK: crate::tcflag_t = 0x00000008; |
| 306 | pub const INPCK: crate::tcflag_t = 0x00000010; |
| 307 | pub const ISTRIP: crate::tcflag_t = 0x00000020; |
| 308 | pub const INLCR: crate::tcflag_t = 0x00000040; |
| 309 | pub const IGNCR: crate::tcflag_t = 0x00000080; |
| 310 | pub const ICRNL: crate::tcflag_t = 0x00000100; |
| 311 | pub const IXON: crate::tcflag_t = 0x00000200; |
| 312 | pub const IXOFF: crate::tcflag_t = 0x00000400; |
| 313 | pub const IXANY: crate::tcflag_t = 0x00000800; |
| 314 | pub const IMAXBEL: crate::tcflag_t = 0x00002000; |
| 315 | pub const OPOST: crate::tcflag_t = 0x1; |
| 316 | pub const ONLCR: crate::tcflag_t = 0x2; |
| 317 | pub const OXTABS: crate::tcflag_t = 0x4; |
| 318 | pub const ONOEOT: crate::tcflag_t = 0x8; |
| 319 | pub const CIGNORE: crate::tcflag_t = 0x00000001; |
| 320 | pub const CSIZE: crate::tcflag_t = 0x00000300; |
| 321 | pub const CS5: crate::tcflag_t = 0x00000000; |
| 322 | pub const CS6: crate::tcflag_t = 0x00000100; |
| 323 | pub const CS7: crate::tcflag_t = 0x00000200; |
| 324 | pub const CS8: crate::tcflag_t = 0x00000300; |
| 325 | pub const CSTOPB: crate::tcflag_t = 0x00000400; |
| 326 | pub const CREAD: crate::tcflag_t = 0x00000800; |
| 327 | pub const PARENB: crate::tcflag_t = 0x00001000; |
| 328 | pub const PARODD: crate::tcflag_t = 0x00002000; |
| 329 | pub const HUPCL: crate::tcflag_t = 0x00004000; |
| 330 | pub const CLOCAL: crate::tcflag_t = 0x00008000; |
| 331 | pub const ECHOKE: crate::tcflag_t = 0x00000001; |
| 332 | pub const ECHOE: crate::tcflag_t = 0x00000002; |
| 333 | pub const ECHOK: crate::tcflag_t = 0x00000004; |
| 334 | pub const ECHO: crate::tcflag_t = 0x00000008; |
| 335 | pub const ECHONL: crate::tcflag_t = 0x00000010; |
| 336 | pub const ECHOPRT: crate::tcflag_t = 0x00000020; |
| 337 | pub const ECHOCTL: crate::tcflag_t = 0x00000040; |
| 338 | pub const ISIG: crate::tcflag_t = 0x00000080; |
| 339 | pub const ICANON: crate::tcflag_t = 0x00000100; |
| 340 | pub const ALTWERASE: crate::tcflag_t = 0x00000200; |
| 341 | pub const IEXTEN: crate::tcflag_t = 0x00000400; |
| 342 | pub const EXTPROC: crate::tcflag_t = 0x00000800; |
| 343 | pub const TOSTOP: crate::tcflag_t = 0x00400000; |
| 344 | pub const FLUSHO: crate::tcflag_t = 0x00800000; |
| 345 | pub const NOKERNINFO: crate::tcflag_t = 0x02000000; |
| 346 | pub const PENDIN: crate::tcflag_t = 0x20000000; |
| 347 | pub const NOFLSH: crate::tcflag_t = 0x80000000; |
| 348 | pub const MDMBUF: crate::tcflag_t = 0x00100000; |
| 349 | |
| 350 | pub const WNOHANG: c_int = 0x00000001; |
| 351 | pub const WUNTRACED: c_int = 0x00000002; |
| 352 | |
| 353 | pub const RTLD_LAZY: c_int = 0x1; |
| 354 | pub const RTLD_NOW: c_int = 0x2; |
| 355 | pub const RTLD_NEXT: *mut c_void = -1isize as *mut c_void; |
| 356 | pub const RTLD_DEFAULT: *mut c_void = -2isize as *mut c_void; |
| 357 | pub const RTLD_SELF: *mut c_void = -3isize as *mut c_void; |
| 358 | |
| 359 | pub const LOG_CRON: c_int = 9 << 3; |
| 360 | pub const LOG_AUTHPRIV: c_int = 10 << 3; |
| 361 | pub const LOG_FTP: c_int = 11 << 3; |
| 362 | pub const LOG_PERROR: c_int = 0x20; |
| 363 | |
| 364 | pub const TCP_NODELAY: c_int = 1; |
| 365 | pub const TCP_MAXSEG: c_int = 2; |
| 366 | |
| 367 | pub const PIPE_BUF: usize = 512; |
| 368 | |
| 369 | // si_code values for SIGBUS signal |
| 370 | pub const BUS_ADRALN: c_int = 1; |
| 371 | pub const BUS_ADRERR: c_int = 2; |
| 372 | pub const BUS_OBJERR: c_int = 3; |
| 373 | |
| 374 | // si_code values for SIGCHLD signal |
| 375 | pub const CLD_EXITED: c_int = 1; |
| 376 | pub const CLD_KILLED: c_int = 2; |
| 377 | pub const CLD_DUMPED: c_int = 3; |
| 378 | pub const CLD_TRAPPED: c_int = 4; |
| 379 | pub const CLD_STOPPED: c_int = 5; |
| 380 | pub const CLD_CONTINUED: c_int = 6; |
| 381 | |
| 382 | pub const POLLIN: c_short = 0x1; |
| 383 | pub const POLLPRI: c_short = 0x2; |
| 384 | pub const POLLOUT: c_short = 0x4; |
| 385 | pub const POLLERR: c_short = 0x8; |
| 386 | pub const POLLHUP: c_short = 0x10; |
| 387 | pub const POLLNVAL: c_short = 0x20; |
| 388 | pub const POLLRDNORM: c_short = 0x040; |
| 389 | pub const POLLWRNORM: c_short = 0x004; |
| 390 | pub const POLLRDBAND: c_short = 0x080; |
| 391 | pub const POLLWRBAND: c_short = 0x100; |
| 392 | |
| 393 | cfg_if! { |
| 394 | // Not yet implemented on NetBSD |
| 395 | if #[cfg(not(any(target_os = "netbsd")))] { |
| 396 | pub const BIOCGBLEN: c_ulong = 0x40044266; |
| 397 | pub const BIOCSBLEN: c_ulong = 0xc0044266; |
| 398 | pub const BIOCFLUSH: c_uint = 0x20004268; |
| 399 | pub const BIOCPROMISC: c_uint = 0x20004269; |
| 400 | pub const BIOCGDLT: c_ulong = 0x4004426a; |
| 401 | pub const BIOCGETIF: c_ulong = 0x4020426b; |
| 402 | pub const BIOCSETIF: c_ulong = 0x8020426c; |
| 403 | pub const BIOCGSTATS: c_ulong = 0x4008426f; |
| 404 | pub const BIOCIMMEDIATE: c_ulong = 0x80044270; |
| 405 | pub const BIOCVERSION: c_ulong = 0x40044271; |
| 406 | pub const BIOCGHDRCMPLT: c_ulong = 0x40044274; |
| 407 | pub const BIOCSHDRCMPLT: c_ulong = 0x80044275; |
| 408 | pub const SIOCGIFADDR: c_ulong = 0xc0206921; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | cfg_if! { |
| 413 | // Redefined in `new/apple` |
| 414 | if #[cfg(not(target_vendor = "apple"))] { |
| 415 | pub const TIOCCBRK: c_uint = 0x2000747a; |
| 416 | pub const TIOCSBRK: c_uint = 0x2000747b; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | pub const PRIO_PROCESS: c_int = 0; |
| 421 | pub const PRIO_PGRP: c_int = 1; |
| 422 | pub const PRIO_USER: c_int = 2; |
| 423 | |
| 424 | pub const ITIMER_REAL: c_int = 0; |
| 425 | pub const ITIMER_VIRTUAL: c_int = 1; |
| 426 | pub const ITIMER_PROF: c_int = 2; |
| 427 | |
| 428 | // net/route.h |
| 429 | |
| 430 | pub const RTF_UP: c_int = 0x1; |
| 431 | pub const RTF_GATEWAY: c_int = 0x2; |
| 432 | pub const RTF_HOST: c_int = 0x4; |
| 433 | pub const RTF_REJECT: c_int = 0x8; |
| 434 | pub const RTF_DYNAMIC: c_int = 0x10; |
| 435 | pub const RTF_MODIFIED: c_int = 0x20; |
| 436 | pub const RTF_DONE: c_int = 0x40; |
| 437 | pub const RTF_STATIC: c_int = 0x800; |
| 438 | pub const RTF_BLACKHOLE: c_int = 0x1000; |
| 439 | pub const RTF_PROTO2: c_int = 0x4000; |
| 440 | pub const RTF_PROTO1: c_int = 0x8000; |
| 441 | |
| 442 | // Message types |
| 443 | pub const RTM_ADD: c_int = 0x1; |
| 444 | pub const RTM_DELETE: c_int = 0x2; |
| 445 | pub const RTM_CHANGE: c_int = 0x3; |
| 446 | pub const RTM_GET: c_int = 0x4; |
| 447 | pub const RTM_LOSING: c_int = 0x5; |
| 448 | pub const RTM_REDIRECT: c_int = 0x6; |
| 449 | pub const RTM_MISS: c_int = 0x7; |
| 450 | |
| 451 | // Bitmask values for rtm_addrs. |
| 452 | pub const RTA_DST: c_int = 0x1; |
| 453 | pub const RTA_GATEWAY: c_int = 0x2; |
| 454 | pub const RTA_NETMASK: c_int = 0x4; |
| 455 | pub const RTA_GENMASK: c_int = 0x8; |
| 456 | pub const RTA_IFP: c_int = 0x10; |
| 457 | pub const RTA_IFA: c_int = 0x20; |
| 458 | pub const RTA_AUTHOR: c_int = 0x40; |
| 459 | pub const RTA_BRD: c_int = 0x80; |
| 460 | |
| 461 | // Index offsets for sockaddr array for alternate internal encoding. |
| 462 | pub const RTAX_DST: c_int = 0; |
| 463 | pub const RTAX_GATEWAY: c_int = 1; |
| 464 | pub const RTAX_NETMASK: c_int = 2; |
| 465 | pub const RTAX_GENMASK: c_int = 3; |
| 466 | pub const RTAX_IFP: c_int = 4; |
| 467 | pub const RTAX_IFA: c_int = 5; |
| 468 | pub const RTAX_AUTHOR: c_int = 6; |
| 469 | pub const RTAX_BRD: c_int = 7; |
| 470 | |
| 471 | f! { |
| 472 | pub unsafe fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut cmsghdr { |
| 473 | if (*mhdr).msg_controllen as usize >= size_of::<cmsghdr>() { |
| 474 | (*mhdr).msg_control.cast() |
| 475 | } else { |
| 476 | ptr::null_mut() |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () { |
| 481 | let bits = size_of_val(&(*set).fds_bits[0]) * 8; |
| 482 | let fd = fd as usize; |
| 483 | (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | pub unsafe fn FD_ISSET(fd: c_int, set: *const fd_set) -> bool { |
| 488 | let bits = size_of_val(&(*set).fds_bits[0]) * 8; |
| 489 | let fd = fd as usize; |
| 490 | return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0; |
| 491 | } |
| 492 | |
| 493 | pub unsafe fn FD_SET(fd: c_int, set: *mut fd_set) -> () { |
| 494 | let bits = size_of_val(&(*set).fds_bits[0]) * 8; |
| 495 | let fd = fd as usize; |
| 496 | (*set).fds_bits[fd / bits] |= 1 << (fd % bits); |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | pub unsafe fn FD_ZERO(set: *mut fd_set) -> () { |
| 501 | (*set).fds_bits.fill(0); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | safe_f! { |
| 506 | pub const safe fn WTERMSIG(status: c_int) -> c_int { |
| 507 | status & 0o177 |
| 508 | } |
| 509 | |
| 510 | pub const safe fn WIFEXITED(status: c_int) -> bool { |
| 511 | (status & 0o177) == 0 |
| 512 | } |
| 513 | |
| 514 | pub const safe fn WEXITSTATUS(status: c_int) -> c_int { |
| 515 | (status >> 8) & 0x00ff |
| 516 | } |
| 517 | |
| 518 | pub const safe fn WCOREDUMP(status: c_int) -> bool { |
| 519 | (status & 0o200) != 0 |
| 520 | } |
| 521 | |
| 522 | pub const safe fn QCMD(cmd: c_int, type_: c_int) -> c_int { |
| 523 | (cmd << 8) | (type_ & 0x00ff) |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | extern "C" { |
| 528 | #[cfg_attr( |
| 529 | all(target_os = "macos", target_arch = "x86"), |
| 530 | link_name = "getrlimit$UNIX2003" |
| 531 | )] |
| 532 | pub fn getrlimit(resource: c_int, rlim: *mut crate::rlimit) -> c_int; |
| 533 | #[cfg_attr( |
| 534 | all(target_os = "macos", target_arch = "x86"), |
| 535 | link_name = "setrlimit$UNIX2003" |
| 536 | )] |
| 537 | pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int; |
| 538 | |
| 539 | pub fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int; |
| 540 | pub fn abs(i: c_int) -> c_int; |
| 541 | pub fn labs(i: c_long) -> c_long; |
| 542 | #[cfg_attr( |
| 543 | all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), |
| 544 | link_name = "rand@FBSD_1.0" |
| 545 | )] |
| 546 | pub fn rand() -> c_int; |
| 547 | #[cfg_attr( |
| 548 | all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), |
| 549 | link_name = "srand@FBSD_1.0" |
| 550 | )] |
| 551 | pub fn srand(seed: c_uint); |
| 552 | |
| 553 | pub fn getifaddrs(ifap: *mut *mut crate::ifaddrs) -> c_int; |
| 554 | pub fn freeifaddrs(ifa: *mut crate::ifaddrs); |
| 555 | pub fn setgroups(ngroups: c_int, ptr: *const crate::gid_t) -> c_int; |
| 556 | pub fn setlogin(name: *const c_char) -> c_int; |
| 557 | pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int; |
| 558 | pub fn kqueue() -> c_int; |
| 559 | pub fn unmount(target: *const c_char, arg: c_int) -> c_int; |
| 560 | pub fn syscall(num: c_int, ...) -> c_int; |
| 561 | #[cfg_attr(target_os = "netbsd", link_name = "__getpwent50")] |
| 562 | pub fn getpwent() -> *mut passwd; |
| 563 | pub fn setpwent(); |
| 564 | pub fn endpwent(); |
| 565 | pub fn endgrent(); |
| 566 | pub fn getgrent() -> *mut crate::group; |
| 567 | |
| 568 | pub fn getprogname() -> *const c_char; |
| 569 | pub fn setprogname(name: *const c_char); |
| 570 | pub fn getloadavg(loadavg: *mut c_double, nelem: c_int) -> c_int; |
| 571 | pub fn if_nameindex() -> *mut if_nameindex; |
| 572 | pub fn if_freenameindex(ptr: *mut if_nameindex); |
| 573 | |
| 574 | pub fn getpeereid(socket: c_int, euid: *mut crate::uid_t, egid: *mut crate::gid_t) -> c_int; |
| 575 | |
| 576 | #[cfg_attr( |
| 577 | all(target_os = "macos", not(target_arch = "aarch64")), |
| 578 | link_name = "glob$INODE64" |
| 579 | )] |
| 580 | #[cfg_attr(target_os = "netbsd", link_name = "__glob30")] |
| 581 | #[cfg_attr( |
| 582 | all(target_os = "freebsd", any(freebsd11, freebsd10)), |
| 583 | link_name = "glob@FBSD_1.0" |
| 584 | )] |
| 585 | pub fn glob( |
| 586 | pattern: *const c_char, |
| 587 | flags: c_int, |
| 588 | errfunc: Option<extern "C" fn(epath: *const c_char, errno: c_int) -> c_int>, |
| 589 | pglob: *mut crate::glob_t, |
| 590 | ) -> c_int; |
| 591 | #[cfg_attr(target_os = "netbsd", link_name = "__globfree30")] |
| 592 | #[cfg_attr( |
| 593 | all(target_os = "freebsd", any(freebsd11, freebsd10)), |
| 594 | link_name = "globfree@FBSD_1.0" |
| 595 | )] |
| 596 | pub fn globfree(pglob: *mut crate::glob_t); |
| 597 | |
| 598 | pub fn posix_madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int; |
| 599 | |
| 600 | pub fn shm_unlink(name: *const c_char) -> c_int; |
| 601 | |
| 602 | #[cfg_attr( |
| 603 | all(target_os = "macos", target_arch = "x86_64"), |
| 604 | link_name = "seekdir$INODE64" |
| 605 | )] |
| 606 | #[cfg_attr( |
| 607 | all(target_os = "macos", target_arch = "x86"), |
| 608 | link_name = "seekdir$INODE64$UNIX2003" |
| 609 | )] |
| 610 | pub fn seekdir(dirp: *mut crate::DIR, loc: c_long); |
| 611 | |
| 612 | #[cfg_attr( |
| 613 | all(target_os = "macos", target_arch = "x86_64"), |
| 614 | link_name = "telldir$INODE64" |
| 615 | )] |
| 616 | #[cfg_attr( |
| 617 | all(target_os = "macos", target_arch = "x86"), |
| 618 | link_name = "telldir$INODE64$UNIX2003" |
| 619 | )] |
| 620 | pub fn telldir(dirp: *mut crate::DIR) -> c_long; |
| 621 | pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int; |
| 622 | |
| 623 | #[cfg_attr( |
| 624 | all(target_os = "macos", target_arch = "x86"), |
| 625 | link_name = "msync$UNIX2003" |
| 626 | )] |
| 627 | #[cfg_attr(target_os = "netbsd", link_name = "__msync13")] |
| 628 | pub fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int; |
| 629 | |
| 630 | #[cfg_attr( |
| 631 | all(target_os = "macos", target_arch = "x86"), |
| 632 | link_name = "recvfrom$UNIX2003" |
| 633 | )] |
| 634 | pub fn recvfrom( |
| 635 | socket: c_int, |
| 636 | buf: *mut c_void, |
| 637 | len: size_t, |
| 638 | flags: c_int, |
| 639 | addr: *mut crate::sockaddr, |
| 640 | addrlen: *mut crate::socklen_t, |
| 641 | ) -> ssize_t; |
| 642 | pub fn mkstemps(template: *mut c_char, suffixlen: c_int) -> c_int; |
| 643 | #[cfg_attr(target_os = "netbsd", link_name = "__futimes50")] |
| 644 | pub fn futimes(fd: c_int, times: *const crate::timeval) -> c_int; |
| 645 | pub fn nl_langinfo(item: crate::nl_item) -> *mut c_char; |
| 646 | |
| 647 | #[cfg_attr( |
| 648 | all(target_os = "macos", target_arch = "x86"), |
| 649 | link_name = "bind$UNIX2003" |
| 650 | )] |
| 651 | pub fn bind( |
| 652 | socket: c_int, |
| 653 | address: *const crate::sockaddr, |
| 654 | address_len: crate::socklen_t, |
| 655 | ) -> c_int; |
| 656 | |
| 657 | #[cfg_attr( |
| 658 | all(target_os = "macos", target_arch = "x86"), |
| 659 | link_name = "writev$UNIX2003" |
| 660 | )] |
| 661 | pub fn writev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t; |
| 662 | #[cfg_attr( |
| 663 | all(target_os = "macos", target_arch = "x86"), |
| 664 | link_name = "readv$UNIX2003" |
| 665 | )] |
| 666 | pub fn readv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int) -> ssize_t; |
| 667 | |
| 668 | #[cfg_attr( |
| 669 | all(target_os = "macos", target_arch = "x86"), |
| 670 | link_name = "sendmsg$UNIX2003" |
| 671 | )] |
| 672 | pub fn sendmsg(fd: c_int, msg: *const crate::msghdr, flags: c_int) -> ssize_t; |
| 673 | #[cfg_attr( |
| 674 | all(target_os = "macos", target_arch = "x86"), |
| 675 | link_name = "recvmsg$UNIX2003" |
| 676 | )] |
| 677 | pub fn recvmsg(fd: c_int, msg: *mut crate::msghdr, flags: c_int) -> ssize_t; |
| 678 | |
| 679 | pub fn sync(); |
| 680 | pub fn getgrgid_r( |
| 681 | gid: crate::gid_t, |
| 682 | grp: *mut crate::group, |
| 683 | buf: *mut c_char, |
| 684 | buflen: size_t, |
| 685 | result: *mut *mut crate::group, |
| 686 | ) -> c_int; |
| 687 | #[cfg_attr( |
| 688 | all(target_os = "macos", target_arch = "x86"), |
| 689 | link_name = "sigaltstack$UNIX2003" |
| 690 | )] |
| 691 | #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] |
| 692 | pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> c_int; |
| 693 | #[cfg_attr(target_os = "netbsd", link_name = "__sigsuspend14")] |
| 694 | pub fn sigsuspend(mask: *const crate::sigset_t) -> c_int; |
| 695 | pub fn sem_close(sem: *mut sem_t) -> c_int; |
| 696 | pub fn getdtablesize() -> c_int; |
| 697 | pub fn getgrnam_r( |
| 698 | name: *const c_char, |
| 699 | grp: *mut crate::group, |
| 700 | buf: *mut c_char, |
| 701 | buflen: size_t, |
| 702 | result: *mut *mut crate::group, |
| 703 | ) -> c_int; |
| 704 | #[cfg_attr( |
| 705 | all(target_os = "macos", target_arch = "x86"), |
| 706 | link_name = "pthread_sigmask$UNIX2003" |
| 707 | )] |
| 708 | pub fn pthread_sigmask(how: c_int, set: *const sigset_t, oldset: *mut sigset_t) -> c_int; |
| 709 | pub fn sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t; |
| 710 | pub fn getgrnam(name: *const c_char) -> *mut crate::group; |
| 711 | #[cfg_attr( |
| 712 | all(target_os = "macos", target_arch = "x86"), |
| 713 | link_name = "pthread_cancel$UNIX2003" |
| 714 | )] |
| 715 | pub fn pthread_cancel(thread: crate::pthread_t) -> c_int; |
| 716 | pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int; |
| 717 | pub fn sched_get_priority_min(policy: c_int) -> c_int; |
| 718 | pub fn sched_get_priority_max(policy: c_int) -> c_int; |
| 719 | pub fn sem_unlink(name: *const c_char) -> c_int; |
| 720 | #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam_r50")] |
| 721 | pub fn getpwnam_r( |
| 722 | name: *const c_char, |
| 723 | pwd: *mut passwd, |
| 724 | buf: *mut c_char, |
| 725 | buflen: size_t, |
| 726 | result: *mut *mut passwd, |
| 727 | ) -> c_int; |
| 728 | #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")] |
| 729 | pub fn getpwuid_r( |
| 730 | uid: crate::uid_t, |
| 731 | pwd: *mut passwd, |
| 732 | buf: *mut c_char, |
| 733 | buflen: size_t, |
| 734 | result: *mut *mut passwd, |
| 735 | ) -> c_int; |
| 736 | #[cfg_attr( |
| 737 | all(target_os = "macos", target_arch = "x86"), |
| 738 | link_name = "sigwait$UNIX2003" |
| 739 | )] |
| 740 | pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int; |
| 741 | pub fn pthread_atfork( |
| 742 | prepare: Option<unsafe extern "C" fn()>, |
| 743 | parent: Option<unsafe extern "C" fn()>, |
| 744 | child: Option<unsafe extern "C" fn()>, |
| 745 | ) -> c_int; |
| 746 | pub fn getgrgid(gid: crate::gid_t) -> *mut crate::group; |
| 747 | #[cfg_attr( |
| 748 | all(target_os = "macos", target_arch = "x86"), |
| 749 | link_name = "popen$UNIX2003" |
| 750 | )] |
| 751 | pub fn popen(command: *const c_char, mode: *const c_char) -> *mut crate::FILE; |
| 752 | pub fn faccessat(dirfd: c_int, pathname: *const c_char, mode: c_int, flags: c_int) -> c_int; |
| 753 | pub fn pthread_create( |
| 754 | native: *mut crate::pthread_t, |
| 755 | attr: *const crate::pthread_attr_t, |
| 756 | f: extern "C" fn(*mut c_void) -> *mut c_void, |
| 757 | value: *mut c_void, |
| 758 | ) -> c_int; |
| 759 | pub fn acct(filename: *const c_char) -> c_int; |
| 760 | #[cfg_attr( |
| 761 | all(target_os = "macos", target_arch = "x86"), |
| 762 | link_name = "wait4$UNIX2003" |
| 763 | )] |
| 764 | #[cfg_attr( |
| 765 | all(target_os = "freebsd", any(freebsd12, freebsd11, freebsd10)), |
| 766 | link_name = "wait4@FBSD_1.0" |
| 767 | )] |
| 768 | #[cfg_attr(target_os = "netbsd", link_name = "__wait450")] |
| 769 | pub fn wait4( |
| 770 | pid: crate::pid_t, |
| 771 | status: *mut c_int, |
| 772 | options: c_int, |
| 773 | rusage: *mut crate::rusage, |
| 774 | ) -> crate::pid_t; |
| 775 | #[cfg_attr( |
| 776 | all(target_os = "macos", target_arch = "x86"), |
| 777 | link_name = "getitimer$UNIX2003" |
| 778 | )] |
| 779 | #[cfg_attr(target_os = "netbsd", link_name = "__getitimer50")] |
| 780 | pub fn getitimer(which: c_int, curr_value: *mut crate::itimerval) -> c_int; |
| 781 | #[cfg_attr( |
| 782 | all(target_os = "macos", target_arch = "x86"), |
| 783 | link_name = "setitimer$UNIX2003" |
| 784 | )] |
| 785 | #[cfg_attr(target_os = "netbsd", link_name = "__setitimer50")] |
| 786 | pub fn setitimer( |
| 787 | which: c_int, |
| 788 | new_value: *const crate::itimerval, |
| 789 | old_value: *mut crate::itimerval, |
| 790 | ) -> c_int; |
| 791 | |
| 792 | pub fn regcomp(preg: *mut regex_t, pattern: *const c_char, cflags: c_int) -> c_int; |
| 793 | |
| 794 | pub fn regexec( |
| 795 | preg: *const regex_t, |
| 796 | input: *const c_char, |
| 797 | nmatch: size_t, |
| 798 | pmatch: *mut regmatch_t, |
| 799 | eflags: c_int, |
| 800 | ) -> c_int; |
| 801 | |
| 802 | pub fn regerror( |
| 803 | errcode: c_int, |
| 804 | preg: *const regex_t, |
| 805 | errbuf: *mut c_char, |
| 806 | errbuf_size: size_t, |
| 807 | ) -> size_t; |
| 808 | |
| 809 | pub fn regfree(preg: *mut regex_t); |
| 810 | |
| 811 | pub fn arc4random() -> u32; |
| 812 | pub fn arc4random_buf(buf: *mut c_void, size: size_t); |
| 813 | pub fn arc4random_uniform(l: u32) -> u32; |
| 814 | |
| 815 | pub fn drand48() -> c_double; |
| 816 | pub fn erand48(xseed: *mut c_ushort) -> c_double; |
| 817 | pub fn lrand48() -> c_long; |
| 818 | pub fn nrand48(xseed: *mut c_ushort) -> c_long; |
| 819 | pub fn mrand48() -> c_long; |
| 820 | pub fn jrand48(xseed: *mut c_ushort) -> c_long; |
| 821 | pub fn srand48(seed: c_long); |
| 822 | pub fn seed48(xseed: *mut c_ushort) -> *mut c_ushort; |
| 823 | pub fn lcong48(p: *mut c_ushort); |
| 824 | pub fn getopt_long( |
| 825 | argc: c_int, |
| 826 | argv: *const *mut c_char, |
| 827 | optstring: *const c_char, |
| 828 | longopts: *const option, |
| 829 | longindex: *mut c_int, |
| 830 | ) -> c_int; |
| 831 | |
| 832 | pub fn strftime( |
| 833 | buf: *mut c_char, |
| 834 | maxsize: size_t, |
| 835 | format: *const c_char, |
| 836 | timeptr: *const crate::tm, |
| 837 | ) -> size_t; |
| 838 | pub fn strftime_l( |
| 839 | buf: *mut c_char, |
| 840 | maxsize: size_t, |
| 841 | format: *const c_char, |
| 842 | timeptr: *const crate::tm, |
| 843 | locale: crate::locale_t, |
| 844 | ) -> size_t; |
| 845 | |
| 846 | #[cfg_attr(target_os = "netbsd", link_name = "__devname50")] |
| 847 | pub fn devname(dev: crate::dev_t, mode_t: crate::mode_t) -> *mut c_char; |
| 848 | |
| 849 | pub fn issetugid() -> c_int; |
| 850 | } |
| 851 | |
| 852 | cfg_if! { |
| 853 | if #[cfg(any( |
| 854 | target_os = "macos", |
| 855 | target_os = "ios", |
| 856 | target_os = "tvos", |
| 857 | target_os = "watchos", |
| 858 | target_os = "visionos" |
| 859 | ))] { |
| 860 | mod apple; |
| 861 | pub use self::apple::*; |
| 862 | } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] { |
| 863 | mod netbsdlike; |
| 864 | pub use self::netbsdlike::*; |
| 865 | } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { |
| 866 | mod freebsdlike; |
| 867 | pub use self::freebsdlike::*; |
| 868 | } else { |
| 869 | // Unknown target_os |
| 870 | } |
| 871 | } |