interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / libc / src / unix / bsd / freebsdlike / freebsd / freebsd12 / mod.rs

371 lines · 11933 bytes Raw Blame History
1use crate::off_t;
2use crate::prelude::*;
3
4// APIs in FreeBSD 12 that have changed since 11.
5
6pub type nlink_t = u64;
7pub type dev_t = u64;
8pub type ino_t = u64;
9pub type shmatt_t = c_uint;
10
11s! {
12 pub struct shmid_ds {
13 pub shm_perm: crate::ipc_perm,
14 pub shm_segsz: size_t,
15 pub shm_lpid: crate::pid_t,
16 pub shm_cpid: crate::pid_t,
17 pub shm_nattch: crate::shmatt_t,
18 pub shm_atime: crate::time_t,
19 pub shm_dtime: crate::time_t,
20 pub shm_ctime: crate::time_t,
21 }
22
23 pub struct kevent {
24 pub ident: crate::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 version: c_uint,
35 pub paddr: c_ulong,
36 pub kmap_vaddr: c_ulong,
37 pub dmap_vaddr: c_ulong,
38 pub prot: crate::vm_prot_t,
39 pub offset: crate::u_long,
40 pub len: size_t,
41 }
42
43 pub struct kinfo_proc {
44 /// Size of this structure.
45 pub ki_structsize: c_int,
46 /// Reserved: layout identifier.
47 pub ki_layout: c_int,
48 /// Address of command arguments.
49 pub ki_args: *mut crate::pargs,
50 // This is normally "struct proc".
51 /// Address of proc.
52 pub ki_paddr: *mut c_void,
53 // This is normally "struct user".
54 /// Kernel virtual address of u-area.
55 pub ki_addr: *mut c_void,
56 // This is normally "struct vnode".
57 /// Pointer to trace file.
58 pub ki_tracep: *mut c_void,
59 // This is normally "struct vnode".
60 /// Pointer to executable file.
61 pub ki_textvp: *mut c_void,
62 /// Pointer to open file info.
63 pub ki_fd: *mut crate::filedesc,
64 // This is normally "struct vmspace".
65 /// Pointer to kernel vmspace struct.
66 pub ki_vmspace: *mut c_void,
67 /// Sleep address.
68 pub ki_wchan: *mut c_void,
69 /// Process identifier.
70 pub ki_pid: crate::pid_t,
71 /// Parent process ID.
72 pub ki_ppid: crate::pid_t,
73 /// Process group ID.
74 pub ki_pgid: crate::pid_t,
75 /// tty process group ID.
76 pub ki_tpgid: crate::pid_t,
77 /// Process session ID.
78 pub ki_sid: crate::pid_t,
79 /// Terminal session ID.
80 pub ki_tsid: crate::pid_t,
81 /// Job control counter.
82 pub ki_jobc: c_short,
83 /// Unused (just here for alignment).
84 pub ki_spare_short1: c_short,
85 /// Controlling tty dev.
86 pub ki_tdev_freebsd11: u32,
87 /// Signals arrived but not delivered.
88 pub ki_siglist: crate::sigset_t,
89 /// Current signal mask.
90 pub ki_sigmask: crate::sigset_t,
91 /// Signals being ignored.
92 pub ki_sigignore: crate::sigset_t,
93 /// Signals being caught by user.
94 pub ki_sigcatch: crate::sigset_t,
95 /// Effective user ID.
96 pub ki_uid: crate::uid_t,
97 /// Real user ID.
98 pub ki_ruid: crate::uid_t,
99 /// Saved effective user ID.
100 pub ki_svuid: crate::uid_t,
101 /// Real group ID.
102 pub ki_rgid: crate::gid_t,
103 /// Saved effective group ID.
104 pub ki_svgid: crate::gid_t,
105 /// Number of groups.
106 pub ki_ngroups: c_short,
107 /// Unused (just here for alignment).
108 pub ki_spare_short2: c_short,
109 /// Groups.
110 pub ki_groups: [crate::gid_t; crate::KI_NGROUPS],
111 /// Virtual size.
112 pub ki_size: crate::vm_size_t,
113 /// Current resident set size in pages.
114 pub ki_rssize: crate::segsz_t,
115 /// Resident set size before last swap.
116 pub ki_swrss: crate::segsz_t,
117 /// Text size (pages) XXX.
118 pub ki_tsize: crate::segsz_t,
119 /// Data size (pages) XXX.
120 pub ki_dsize: crate::segsz_t,
121 /// Stack size (pages).
122 pub ki_ssize: crate::segsz_t,
123 /// Exit status for wait & stop signal.
124 pub ki_xstat: crate::u_short,
125 /// Accounting flags.
126 pub ki_acflag: crate::u_short,
127 /// %cpu for process during `ki_swtime`.
128 pub ki_pctcpu: crate::fixpt_t,
129 /// Time averaged value of `ki_cpticks`.
130 pub ki_estcpu: crate::u_int,
131 /// Time since last blocked.
132 pub ki_slptime: crate::u_int,
133 /// Time swapped in or out.
134 pub ki_swtime: crate::u_int,
135 /// Number of copy-on-write faults.
136 pub ki_cow: crate::u_int,
137 /// Real time in microsec.
138 pub ki_runtime: u64,
139 /// Starting time.
140 pub ki_start: crate::timeval,
141 /// Time used by process children.
142 pub ki_childtime: crate::timeval,
143 /// P_* flags.
144 pub ki_flag: c_long,
145 /// KI_* flags (below).
146 pub ki_kiflag: c_long,
147 /// Kernel trace points.
148 pub ki_traceflag: c_int,
149 /// S* process status.
150 pub ki_stat: c_char,
151 /// Process "nice" value.
152 pub ki_nice: i8, // signed char
153 /// Process lock (prevent swap) count.
154 pub ki_lock: c_char,
155 /// Run queue index.
156 pub ki_rqindex: c_char,
157 /// Which cpu we are on.
158 pub ki_oncpu_old: c_uchar,
159 /// Last cpu we were on.
160 pub ki_lastcpu_old: c_uchar,
161 /// Thread name.
162 pub ki_tdname: [c_char; crate::TDNAMLEN + 1],
163 /// Wchan message.
164 pub ki_wmesg: [c_char; crate::WMESGLEN + 1],
165 /// Setlogin name.
166 pub ki_login: [c_char; crate::LOGNAMELEN + 1],
167 /// Lock name.
168 pub ki_lockname: [c_char; crate::LOCKNAMELEN + 1],
169 /// Command name.
170 pub ki_comm: [c_char; crate::COMMLEN + 1],
171 /// Emulation name.
172 pub ki_emul: [c_char; crate::KI_EMULNAMELEN + 1],
173 /// Login class.
174 pub ki_loginclass: [c_char; crate::LOGINCLASSLEN + 1],
175 /// More thread name.
176 pub ki_moretdname: [c_char; crate::MAXCOMLEN - crate::TDNAMLEN + 1],
177 /// Spare string space.
178 pub ki_sparestrings: [[c_char; 23]; 2], // little hack to allow PartialEq
179 /// Spare room for growth.
180 pub ki_spareints: [c_int; crate::KI_NSPARE_INT],
181 /// Controlling tty dev.
182 pub ki_tdev: crate::dev_t,
183 /// Which cpu we are on.
184 pub ki_oncpu: c_int,
185 /// Last cpu we were on.
186 pub ki_lastcpu: c_int,
187 /// PID of tracing process.
188 pub ki_tracer: c_int,
189 /// P2_* flags.
190 pub ki_flag2: c_int,
191 /// Default FIB number.
192 pub ki_fibnum: c_int,
193 /// Credential flags.
194 pub ki_cr_flags: crate::u_int,
195 /// Process jail ID.
196 pub ki_jid: c_int,
197 /// Number of threads in total.
198 pub ki_numthreads: c_int,
199 /// Thread ID.
200 pub ki_tid: crate::lwpid_t,
201 /// Process priority.
202 pub ki_pri: crate::priority,
203 /// Process rusage statistics.
204 pub ki_rusage: crate::rusage,
205 /// rusage of children processes.
206 pub ki_rusage_ch: crate::rusage,
207 // This is normally "struct pcb".
208 /// Kernel virtual addr of pcb.
209 pub ki_pcb: *mut c_void,
210 /// Kernel virtual addr of stack.
211 pub ki_kstack: *mut c_void,
212 /// User convenience pointer.
213 pub ki_udata: *mut c_void,
214 // This is normally "struct thread".
215 pub ki_tdaddr: *mut c_void,
216 pub ki_spareptrs: [*mut c_void; crate::KI_NSPARE_PTR],
217 pub ki_sparelongs: [c_long; crate::KI_NSPARE_LONG],
218 /// PS_* flags.
219 pub ki_sflag: c_long,
220 /// kthread flag.
221 pub ki_tdflags: c_long,
222 }
223
224 pub struct stat {
225 pub st_dev: crate::dev_t,
226 pub st_ino: crate::ino_t,
227 pub st_nlink: crate::nlink_t,
228 pub st_mode: crate::mode_t,
229 st_padding0: Padding<i16>,
230 pub st_uid: crate::uid_t,
231 pub st_gid: crate::gid_t,
232 st_padding1: Padding<i32>,
233 pub st_rdev: crate::dev_t,
234 #[cfg(target_arch = "x86")]
235 st_atim_ext: i32,
236 pub st_atime: crate::time_t,
237 pub st_atime_nsec: c_long,
238 #[cfg(target_arch = "x86")]
239 st_mtim_ext: i32,
240 pub st_mtime: crate::time_t,
241 pub st_mtime_nsec: c_long,
242 #[cfg(target_arch = "x86")]
243 st_ctim_ext: i32,
244 pub st_ctime: crate::time_t,
245 pub st_ctime_nsec: c_long,
246 #[cfg(target_arch = "x86")]
247 st_btim_ext: i32,
248 pub st_birthtime: crate::time_t,
249 pub st_birthtime_nsec: c_long,
250 pub st_size: off_t,
251 pub st_blocks: crate::blkcnt_t,
252 pub st_blksize: crate::blksize_t,
253 pub st_flags: crate::fflags_t,
254 pub st_gen: u64,
255 pub st_spare: [u64; 10],
256 }
257
258 pub struct dirent {
259 pub d_fileno: crate::ino_t,
260 pub d_off: off_t,
261 pub d_reclen: u16,
262 pub d_type: u8,
263 d_pad0: Padding<u8>,
264 pub d_namlen: u16,
265 d_pad1: Padding<u16>,
266 pub d_name: [c_char; 256],
267 }
268
269 pub struct statfs {
270 pub f_version: u32,
271 pub f_type: u32,
272 pub f_flags: u64,
273 pub f_bsize: u64,
274 pub f_iosize: u64,
275 pub f_blocks: u64,
276 pub f_bfree: u64,
277 pub f_bavail: i64,
278 pub f_files: u64,
279 pub f_ffree: i64,
280 pub f_syncwrites: u64,
281 pub f_asyncwrites: u64,
282 pub f_syncreads: u64,
283 pub f_asyncreads: u64,
284 f_spare: [u64; 10],
285 pub f_namemax: u32,
286 pub f_owner: crate::uid_t,
287 pub f_fsid: crate::fsid_t,
288 f_charspare: [c_char; 80],
289 pub f_fstypename: [c_char; 16],
290 pub f_mntfromname: [c_char; 1024],
291 pub f_mntonname: [c_char; 1024],
292 }
293
294 pub struct vnstat {
295 pub vn_fileid: u64,
296 pub vn_size: u64,
297 pub vn_dev: u64,
298 pub vn_fsid: u64,
299 pub vn_mntdir: *mut c_char,
300 pub vn_type: c_int,
301 pub vn_mode: u16,
302 pub vn_devname: [c_char; crate::SPECNAMELEN as usize + 1],
303 }
304}
305
306/// Constants may change across releases. See the [usage guidelines](crate#usage-guidelines)
307/// for details.
308pub const RAND_MAX: c_int = 0x7fff_fffd;
309
310/// Constants may change across releases. See the [usage guidelines](crate#usage-guidelines)
311/// for details.
312pub const ELAST: c_int = 97;
313
314/// max length of devicename
315pub const SPECNAMELEN: c_int = 63;
316pub const KI_NSPARE_PTR: usize = 6;
317
318pub const MINCORE_SUPER: c_int = 0x20;
319
320safe_f! {
321 pub const safe fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t {
322 let major = major as crate::dev_t;
323 let minor = minor as crate::dev_t;
324 let mut dev = 0;
325 dev |= ((major & 0xffffff00) as dev_t) << 32;
326 dev |= ((major & 0x000000ff) as dev_t) << 8;
327 dev |= ((minor & 0x0000ff00) as dev_t) << 24;
328 dev |= ((minor & 0xffff00ff) as dev_t) << 0;
329 dev
330 }
331
332 pub const safe fn major(dev: crate::dev_t) -> c_int {
333 (((dev >> 32) & 0xffffff00) | ((dev >> 8) & 0xff)) as c_int
334 }
335
336 pub const safe fn minor(dev: crate::dev_t) -> c_int {
337 (((dev >> 24) & 0xff00) | (dev & 0xffff00ff)) as c_int
338 }
339}
340
341extern "C" {
342 pub fn setgrent();
343 pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int;
344 pub fn freelocale(loc: crate::locale_t);
345 pub fn msgrcv(
346 msqid: c_int,
347 msgp: *mut c_void,
348 msgsz: size_t,
349 msgtyp: c_long,
350 msgflg: c_int,
351 ) -> ssize_t;
352
353 pub fn dirname(path: *mut c_char) -> *mut c_char;
354 pub fn basename(path: *mut c_char) -> *mut c_char;
355
356 #[link_name = "qsort_r@FBSD_1.0"]
357 pub fn qsort_r(
358 base: *mut c_void,
359 num: size_t,
360 size: size_t,
361 arg: *mut c_void,
362 compar: Option<unsafe extern "C" fn(*mut c_void, *const c_void, *const c_void) -> c_int>,
363 );
364}
365
366cfg_if! {
367 if #[cfg(target_arch = "x86_64")] {
368 mod x86_64;
369 pub use self::x86_64::*;
370 }
371}