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