diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/mach/src | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/mach/src')
35 files changed, 1878 insertions, 0 deletions
diff --git a/third_party/rust/mach/src/boolean.rs b/third_party/rust/mach/src/boolean.rs new file mode 100644 index 0000000000..cedffa1220 --- /dev/null +++ b/third_party/rust/mach/src/boolean.rs @@ -0,0 +1,7 @@ +//! This module corresponds to `mach/i386/boolean.h`. + +#[cfg(target_arch = "x86_64")] +pub type boolean_t = ::libc::c_uint; + +#[cfg(not(target_arch = "x86_64"))] +pub type boolean_t = ::libc::c_int; diff --git a/third_party/rust/mach/src/bootstrap.rs b/third_party/rust/mach/src/bootstrap.rs new file mode 100644 index 0000000000..3642b94627 --- /dev/null +++ b/third_party/rust/mach/src/bootstrap.rs @@ -0,0 +1,76 @@ +//! This module corresponds to `bootstrap.h` + +use boolean::boolean_t; +use kern_return::kern_return_t; +use port::mach_port_t; + +pub const BOOTSTRAP_MAX_NAME_LEN: ::libc::c_uint = 128; +pub const BOOTSTRAP_MAX_CMD_LEN: ::libc::c_uint = 512; + +pub const BOOTSTRAP_MAX_LOOKUP_COUNT: ::libc::c_uint = 20; + +pub const BOOTSTRAP_SUCCESS: ::libc::c_uint = 0; +pub const BOOTSTRAP_NOT_PRIVILEGED: ::libc::c_uint = 1100; +pub const BOOTSTRAP_NAME_IN_USE: ::libc::c_uint = 1101; +pub const BOOTSTRAP_UNKNOWN_SERVICE: ::libc::c_uint = 1102; +pub const BOOTSTRAP_SERVICE_ACTIVE: ::libc::c_uint = 1103; +pub const BOOTSTRAP_BAD_COUNT: ::libc::c_uint = 1104; +pub const BOOTSTRAP_NO_MEMORY: ::libc::c_uint = 1105; +pub const BOOTSTRAP_NO_CHILDREN: ::libc::c_uint = 1106; + +pub const BOOTSTRAP_STATUS_INACTIVE: ::libc::c_uint = 0; +pub const BOOTSTRAP_STATUS_ACTIVE: ::libc::c_uint = 1; +pub const BOOTSTRAP_STATUS_ON_DEMAND: ::libc::c_uint = 2; + +pub type name_t = [::libc::c_char; 128]; +pub type cmd_t = [::libc::c_char; 512]; +pub type name_array_t = *mut name_t; +pub type bootstrap_status_t = ::libc::c_int; +pub type bootstrap_status_array_t = *mut bootstrap_status_t; +pub type bootstrap_property_t = ::libc::c_uint; +pub type bootstrap_property_array_t = *mut bootstrap_property_t; +pub type bool_array_t = *mut boolean_t; + +extern "C" { + pub static bootstrap_port: mach_port_t; + pub fn bootstrap_create_server( + bp: mach_port_t, + server_cmd: *mut ::libc::c_char, + server_uid: ::libc::uid_t, + on_demand: boolean_t, + server_port: *mut mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_subset( + bp: mach_port_t, + requestor_port: mach_port_t, + subset_port: *mut mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_unprivileged(bp: mach_port_t, unpriv_port: *mut mach_port_t) -> kern_return_t; + pub fn bootstrap_parent(bp: mach_port_t, parent_port: *mut mach_port_t) -> kern_return_t; + pub fn bootstrap_register( + bp: mach_port_t, + service_name: *mut ::libc::c_char, + sp: mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_create_service( + bp: mach_port_t, + service_name: *mut ::libc::c_char, + sp: *mut mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_check_in( + bp: mach_port_t, + service_name: *const ::libc::c_char, + sp: *mut mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_look_up( + bp: mach_port_t, + service_name: *const ::libc::c_char, + sp: *mut mach_port_t, + ) -> kern_return_t; + pub fn bootstrap_status( + bp: mach_port_t, + service_name: *mut ::libc::c_char, + service_active: *mut bootstrap_status_t, + ) -> kern_return_t; + pub fn bootstrap_strerror(r: kern_return_t) -> *const ::libc::c_char; +} diff --git a/third_party/rust/mach/src/clock.rs b/third_party/rust/mach/src/clock.rs new file mode 100644 index 0000000000..1d5437951d --- /dev/null +++ b/third_party/rust/mach/src/clock.rs @@ -0,0 +1,27 @@ +//! This module roughly corresponds to `mach/clock.h`. + +pub const clock_MSG_COUNT: ::libc::c_uint = 3; + +use clock_types::{alarm_type_t, clock_attr_t, clock_flavor_t, mach_timespec_t}; +use kern_return::kern_return_t; +use mach_types::{clock_reply_t, clock_serv_t}; +use message::mach_msg_type_number_t; + +extern "C" { + pub fn clock_get_time( + clock_serv: clock_serv_t, + cur_time: *mut mach_timespec_t, + ) -> kern_return_t; + pub fn clock_get_attributes( + clock_serv: clock_serv_t, + flavor: clock_flavor_t, + clock_attr: clock_attr_t, + clock_attrCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + pub fn clock_alarm( + clock_serv: clock_serv_t, + alarm_type: alarm_type_t, + alarm_time: mach_timespec_t, + alarm_port: clock_reply_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/clock_priv.rs b/third_party/rust/mach/src/clock_priv.rs new file mode 100644 index 0000000000..d534e79a3c --- /dev/null +++ b/third_party/rust/mach/src/clock_priv.rs @@ -0,0 +1,16 @@ +//! This module roughly corresponds to `mach/clock_priv.h`. + +use clock_types::{clock_attr_t, clock_flavor_t, mach_timespec_t}; +use kern_return::kern_return_t; +use mach_types::clock_ctrl_t; +use message::mach_msg_type_number_t; + +extern "C" { + pub fn clock_set_time(clock_ctrl: clock_ctrl_t, new_time: mach_timespec_t) -> kern_return_t; + pub fn clock_set_attributes( + clock_ctrl: clock_ctrl_t, + flavor: clock_flavor_t, + clock_attr: clock_attr_t, + clock_attrCnt: mach_msg_type_number_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/clock_reply.rs b/third_party/rust/mach/src/clock_reply.rs new file mode 100644 index 0000000000..854eb22bf5 --- /dev/null +++ b/third_party/rust/mach/src/clock_reply.rs @@ -0,0 +1,16 @@ +//! This module roughly corresponds to `mach/clock_reply.h`. + +use clock_types::{alarm_type_t, mach_timespec_t}; +use kern_return::kern_return_t; +use mach_types::clock_reply_t; +use message::mach_msg_type_name_t; + +extern "C" { + pub fn clock_alarm_reply( + alarm_port: clock_reply_t, + alarm_portPoly: mach_msg_type_name_t, + alarm_code: kern_return_t, + alarm_type: alarm_type_t, + alarm_time: mach_timespec_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/clock_types.rs b/third_party/rust/mach/src/clock_types.rs new file mode 100644 index 0000000000..c0949c8315 --- /dev/null +++ b/third_party/rust/mach/src/clock_types.rs @@ -0,0 +1,75 @@ +//! This module roughly corresponds to `mach/clock_types.h`. + +pub type alarm_type_t = ::libc::c_int; +pub type sleep_type_t = ::libc::c_int; +pub type clock_id_t = ::libc::c_int; +pub type clock_flavor_t = ::libc::c_int; +pub type clock_attr_t = *mut ::libc::c_int; +pub type clock_res_t = ::libc::c_int; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_timespec { + pub tv_sec: ::libc::c_uint, + pub tv_nsec: clock_res_t, +} +pub type mach_timespec_t = mach_timespec; + +pub const SYSTEM_CLOCK: ::libc::c_uint = 0; +pub const CALENDAR_CLOCK: ::libc::c_uint = 1; +pub const REALTIME_CLOCK: ::libc::c_uint = 0; + +pub const CLOCK_GET_TIME_RES: ::libc::c_uint = 1; +pub const CLOCK_ALARM_CURRES: ::libc::c_uint = 3; +pub const CLOCK_ALARM_MINRES: ::libc::c_uint = 4; +pub const CLOCK_ALARM_MAXRES: ::libc::c_uint = 5; + +pub const NSEC_PER_USEC: ::libc::c_ulonglong = 1000; +pub const USEC_PER_SEC: ::libc::c_ulonglong = 1_000_000; +pub const NSEC_PER_SEC: ::libc::c_ulonglong = 1_000_000_000; +pub const NSEC_PER_MSEC: ::libc::c_ulonglong = 1_000_000; + +#[allow(non_snake_case)] +pub fn BAD_MACH_TIMESPEC(t: mach_timespec) -> bool { + t.tv_nsec < 0 || (t.tv_nsec as ::libc::c_ulonglong) >= NSEC_PER_SEC +} + +#[allow(non_snake_case)] +pub fn CMP_MACH_TIMESPEC(t1: &mach_timespec, t2: &mach_timespec) -> ::libc::c_ulonglong { + if t1.tv_sec > t2.tv_sec { + return NSEC_PER_SEC; + } + if t1.tv_sec < t2.tv_sec { + return !NSEC_PER_SEC; + } + (t1.tv_nsec as ::libc::c_ulonglong) - (t2.tv_nsec as ::libc::c_ulonglong) +} + +#[allow(non_snake_case)] +pub fn ADD_MACH_TIMESPEC(t1: &mut mach_timespec, t2: &mach_timespec) { + t1.tv_nsec += t2.tv_nsec; + if (t1.tv_nsec as ::libc::c_ulonglong) >= NSEC_PER_SEC { + t1.tv_nsec = (t1.tv_nsec as ::libc::c_ulonglong - NSEC_PER_SEC) as clock_res_t; + t1.tv_sec += 1; + } + t1.tv_sec += t2.tv_sec; +} + +#[allow(non_snake_case)] +pub fn SUB_MACH_TIMESPEC(t1: &mut mach_timespec, t2: &mach_timespec) { + t1.tv_nsec -= t2.tv_nsec; + if t1.tv_nsec < 0 { + t1.tv_nsec = (t1.tv_nsec as ::libc::c_ulonglong + NSEC_PER_SEC) as clock_res_t; + t1.tv_sec -= 1; + } + t1.tv_sec -= t2.tv_sec; +} + +pub const ALRMTYPE: ::libc::c_uint = 0xff; +pub const TIME_ABSOLUTE: ::libc::c_uint = 0x00; +pub const TIME_RELATIVE: ::libc::c_uint = 0x01; + +#[allow(non_snake_case)] +pub fn BAD_ALRMTYPE(t: ::libc::c_uint) -> bool { + t & (!TIME_RELATIVE) != 0 +} diff --git a/third_party/rust/mach/src/dyld_kernel.rs b/third_party/rust/mach/src/dyld_kernel.rs new file mode 100644 index 0000000000..9a264dfafd --- /dev/null +++ b/third_party/rust/mach/src/dyld_kernel.rs @@ -0,0 +1,30 @@ +//! This module roughly corresponds to `mach/dyld_kernel.h`. + +use boolean::boolean_t; +use mach_types::{fsid_t, fsobj_id_t, uuid_t}; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct dyld_kernel_image_info { + pub uuid: uuid_t, + pub fsobjid: fsobj_id_t, + pub fsid: fsid_t, + pub load_addr: u64, +} + +#[allow(non_snake_case)] +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct dyld_kernel_process_info { + pub cache_image_info: dyld_kernel_image_info, + pub timestamp: u64, + pub imageCount: u32, + pub initialImageCount: u32, + pub dyldState: u8, + pub no_cache: boolean_t, + pub private_cache: boolean_t, +} + +pub type dyld_kernel_image_info_t = dyld_kernel_image_info; +pub type dyld_kernel_process_info_t = dyld_kernel_process_info; +pub type dyld_kernel_image_info_array_t = *mut dyld_kernel_image_info_t; diff --git a/third_party/rust/mach/src/exc.rs b/third_party/rust/mach/src/exc.rs new file mode 100644 index 0000000000..9330740c4e --- /dev/null +++ b/third_party/rust/mach/src/exc.rs @@ -0,0 +1,44 @@ +//! This module roughly corresponds to `mach/exc.h`. + +use exception_types::{exception_data_t, exception_type_t}; +use kern_return::kern_return_t; +use message::mach_msg_type_number_t; +use port::mach_port_t; +use thread_status::thread_state_t; + +pub const exc_MSG_COUNT: ::libc::c_uint = 3; + +extern "C" { + pub fn exception_raise( + exception_port: mach_port_t, + thread: mach_port_t, + task: mach_port_t, + exception: exception_type_t, + code: exception_data_t, + codeCnt: mach_msg_type_number_t, + ) -> kern_return_t; + pub fn exception_raise_state( + exception_port: mach_port_t, + exception: exception_type_t, + code: exception_data_t, + codeCnt: mach_msg_type_number_t, + flavor: *mut ::libc::c_int, + old_state: thread_state_t, + old_stateCnt: mach_msg_type_number_t, + new_state: thread_state_t, + new_stateCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + pub fn exception_raise_state_identity( + exception_port: mach_port_t, + thread: mach_port_t, + task: mach_port_t, + exception: exception_type_t, + code: exception_data_t, + codeCnt: mach_msg_type_number_t, + flavor: *mut ::libc::c_int, + old_state: thread_state_t, + old_stateCnt: mach_msg_type_number_t, + new_state: thread_state_t, + new_stateCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/exception_types.rs b/third_party/rust/mach/src/exception_types.rs new file mode 100644 index 0000000000..f042443d8a --- /dev/null +++ b/third_party/rust/mach/src/exception_types.rs @@ -0,0 +1,56 @@ +//! This module roughly corresponds to `mach/exception_types.h`. + +use port::mach_port_t; +use thread_status::thread_state_flavor_t; +use vm_types::integer_t; + +pub const EXC_BAD_ACCESS: ::libc::c_uint = 1; +pub const EXC_BAD_INSTRUCTION: ::libc::c_uint = 2; +pub const EXC_ARITHMETIC: ::libc::c_uint = 3; +pub const EXC_EMULATION: ::libc::c_uint = 4; +pub const EXC_SOFTWARE: ::libc::c_uint = 5; +pub const EXC_BREAKPOINT: ::libc::c_uint = 6; +pub const EXC_SYSCALL: ::libc::c_uint = 7; +pub const EXC_MACH_SYSCALL: ::libc::c_uint = 8; +pub const EXC_RPC_ALERT: ::libc::c_uint = 9; +pub const EXC_CRASH: ::libc::c_uint = 10; +pub const EXC_RESOURCE: ::libc::c_uint = 11; +pub const EXC_GUARD: ::libc::c_uint = 12; +pub const EXC_CORPSE_NOTIFY: ::libc::c_uint = 13; +pub const EXC_CORPSE_VARIANT_BIT: ::libc::c_uint = 256; +pub const EXCEPTION_DEFAULT: ::libc::c_uint = 1; +pub const EXCEPTION_STATE: ::libc::c_uint = 2; +pub const EXCEPTION_STATE_IDENTITY: ::libc::c_uint = 3; +pub const MACH_EXCEPTION_CODES: ::libc::c_uint = 2_147_483_648; +pub const EXC_MASK_BAD_ACCESS: ::libc::c_uint = 2; +pub const EXC_MASK_BAD_INSTRUCTION: ::libc::c_uint = 4; +pub const EXC_MASK_ARITHMETIC: ::libc::c_uint = 8; +pub const EXC_MASK_EMULATION: ::libc::c_uint = 16; +pub const EXC_MASK_SOFTWARE: ::libc::c_uint = 32; +pub const EXC_MASK_BREAKPOINT: ::libc::c_uint = 64; +pub const EXC_MASK_SYSCALL: ::libc::c_uint = 128; +pub const EXC_MASK_MACH_SYSCALL: ::libc::c_uint = 256; +pub const EXC_MASK_RPC_ALERT: ::libc::c_uint = 512; +pub const EXC_MASK_CRASH: ::libc::c_uint = 1024; +pub const EXC_MASK_RESOURCE: ::libc::c_uint = 2048; +pub const EXC_MASK_GUARD: ::libc::c_uint = 4096; +pub const EXC_MASK_CORPSE_NOTIFY: ::libc::c_uint = 8192; +pub const EXC_MASK_ALL: ::libc::c_uint = 7166; +pub const FIRST_EXCEPTION: ::libc::c_uint = 1; +pub const EXC_SOFT_SIGNAL: ::libc::c_uint = 65_539; +pub const EXC_MACF_MIN: ::libc::c_uint = 131_072; +pub const EXC_MACF_MAX: ::libc::c_uint = 196_607; + +pub type exception_type_t = ::libc::c_int; +pub type exception_data_type_t = integer_t; +pub type mach_exception_data_type_t = i64; +pub type exception_behavior_t = ::libc::c_int; +pub type exception_data_t = *mut exception_data_type_t; +pub type mach_exception_data_t = *mut mach_exception_data_type_t; +pub type exception_mask_t = ::libc::c_uint; +pub type exception_mask_array_t = *mut exception_mask_t; +pub type exception_behavior_array_t = *mut exception_behavior_t; +pub type exception_flavor_array_t = *mut thread_state_flavor_t; +pub type exception_port_array_t = *mut mach_port_t; +pub type mach_exception_code_t = mach_exception_data_type_t; +pub type mach_exception_subcode_t = mach_exception_data_type_t; diff --git a/third_party/rust/mach/src/kern_return.rs b/third_party/rust/mach/src/kern_return.rs new file mode 100644 index 0000000000..3d447b4026 --- /dev/null +++ b/third_party/rust/mach/src/kern_return.rs @@ -0,0 +1,58 @@ +//! This module corresponds to `mach/kern_return.h` and +//! `mach/i386/kern_return.h`. + +pub type kern_return_t = ::libc::c_int; + +pub const KERN_SUCCESS: kern_return_t = 0; +pub const KERN_INVALID_ADDRESS: kern_return_t = 1; +pub const KERN_PROTECTION_FAILURE: kern_return_t = 2; +pub const KERN_NO_SPACE: kern_return_t = 3; +pub const KERN_INVALID_ARGUMENT: kern_return_t = 4; +pub const KERN_FAILURE: kern_return_t = 5; +pub const KERN_RESOURCE_SHORTAGE: kern_return_t = 6; +pub const KERN_NOT_RECEIVER: kern_return_t = 7; +pub const KERN_NO_ACCESS: kern_return_t = 8; +pub const KERN_MEMORY_FAILURE: kern_return_t = 9; +pub const KERN_MEMORY_ERROR: kern_return_t = 10; +pub const KERN_ALREADY_IN_SET: kern_return_t = 11; +pub const KERN_NOT_IN_SET: kern_return_t = 12; +pub const KERN_NAME_EXISTS: kern_return_t = 13; +pub const KERN_ABORTED: kern_return_t = 14; +pub const KERN_INVALID_NAME: kern_return_t = 15; +pub const KERN_INVALID_TASK: kern_return_t = 16; +pub const KERN_INVALID_RIGHT: kern_return_t = 17; +pub const KERN_INVALID_VALUE: kern_return_t = 18; +pub const KERN_UREFS_OVERFLOW: kern_return_t = 19; +pub const KERN_INVALID_CAPABILITY: kern_return_t = 20; +pub const KERN_RIGHT_EXISTS: kern_return_t = 21; +pub const KERN_INVALID_HOST: kern_return_t = 22; +pub const KERN_MEMORY_PRESENT: kern_return_t = 23; +pub const KERN_MEMORY_DATA_MOVED: kern_return_t = 24; +pub const KERN_MEMORY_RESTART_COPY: kern_return_t = 25; +pub const KERN_INVALID_PROCESSOR_SET: kern_return_t = 26; +pub const KERN_POLICY_LIMIT: kern_return_t = 27; +pub const KERN_INVALID_POLICY: kern_return_t = 28; +pub const KERN_INVALID_OBJECT: kern_return_t = 29; +pub const KERN_ALREADY_WAITING: kern_return_t = 30; +pub const KERN_DEFAULT_SET: kern_return_t = 31; +pub const KERN_EXCEPTION_PROTECTED: kern_return_t = 32; +pub const KERN_INVALID_LEDGER: kern_return_t = 33; +pub const KERN_INVALID_MEMORY_CONTROL: kern_return_t = 34; +pub const KERN_INVALID_SECURITY: kern_return_t = 35; +pub const KERN_NOT_DEPRESSED: kern_return_t = 36; +pub const KERN_TERMINATED: kern_return_t = 37; +pub const KERN_LOCK_SET_DESTROYED: kern_return_t = 38; +pub const KERN_LOCK_UNSTABLE: kern_return_t = 39; +pub const KERN_LOCK_OWNED: kern_return_t = 40; +pub const KERN_LOCK_OWNED_SELF: kern_return_t = 41; +pub const KERN_SEMAPHORE_DESTROYED: kern_return_t = 42; +pub const KERN_RPC_SERVER_TERMINATED: kern_return_t = 43; +pub const KERN_RPC_TERMINATE_ORPHAN: kern_return_t = 44; +pub const KERN_RPC_CONTINUE_ORPHAN: kern_return_t = 45; +pub const KERN_NOT_SUPPORTED: kern_return_t = 46; +pub const KERN_NODE_DOWN: kern_return_t = 47; +pub const KERN_NOT_WAITING: kern_return_t = 48; +pub const KERN_OPERATION_TIMED_OUT: kern_return_t = 49; +pub const KERN_CODESIGN_ERROR: kern_return_t = 50; +pub const KERN_POLICY_STATIC: kern_return_t = 51; +pub const KERN_RETURN_MAX: kern_return_t = 0x100; diff --git a/third_party/rust/mach/src/lib.rs b/third_party/rust/mach/src/lib.rs new file mode 100644 index 0000000000..faec2cbfa5 --- /dev/null +++ b/third_party/rust/mach/src/lib.rs @@ -0,0 +1,60 @@ +#![allow(non_camel_case_types)] +#![allow(non_upper_case_globals)] +#![deny(missing_debug_implementations)] +#![deny(missing_copy_implementations)] +#![cfg_attr(feature = "rustc-dep-of-std", feature(no_core))] +#![cfg_attr(feature = "rustc-dep-of-std", no_core)] +#![cfg_attr(not(feature = "rustc-dep-of-std"), no_std)] +#![allow( + clippy::module_name_repetitions, + clippy::cast_sign_loss, + clippy::cast_possible_truncation, + clippy::trivially_copy_pass_by_ref +)] + +#[cfg(not(any(target_os = "macos", target_os = "ios")))] +compile_error!("mach requires MacOSX or iOS"); + +#[cfg(feature = "rustc-dep-of-std")] +extern crate rustc_std_workspace_core as core; + +extern crate libc; + +#[allow(unused_imports)] +use core::{clone, cmp, default, fmt, hash, marker, mem, option}; + +pub mod boolean; +pub mod bootstrap; +pub mod clock; +pub mod clock_priv; +pub mod clock_reply; +pub mod clock_types; // TODO: test +pub mod dyld_kernel; +// pub mod error; // TODO +pub mod exc; +pub mod exception_types; +pub mod kern_return; +pub mod mach_init; +pub mod mach_port; +pub mod mach_time; +pub mod mach_types; +pub mod memory_object_types; +pub mod message; +pub mod port; +pub mod structs; +pub mod task; +pub mod task_info; +pub mod thread_act; +pub mod thread_status; +pub mod traps; +pub mod vm; +pub mod vm_attributes; +pub mod vm_behavior; +pub mod vm_inherit; +pub mod vm_page_size; +pub mod vm_prot; +pub mod vm_purgable; +pub mod vm_region; +pub mod vm_statistics; +pub mod vm_sync; +pub mod vm_types; diff --git a/third_party/rust/mach/src/mach_init.rs b/third_party/rust/mach/src/mach_init.rs new file mode 100644 index 0000000000..5776988cb5 --- /dev/null +++ b/third_party/rust/mach/src/mach_init.rs @@ -0,0 +1,22 @@ +//! This module corresponds to `mach/mach_init.h`. + +use mach_types::thread_port_t; + +extern "C" { + pub fn mach_thread_self() -> thread_port_t; +} + +#[cfg(test)] +mod tests { + use mach_init::*; + use port::*; + + #[test] + fn mach_thread_self_test() { + unsafe { + let this_thread = mach_thread_self(); + assert!(this_thread != MACH_PORT_NULL); + assert!(this_thread != MACH_PORT_DEAD); + } + } +} diff --git a/third_party/rust/mach/src/mach_port.rs b/third_party/rust/mach/src/mach_port.rs new file mode 100644 index 0000000000..76a34001df --- /dev/null +++ b/third_party/rust/mach/src/mach_port.rs @@ -0,0 +1,29 @@ +//! This module corresponds to `mach/mach_port.h` + +use kern_return::kern_return_t; +use mach_types::ipc_space_t; +use message::mach_msg_type_name_t; +use port::{mach_port_name_t, mach_port_right_t, mach_port_t}; + +extern "C" { + pub fn mach_port_allocate( + task: ipc_space_t, + right: mach_port_right_t, + name: *mut mach_port_name_t, + ) -> kern_return_t; + pub fn mach_port_destroy(task: ipc_space_t, name: mach_port_name_t) -> kern_return_t; + pub fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) -> kern_return_t; + pub fn mach_port_insert_right( + task: ipc_space_t, + name: mach_port_name_t, + poly: mach_port_t, + polyPoly: mach_msg_type_name_t, + ) -> kern_return_t; + pub fn mach_port_extract_right( + task: ipc_space_t, + name: mach_port_name_t, + msgt_name: mach_msg_type_name_t, + poly: *mut mach_port_t, + polyPoly: *mut mach_msg_type_name_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/mach_time.rs b/third_party/rust/mach/src/mach_time.rs new file mode 100644 index 0000000000..9011c0c0af --- /dev/null +++ b/third_party/rust/mach/src/mach_time.rs @@ -0,0 +1,20 @@ +//! This module corresponds to `mach/mach_time.h` +use kern_return::kern_return_t; +pub type mach_timebase_info_t = *mut mach_timebase_info; +pub type mach_timebase_info_data_t = mach_timebase_info; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_timebase_info { + pub numer: u32, + pub denom: u32, +} + +extern "C" { + pub fn mach_timebase_info(info: mach_timebase_info_t) -> kern_return_t; + pub fn mach_wait_until(deadline: u64) -> kern_return_t; + pub fn mach_absolute_time() -> u64; + pub fn mach_approximate_time() -> u64; + pub fn mach_continuous_time() -> u64; + pub fn mach_continuous_approximate_time() -> u64; +} diff --git a/third_party/rust/mach/src/mach_types.rs b/third_party/rust/mach/src/mach_types.rs new file mode 100644 index 0000000000..fa257b2a53 --- /dev/null +++ b/third_party/rust/mach/src/mach_types.rs @@ -0,0 +1,106 @@ +//! This module corresponds to `mach/mach_types.h` + +use port::mach_port_t; + +pub type task_t = mach_port_t; +pub type task_name_t = mach_port_t; +pub type task_suspension_token_t = mach_port_t; +pub type thread_t = mach_port_t; +pub type thread_act_t = mach_port_t; +pub type ipc_space_t = mach_port_t; +pub type coalition_t = mach_port_t; +pub type host_t = mach_port_t; +pub type host_priv_t = mach_port_t; +pub type host_security_t = mach_port_t; +pub type processor_t = mach_port_t; +pub type processor_set_t = mach_port_t; +pub type processor_set_control_t = mach_port_t; +pub type semaphore_t = mach_port_t; +pub type lock_set_t = mach_port_t; +pub type ledger_t = mach_port_t; +pub type alarm_t = mach_port_t; +pub type clock_serv_t = mach_port_t; +pub type clock_ctrl_t = mach_port_t; + +pub type processor_set_name_t = processor_set_t; + +pub type clock_reply_t = mach_port_t; +pub type bootstrap_t = mach_port_t; +pub type mem_entry_name_port_t = mach_port_t; +pub type exception_handler_t = mach_port_t; +pub type exception_handler_array_t = *mut exception_handler_t; +pub type vm_task_entry_t = mach_port_t; +pub type io_master_t = mach_port_t; +pub type UNDServerRef = mach_port_t; + +pub type task_array_t = *mut task_t; +pub type thread_array_t = *mut thread_t; +pub type processor_set_array_t = *mut processor_set_t; +pub type processor_set_name_array_t = *mut processor_set_t; +pub type processor_array_t = *mut processor_t; +pub type thread_act_array_t = *mut thread_act_t; +pub type ledger_array_t = *mut ledger_t; + +pub type task_port_t = task_t; +pub type task_port_array_t = task_array_t; +pub type thread_port_t = thread_t; +pub type thread_port_array_t = thread_array_t; +pub type ipc_space_port_t = ipc_space_t; +pub type host_name_t = host_t; +pub type host_name_port_t = host_t; +pub type processor_set_port_t = processor_set_t; +pub type processor_set_name_port_t = processor_set_t; +pub type processor_set_name_port_array_t = processor_set_array_t; +pub type processor_set_control_port_t = processor_set_t; +pub type processor_port_t = processor_t; +pub type processor_port_array_t = processor_array_t; +pub type thread_act_port_t = thread_act_t; +pub type thread_act_port_array_t = thread_act_array_t; +pub type semaphore_port_t = semaphore_t; +pub type lock_set_port_t = lock_set_t; +pub type ledger_port_t = ledger_t; +pub type ledger_port_array_t = ledger_array_t; +pub type alarm_port_t = alarm_t; +pub type clock_serv_port_t = clock_serv_t; +pub type clock_ctrl_port_t = clock_ctrl_t; +pub type exception_port_t = exception_handler_t; +pub type exception_port_arrary_t = exception_handler_array_t; + +pub const TASK_NULL: task_t = 0; +pub const TASK_NAME_NULL: task_name_t = 0; +pub const THREAD_NULL: thread_t = 0; +pub const TID_NULL: u64 = 0; +pub const THR_ACT_NULL: thread_act_t = 0; +pub const IPC_SPACE_NULL: ipc_space_t = 0; +pub const COALITION_NULL: coalition_t = 0; +pub const HOST_NULL: host_t = 0; +pub const HOST_PRIV_NULL: host_priv_t = 0; +pub const HOST_SECURITY_NULL: host_security_t = 0; +pub const PROCESSOR_SET_NULL: processor_set_t = 0; +pub const PROCESSOR_NULL: processor_t = 0; +pub const SEMAPHORE_NULL: semaphore_t = 0; +pub const LOCK_SET_NULL: lock_set_t = 0; +pub const LEDGER_NULL: ledger_t = 0; +pub const ALARM_NULL: alarm_t = 0; +pub const CLOCK_NULL: ::libc::clock_t = 0; +pub const UND_SERVER_NULL: UNDServerRef = 0; + +// <sys/_types.h>: typedef unsigned char __darwin_uuid_t[16]; +pub type uuid_t = [::libc::c_uchar; 16]; + +// <sys/_types/_fsid_t.h> +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct fsid { + pub val: [i32; 2], +} +pub type fsid_t = fsid; + +// <sys/_types/_fsobj_id_t.h> +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct fsobj_id { + pub fid_objno: u32, + pub fid_generation: u32, +} +pub type fsobj_id_t = fsobj_id; diff --git a/third_party/rust/mach/src/memory_object_types.rs b/third_party/rust/mach/src/memory_object_types.rs new file mode 100644 index 0000000000..8399e71676 --- /dev/null +++ b/third_party/rust/mach/src/memory_object_types.rs @@ -0,0 +1,9 @@ +//! This module roughly corresponds to `mach/memory_object_types.h`. + +use vm_types::natural_t; + +pub type memory_object_offset_t = ::libc::c_ulonglong; +pub type memory_object_size_t = ::libc::c_ulonglong; +pub type memory_object_cluster_size_t = natural_t; +pub type memory_object_fault_info_t = *mut natural_t; +pub type vm_object_id_t = ::libc::c_ulonglong; diff --git a/third_party/rust/mach/src/message.rs b/third_party/rust/mach/src/message.rs new file mode 100644 index 0000000000..4eafa5e9a4 --- /dev/null +++ b/third_party/rust/mach/src/message.rs @@ -0,0 +1,248 @@ +//! This module corresponds to `mach/message.h`. + +use kern_return::kern_return_t; +use port::{mach_port_name_t, mach_port_t}; +use vm_types::{integer_t, natural_t}; + +pub type mach_msg_timeout_t = natural_t; + +pub type mach_msg_bits_t = ::libc::c_uint; +pub type mach_msg_id_t = integer_t; +pub type mach_msg_size_t = natural_t; + +pub type mach_msg_copy_options_t = ::libc::c_uint; +pub type mach_msg_descriptor_type_t = ::libc::c_uint; +pub type mach_msg_type_name_t = ::libc::c_uint; + +pub type mach_msg_trailer_type_t = ::libc::c_uint; +pub type mach_msg_trailer_size_t = ::libc::c_uint; + +pub type mach_msg_option_t = integer_t; + +pub type mach_msg_type_number_t = natural_t; +pub type mach_msg_type_size_t = natural_t; + +pub type mach_msg_return_t = kern_return_t; + +pub const MACH_MSG_TIMEOUT_NONE: mach_msg_timeout_t = 0; + +pub const MACH_MSGH_BITS_ZERO: mach_msg_bits_t = 0x0000_0000; + +pub const MACH_MSGH_BITS_REMOTE_MASK: mach_msg_bits_t = 0x0000_001f; +pub const MACH_MSGH_BITS_LOCAL_MASK: mach_msg_bits_t = 0x0000_1f00; +pub const MACH_MSGH_BITS_VOUCHER_MASK: mach_msg_bits_t = 0x001f_0000; + +pub const MACH_MSGH_BITS_PORTS_MASK: mach_msg_bits_t = + MACH_MSGH_BITS_REMOTE_MASK | MACH_MSGH_BITS_LOCAL_MASK | MACH_MSGH_BITS_VOUCHER_MASK; + +pub const MACH_MSGH_BITS_COMPLEX: mach_msg_bits_t = 0x8000_0000; + +pub const MACH_MSGH_BITS_USER: mach_msg_bits_t = 0x801f_1f1f; + +#[allow(non_snake_case)] +pub fn MACH_MSGH_BITS(remote: mach_msg_bits_t, local: mach_msg_bits_t) -> mach_msg_bits_t { + remote | (local << 8) +} + +pub const MACH_MSG_TYPE_MOVE_RECEIVE: mach_msg_type_name_t = 16; +pub const MACH_MSG_TYPE_MOVE_SEND: mach_msg_type_name_t = 17; +pub const MACH_MSG_TYPE_MOVE_SEND_ONCE: mach_msg_type_name_t = 18; +pub const MACH_MSG_TYPE_COPY_SEND: mach_msg_type_name_t = 19; +pub const MACH_MSG_TYPE_MAKE_SEND: mach_msg_type_name_t = 20; +pub const MACH_MSG_TYPE_MAKE_SEND_ONCE: mach_msg_type_name_t = 21; +pub const MACH_MSG_TYPE_COPY_RECEIVE: mach_msg_type_name_t = 22; +pub const MACH_MSG_TYPE_DISPOSE_RECEIVE: mach_msg_type_name_t = 24; +pub const MACH_MSG_TYPE_DISPOSE_SEND: mach_msg_type_name_t = 25; +pub const MACH_MSG_TYPE_DISPOSE_SEND_ONCE: mach_msg_type_name_t = 26; + +pub const MACH_MSG_PHYSICAL_COPY: mach_msg_copy_options_t = 0; +pub const MACH_MSG_VIRTUAL_COPY: mach_msg_copy_options_t = 1; +pub const MACH_MSG_ALLOCATE: mach_msg_copy_options_t = 2; + +pub const MACH_MSG_PORT_DESCRIPTOR: mach_msg_descriptor_type_t = 0; +pub const MACH_MSG_OOL_DESCRIPTOR: mach_msg_descriptor_type_t = 1; +pub const MACH_MSG_OOL_PORTS_DESCRIPTOR: mach_msg_descriptor_type_t = 2; +pub const MACH_MSG_OOL_VOLATILE_DESCRIPTOR: mach_msg_descriptor_type_t = 3; + +pub const MACH_MSG_OPTION_NONE: mach_msg_option_t = 0x0000_0000; + +pub const MACH_SEND_MSG: mach_msg_option_t = 0x0000_0001; +pub const MACH_RCV_MSG: mach_msg_option_t = 0x0000_0002; + +pub const MACH_RCV_LARGE: mach_msg_option_t = 0x0000_0004; +pub const MACH_RCV_LARGE_IDENTITY: mach_msg_option_t = 0x0000_0008; + +pub const MACH_SEND_TIMEOUT: mach_msg_option_t = 0x0000_0010; +pub const MACH_SEND_INTERRUPT: mach_msg_option_t = 0x0000_0040; +pub const MACH_SEND_NOTIFY: mach_msg_option_t = 0x0000_0080; +pub const MACH_SEND_ALWAYS: mach_msg_option_t = 0x0001_0000; +pub const MACH_SEND_TRAILER: mach_msg_option_t = 0x0002_0000; +pub const MACH_SEND_NOIMPORTANCE: mach_msg_option_t = 0x0004_0000; +pub const MACH_SEND_NODENAP: mach_msg_option_t = MACH_SEND_NOIMPORTANCE; +pub const MACH_SEND_IMPORTANCE: mach_msg_option_t = 0x0008_0000; + +pub const MACH_RCV_TIMEOUT: mach_msg_option_t = 0x0000_0100; +pub const MACH_RCV_NOTIFY: mach_msg_option_t = 0x0000_0200; +pub const MACH_RCV_INTERRUPT: mach_msg_option_t = 0x0000_0400; +pub const MACH_RCV_VOUCHER: mach_msg_option_t = 0x0000_0800; +pub const MACH_RCV_OVERWRITE: mach_msg_option_t = 0x0000_1000; + +pub const MACH_MSG_SUCCESS: mach_msg_return_t = 0x0000_0000; + +pub const MACH_MSG_MASK: mach_msg_return_t = 0x0000_3e00; +pub const MACH_MSG_IPC_SPACE: mach_msg_return_t = 0x0000_2000; +pub const MACH_MSG_VM_SPACE: mach_msg_return_t = 0x0000_1000; +pub const MACH_MSG_IPC_KERNEL: mach_msg_return_t = 0x0000_0800; +pub const MACH_MSG_VM_KERNEL: mach_msg_return_t = 0x0000_0400; + +pub const MACH_SEND_IN_PROGRESS: mach_msg_return_t = 0x1000_0001; +pub const MACH_SEND_INVALID_DATA: mach_msg_return_t = 0x1000_0002; +pub const MACH_SEND_INVALID_DEST: mach_msg_return_t = 0x1000_0003; +pub const MACH_SEND_TIMED_OUT: mach_msg_return_t = 0x1000_0004; +pub const MACH_SEND_INVALID_VOUCHER: mach_msg_return_t = 0x1000_0005; +pub const MACH_SEND_INTERRUPTED: mach_msg_return_t = 0x1000_0007; +pub const MACH_SEND_MSG_TOO_SMALL: mach_msg_return_t = 0x1000_0008; +pub const MACH_SEND_INVALID_REPLY: mach_msg_return_t = 0x1000_0009; +pub const MACH_SEND_INVALID_RIGHT: mach_msg_return_t = 0x1000_000a; +pub const MACH_SEND_INVALID_NOTIFY: mach_msg_return_t = 0x1000_000b; +pub const MACH_SEND_INVALID_MEMORY: mach_msg_return_t = 0x1000_000c; +pub const MACH_SEND_NO_BUFFER: mach_msg_return_t = 0x1000_000d; +pub const MACH_SEND_TOO_LARGE: mach_msg_return_t = 0x1000_000e; +pub const MACH_SEND_INVALID_TYPE: mach_msg_return_t = 0x1000_000f; +pub const MACH_SEND_INVALID_HEADER: mach_msg_return_t = 0x1000_0010; +pub const MACH_SEND_INVALID_TRAILER: mach_msg_return_t = 0x1000_0011; +pub const MACH_SEND_INVALID_RT_OOL_SIZE: mach_msg_return_t = 0x1000_0015; + +pub const MACH_RCV_IN_PROGRESS: mach_msg_return_t = 0x1000_4001; +pub const MACH_RCV_INVALID_NAME: mach_msg_return_t = 0x1000_4002; +pub const MACH_RCV_TIMED_OUT: mach_msg_return_t = 0x1000_4003; +pub const MACH_RCV_TOO_LARGE: mach_msg_return_t = 0x1000_4004; +pub const MACH_RCV_INTERRUPTED: mach_msg_return_t = 0x1000_4005; +pub const MACH_RCV_PORT_CHANGED: mach_msg_return_t = 0x1000_4006; +pub const MACH_RCV_INVALID_NOTIFY: mach_msg_return_t = 0x1000_4007; +pub const MACH_RCV_INVALID_DATA: mach_msg_return_t = 0x1000_4008; +pub const MACH_RCV_PORT_DIED: mach_msg_return_t = 0x1000_4009; +pub const MACH_RCV_IN_SET: mach_msg_return_t = 0x1000_400a; +pub const MACH_RCV_HEADER_ERROR: mach_msg_return_t = 0x1000_400b; +pub const MACH_RCV_BODY_ERROR: mach_msg_return_t = 0x1000_400c; +pub const MACH_RCV_INVALID_TYPE: mach_msg_return_t = 0x1000_400d; +pub const MACH_RCV_SCATTER_SMALL: mach_msg_return_t = 0x1000_400e; +pub const MACH_RCV_INVALID_TRAILER: mach_msg_return_t = 0x1000_400f; +pub const MACH_RCV_IN_PROGRESS_TIMED: mach_msg_return_t = 0x1000_4011; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_header_t { + pub msgh_bits: mach_msg_bits_t, + pub msgh_size: mach_msg_size_t, + pub msgh_remote_port: mach_port_t, + pub msgh_local_port: mach_port_t, + pub msgh_voucher_port: mach_port_name_t, + pub msgh_id: mach_msg_id_t, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_body_t { + pub msgh_descriptor_count: mach_msg_size_t, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_base_t { + pub header: mach_msg_header_t, + pub body: mach_msg_body_t, +} + +pub const MACH_MSG_TRAILER_FORMAT_0: mach_msg_trailer_type_t = 0; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_trailer_t { + pub msgh_trailer_type: mach_msg_trailer_type_t, + pub msgh_trailer_size: mach_msg_trailer_size_t, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_port_descriptor_t { + pub name: mach_port_t, + pub pad1: mach_msg_size_t, + pub pad2: u16, + pub disposition: u8, // mach_msg_type_name_t bitfield + pub type_: u8, // mach_msg_descriptor_type_t bitfield +} + +impl mach_msg_port_descriptor_t { + pub fn new(name: mach_port_t, disposition: mach_msg_type_name_t) -> Self { + Self { + name, + pad1: 0, + pad2: 0, + disposition: disposition as u8, + type_: MACH_MSG_PORT_DESCRIPTOR as u8, + } + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_ool_descriptor_t { + pub address: *mut ::libc::c_void, + #[cfg(not(target_pointer_width = "64"))] + pub size: mach_msg_size_t, + pub deallocate: u8, // boolean_t bitfield + pub copy: u8, // mach_msg_copy_options_t bitfield + pub pad1: u8, + pub type_: u8, // mach_msg_descriptor_type_t bitfield + #[cfg(target_pointer_width = "64")] + pub size: mach_msg_size_t, +} + +impl mach_msg_ool_descriptor_t { + pub fn new( + address: *mut ::libc::c_void, + deallocate: bool, + copy: mach_msg_copy_options_t, + size: u32, + ) -> Self { + Self { + address, + deallocate: if deallocate { 1 } else { 0 }, + copy: copy as u8, + pad1: 0, + type_: MACH_MSG_OOL_DESCRIPTOR as u8, + size, + } + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_msg_ool_ports_descriptor_t { + pub address: *mut ::libc::c_void, + #[cfg(not(target_pointer_width = "64"))] + pub count: mach_msg_size_t, + pub deallocate: u8, // boolean_t bitfield + pub copy: u8, // mach_msg_copy_options_t bitfield + pub disposition: u8, // mach_msg_type_name_t bitfield + pub type_: u8, // mach_msg_descriptor_type_t bitfield + #[cfg(target_pointer_width = "64")] + pub count: mach_msg_size_t, +} + +extern "C" { + pub fn mach_msg( + msg: *mut mach_msg_header_t, + option: mach_msg_option_t, + send_size: mach_msg_size_t, + recv_size: mach_msg_size_t, + recv_name: mach_port_name_t, + timeout: mach_msg_timeout_t, + notify: mach_port_name_t, + ) -> mach_msg_return_t; + + // from mach/mach.h + pub fn mach_msg_send(msg: *mut mach_msg_header_t) -> mach_msg_return_t; + pub fn mach_msg_destroy(msg: *mut mach_msg_header_t); +} diff --git a/third_party/rust/mach/src/port.rs b/third_party/rust/mach/src/port.rs new file mode 100644 index 0000000000..e43e81d0d3 --- /dev/null +++ b/third_party/rust/mach/src/port.rs @@ -0,0 +1,26 @@ +//! This module corresponds to `mach/port.h` + +use vm_types::natural_t; + +pub type mach_port_name_t = natural_t; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct ipc_port; + +pub type ipc_port_t = *mut ipc_port; + +pub type mach_port_t = ::libc::c_uint; + +pub const MACH_PORT_NULL: mach_port_t = 0; +pub const MACH_PORT_DEAD: mach_port_t = !0; + +pub type mach_port_right_t = natural_t; + +pub const MACH_PORT_RIGHT_SEND: mach_port_right_t = 0; +pub const MACH_PORT_RIGHT_RECEIVE: mach_port_right_t = 1; +pub const MACH_PORT_RIGHT_SEND_ONCE: mach_port_right_t = 2; +pub const MACH_PORT_RIGHT_PORT_SET: mach_port_right_t = 3; +pub const MACH_PORT_RIGHT_DEAD_NAME: mach_port_right_t = 4; +pub const MACH_PORT_RIGHT_LABELH: mach_port_right_t = 5; +pub const MACH_PORT_RIGHT_NUMBER: mach_port_right_t = 6; diff --git a/third_party/rust/mach/src/structs.rs b/third_party/rust/mach/src/structs.rs new file mode 100644 index 0000000000..75dc0e8dba --- /dev/null +++ b/third_party/rust/mach/src/structs.rs @@ -0,0 +1,62 @@ +//! This module corresponds to `mach/_structs.h`. + +use mem; +use message::mach_msg_type_number_t; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct x86_thread_state64_t { + pub __rax: u64, + pub __rbx: u64, + pub __rcx: u64, + pub __rdx: u64, + pub __rdi: u64, + pub __rsi: u64, + pub __rbp: u64, + pub __rsp: u64, + pub __r8: u64, + pub __r9: u64, + pub __r10: u64, + pub __r11: u64, + pub __r12: u64, + pub __r13: u64, + pub __r14: u64, + pub __r15: u64, + pub __rip: u64, + pub __rflags: u64, + pub __cs: u64, + pub __fs: u64, + pub __gs: u64, +} + +impl x86_thread_state64_t { + pub fn new() -> Self { + Self { + __rax: 0, + __rbx: 0, + __rcx: 0, + __rdx: 0, + __rdi: 0, + __rsi: 0, + __rbp: 0, + __rsp: 0, + __r8: 0, + __r9: 0, + __r10: 0, + __r11: 0, + __r12: 0, + __r13: 0, + __r14: 0, + __r15: 0, + __rip: 0, + __rflags: 0, + __cs: 0, + __fs: 0, + __gs: 0, + } + } + + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} diff --git a/third_party/rust/mach/src/task.rs b/third_party/rust/mach/src/task.rs new file mode 100644 index 0000000000..1ca2280eb1 --- /dev/null +++ b/third_party/rust/mach/src/task.rs @@ -0,0 +1,41 @@ +//! This module corresponds to `mach/task.defs`. + +use kern_return::kern_return_t; +use mach_types::{task_name_t, task_t, thread_act_array_t}; +use message::mach_msg_type_number_t; +use port::mach_port_t; +use task_info::{task_flavor_t, task_info_t}; + +pub type task_special_port_t = ::libc::c_int; + +pub const TASK_KERNEL_PORT: task_special_port_t = 1; +pub const TASK_HOST_PORT: task_special_port_t = 2; +pub const TASK_NAME_PORT: task_special_port_t = 3; +pub const TASK_BOOTSTRAP_PORT: task_special_port_t = 4; + +extern "C" { + pub fn task_resume(target_task: task_t) -> kern_return_t; + pub fn task_suspend(target_task: task_t) -> kern_return_t; + pub fn task_get_special_port( + task: task_t, + which_port: task_special_port_t, + special_port: *mut mach_port_t, + ) -> kern_return_t; + pub fn task_threads( + target_task: task_t, + act_list: *mut thread_act_array_t, + act_list_cnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + pub fn task_info( + target_task: task_name_t, + flavor: task_flavor_t, + task_info_out: task_info_t, + task_info_outCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + pub fn task_set_info( + target_task: task_t, + flavor: task_flavor_t, + task_info_in: task_info_t, + task_info_inCnt: mach_msg_type_number_t, + ) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/task_info.rs b/third_party/rust/mach/src/task_info.rs new file mode 100644 index 0000000000..4a3b8ed710 --- /dev/null +++ b/third_party/rust/mach/src/task_info.rs @@ -0,0 +1,44 @@ +//! This module roughly corresponds to `mach/task_info.h`. + +use vm_types::{integer_t, mach_vm_address_t, mach_vm_size_t, natural_t}; + +pub const TASK_INFO_MAX: ::libc::c_uint = 1024; +pub const TASK_BASIC_INFO_32: ::libc::c_uint = 4; +pub const TASK_BASIC2_INFO_32: ::libc::c_uint = 6; +pub const TASK_BASIC_INFO_64: ::libc::c_uint = 5; +#[cfg(target_arch = "x86_64")] +pub const TASK_BASIC_INFO: ::libc::c_uint = 5; +#[cfg(target_arch = "x86")] +pub const TASK_BASIC_INFO: ::libc::c_uint = 4; +pub const TASK_EVENTS_INFO: ::libc::c_uint = 2; +pub const TASK_THREAD_TIMES_INFO: ::libc::c_uint = 3; +pub const TASK_ABSOLUTETIME_INFO: ::libc::c_uint = 1; +pub const TASK_KERNELMEMORY_INFO: ::libc::c_uint = 7; +pub const TASK_SECURITY_TOKEN: ::libc::c_uint = 13; +pub const TASK_AUDIT_TOKEN: ::libc::c_uint = 15; +pub const TASK_AFFINITY_TAG_INFO: ::libc::c_uint = 16; +pub const TASK_DYLD_INFO: ::libc::c_uint = 17; +pub const TASK_DYLD_ALL_IMAGE_INFO_32: ::libc::c_uint = 0; +pub const TASK_DYLD_ALL_IMAGE_INFO_64: ::libc::c_uint = 1; +pub const TASK_EXTMOD_INFO: ::libc::c_uint = 19; +pub const MACH_TASK_BASIC_INFO: ::libc::c_uint = 20; +pub const TASK_POWER_INFO: ::libc::c_uint = 21; +pub const TASK_VM_INFO: ::libc::c_uint = 22; +pub const TASK_VM_INFO_PURGEABLE: ::libc::c_uint = 23; +pub const TASK_TRACE_MEMORY_INFO: ::libc::c_uint = 24; +pub const TASK_WAIT_STATE_INFO: ::libc::c_uint = 25; +pub const TASK_POWER_INFO_V2: ::libc::c_uint = 26; +pub const TASK_VM_INFO_PURGEABLE_ACCOUNT: ::libc::c_uint = 27; +pub const TASK_FLAGS_INFO: ::libc::c_uint = 28; +pub const TASK_DEBUG_INFO_INTERNAL: ::libc::c_uint = 29; + +pub type task_flavor_t = natural_t; +pub type task_info_t = *mut integer_t; + +#[repr(C, packed(4))] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct task_dyld_info { + pub all_image_info_addr: mach_vm_address_t, + pub all_image_info_size: mach_vm_size_t, + pub all_image_info_format: integer_t, +} diff --git a/third_party/rust/mach/src/thread_act.rs b/third_party/rust/mach/src/thread_act.rs new file mode 100644 index 0000000000..f2f9809a2b --- /dev/null +++ b/third_party/rust/mach/src/thread_act.rs @@ -0,0 +1,23 @@ +//! This module corresponds to `mach/thread_act.defs`. + +use kern_return::kern_return_t; +use mach_types::thread_act_t; +use message::mach_msg_type_number_t; +use thread_status::{thread_state_flavor_t, thread_state_t}; + +extern "C" { + pub fn thread_get_state( + target_act: thread_act_t, + flavor: thread_state_flavor_t, + new_state: thread_state_t, + new_state_count: *mut mach_msg_type_number_t, + ) -> kern_return_t; +} + +extern "C" { + pub fn thread_suspend(target_act: thread_act_t) -> kern_return_t; +} + +extern "C" { + pub fn thread_resume(target_act: thread_act_t) -> kern_return_t; +} diff --git a/third_party/rust/mach/src/thread_status.rs b/third_party/rust/mach/src/thread_status.rs new file mode 100644 index 0000000000..951256622c --- /dev/null +++ b/third_party/rust/mach/src/thread_status.rs @@ -0,0 +1,23 @@ +//! This module corresponds to `mach/thread_status.h`. + +use vm_types::natural_t; + +pub type thread_state_t = *mut natural_t; +pub type thread_state_flavor_t = ::libc::c_int; + +pub static x86_THREAD_STATE32: thread_state_flavor_t = 1; +pub static x86_FLOAT_STATE32: thread_state_flavor_t = 2; +pub static x86_EXCEPTION_STATE32: thread_state_flavor_t = 3; +pub static x86_THREAD_STATE64: thread_state_flavor_t = 4; +pub static x86_FLOAT_STATE64: thread_state_flavor_t = 5; +pub static x86_EXCEPTION_STATE64: thread_state_flavor_t = 6; +pub static x86_THREAD_STATE: thread_state_flavor_t = 7; +pub static x86_FLOAT_STATE: thread_state_flavor_t = 8; +pub static x86_EXCEPTION_STATE: thread_state_flavor_t = 9; +pub static x86_DEBUG_STATE32: thread_state_flavor_t = 10; +pub static x86_DEBUG_STATE64: thread_state_flavor_t = 11; +pub static x86_DEBUG_STATE: thread_state_flavor_t = 12; +pub static THREAD_STATE_NONE: thread_state_flavor_t = 13; +pub static x86_AVX_STATE32: thread_state_flavor_t = 16; +pub static x86_AVX_STATE64: thread_state_flavor_t = 17; +pub static x86_AVX_STATE: thread_state_flavor_t = 18; diff --git a/third_party/rust/mach/src/traps.rs b/third_party/rust/mach/src/traps.rs new file mode 100644 index 0000000000..bc8694fcbf --- /dev/null +++ b/third_party/rust/mach/src/traps.rs @@ -0,0 +1,35 @@ +//! This module corresponds to `mach/mach_traps.h`. +use kern_return::kern_return_t; +use port::{mach_port_name_t, mach_port_t}; + +extern "C" { + static mach_task_self_: mach_port_t; + pub fn task_for_pid( + target_tport: mach_port_name_t, + pid: ::libc::c_int, + tn: *mut mach_port_name_t, + ) -> kern_return_t; +} + +pub unsafe fn mach_task_self() -> mach_port_t { + mach_task_self_ +} + +pub unsafe fn current_task() -> mach_port_t { + mach_task_self() +} + +#[cfg(test)] +mod tests { + use port::*; + use traps::*; + + #[test] + fn mach_task_self_sanity() { + unsafe { + let this_task = mach_task_self(); + assert!(this_task != MACH_PORT_NULL); + assert!(this_task != MACH_PORT_DEAD); + } + } +} diff --git a/third_party/rust/mach/src/vm.rs b/third_party/rust/mach/src/vm.rs new file mode 100644 index 0000000000..400ff2bf8a --- /dev/null +++ b/third_party/rust/mach/src/vm.rs @@ -0,0 +1,247 @@ +//! This module roughly corresponds to `mach/mach_vm.defs`. + +use boolean::boolean_t; +use kern_return::kern_return_t; +use mach_types::{mem_entry_name_port_t, vm_task_entry_t}; +use memory_object_types::{memory_object_offset_t, memory_object_size_t}; +use message::mach_msg_type_number_t; +use port::mach_port_t; +use vm_attributes::{vm_machine_attribute_t, vm_machine_attribute_val_t}; +use vm_behavior::vm_behavior_t; +use vm_inherit::vm_inherit_t; +use vm_prot::vm_prot_t; +use vm_purgable::vm_purgable_t; +use vm_region::mach_vm_read_entry_t; +use vm_region::{ + vm_page_info_flavor_t, vm_page_info_t, vm_region_flavor_t, vm_region_info_t, + vm_region_recurse_info_t, +}; +use vm_sync::vm_sync_t; +use vm_types::{ + integer_t, mach_vm_address_t, mach_vm_offset_t, mach_vm_size_t, natural_t, vm_map_t, + vm_offset_t, vm_size_t, +}; + +extern "C" { + pub fn mach_vm_allocate( + target: vm_task_entry_t, + address: *mut mach_vm_address_t, + size: mach_vm_size_t, + flags: ::libc::c_int, + ) -> kern_return_t; + + pub fn mach_vm_deallocate( + target: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + ) -> kern_return_t; + + pub fn mach_vm_protect( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + set_maximum: boolean_t, + new_protection: vm_prot_t, + ) -> kern_return_t; + + pub fn mach_vm_inherit( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + new_inheritance: vm_inherit_t, + ) -> kern_return_t; + + pub fn mach_vm_read( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + data: *mut vm_offset_t, + dataCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + + pub fn mach_vm_read_list( + target_task: vm_task_entry_t, + data_list: mach_vm_read_entry_t, + count: natural_t, + ) -> kern_return_t; + + pub fn mach_vm_write( + target_task: vm_map_t, + address: mach_vm_address_t, + data: vm_offset_t, + dataCnt: mach_msg_type_number_t, + ) -> kern_return_t; + + pub fn mach_vm_copy( + target_task: vm_task_entry_t, + source_address: mach_vm_address_t, + size: mach_vm_size_t, + dest_address: mach_vm_address_t, + ) -> kern_return_t; + + pub fn mach_vm_read_overwrite( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + data: mach_vm_address_t, + outsize: *mut mach_vm_size_t, + ) -> kern_return_t; + + pub fn mach_vm_msync( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + sync_flags: vm_sync_t, + ) -> kern_return_t; + + pub fn mach_vm_behavior_set( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + new_behavior: vm_behavior_t, + ) -> kern_return_t; + + pub fn mach_vm_map( + target_task: vm_task_entry_t, + inout: *mut mach_vm_address_t, + size: mach_vm_size_t, + mask: mach_vm_offset_t, + flags: ::libc::c_int, + object: mem_entry_name_port_t, + offset: memory_object_offset_t, + copy: boolean_t, + cur_protection: vm_prot_t, + max_protection: vm_prot_t, + inheritance: vm_inherit_t, + ) -> kern_return_t; + + pub fn mach_vm_machine_attribute( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + size: mach_vm_size_t, + attribute: vm_machine_attribute_t, + value: *mut vm_machine_attribute_val_t, + ) -> kern_return_t; + + pub fn mach_vm_remap( + target_task: vm_task_entry_t, + target_address: *mut mach_vm_address_t, + size: mach_vm_size_t, + mask: mach_vm_offset_t, + flags: ::libc::c_int, + src_task: vm_task_entry_t, + src_address: mach_vm_address_t, + copy: boolean_t, + cur_protection: *mut vm_prot_t, + out: *mut vm_prot_t, + inheritance: vm_inherit_t, + ) -> kern_return_t; + + pub fn mach_vm_page_query( + target_map: vm_map_t, + offset: mach_vm_offset_t, + disposition: *mut integer_t, + ref_count: *mut integer_t, + ) -> kern_return_t; + + pub fn mach_vm_region_recurse( + target_task: vm_task_entry_t, + address: *mut mach_vm_address_t, + size: *mut mach_vm_size_t, + nesting_depth: *mut natural_t, + info: vm_region_recurse_info_t, + infoCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; + + pub fn mach_vm_region( + target_task: vm_task_entry_t, + address: *mut mach_vm_address_t, + size: *mut mach_vm_size_t, + flavor: vm_region_flavor_t, + info: vm_region_info_t, + infoCnt: *mut mach_msg_type_number_t, + object_name: *mut mach_port_t, + ) -> kern_return_t; + + pub fn mach_make_memory_entry( + target_task: vm_map_t, + size: *mut vm_size_t, + offset: vm_offset_t, + permission: vm_prot_t, + object_handle: *mut mem_entry_name_port_t, + parent_handle: mem_entry_name_port_t, + ) -> kern_return_t; + + pub fn mach_make_memory_entry_64( + target_task: vm_map_t, + size: *mut memory_object_size_t, + offset: memory_object_offset_t, + permission: vm_prot_t, + object_handle: *mut mach_port_t, + parent_entry: mem_entry_name_port_t, + ) -> kern_return_t; + + pub fn mach_vm_purgable_control( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + control: vm_purgable_t, + state: *mut ::libc::c_int, + ) -> kern_return_t; + + pub fn mach_vm_page_info( + target_task: vm_task_entry_t, + address: mach_vm_address_t, + flavor: vm_page_info_flavor_t, + info: vm_page_info_t, + infoCnt: *mut mach_msg_type_number_t, + ) -> kern_return_t; +} + +#[cfg(test)] +mod tests { + use super::*; + use kern_return::KERN_SUCCESS; + use traps::mach_task_self; + use vm_statistics::VM_FLAGS_ANYWHERE; + + #[test] + fn mach_vm_allocate_sanity() { + unsafe { + let size = 0x100; + let task = mach_task_self(); + + let mut address: mach_vm_address_t = 0; + assert_eq!( + mach_vm_allocate(task, &mut address, size, VM_FLAGS_ANYWHERE), + KERN_SUCCESS + ); + assert_eq!(mach_vm_deallocate(task, address, size), KERN_SUCCESS); + } + } + + #[test] + fn mach_vm_region_sanity() { + use mem; + use vm_prot::{VM_PROT_EXECUTE, VM_PROT_READ}; + use vm_region::{vm_region_basic_info_64, VM_REGION_BASIC_INFO_64}; + unsafe { + let mut size = 0x10; + let mut object_name = 0; + let mut address = mach_vm_region_sanity as mach_vm_address_t; + let mut info: vm_region_basic_info_64 = mem::zeroed(); + let mut info_size = vm_region_basic_info_64::count(); + + let result = mach_vm_region( + mach_task_self(), + &mut address, + &mut size, + VM_REGION_BASIC_INFO_64, + (&mut info as *mut _) as vm_region_info_t, + &mut info_size, + &mut object_name, + ); + assert_eq!(result, KERN_SUCCESS); + assert_eq!(info.protection, VM_PROT_READ | VM_PROT_EXECUTE); + } + } +} diff --git a/third_party/rust/mach/src/vm_attributes.rs b/third_party/rust/mach/src/vm_attributes.rs new file mode 100644 index 0000000000..9c484b1d17 --- /dev/null +++ b/third_party/rust/mach/src/vm_attributes.rs @@ -0,0 +1,18 @@ +//! This module corresponds to `mach/vm_attributes.h`. + +pub type vm_machine_attribute_t = ::libc::c_uint; + +pub const MATTR_CACHE: vm_machine_attribute_t = 1; +pub const MATTR_MIGRATE: vm_machine_attribute_t = (1 << 1); +pub const MATTR_REPLICATE: vm_machine_attribute_t = (1 << 2); + +pub type vm_machine_attribute_val_t = ::libc::c_int; + +pub const MATTR_VAL_OFF: vm_machine_attribute_val_t = 0; +pub const MATTR_VAL_ON: vm_machine_attribute_val_t = 1; +pub const MATTR_VAL_GET: vm_machine_attribute_val_t = 2; +pub const MATTR_VAL_CACHE_FLUSH: vm_machine_attribute_val_t = 6; +pub const MATTR_VAL_DCACHE_FLUSH: vm_machine_attribute_val_t = 7; +pub const MATTR_VAL_ICACHE_FLUSH: vm_machine_attribute_val_t = 8; +pub const MATTR_VAL_CACHE_SYNC: vm_machine_attribute_val_t = 9; +pub const MATTR_VAL_GET_INFO: vm_machine_attribute_val_t = 10; diff --git a/third_party/rust/mach/src/vm_behavior.rs b/third_party/rust/mach/src/vm_behavior.rs new file mode 100644 index 0000000000..8ab692e550 --- /dev/null +++ b/third_party/rust/mach/src/vm_behavior.rs @@ -0,0 +1,15 @@ +//! This module corresponds to `mach/vm_behavior.h`. + +pub type vm_behavior_t = ::libc::c_int; + +pub const VM_BEHAVIOR_DEFAULT: vm_behavior_t = 0; +pub const VM_BEHAVIOR_RANDOM: vm_behavior_t = 1; +pub const VM_BEHAVIOR_SEQUENTIAL: vm_behavior_t = 2; +pub const VM_BEHAVIOR_RSEQNTL: vm_behavior_t = 3; +pub const VM_BEHAVIOR_WILLNEED: vm_behavior_t = 4; +pub const VM_BEHAVIOR_DONTNEED: vm_behavior_t = 5; +pub const VM_BEHAVIOR_FREE: vm_behavior_t = 6; +pub const VM_BEHAVIOR_ZERO_WIRED_PAGES: vm_behavior_t = 7; +pub const VM_BEHAVIOR_REUSABLE: vm_behavior_t = 8; +pub const VM_BEHAVIOR_REUSE: vm_behavior_t = 9; +pub const VM_BEHAVIOR_CAN_REUSE: vm_behavior_t = 10; diff --git a/third_party/rust/mach/src/vm_inherit.rs b/third_party/rust/mach/src/vm_inherit.rs new file mode 100644 index 0000000000..4f4c9e5ef7 --- /dev/null +++ b/third_party/rust/mach/src/vm_inherit.rs @@ -0,0 +1,10 @@ +//! This module corresponds to `mach/vm_inherit.h`. + +pub type vm_inherit_t = ::libc::c_uint; + +pub const VM_INHERIT_SHARE: vm_inherit_t = 0; +pub const VM_INHERIT_COPY: vm_inherit_t = 1; +pub const VM_INHERIT_NONE: vm_inherit_t = 2; +pub const VM_INHERIT_DONATE_COPY: vm_inherit_t = 3; +pub const VM_INHERIT_DEFAULT: vm_inherit_t = VM_INHERIT_COPY; +pub const VM_INHERIT_LAST_VALID: vm_inherit_t = VM_INHERIT_NONE; diff --git a/third_party/rust/mach/src/vm_page_size.rs b/third_party/rust/mach/src/vm_page_size.rs new file mode 100644 index 0000000000..511932eb09 --- /dev/null +++ b/third_party/rust/mach/src/vm_page_size.rs @@ -0,0 +1,33 @@ +//! This module roughly corresponds to `mach/vm_page_size.h` + +use vm_types::{mach_vm_offset_t, mach_vm_size_t, vm_size_t}; + +extern "C" { + pub static vm_page_size: vm_size_t; + pub static vm_page_mask: vm_size_t; + pub static vm_page_shift: ::libc::c_int; +} + +pub unsafe fn mach_vm_trunc_page(x: mach_vm_offset_t) -> mach_vm_offset_t { + (x & !(vm_page_mask as mach_vm_size_t)) +} + +pub unsafe fn mach_vm_round_page(x: mach_vm_offset_t) -> mach_vm_offset_t { + ((x + vm_page_mask as mach_vm_size_t) & !(vm_page_mask as mach_vm_size_t)) +} + +#[cfg(test)] +mod tests { + use vm_page_size::*; + use vm_types::mach_vm_size_t; + + #[test] + fn page_size() { + unsafe { + assert!(vm_page_size > 0); + assert!(vm_page_size % 2 == 0); + assert_eq!(mach_vm_round_page(1), vm_page_size as mach_vm_size_t); + assert_eq!(vm_page_size, 4096); + } + } +} diff --git a/third_party/rust/mach/src/vm_prot.rs b/third_party/rust/mach/src/vm_prot.rs new file mode 100644 index 0000000000..8f7d3fbc53 --- /dev/null +++ b/third_party/rust/mach/src/vm_prot.rs @@ -0,0 +1,14 @@ +//! This module corresponds to `mach/vm_prot.h`. + +pub type vm_prot_t = ::libc::c_int; + +pub const VM_PROT_NONE: vm_prot_t = 0; +pub const VM_PROT_READ: vm_prot_t = 1; +pub const VM_PROT_WRITE: vm_prot_t = (1 << 1); +pub const VM_PROT_EXECUTE: vm_prot_t = (1 << 2); +pub const VM_PROT_NO_CHANGE: vm_prot_t = (1 << 3); +pub const VM_PROT_COPY: vm_prot_t = (1 << 4); +pub const VM_PROT_WANTS_COPY: vm_prot_t = (1 << 4); +pub const VM_PROT_TRUSTED: vm_prot_t = (1 << 5); +pub const VM_PROT_DEFAULT: vm_prot_t = VM_PROT_READ | VM_PROT_WRITE; +pub const VM_PROT_ALL: vm_prot_t = VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE; diff --git a/third_party/rust/mach/src/vm_purgable.rs b/third_party/rust/mach/src/vm_purgable.rs new file mode 100644 index 0000000000..622f3b8bb0 --- /dev/null +++ b/third_party/rust/mach/src/vm_purgable.rs @@ -0,0 +1,42 @@ +//! This module corresponds to `mach/vm_purgable.h`. + +pub type vm_purgable_t = ::libc::c_int; + +pub const VM_PURGABLE_SET_STATE: vm_purgable_t = 0; +pub const VM_PURGABLE_GET_STATE: vm_purgable_t = 1; + +pub const VM_VOLATILE_GROUP_SHIFT: ::libc::c_int = 8; +pub const VM_VOLATILE_GROUP_MASK: ::libc::c_int = (7 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_DEFAULT: ::libc::c_int = VM_VOLATILE_GROUP_0; + +pub const VM_VOLATILE_GROUP_0: ::libc::c_int = (0 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_1: ::libc::c_int = (1 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_2: ::libc::c_int = (2 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_3: ::libc::c_int = (3 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_4: ::libc::c_int = (4 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_5: ::libc::c_int = (5 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_6: ::libc::c_int = (6 << VM_VOLATILE_GROUP_SHIFT); +pub const VM_VOLATILE_GROUP_7: ::libc::c_int = (7 << VM_VOLATILE_GROUP_SHIFT); + +pub const VM_PURGABLE_BEHAVIOR_SHIFT: ::libc::c_int = 6; +pub const VM_PURGABLE_BEHAVIOR_MASK: ::libc::c_int = (1 << VM_PURGABLE_BEHAVIOR_SHIFT); +pub const VM_PURGABLE_BEHAVIOR_FIFO: ::libc::c_int = (0 << VM_PURGABLE_BEHAVIOR_SHIFT); +pub const VM_PURGABLE_BEHAVIOR_LIFO: ::libc::c_int = (1 << VM_PURGABLE_BEHAVIOR_SHIFT); + +pub const VM_PURGABLE_ORDERING_SHIFT: ::libc::c_int = 5; +pub const VM_PURGABLE_ORDERING_MASK: ::libc::c_int = (1 << VM_PURGABLE_ORDERING_SHIFT); +pub const VM_PURGABLE_ORDERING_OBSOLETE: ::libc::c_int = (1 << VM_PURGABLE_ORDERING_SHIFT); +pub const VM_PURGABLE_ORDERING_NORMAL: ::libc::c_int = (0 << VM_PURGABLE_ORDERING_SHIFT); + +pub const VM_VOLATILE_ORDER_SHIFT: ::libc::c_int = 4; +pub const VM_VOLATILE_ORDER_MASK: ::libc::c_int = (1 << VM_VOLATILE_ORDER_SHIFT); +pub const VM_VOLATILE_MAKE_FIRST_IN_GROUP: ::libc::c_int = (1 << VM_VOLATILE_ORDER_SHIFT); +pub const VM_VOLATILE_MAKE_LAST_IN_GROUP: ::libc::c_int = (0 << VM_VOLATILE_ORDER_SHIFT); + +pub const VM_PURGABLE_STATE_MIN: ::libc::c_int = 0; +pub const VM_PURGABLE_STATE_MAX: ::libc::c_int = 3; +pub const VM_PURGABLE_STATE_MASK: ::libc::c_int = 3; +pub const VM_PURGABLE_NONVOLATILE: ::libc::c_int = 0; +pub const VM_PURGABLE_VOLATILE: ::libc::c_int = 1; +pub const VM_PURGABLE_EMPTY: ::libc::c_int = 2; +pub const VM_PURGABLE_DENY: ::libc::c_int = 3; diff --git a/third_party/rust/mach/src/vm_region.rs b/third_party/rust/mach/src/vm_region.rs new file mode 100644 index 0000000000..0586d4ea57 --- /dev/null +++ b/third_party/rust/mach/src/vm_region.rs @@ -0,0 +1,238 @@ +//! This module roughly corresponds to `mach/vm_region.h`. + +use boolean::boolean_t; +use mem; +use memory_object_types::{memory_object_offset_t, vm_object_id_t}; +use message::mach_msg_type_number_t; +use vm_behavior::vm_behavior_t; +use vm_inherit::vm_inherit_t; +use vm_prot::vm_prot_t; +use vm_types::{mach_vm_address_t, mach_vm_size_t}; + +pub type vm32_object_id_t = u32; + +pub type vm_region_info_t = *mut ::libc::c_int; +pub type vm_region_info_64_t = *mut ::libc::c_int; +pub type vm_region_recurse_info_t = *mut ::libc::c_int; +pub type vm_region_recurse_info_64_t = *mut ::libc::c_int; +pub type vm_region_flavor_t = ::libc::c_int; +pub type vm_region_info_data_t = [::libc::c_int; VM_REGION_INFO_MAX as usize]; + +pub type vm_region_basic_info_64_t = *mut vm_region_basic_info_64; +pub type vm_region_basic_info_data_64_t = vm_region_basic_info_64; +pub type vm_region_basic_info_t = *mut vm_region_basic_info; +pub type vm_region_basic_info_data_t = vm_region_basic_info; +pub type vm_region_extended_info_t = *mut vm_region_extended_info; +pub type vm_region_extended_info_data_t = vm_region_extended_info; +pub type vm_region_top_info_t = *mut vm_region_top_info; +pub type vm_region_top_info_data_t = vm_region_top_info; +pub type vm_region_submap_info_t = *mut vm_region_submap_info; +pub type vm_region_submap_info_data_t = vm_region_submap_info; +pub type vm_region_submap_info_64_t = *mut vm_region_submap_info_64; +pub type vm_region_submap_info_data_64_t = vm_region_submap_info_64; +pub type vm_region_submap_short_info_64_t = *mut vm_region_submap_short_info_64; +pub type vm_region_submap_short_info_data_64_t = vm_region_submap_short_info_64; +pub type vm_page_info_t = *mut ::libc::c_int; +pub type vm_page_info_flavor_t = ::libc::c_int; +pub type vm_page_info_basic_t = *mut vm_page_info_basic; +pub type vm_page_info_basic_data_t = vm_page_info_basic; +pub type mach_vm_read_entry_t = [mach_vm_read_entry; VM_MAP_ENTRY_MAX as usize]; + +pub const VM_REGION_INFO_MAX: ::libc::c_int = (1 << 10); +pub const VM_MAP_ENTRY_MAX: ::libc::c_int = (1 << 8); + +pub const VM_PAGE_INFO_BASIC: vm_page_info_flavor_t = 1; + +pub const VM_REGION_BASIC_INFO_64: vm_region_flavor_t = 9; +pub const VM_REGION_BASIC_INFO: vm_region_flavor_t = 10; +pub const VM_REGION_EXTENDED_INFO: vm_region_flavor_t = 13; +pub const VM_REGION_TOP_INFO: vm_region_flavor_t = 12; + +pub const SM_COW: ::libc::c_uchar = 1; +pub const SM_PRIVATE: ::libc::c_uchar = 2; +pub const SM_EMPTY: ::libc::c_uchar = 3; +pub const SM_SHARED: ::libc::c_uchar = 4; +pub const SM_TRUESHARED: ::libc::c_uchar = 5; +pub const SM_PRIVATE_ALIASED: ::libc::c_uchar = 6; +pub const SM_SHARED_ALIASED: ::libc::c_uchar = 7; + +#[repr(C, packed(4))] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_basic_info_64 { + pub protection: vm_prot_t, + pub max_protection: vm_prot_t, + pub inheritance: vm_inherit_t, + pub shared: boolean_t, + pub reserved: boolean_t, + pub offset: memory_object_offset_t, + pub behavior: vm_behavior_t, + pub user_wired_count: ::libc::c_ushort, +} + +impl vm_region_basic_info_64 { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_basic_info { + pub protection: vm_prot_t, + pub max_protection: vm_prot_t, + pub inheritance: vm_inherit_t, + pub shared: boolean_t, + pub reserved: boolean_t, + pub offset: u32, + pub behavior: vm_behavior_t, + pub user_wired_count: ::libc::c_ushort, +} + +impl vm_region_basic_info { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_extended_info { + pub protection: vm_prot_t, + pub user_tag: ::libc::c_uint, + pub pages_resident: ::libc::c_uint, + pub pages_shared_now_private: ::libc::c_uint, + pub pages_swapped_out: ::libc::c_uint, + pub pages_dirtied: ::libc::c_uint, + pub ref_count: ::libc::c_uint, + pub shadow_depth: ::libc::c_ushort, + pub external_pager: ::libc::c_uchar, + pub share_mode: ::libc::c_uchar, + pub pages_reusable: ::libc::c_uint, +} + +impl vm_region_extended_info { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_top_info { + pub obj_id: ::libc::c_uint, + pub ref_count: ::libc::c_uint, + pub private_pages_resident: ::libc::c_uint, + pub shared_pages_resident: ::libc::c_uint, + pub share_mode: ::libc::c_uchar, +} + +impl vm_region_top_info { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_submap_info { + pub protection: vm_prot_t, + pub max_protection: vm_prot_t, + pub inheritance: vm_inherit_t, + pub offset: u32, + pub user_tag: ::libc::c_uint, + pub pages_resident: ::libc::c_uint, + pub pages_shared_now_private: ::libc::c_uint, + pub pages_swapped_out: ::libc::c_uint, + pub pages_dirtied: ::libc::c_uint, + pub ref_count: ::libc::c_uint, + pub shadow_depth: ::libc::c_ushort, + pub external_pager: ::libc::c_uchar, + pub share_mode: ::libc::c_uchar, + pub is_submap: boolean_t, + pub behavior: vm_behavior_t, + pub object_id: vm32_object_id_t, + pub user_wired_count: ::libc::c_ushort, +} + +impl vm_region_submap_info { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C, packed(4))] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_submap_info_64 { + pub protection: vm_prot_t, + pub max_protection: vm_prot_t, + pub inheritance: vm_inherit_t, + pub offset: memory_object_offset_t, + pub user_tag: ::libc::c_uint, + pub pages_resident: ::libc::c_uint, + pub pages_shared_now_private: ::libc::c_uint, + pub pages_swapped_out: ::libc::c_uint, + pub pages_dirtied: ::libc::c_uint, + pub ref_count: ::libc::c_uint, + pub shadow_depth: ::libc::c_ushort, + pub external_pager: ::libc::c_uchar, + pub share_mode: ::libc::c_uchar, + pub is_submap: boolean_t, + pub behavior: vm_behavior_t, + pub object_id: vm32_object_id_t, + pub user_wired_count: ::libc::c_ushort, + pub pages_reusable: ::libc::c_uint, +} + +impl vm_region_submap_info_64 { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C, packed(4))] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_region_submap_short_info_64 { + pub protection: vm_prot_t, + pub max_protection: vm_prot_t, + pub inheritance: vm_inherit_t, + pub offset: memory_object_offset_t, + pub user_tag: ::libc::c_uint, + pub ref_count: ::libc::c_uint, + pub shadow_depth: ::libc::c_ushort, + pub external_pager: ::libc::c_uchar, + pub share_mode: ::libc::c_uchar, + pub is_submap: boolean_t, + pub behavior: vm_behavior_t, + pub object_id: vm32_object_id_t, + pub user_wired_count: ::libc::c_ushort, +} + +impl vm_region_submap_short_info_64 { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_page_info_basic { + pub disposition: ::libc::c_int, + pub ref_count: ::libc::c_int, + pub object_id: vm_object_id_t, + pub offset: memory_object_offset_t, + pub depth: ::libc::c_int, + pub __pad: ::libc::c_int, +} + +impl vm_page_info_basic { + pub fn count() -> mach_msg_type_number_t { + (mem::size_of::<Self>() / mem::size_of::<::libc::c_int>()) as mach_msg_type_number_t + } +} + +#[repr(C, packed(4))] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct mach_vm_read_entry { + pub address: mach_vm_address_t, + pub size: mach_vm_size_t, +} diff --git a/third_party/rust/mach/src/vm_statistics.rs b/third_party/rust/mach/src/vm_statistics.rs new file mode 100644 index 0000000000..5cc3a15548 --- /dev/null +++ b/third_party/rust/mach/src/vm_statistics.rs @@ -0,0 +1,78 @@ +//! This module roughly corresponds to `mach/vm_statistics.h` + +use vm_types::{integer_t, natural_t}; + +pub type vm_statistics_t = *mut vm_statistics; +pub type vm_statistics_data_t = vm_statistics; +#[cfg(feature = "deprecated")] +#[deprecated( + since = "0.2.3", + note = "`pmap_statistics_t` was removed after MacOSX 10.3.9" +)] +#[allow(deprecated)] +pub type pmap_statistics_t = *mut pmap_statistics; + +pub const VM_PAGE_QUERY_PAGE_PRESENT: integer_t = 1; +pub const VM_PAGE_QUERY_PAGE_FICTITIOUS: integer_t = (1 << 1); +pub const VM_PAGE_QUERY_PAGE_REF: integer_t = (1 << 2); +pub const VM_PAGE_QUERY_PAGE_DIRTY: integer_t = (1 << 3); + +pub const VM_MEMORY_MALLOC: ::libc::c_uint = 1; +pub const VM_MEMORY_MALLOC_SMALL: ::libc::c_uint = 2; +pub const VM_MEMORY_MALLOC_LARGE: ::libc::c_uint = 3; +pub const VM_MEMORY_MALLOC_HUGE: ::libc::c_uint = 4; +pub const VM_MEMORY_SBRK: ::libc::c_uint = 5; +pub const VM_MEMORY_ANALYSIS_TOOL: ::libc::c_uint = 10; +pub const VM_MEMORY_MACH_MSG: ::libc::c_uint = 20; +pub const VM_MEMORY_IOKIT: ::libc::c_uint = 21; +pub const VM_MEMORY_STACK: ::libc::c_uint = 30; +pub const VM_MEMORY_GUARD: ::libc::c_uint = 31; +pub const VM_MEMORY_SHARED_PMAP: ::libc::c_uint = 32; +pub const VM_MEMORY_DYLIB: ::libc::c_uint = 33; +pub const VM_MEMORY_APPKIT: ::libc::c_uint = 40; +pub const VM_MEMORY_FOUNDATION: ::libc::c_uint = 41; +pub const VM_MEMORY_COREGRAPHICS: ::libc::c_uint = 42; +pub const VM_MEMORY_CARBON: ::libc::c_uint = 43; +pub const VM_MEMORY_JAVA: ::libc::c_uint = 44; +pub const VM_MEMORY_ATS: ::libc::c_uint = 50; +pub const VM_MEMORY_DYLD: ::libc::c_uint = 60; +pub const VM_MEMORY_DYLD_MALLOC: ::libc::c_uint = 61; +pub const VM_MEMORY_APPLICATION_SPECIFIC_1: ::libc::c_uint = 240; +pub const VM_MEMORY_APPLICATION_SPECIFIC_16: ::libc::c_uint = 255; + +pub const VM_FLAGS_FIXED: ::libc::c_int = 0x0; +pub const VM_FLAGS_ANYWHERE: ::libc::c_int = 0x1; +pub const VM_FLAGS_OVERWRITE: ::libc::c_int = 0x4000; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct vm_statistics { + pub free_count: natural_t, + pub active_count: natural_t, + pub inactive_count: natural_t, + pub wire_count: natural_t, + pub zero_fill_count: natural_t, + pub reactivations: natural_t, + pub pageins: natural_t, + pub pageouts: natural_t, + pub faults: natural_t, + pub cow_faults: natural_t, + pub lookups: natural_t, + pub hits: natural_t, + pub purgeable_count: natural_t, + pub purges: natural_t, + pub speculative_count: natural_t, +} + +#[cfg(feature = "deprecated")] +#[deprecated( + since = "0.2.3", + note = "`pmap_statistics` was removed after MacOSX 10.3.9" +)] +#[cfg_attr(feature = "deprecated", allow(deprecated))] +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] +pub struct pmap_statistics { + pub resident_count: integer_t, + pub wired_count: integer_t, +} diff --git a/third_party/rust/mach/src/vm_sync.rs b/third_party/rust/mach/src/vm_sync.rs new file mode 100644 index 0000000000..b4e21c224a --- /dev/null +++ b/third_party/rust/mach/src/vm_sync.rs @@ -0,0 +1,11 @@ +//! This module corresponds to `mach/vm_sync.h`. + +pub type vm_sync_t = ::libc::c_uint; + +pub const VM_SYNC_ASYNCHRONOUS: vm_sync_t = 1; +pub const VM_SYNC_SYNCHRONOUS: vm_sync_t = (1 << 1); +pub const VM_SYNC_INVALIDATE: vm_sync_t = (1 << 2); +pub const VM_SYNC_KILLPAGES: vm_sync_t = (1 << 3); +pub const VM_SYNC_DEACTIVATE: vm_sync_t = (1 << 4); +pub const VM_SYNC_CONTIGUOUS: vm_sync_t = (1 << 5); +pub const VM_SYNC_REUSABLEPAGES: vm_sync_t = (1 << 6); diff --git a/third_party/rust/mach/src/vm_types.rs b/third_party/rust/mach/src/vm_types.rs new file mode 100644 index 0000000000..e37b9804c4 --- /dev/null +++ b/third_party/rust/mach/src/vm_types.rs @@ -0,0 +1,19 @@ +//! This module roughly corresponds to `mach/i386/vm_types.h`. + +pub type natural_t = ::libc::c_uint; +pub type integer_t = ::libc::c_int; + +pub type user_addr_t = u64; + +pub type mach_vm_address_t = u64; +pub type mach_vm_offset_t = u64; +pub type mach_vm_size_t = u64; +pub type vm_map_offset_t = u64; +pub type vm_map_address_t = u64; +pub type vm_map_size_t = u64; +pub type vm_map_t = ::port::mach_port_t; +pub type vm_offset_t = ::libc::uintptr_t; +pub type vm_size_t = ::libc::uintptr_t; +pub type vm_address_t = vm_offset_t; + +pub type mach_port_context_t = mach_vm_address_t; |