mach_sys/
lib.rs

1#![doc = include_str!("../README.md")]
2
3#![allow(non_camel_case_types)]
4#![allow(non_upper_case_globals)]
5
6#![allow(
7    clippy::module_name_repetitions,
8    clippy::cast_sign_loss,
9    clippy::cast_possible_truncation,
10    clippy::trivially_copy_pass_by_ref
11)]
12
13#![deny(missing_debug_implementations)]
14#![deny(missing_copy_implementations)]
15
16// why rust does not have this?
17//#![deny(missing_clone_implementations)]
18
19// by default #![no_std] is set (unless the std feature enabled)
20#![cfg_attr(not(feature = "std"), no_std)]
21
22// if this is a test, define some useful things
23#[cfg(test)]
24mod _test_utils {
25    // if run tests from `cargo test`, this will force disply to stderr
26    #[macro_export]
27    macro_rules! p {
28        ($($args:tt)*) => {{
29            let out = format!( $($args)* );
30            let n =
31                out.lines()
32                .map(|x|{ x.len() })
33                .max().unwrap_or(20);
34
35            let mut stderr = std::io::stderr().lock();
36            writeln!(stderr, "{}", ".".repeat(n)).expect("cannot print to stderr");
37            write!(stderr, "{}", out).expect("cannot print to stderr");
38            writeln!(stderr, "{}", ".".repeat(n)).expect("cannot print to stderr");
39        }};
40    }
41
42    #[macro_export]
43    macro_rules! pl {
44        ($($args:tt)*) => {{
45            let mut s = format!( $($args)* );
46            s.push('\n');
47            $crate::p!("{}", s);
48        }}
49    }
50}
51
52#[cfg(not(target_vendor="apple"))]
53mod _err {
54    //compile_error!("mach requires macOS or iOS");
55}
56
57#[allow(unused_imports)]
58use core::{clone, cmp, default, fmt, hash, marker, mem, option};
59
60pub const NONCE_RANDOM: u64 = include!(env!("MACH_SYS_NONCE_RANDOM"));
61
62/// imports C types from core::ffi
63pub mod ffi {
64    pub use core::ffi::{
65        c_void,
66        c_uchar, c_char,
67        c_ushort,
68        c_uint, c_int,
69        c_ulong, c_long,
70        c_ulonglong, c_longlong,
71    };
72
73    pub type clock_t  = c_ulong; /// in all apple/darwin platforms, type `clock_t` is equiv to `c_ulong`.
74    pub type policy_t = c_int;   /// in all apple/darwin platforms, type `policy_t` is equiv to `c_int`.
75
76    pub type intptr_t  = isize; /// in all platforms, `intptr_t` equiv to `isize`
77    pub type uintptr_t = usize; /// in all platforms, `uintptr_t` is equiv to `usize`
78
79    /// in all apple/darwin platforms,
80    /// type `cpu_type_t` and `cpu_subtype_t`,
81    /// both equiv to `integer_t`.
82    use crate::vm_types::integer_t;
83    pub type cpu_type_t    = integer_t;
84    pub type cpu_subtype_t = integer_t;
85
86    /// in all apple/darwin platforms,
87    /// `pid_t` and `uid_t` both are 32-bit integer.
88    /// but PID is signed, UID is unsigned.
89    pub type pid_t = i32;
90    pub type uid_t = u32;
91}
92
93pub mod boolean;
94pub mod bootstrap;
95pub mod clock;
96pub mod clock_priv;
97pub mod clock_reply;
98pub mod clock_types;
99
100pub mod dyld_kernel;
101pub mod error;
102pub mod exc;
103pub mod exception_types;
104pub mod kern_return;
105
106pub mod loader;
107pub mod mach_init;
108pub mod mach_port;
109pub mod mach_time;
110pub mod mach_types;
111pub mod memory_object_types;
112pub mod message;
113pub mod ndr;
114pub mod port;
115pub mod semaphore;
116pub mod structs;
117pub mod sync_policy;
118pub mod task;
119pub mod task_info;
120pub mod thread_act;
121pub mod thread_policy;
122pub mod thread_status;
123pub mod time_value;
124pub mod traps;
125pub mod vm;
126pub mod vm_attributes;
127pub mod vm_behavior;
128pub mod vm_inherit;
129pub mod vm_page_size;
130pub mod vm_prot;
131pub mod vm_purgable;
132pub mod vm_region;
133pub mod vm_statistics;
134pub mod vm_sync;
135pub mod vm_types;
136
137// added by machx
138pub mod dyld;
139pub mod dlfcn;
140pub mod dyld_images;
141pub mod libproc;
142pub mod nlist;
143