1 // APIs in FreeBSD 12 that have changed since 11. 2 3 pub type nlink_t = u64; 4 pub type dev_t = u64; 5 pub type ino_t = ::c_ulong; 6 pub type shmatt_t = ::c_uint; 7 8 s! { 9 pub struct shmid_ds { 10 pub shm_perm: ::ipc_perm, 11 pub shm_segsz: ::size_t, 12 pub shm_lpid: ::pid_t, 13 pub shm_cpid: ::pid_t, 14 pub shm_nattch: ::shmatt_t, 15 pub shm_atime: ::time_t, 16 pub shm_dtime: ::time_t, 17 pub shm_ctime: ::time_t, 18 } 19 20 pub struct kevent { 21 pub ident: ::uintptr_t, 22 pub filter: ::c_short, 23 pub flags: ::c_ushort, 24 pub fflags: ::c_uint, 25 pub data: i64, 26 pub udata: *mut ::c_void, 27 pub ext: [u64; 4], 28 } 29 30 pub struct kvm_page { 31 pub version: ::c_uint, 32 pub paddr: ::c_ulong, 33 pub kmap_vaddr: ::c_ulong, 34 pub dmap_vaddr: ::c_ulong, 35 pub prot: ::vm_prot_t, 36 pub offset: ::u_long, 37 pub len: ::size_t, 38 } 39 40 pub struct kinfo_proc { 41 /// Size of this structure. 42 pub ki_structsize: ::c_int, 43 /// Reserved: layout identifier. 44 pub ki_layout: ::c_int, 45 /// Address of command arguments. 46 pub ki_args: *mut ::pargs, 47 // This is normally "struct proc". 48 /// Address of proc. 49 pub ki_paddr: *mut ::c_void, 50 // This is normally "struct user". 51 /// Kernel virtual address of u-area. 52 pub ki_addr: *mut ::c_void, 53 // This is normally "struct vnode". 54 /// Pointer to trace file. 55 pub ki_tracep: *mut ::c_void, 56 // This is normally "struct vnode". 57 /// Pointer to executable file. 58 pub ki_textvp: *mut ::c_void, 59 // This is normally "struct filedesc". 60 /// Pointer to open file info. 61 pub ki_fd: *mut ::c_void, 62 // This is normally "struct vmspace". 63 /// Pointer to kernel vmspace struct. 64 pub ki_vmspace: *mut ::c_void, 65 /// Sleep address. 66 pub ki_wchan: *mut ::c_void, 67 /// Process identifier. 68 pub ki_pid: ::pid_t, 69 /// Parent process ID. 70 pub ki_ppid: ::pid_t, 71 /// Process group ID. 72 pub ki_pgid: ::pid_t, 73 /// tty process group ID. 74 pub ki_tpgid: ::pid_t, 75 /// Process session ID. 76 pub ki_sid: ::pid_t, 77 /// Terminal session ID. 78 pub ki_tsid: ::pid_t, 79 /// Job control counter. 80 pub ki_jobc: ::c_short, 81 /// Unused (just here for alignment). 82 pub ki_spare_short1: ::c_short, 83 /// Controlling tty dev. 84 pub ki_tdev_freebsd11: u32, 85 /// Signals arrived but not delivered. 86 pub ki_siglist: ::sigset_t, 87 /// Current signal mask. 88 pub ki_sigmask: ::sigset_t, 89 /// Signals being ignored. 90 pub ki_sigignore: ::sigset_t, 91 /// Signals being caught by user. 92 pub ki_sigcatch: ::sigset_t, 93 /// Effective user ID. 94 pub ki_uid: ::uid_t, 95 /// Real user ID. 96 pub ki_ruid: ::uid_t, 97 /// Saved effective user ID. 98 pub ki_svuid: ::uid_t, 99 /// Real group ID. 100 pub ki_rgid: ::gid_t, 101 /// Saved effective group ID. 102 pub ki_svgid: ::gid_t, 103 /// Number of groups. 104 pub ki_ngroups: ::c_short, 105 /// Unused (just here for alignment). 106 pub ki_spare_short2: ::c_short, 107 /// Groups. 108 pub ki_groups: [::gid_t; ::KI_NGROUPS], 109 /// Virtual size. 110 pub ki_size: ::vm_size_t, 111 /// Current resident set size in pages. 112 pub ki_rssize: ::segsz_t, 113 /// Resident set size before last swap. 114 pub ki_swrss: ::segsz_t, 115 /// Text size (pages) XXX. 116 pub ki_tsize: ::segsz_t, 117 /// Data size (pages) XXX. 118 pub ki_dsize: ::segsz_t, 119 /// Stack size (pages). 120 pub ki_ssize: ::segsz_t, 121 /// Exit status for wait & stop signal. 122 pub ki_xstat: ::u_short, 123 /// Accounting flags. 124 pub ki_acflag: ::u_short, 125 /// %cpu for process during `ki_swtime`. 126 pub ki_pctcpu: ::fixpt_t, 127 /// Time averaged value of `ki_cpticks`. 128 pub ki_estcpu: ::u_int, 129 /// Time since last blocked. 130 pub ki_slptime: ::u_int, 131 /// Time swapped in or out. 132 pub ki_swtime: ::u_int, 133 /// Number of copy-on-write faults. 134 pub ki_cow: ::u_int, 135 /// Real time in microsec. 136 pub ki_runtime: u64, 137 /// Starting time. 138 pub ki_start: ::timeval, 139 /// Time used by process children. 140 pub ki_childtime: ::timeval, 141 /// P_* flags. 142 pub ki_flag: ::c_long, 143 /// KI_* flags (below). 144 pub ki_kiflag: ::c_long, 145 /// Kernel trace points. 146 pub ki_traceflag: ::c_int, 147 /// S* process status. 148 pub ki_stat: ::c_char, 149 /// Process "nice" value. 150 pub ki_nice: i8, // signed char 151 /// Process lock (prevent swap) count. 152 pub ki_lock: ::c_char, 153 /// Run queue index. 154 pub ki_rqindex: ::c_char, 155 /// Which cpu we are on. 156 pub ki_oncpu_old: ::c_uchar, 157 /// Last cpu we were on. 158 pub ki_lastcpu_old: ::c_uchar, 159 /// Thread name. 160 pub ki_tdname: [::c_char; ::TDNAMLEN + 1], 161 /// Wchan message. 162 pub ki_wmesg: [::c_char; ::WMESGLEN + 1], 163 /// Setlogin name. 164 pub ki_login: [::c_char; ::LOGNAMELEN + 1], 165 /// Lock name. 166 pub ki_lockname: [::c_char; ::LOCKNAMELEN + 1], 167 /// Command name. 168 pub ki_comm: [::c_char; ::COMMLEN + 1], 169 /// Emulation name. 170 pub ki_emul: [::c_char; ::KI_EMULNAMELEN + 1], 171 /// Login class. 172 pub ki_loginclass: [::c_char; ::LOGINCLASSLEN + 1], 173 /// More thread name. 174 pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1], 175 /// Spare string space. 176 pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq 177 /// Spare room for growth. 178 pub ki_spareints: [::c_int; ::KI_NSPARE_INT], 179 /// Controlling tty dev. 180 pub ki_tdev: ::dev_t, 181 /// Which cpu we are on. 182 pub ki_oncpu: ::c_int, 183 /// Last cpu we were on. 184 pub ki_lastcpu: ::c_int, 185 /// PID of tracing process. 186 pub ki_tracer: ::c_int, 187 /// P2_* flags. 188 pub ki_flag2: ::c_int, 189 /// Default FIB number. 190 pub ki_fibnum: ::c_int, 191 /// Credential flags. 192 pub ki_cr_flags: ::u_int, 193 /// Process jail ID. 194 pub ki_jid: ::c_int, 195 /// Number of threads in total. 196 pub ki_numthreads: ::c_int, 197 /// Thread ID. 198 pub ki_tid: ::lwpid_t, 199 /// Process priority. 200 pub ki_pri: ::priority, 201 /// Process rusage statistics. 202 pub ki_rusage: ::rusage, 203 /// rusage of children processes. 204 pub ki_rusage_ch: ::rusage, 205 // This is normally "struct pcb". 206 /// Kernel virtual addr of pcb. 207 pub ki_pcb: *mut ::c_void, 208 /// Kernel virtual addr of stack. 209 pub ki_kstack: *mut ::c_void, 210 /// User convenience pointer. 211 pub ki_udata: *mut ::c_void, 212 // This is normally "struct thread". 213 pub ki_tdaddr: *mut ::c_void, 214 pub ki_spareptrs: [*mut ::c_void; ::KI_NSPARE_PTR], 215 pub ki_sparelongs: [::c_long; ::KI_NSPARE_LONG], 216 /// PS_* flags. 217 pub ki_sflag: ::c_long, 218 /// kthread flag. 219 pub ki_tdflags: ::c_long, 220 } 221 } 222 223 s_no_extra_traits! { 224 pub struct dirent { 225 pub d_fileno: ::ino_t, 226 pub d_off: ::off_t, 227 pub d_reclen: u16, 228 pub d_type: u8, 229 d_pad0: u8, 230 pub d_namlen: u16, 231 d_pad1: u16, 232 pub d_name: [::c_char; 256], 233 } 234 235 pub struct statfs { 236 pub f_version: u32, 237 pub f_type: u32, 238 pub f_flags: u64, 239 pub f_bsize: u64, 240 pub f_iosize: u64, 241 pub f_blocks: u64, 242 pub f_bfree: u64, 243 pub f_bavail: i64, 244 pub f_files: u64, 245 pub f_ffree: i64, 246 pub f_syncwrites: u64, 247 pub f_asyncwrites: u64, 248 pub f_syncreads: u64, 249 pub f_asyncreads: u64, 250 f_spare: [u64; 10], 251 pub f_namemax: u32, 252 pub f_owner: ::uid_t, 253 pub f_fsid: ::fsid_t, 254 f_charspare: [::c_char; 80], 255 pub f_fstypename: [::c_char; 16], 256 pub f_mntfromname: [::c_char; 1024], 257 pub f_mntonname: [::c_char; 1024], 258 } 259 260 pub struct vnstat { 261 pub vn_fileid: u64, 262 pub vn_size: u64, 263 pub vn_dev: u64, 264 pub vn_fsid: u64, 265 pub vn_mntdir: *mut ::c_char, 266 pub vn_type: ::c_int, 267 pub vn_mode: u16, 268 pub vn_devname: [::c_char; ::SPECNAMELEN as usize + 1], 269 } 270 } 271 272 cfg_if! { 273 if #[cfg(feature = "extra_traits")] { 274 impl PartialEq for statfs { 275 fn eq(&self, other: &statfs) -> bool { 276 self.f_version == other.f_version 277 && self.f_type == other.f_type 278 && self.f_flags == other.f_flags 279 && self.f_bsize == other.f_bsize 280 && self.f_iosize == other.f_iosize 281 && self.f_blocks == other.f_blocks 282 && self.f_bfree == other.f_bfree 283 && self.f_bavail == other.f_bavail 284 && self.f_files == other.f_files 285 && self.f_ffree == other.f_ffree 286 && self.f_syncwrites == other.f_syncwrites 287 && self.f_asyncwrites == other.f_asyncwrites 288 && self.f_syncreads == other.f_syncreads 289 && self.f_asyncreads == other.f_asyncreads 290 && self.f_namemax == other.f_namemax 291 && self.f_owner == other.f_owner 292 && self.f_fsid == other.f_fsid 293 && self.f_fstypename == other.f_fstypename 294 && self 295 .f_mntfromname 296 .iter() 297 .zip(other.f_mntfromname.iter()) 298 .all(|(a,b)| a == b) 299 && self 300 .f_mntonname 301 .iter() 302 .zip(other.f_mntonname.iter()) 303 .all(|(a,b)| a == b) 304 } 305 } 306 impl Eq for statfs {} 307 impl ::fmt::Debug for statfs { 308 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { 309 f.debug_struct("statfs") 310 .field("f_bsize", &self.f_bsize) 311 .field("f_iosize", &self.f_iosize) 312 .field("f_blocks", &self.f_blocks) 313 .field("f_bfree", &self.f_bfree) 314 .field("f_bavail", &self.f_bavail) 315 .field("f_files", &self.f_files) 316 .field("f_ffree", &self.f_ffree) 317 .field("f_syncwrites", &self.f_syncwrites) 318 .field("f_asyncwrites", &self.f_asyncwrites) 319 .field("f_syncreads", &self.f_syncreads) 320 .field("f_asyncreads", &self.f_asyncreads) 321 .field("f_namemax", &self.f_namemax) 322 .field("f_owner", &self.f_owner) 323 .field("f_fsid", &self.f_fsid) 324 .field("f_fstypename", &self.f_fstypename) 325 .field("f_mntfromname", &&self.f_mntfromname[..]) 326 .field("f_mntonname", &&self.f_mntonname[..]) 327 .finish() 328 } 329 } 330 impl ::hash::Hash for statfs { 331 fn hash<H: ::hash::Hasher>(&self, state: &mut H) { 332 self.f_version.hash(state); 333 self.f_type.hash(state); 334 self.f_flags.hash(state); 335 self.f_bsize.hash(state); 336 self.f_iosize.hash(state); 337 self.f_blocks.hash(state); 338 self.f_bfree.hash(state); 339 self.f_bavail.hash(state); 340 self.f_files.hash(state); 341 self.f_ffree.hash(state); 342 self.f_syncwrites.hash(state); 343 self.f_asyncwrites.hash(state); 344 self.f_syncreads.hash(state); 345 self.f_asyncreads.hash(state); 346 self.f_namemax.hash(state); 347 self.f_owner.hash(state); 348 self.f_fsid.hash(state); 349 self.f_charspare.hash(state); 350 self.f_fstypename.hash(state); 351 self.f_mntfromname.hash(state); 352 self.f_mntonname.hash(state); 353 } 354 } 355 356 impl PartialEq for dirent { 357 fn eq(&self, other: &dirent) -> bool { 358 self.d_fileno == other.d_fileno 359 && self.d_off == other.d_off 360 && self.d_reclen == other.d_reclen 361 && self.d_type == other.d_type 362 && self.d_namlen == other.d_namlen 363 && self 364 .d_name[..self.d_namlen as _] 365 .iter() 366 .zip(other.d_name.iter()) 367 .all(|(a,b)| a == b) 368 } 369 } 370 impl Eq for dirent {} 371 impl ::fmt::Debug for dirent { 372 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { 373 f.debug_struct("dirent") 374 .field("d_fileno", &self.d_fileno) 375 .field("d_off", &self.d_off) 376 .field("d_reclen", &self.d_reclen) 377 .field("d_type", &self.d_type) 378 .field("d_namlen", &self.d_namlen) 379 .field("d_name", &&self.d_name[..self.d_namlen as _]) 380 .finish() 381 } 382 } 383 impl ::hash::Hash for dirent { 384 fn hash<H: ::hash::Hasher>(&self, state: &mut H) { 385 self.d_fileno.hash(state); 386 self.d_off.hash(state); 387 self.d_reclen.hash(state); 388 self.d_type.hash(state); 389 self.d_namlen.hash(state); 390 self.d_name[..self.d_namlen as _].hash(state); 391 } 392 } 393 394 impl PartialEq for vnstat { 395 fn eq(&self, other: &vnstat) -> bool { 396 let self_vn_devname: &[::c_char] = &self.vn_devname; 397 let other_vn_devname: &[::c_char] = &other.vn_devname; 398 399 self.vn_fileid == other.vn_fileid && 400 self.vn_size == other.vn_size && 401 self.vn_dev == other.vn_dev && 402 self.vn_fsid == other.vn_fsid && 403 self.vn_mntdir == other.vn_mntdir && 404 self.vn_type == other.vn_type && 405 self.vn_mode == other.vn_mode && 406 self_vn_devname == other_vn_devname 407 } 408 } 409 impl Eq for vnstat {} 410 impl ::fmt::Debug for vnstat { 411 fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { 412 let self_vn_devname: &[::c_char] = &self.vn_devname; 413 414 f.debug_struct("vnstat") 415 .field("vn_fileid", &self.vn_fileid) 416 .field("vn_size", &self.vn_size) 417 .field("vn_dev", &self.vn_dev) 418 .field("vn_fsid", &self.vn_fsid) 419 .field("vn_mntdir", &self.vn_mntdir) 420 .field("vn_type", &self.vn_type) 421 .field("vn_mode", &self.vn_mode) 422 .field("vn_devname", &self_vn_devname) 423 .finish() 424 } 425 } 426 impl ::hash::Hash for vnstat { 427 fn hash<H: ::hash::Hasher>(&self, state: &mut H) { 428 let self_vn_devname: &[::c_char] = &self.vn_devname; 429 430 self.vn_fileid.hash(state); 431 self.vn_size.hash(state); 432 self.vn_dev.hash(state); 433 self.vn_fsid.hash(state); 434 self.vn_mntdir.hash(state); 435 self.vn_type.hash(state); 436 self.vn_mode.hash(state); 437 self_vn_devname.hash(state); 438 } 439 } 440 } 441 } 442 443 pub const RAND_MAX: ::c_int = 0x7fff_fffd; 444 pub const ELAST: ::c_int = 97; 445 446 /// max length of devicename 447 pub const SPECNAMELEN: ::c_int = 63; 448 pub const KI_NSPARE_PTR: usize = 6; 449 450 pub const MINCORE_SUPER: ::c_int = 0x20; 451 452 safe_f! { 453 pub {const} fn makedev(major: ::c_uint, minor: ::c_uint) -> ::dev_t { 454 let major = major as ::dev_t; 455 let minor = minor as ::dev_t; 456 let mut dev = 0; 457 dev |= ((major & 0xffffff00) as dev_t) << 32; 458 dev |= ((major & 0x000000ff) as dev_t) << 8; 459 dev |= ((minor & 0x0000ff00) as dev_t) << 24; 460 dev |= ((minor & 0xffff00ff) as dev_t) << 0; 461 dev 462 } 463 } 464 465 extern "C" { setgrent()466 pub fn setgrent(); mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int467 pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int; freelocale(loc: ::locale_t)468 pub fn freelocale(loc: ::locale_t); msgrcv( msqid: ::c_int, msgp: *mut ::c_void, msgsz: ::size_t, msgtyp: ::c_long, msgflg: ::c_int, ) -> ::ssize_t469 pub fn msgrcv( 470 msqid: ::c_int, 471 msgp: *mut ::c_void, 472 msgsz: ::size_t, 473 msgtyp: ::c_long, 474 msgflg: ::c_int, 475 ) -> ::ssize_t; clock_nanosleep( clk_id: ::clockid_t, flags: ::c_int, rqtp: *const ::timespec, rmtp: *mut ::timespec, ) -> ::c_int476 pub fn clock_nanosleep( 477 clk_id: ::clockid_t, 478 flags: ::c_int, 479 rqtp: *const ::timespec, 480 rmtp: *mut ::timespec, 481 ) -> ::c_int; 482 fdatasync(fd: ::c_int) -> ::c_int483 pub fn fdatasync(fd: ::c_int) -> ::c_int; 484 getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t485 pub fn getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t; elf_aux_info(aux: ::c_int, buf: *mut ::c_void, buflen: ::c_int) -> ::c_int486 pub fn elf_aux_info(aux: ::c_int, buf: *mut ::c_void, buflen: ::c_int) -> ::c_int; setproctitle_fast(fmt: *const ::c_char, ...)487 pub fn setproctitle_fast(fmt: *const ::c_char, ...); timingsafe_bcmp(a: *const ::c_void, b: *const ::c_void, len: ::size_t) -> ::c_int488 pub fn timingsafe_bcmp(a: *const ::c_void, b: *const ::c_void, len: ::size_t) -> ::c_int; timingsafe_memcmp(a: *const ::c_void, b: *const ::c_void, len: ::size_t) -> ::c_int489 pub fn timingsafe_memcmp(a: *const ::c_void, b: *const ::c_void, len: ::size_t) -> ::c_int; 490 dirname(path: *mut ::c_char) -> *mut ::c_char491 pub fn dirname(path: *mut ::c_char) -> *mut ::c_char; basename(path: *mut ::c_char) -> *mut ::c_char492 pub fn basename(path: *mut ::c_char) -> *mut ::c_char; 493 } 494 495 cfg_if! { 496 if #[cfg(any(target_arch = "x86_64", 497 target_arch = "aarch64", 498 target_arch = "riscv64"))] { 499 mod b64; 500 pub use self::b64::*; 501 } 502 } 503 504 cfg_if! { 505 if #[cfg(target_arch = "x86_64")] { 506 mod x86_64; 507 pub use self::x86_64::*; 508 } 509 } 510