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: ::intptr_t,
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 
261 cfg_if! {
262     if #[cfg(feature = "extra_traits")] {
263         impl PartialEq for statfs {
264             fn eq(&self, other: &statfs) -> bool {
265                 self.f_version == other.f_version
266                     && self.f_type == other.f_type
267                     && self.f_flags == other.f_flags
268                     && self.f_bsize == other.f_bsize
269                     && self.f_iosize == other.f_iosize
270                     && self.f_blocks == other.f_blocks
271                     && self.f_bfree == other.f_bfree
272                     && self.f_bavail == other.f_bavail
273                     && self.f_files == other.f_files
274                     && self.f_ffree == other.f_ffree
275                     && self.f_syncwrites == other.f_syncwrites
276                     && self.f_asyncwrites == other.f_asyncwrites
277                     && self.f_syncreads == other.f_syncreads
278                     && self.f_asyncreads == other.f_asyncreads
279                     && self.f_namemax == other.f_namemax
280                     && self.f_owner == other.f_owner
281                     && self.f_fsid == other.f_fsid
282                     && self.f_fstypename == other.f_fstypename
283                     && self
284                     .f_mntfromname
285                     .iter()
286                     .zip(other.f_mntfromname.iter())
287                     .all(|(a,b)| a == b)
288                     && self
289                     .f_mntonname
290                     .iter()
291                     .zip(other.f_mntonname.iter())
292                     .all(|(a,b)| a == b)
293             }
294         }
295         impl Eq for statfs {}
296         impl ::fmt::Debug for statfs {
297             fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
298                 f.debug_struct("statfs")
299                     .field("f_bsize", &self.f_bsize)
300                     .field("f_iosize", &self.f_iosize)
301                     .field("f_blocks", &self.f_blocks)
302                     .field("f_bfree", &self.f_bfree)
303                     .field("f_bavail", &self.f_bavail)
304                     .field("f_files", &self.f_files)
305                     .field("f_ffree", &self.f_ffree)
306                     .field("f_syncwrites", &self.f_syncwrites)
307                     .field("f_asyncwrites", &self.f_asyncwrites)
308                     .field("f_syncreads", &self.f_syncreads)
309                     .field("f_asyncreads", &self.f_asyncreads)
310                     .field("f_namemax", &self.f_namemax)
311                     .field("f_owner", &self.f_owner)
312                     .field("f_fsid", &self.f_fsid)
313                     .field("f_fstypename", &self.f_fstypename)
314                     .field("f_mntfromname", &&self.f_mntfromname[..])
315                     .field("f_mntonname", &&self.f_mntonname[..])
316                     .finish()
317             }
318         }
319         impl ::hash::Hash for statfs {
320             fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
321                 self.f_version.hash(state);
322                 self.f_type.hash(state);
323                 self.f_flags.hash(state);
324                 self.f_bsize.hash(state);
325                 self.f_iosize.hash(state);
326                 self.f_blocks.hash(state);
327                 self.f_bfree.hash(state);
328                 self.f_bavail.hash(state);
329                 self.f_files.hash(state);
330                 self.f_ffree.hash(state);
331                 self.f_syncwrites.hash(state);
332                 self.f_asyncwrites.hash(state);
333                 self.f_syncreads.hash(state);
334                 self.f_asyncreads.hash(state);
335                 self.f_namemax.hash(state);
336                 self.f_owner.hash(state);
337                 self.f_fsid.hash(state);
338                 self.f_charspare.hash(state);
339                 self.f_fstypename.hash(state);
340                 self.f_mntfromname.hash(state);
341                 self.f_mntonname.hash(state);
342             }
343         }
344 
345         impl PartialEq for dirent {
346             fn eq(&self, other: &dirent) -> bool {
347                 self.d_fileno == other.d_fileno
348                     && self.d_off == other.d_off
349                     && self.d_reclen == other.d_reclen
350                     && self.d_type == other.d_type
351                     && self.d_namlen == other.d_namlen
352                     && self
353                     .d_name[..self.d_namlen as _]
354                     .iter()
355                     .zip(other.d_name.iter())
356                     .all(|(a,b)| a == b)
357             }
358         }
359         impl Eq for dirent {}
360         impl ::fmt::Debug for dirent {
361             fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
362                 f.debug_struct("dirent")
363                     .field("d_fileno", &self.d_fileno)
364                     .field("d_off", &self.d_off)
365                     .field("d_reclen", &self.d_reclen)
366                     .field("d_type", &self.d_type)
367                     .field("d_namlen", &self.d_namlen)
368                     .field("d_name", &&self.d_name[..self.d_namlen as _])
369                     .finish()
370             }
371         }
372         impl ::hash::Hash for dirent {
373             fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
374                 self.d_fileno.hash(state);
375                 self.d_off.hash(state);
376                 self.d_reclen.hash(state);
377                 self.d_type.hash(state);
378                 self.d_namlen.hash(state);
379                 self.d_name[..self.d_namlen as _].hash(state);
380             }
381         }
382     }
383 }
384 
385 pub const RAND_MAX: ::c_int = 0x7fff_fffd;
386 pub const ELAST: ::c_int = 97;
387 
388 /// max length of devicename
389 pub const SPECNAMELEN: ::c_int = 63;
390 pub const KI_NSPARE_PTR: usize = 6;
391 
392 pub const MINCORE_SUPER: ::c_int = 0x20;
393 
394 extern "C" {
setgrent()395     pub fn setgrent();
mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int396     pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int;
freelocale(loc: ::locale_t)397     pub fn freelocale(loc: ::locale_t);
msgrcv( msqid: ::c_int, msgp: *mut ::c_void, msgsz: ::size_t, msgtyp: ::c_long, msgflg: ::c_int, ) -> ::ssize_t398     pub fn msgrcv(
399         msqid: ::c_int,
400         msgp: *mut ::c_void,
401         msgsz: ::size_t,
402         msgtyp: ::c_long,
403         msgflg: ::c_int,
404     ) -> ::ssize_t;
clock_nanosleep( clk_id: ::clockid_t, flags: ::c_int, rqtp: *const ::timespec, rmtp: *mut ::timespec, ) -> ::c_int405     pub fn clock_nanosleep(
406         clk_id: ::clockid_t,
407         flags: ::c_int,
408         rqtp: *const ::timespec,
409         rmtp: *mut ::timespec,
410     ) -> ::c_int;
411 
fdatasync(fd: ::c_int) -> ::c_int412     pub fn fdatasync(fd: ::c_int) -> ::c_int;
413 
getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t414     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_int415     pub fn elf_aux_info(aux: ::c_int, buf: *mut ::c_void, buflen: ::c_int) -> ::c_int;
setproctitle_fast(fmt: *const ::c_char, ...)416     pub fn setproctitle_fast(fmt: *const ::c_char, ...);
timingsafe_bcmp(a: *const ::c_void, b: *const ::c_void, len: ::size_t) -> ::c_int417     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_int418     pub fn timingsafe_memcmp(a: *const ::c_void, b: *const ::c_void, len: ::size_t) -> ::c_int;
419 }
420 
421 cfg_if! {
422     if #[cfg(any(target_arch = "x86_64",
423                  target_arch = "aarch64"))] {
424         mod b64;
425         pub use self::b64::*;
426     }
427 }
428 
429 cfg_if! {
430     if #[cfg(target_arch = "x86_64")] {
431         mod x86_64;
432         pub use self::x86_64::*;
433     }
434 }
435