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