diff --git a/README.md b/README.md index d81c9b3..b82d1f4 100644 --- a/README.md +++ b/README.md @@ -74,13 +74,13 @@ sudo ./target/debug/examples/dump_process_registers The following table describes the current CI set-up: -| Target | Min. Rust | XCode | build | ctest | run | -|-------------------------|-----------|-----------------|-------|-------|-----| -| `x86_64-apple-darwin` | 1.33.0 | 10.3.0 - 13.1.0 | ✓ | ✓ | ✓ | -| `aarch64-apple-darwin` | nightly | 13.1.0 | ✓ | - | - | -| `aarch64-apple-ios` | nightly | 13.1.0 | ✓ | - | - | -| `aarch64-apple-ios-sim` | nightly | 13.1.0 | ✓ | - | - | -| `x86_64-apple-ios` | nightly | 13.1.0 | ✓ | - | - | +| Target | XCode | build | ctest | run | +|-------------------------|--------|-------|-------|-----| +| `x86_64-apple-darwin` | 26.1.0 | ✓ | ✓ | ✓ | +| `aarch64-apple-darwin` | 26.1.0 | ✓ | ✓ | ✓ | +| `aarch64-apple-ios` | 26.1.0 | ✓ | - | - | +| `aarch64-apple-ios-sim` | 26.1.0 | ✓ | - | - | +| `x86_64-apple-ios` | 26.1.0 | ✓ | - | - | ## License diff --git a/mach-test/build.rs b/mach-test/build.rs index 9682766..2126b56 100644 --- a/mach-test/build.rs +++ b/mach-test/build.rs @@ -94,7 +94,8 @@ fn main() { .header("mach/mach_voucher_types.h") .header("mach/machine.h") .header("mach/memory_object_types.h") - .header("mach/message.h"); + .header("mach/message.h") + .header("mach/mig.h"); cfg.header("mach/ndr.h") .header("mach/notify.h") diff --git a/mach-test/test/main.rs b/mach-test/test/main.rs index 9901a2d..4e08efb 100644 --- a/mach-test/test/main.rs +++ b/mach-test/test/main.rs @@ -16,9 +16,13 @@ use mach2::mach_init::*; use mach2::mach_port::*; use mach2::mach_time::*; use mach2::mach_types::*; +use mach2::mach_voucher_types::*; use mach2::memory_object_types::*; use mach2::message::*; +use mach2::mig::*; use mach2::ndr::*; +use mach2::notify::*; +use mach2::policy::*; use mach2::port::*; // FIXME: semaphore is not used => not tested? #[allow(unused_imports)] @@ -27,9 +31,13 @@ use mach2::structs::*; use mach2::sync_policy::*; use mach2::task::*; use mach2::task_info::*; +use mach2::task_special_ports::*; use mach2::thread_act::*; use mach2::thread_policy::*; +use mach2::thread_special_ports::*; +use mach2::thread_state::*; use mach2::thread_status::*; +use mach2::thread_switch::*; use mach2::time_value::*; use mach2::traps::*; use mach2::vm::*; diff --git a/src/lib.rs b/src/lib.rs index df17a81..ac91cbb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,6 @@ pub mod clock_reply; pub mod clock_types; // TODO: test pub mod dyld; pub mod dyld_kernel; -// pub mod error; // TODO pub mod exc; pub mod exception_types; pub mod kern_return; @@ -33,18 +32,26 @@ pub mod mach_init; pub mod mach_port; pub mod mach_time; pub mod mach_types; +pub mod mach_voucher_types; pub mod memory_object_types; pub mod message; +pub mod mig; pub mod ndr; +pub mod notify; +pub mod policy; pub mod port; pub mod semaphore; pub mod structs; pub mod sync_policy; pub mod task; pub mod task_info; +pub mod task_special_ports; pub mod thread_act; pub mod thread_policy; +pub mod thread_special_ports; +pub mod thread_state; pub mod thread_status; +pub mod thread_switch; pub mod time_value; pub mod traps; pub mod vm; diff --git a/src/mach_voucher_types.rs b/src/mach_voucher_types.rs new file mode 100644 index 0000000..d2d56e7 --- /dev/null +++ b/src/mach_voucher_types.rs @@ -0,0 +1,97 @@ +//! This module corresponds to `mach/mach_voucher_types.h`. + +use crate::message::mach_msg_type_number_t; +use crate::port::{mach_port_name_t, mach_port_t}; + +pub type mach_voucher_t = mach_port_t; +pub const MACH_VOUCHER_NULL: mach_voucher_t = 0; + +pub type mach_voucher_name_t = mach_port_name_t; +pub const MACH_VOUCHER_NAME_NULL: mach_voucher_name_t = 0; + +pub type mach_voucher_name_array_t = *mut mach_voucher_name_t; +pub const MACH_VOUCHER_NAME_ARRAY_NULL: mach_voucher_name_array_t = core::ptr::null_mut(); + +pub type ipc_voucher_t = mach_voucher_t; +pub const IPC_VOUCHER_NULL: ipc_voucher_t = 0; + +pub type mach_voucher_selector_t = u32; +pub const MACH_VOUCHER_SELECTOR_CURRENT: mach_voucher_selector_t = 0; +pub const MACH_VOUCHER_SELECTOR_EFFECTIVE: mach_voucher_selector_t = 1; + +pub type mach_voucher_attr_key_t = u32; +pub type mach_voucher_attr_key_array_t = *mut mach_voucher_attr_key_t; + +pub const MACH_VOUCHER_ATTR_KEY_ALL: mach_voucher_attr_key_t = !0; +pub const MACH_VOUCHER_ATTR_KEY_NONE: mach_voucher_attr_key_t = 0; +pub const MACH_VOUCHER_ATTR_KEY_ATM: mach_voucher_attr_key_t = 1; +pub const MACH_VOUCHER_ATTR_KEY_IMPORTANCE: mach_voucher_attr_key_t = 2; +pub const MACH_VOUCHER_ATTR_KEY_BANK: mach_voucher_attr_key_t = 3; +pub const MACH_VOUCHER_ATTR_KEY_PTHPRIORITY: mach_voucher_attr_key_t = 4; +pub const MACH_VOUCHER_ATTR_KEY_USER_DATA: mach_voucher_attr_key_t = 7; +pub const MACH_VOUCHER_ATTR_KEY_BITS: mach_voucher_attr_key_t = MACH_VOUCHER_ATTR_KEY_USER_DATA; +pub const MACH_VOUCHER_ATTR_KEY_TEST: mach_voucher_attr_key_t = 8; +pub const MACH_VOUCHER_ATTR_KEY_NUM_WELL_KNOWN: mach_voucher_attr_key_t = + MACH_VOUCHER_ATTR_KEY_TEST; + +pub type mach_voucher_attr_content_t = *mut u8; +pub type mach_voucher_attr_content_size_t = u32; + +pub type mach_voucher_attr_command_t = u32; +pub type mach_voucher_attr_recipe_command_t = u32; +pub type mach_voucher_attr_recipe_command_array_t = *mut mach_voucher_attr_recipe_command_t; + +pub const MACH_VOUCHER_ATTR_NOOP: mach_voucher_attr_recipe_command_t = 0; +pub const MACH_VOUCHER_ATTR_COPY: mach_voucher_attr_recipe_command_t = 1; +pub const MACH_VOUCHER_ATTR_REMOVE: mach_voucher_attr_recipe_command_t = 2; +pub const MACH_VOUCHER_ATTR_SET_VALUE_HANDLE: mach_voucher_attr_recipe_command_t = 3; +pub const MACH_VOUCHER_ATTR_AUTO_REDEEM: mach_voucher_attr_recipe_command_t = 4; +pub const MACH_VOUCHER_ATTR_SEND_PREPROCESS: mach_voucher_attr_recipe_command_t = 5; +pub const MACH_VOUCHER_ATTR_REDEEM: mach_voucher_attr_recipe_command_t = 10; +pub const MACH_VOUCHER_ATTR_IMPORTANCE_SELF: mach_voucher_attr_recipe_command_t = 200; +pub const MACH_VOUCHER_ATTR_USER_DATA_STORE: mach_voucher_attr_recipe_command_t = 211; +pub const MACH_VOUCHER_ATTR_BITS_STORE: mach_voucher_attr_recipe_command_t = + MACH_VOUCHER_ATTR_USER_DATA_STORE; +pub const MACH_VOUCHER_ATTR_TEST_STORE: mach_voucher_attr_recipe_command_t = + MACH_VOUCHER_ATTR_USER_DATA_STORE; + +pub type mach_voucher_attr_recipe_size_t = mach_msg_type_number_t; + +pub type mach_voucher_attr_raw_recipe_t = *mut u8; +pub type mach_voucher_attr_raw_recipe_array_t = mach_voucher_attr_raw_recipe_t; +pub type mach_voucher_attr_raw_recipe_size_t = mach_msg_type_number_t; +pub type mach_voucher_attr_raw_recipe_array_size_t = mach_msg_type_number_t; + +pub const MACH_VOUCHER_ATTR_MAX_RAW_RECIPE_ARRAY_SIZE: mach_msg_type_number_t = 5120; +pub const MACH_VOUCHER_TRAP_STACK_LIMIT: mach_msg_type_number_t = 256; + +pub type mach_voucher_attr_manager_t = mach_port_t; +pub const MACH_VOUCHER_ATTR_MANAGER_NULL: mach_voucher_attr_manager_t = 0; + +pub type mach_voucher_attr_control_t = mach_port_t; +pub const MACH_VOUCHER_ATTR_CONTROL_NULL: mach_voucher_attr_control_t = 0; + +pub type ipc_voucher_attr_manager_t = mach_port_t; +pub type ipc_voucher_attr_control_t = mach_port_t; +pub const IPC_VOUCHER_ATTR_MANAGER_NULL: ipc_voucher_attr_manager_t = 0; +pub const IPC_VOUCHER_ATTR_CONTROL_NULL: ipc_voucher_attr_control_t = 0; + +pub type mach_voucher_attr_value_handle_t = u64; +pub type mach_voucher_attr_value_handle_array_t = *mut mach_voucher_attr_value_handle_t; +pub type mach_voucher_attr_value_handle_array_size_t = mach_msg_type_number_t; + +pub const MACH_VOUCHER_ATTR_VALUE_MAX_NESTED: mach_voucher_attr_value_handle_array_size_t = 4; + +pub type mach_voucher_attr_value_reference_t = u32; +pub type mach_voucher_attr_value_flags_t = u32; +pub const MACH_VOUCHER_ATTR_VALUE_FLAGS_NONE: mach_voucher_attr_value_flags_t = 0; +pub const MACH_VOUCHER_ATTR_VALUE_FLAGS_PERSIST: mach_voucher_attr_value_flags_t = 1; + +pub type mach_voucher_attr_control_flags_t = u32; +pub const MACH_VOUCHER_ATTR_CONTROL_FLAGS_NONE: mach_voucher_attr_control_flags_t = 0; + +pub const MACH_VOUCHER_IMPORTANCE_ATTR_ADD_EXTERNAL: u32 = 1; +pub const MACH_VOUCHER_IMPORTANCE_ATTR_DROP_EXTERNAL: u32 = 2; +pub type mach_voucher_attr_importance_refs = u32; + +pub const MACH_ACTIVITY_ID_COUNT_MAX: u32 = 16; diff --git a/src/mig.rs b/src/mig.rs new file mode 100644 index 0000000..446495e --- /dev/null +++ b/src/mig.rs @@ -0,0 +1,81 @@ +//! This module corresponds to `mach/mig.h`. + +use crate::kern_return::kern_return_t; +use crate::message::{ + mach_msg_header_t, mach_msg_id_t, mach_msg_size_t, mach_msg_type_descriptor_t, +}; +use crate::port::mach_port_t; +use crate::vm_types::{vm_address_t, vm_size_t}; +use core::ptr; + +pub type mig_stub_routine_t = + Option; +pub type mig_routine_t = mig_stub_routine_t; +pub type mig_server_routine_t = + Option mig_routine_t>; +pub type mig_impl_routine_t = Option kern_return_t>; + +pub type routine_arg_descriptor_t = *mut mach_msg_type_descriptor_t; +pub type mig_routine_arg_descriptor_t = *mut mach_msg_type_descriptor_t; + +pub const MIG_ROUTINE_ARG_DESCRIPTOR_NULL: mig_routine_arg_descriptor_t = ptr::null_mut(); + +#[repr(C)] +#[derive(Copy, Clone, Debug)] +pub struct routine_descriptor { + pub impl_routine: mig_impl_routine_t, + pub stub_routine: mig_stub_routine_t, + pub argc: libc::c_uint, + pub descr_count: libc::c_uint, + pub arg_descr: routine_arg_descriptor_t, + pub max_reply_msg: libc::c_uint, +} + +pub type routine_descriptor_t = *mut routine_descriptor; +pub type mig_routine_descriptor = routine_descriptor; +pub type mig_routine_descriptor_t = *mut mig_routine_descriptor; + +pub const MIG_ROUTINE_DESCRIPTOR_NULL: mig_routine_descriptor_t = ptr::null_mut(); + +#[repr(C)] +#[derive(Copy, Clone, Debug)] +pub struct mig_subsystem { + pub server: mig_server_routine_t, + pub start: mach_msg_id_t, + pub end: mach_msg_id_t, + pub maxsize: mach_msg_size_t, + pub reserved: vm_address_t, + pub routine: [mig_routine_descriptor; 1], +} + +pub type mig_subsystem_t = *mut mig_subsystem; + +pub const MIG_SUBSYSTEM_NULL: mig_subsystem_t = ptr::null_mut(); + +#[repr(C)] +#[derive(Copy, Clone, Debug)] +pub struct mig_symtab { + pub ms_routine_name: *mut libc::c_char, + pub ms_routine_number: libc::c_int, + pub ms_routine: Option, +} + +pub type mig_symtab_t = mig_symtab; + +unsafe extern "C" { + pub fn mig_get_reply_port() -> mach_port_t; + pub fn mig_dealloc_reply_port(reply_port: mach_port_t); + pub fn mig_put_reply_port(reply_port: mach_port_t); + pub fn mig_strncpy( + dest: *mut libc::c_char, + src: *const libc::c_char, + len: libc::c_int, + ) -> libc::c_int; + pub fn mig_strncpy_zerofill( + dest: *mut libc::c_char, + src: *const libc::c_char, + len: libc::c_int, + ) -> libc::c_int; + pub fn mig_allocate(address: *mut vm_address_t, size: vm_size_t); + pub fn mig_deallocate(address: vm_address_t, size: vm_size_t); +} diff --git a/src/notify.rs b/src/notify.rs new file mode 100644 index 0000000..e65d014 --- /dev/null +++ b/src/notify.rs @@ -0,0 +1,76 @@ +//! This module corresponds to `mach/notify.h`. + +use crate::message::{ + mach_msg_body_t, mach_msg_header_t, mach_msg_port_descriptor_t, mach_msg_security_trailer_t, + mach_msg_type_number_t, +}; +use crate::ndr::NDR_record_t; +use crate::port::mach_port_name_t; +use crate::port::mach_port_t; + +pub const MACH_NOTIFY_FIRST: libc::c_int = 0o100; +pub const MACH_NOTIFY_PORT_DELETED: libc::c_int = MACH_NOTIFY_FIRST + 0o01; +pub const MACH_NOTIFY_SEND_POSSIBLE: libc::c_int = MACH_NOTIFY_FIRST + 0o02; +pub const MACH_NOTIFY_PORT_DESTROYED: libc::c_int = MACH_NOTIFY_FIRST + 0o05; +pub const MACH_NOTIFY_NO_SENDERS: libc::c_int = MACH_NOTIFY_FIRST + 0o06; +pub const MACH_NOTIFY_SEND_ONCE: libc::c_int = MACH_NOTIFY_FIRST + 0o07; +pub const MACH_NOTIFY_DEAD_NAME: libc::c_int = MACH_NOTIFY_FIRST + 0o10; +pub const MACH_NOTIFY_LAST: libc::c_int = MACH_NOTIFY_FIRST + 0o15; + +pub type notify_port_t = mach_port_t; + +#[repr(C)] +#[derive(Copy, Clone, Debug)] +#[allow(non_snake_case)] +pub struct mach_port_deleted_notification_t { + pub not_header: mach_msg_header_t, + pub NDR: NDR_record_t, + pub not_port: mach_port_name_t, + pub trailer: mach_msg_security_trailer_t, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug)] +#[allow(non_snake_case)] +pub struct mach_send_possible_notification_t { + pub not_header: mach_msg_header_t, + pub NDR: NDR_record_t, + pub not_port: mach_port_name_t, + pub trailer: mach_msg_security_trailer_t, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug)] +pub struct mach_port_destroyed_notification_t { + pub not_header: mach_msg_header_t, + pub not_body: mach_msg_body_t, + pub not_port: mach_msg_port_descriptor_t, + pub trailer: mach_msg_security_trailer_t, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug)] +#[allow(non_snake_case)] +pub struct mach_no_senders_notification_t { + pub not_header: mach_msg_header_t, + pub NDR: NDR_record_t, + pub not_count: mach_msg_type_number_t, + pub trailer: mach_msg_security_trailer_t, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug)] +pub struct mach_send_once_notification_t { + pub not_header: mach_msg_header_t, + pub trailer: mach_msg_security_trailer_t, +} + +#[repr(C)] +#[derive(Copy, Clone, Debug)] +#[allow(non_snake_case)] +pub struct mach_dead_name_notification_t { + pub not_header: mach_msg_header_t, + pub NDR: NDR_record_t, + pub not_port: mach_port_name_t, + pub trailer: mach_msg_security_trailer_t, +} diff --git a/src/policy.rs b/src/policy.rs new file mode 100644 index 0000000..edbed61 --- /dev/null +++ b/src/policy.rs @@ -0,0 +1,146 @@ +//! This module corresponds to `mach/policy.h`. + +use crate::boolean::boolean_t; +use crate::message::mach_msg_type_number_t; +use crate::vm_types::integer_t; +use core::mem; + +pub type policy_t = libc::c_int; +pub type policy_info_t = *mut integer_t; +pub type policy_base_t = *mut integer_t; +pub type policy_limit_t = *mut integer_t; + +pub const POLICY_NULL: policy_t = 0; +pub const POLICY_TIMESHARE: policy_t = 1; +pub const POLICY_RR: policy_t = 2; +pub const POLICY_FIFO: policy_t = 4; + +pub const POLICYCLASS_FIXEDPRI: policy_t = POLICY_RR | POLICY_FIFO; + +#[inline] +pub const fn invalid_policy(policy: policy_t) -> bool { + !(policy == POLICY_TIMESHARE || policy == POLICY_RR || policy == POLICY_FIFO) +} + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +pub struct policy_timeshare_base { + pub base_priority: integer_t, +} + +pub type policy_timeshare_base_t = *mut policy_timeshare_base; +pub type policy_timeshare_base_data_t = policy_timeshare_base; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +pub struct policy_timeshare_limit { + pub max_priority: integer_t, +} + +pub type policy_timeshare_limit_t = *mut policy_timeshare_limit; +pub type policy_timeshare_limit_data_t = policy_timeshare_limit; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +pub struct policy_timeshare_info { + pub max_priority: integer_t, + pub base_priority: integer_t, + pub cur_priority: integer_t, + pub depressed: boolean_t, + pub depress_priority: integer_t, +} + +pub type policy_timeshare_info_t = *mut policy_timeshare_info; +pub type policy_timeshare_info_data_t = policy_timeshare_info; + +pub const POLICY_TIMESHARE_BASE_COUNT: mach_msg_type_number_t = + (mem::size_of::() / mem::size_of::()) + as mach_msg_type_number_t; +pub const POLICY_TIMESHARE_LIMIT_COUNT: mach_msg_type_number_t = + (mem::size_of::() / mem::size_of::()) + as mach_msg_type_number_t; +pub const POLICY_TIMESHARE_INFO_COUNT: mach_msg_type_number_t = + (mem::size_of::() / mem::size_of::()) + as mach_msg_type_number_t; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +pub struct policy_rr_base { + pub base_priority: integer_t, + pub quantum: integer_t, +} + +pub type policy_rr_base_t = *mut policy_rr_base; +pub type policy_rr_base_data_t = policy_rr_base; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +pub struct policy_rr_limit { + pub max_priority: integer_t, +} + +pub type policy_rr_limit_t = *mut policy_rr_limit; +pub type policy_rr_limit_data_t = policy_rr_limit; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +pub struct policy_rr_info { + pub max_priority: integer_t, + pub base_priority: integer_t, + pub quantum: integer_t, + pub depressed: boolean_t, + pub depress_priority: integer_t, +} + +pub type policy_rr_info_t = *mut policy_rr_info; +pub type policy_rr_info_data_t = policy_rr_info; + +pub const POLICY_RR_BASE_COUNT: mach_msg_type_number_t = (mem::size_of::() + / mem::size_of::()) + as mach_msg_type_number_t; +pub const POLICY_RR_LIMIT_COUNT: mach_msg_type_number_t = (mem::size_of::() + / mem::size_of::()) + as mach_msg_type_number_t; +pub const POLICY_RR_INFO_COUNT: mach_msg_type_number_t = (mem::size_of::() + / mem::size_of::()) + as mach_msg_type_number_t; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +pub struct policy_fifo_base { + pub base_priority: integer_t, +} + +pub type policy_fifo_base_t = *mut policy_fifo_base; +pub type policy_fifo_base_data_t = policy_fifo_base; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +pub struct policy_fifo_limit { + pub max_priority: integer_t, +} + +pub type policy_fifo_limit_t = *mut policy_fifo_limit; +pub type policy_fifo_limit_data_t = policy_fifo_limit; + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +pub struct policy_fifo_info { + pub max_priority: integer_t, + pub base_priority: integer_t, + pub depressed: boolean_t, + pub depress_priority: integer_t, +} + +pub type policy_fifo_info_t = *mut policy_fifo_info; +pub type policy_fifo_info_data_t = policy_fifo_info; + +pub const POLICY_FIFO_BASE_COUNT: mach_msg_type_number_t = + (mem::size_of::() / mem::size_of::()) + as mach_msg_type_number_t; +pub const POLICY_FIFO_LIMIT_COUNT: mach_msg_type_number_t = + (mem::size_of::() / mem::size_of::()) + as mach_msg_type_number_t; +pub const POLICY_FIFO_INFO_COUNT: mach_msg_type_number_t = + (mem::size_of::() / mem::size_of::()) + as mach_msg_type_number_t; diff --git a/src/task.rs b/src/task.rs index 894a740..c4952f0 100644 --- a/src/task.rs +++ b/src/task.rs @@ -1,4 +1,4 @@ -//! This module corresponds to `mach/task.defs`. +//! This module corresponds to `mach/task.h`. use crate::boolean::boolean_t; use crate::exception_types::{ @@ -15,25 +15,18 @@ use crate::message::{ mach_msg_port_descriptor_t, mach_msg_type_number_t, }; use crate::ndr::NDR_record_t; +use crate::policy::{policy_base_t, policy_limit_t, policy_t}; use crate::port::{mach_port_array_t, mach_port_t}; -use crate::task_info::{policy_t, task_flavor_t, task_info_t}; +use crate::task_info::{task_flavor_t, task_info_t}; +use crate::task_special_ports::task_special_port_t; use crate::thread_status::{thread_state_flavor_t, thread_state_t}; use crate::vm_types::{integer_t, natural_t, vm_address_t}; use core::ffi::{c_int, c_uint}; -pub type task_special_port_t = 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; - pub const task_MSG_COUNT: c_uint = 66; pub type task_policy_flavor_t = natural_t; pub type task_policy_t = *mut integer_t; -pub type policy_base_t = *mut integer_t; -pub type policy_limit_t = *mut integer_t; pub type emulation_vector_t = *mut integer_t; unsafe extern "C" { diff --git a/src/task_info.rs b/src/task_info.rs index 8b00f2b..e3852a0 100644 --- a/src/task_info.rs +++ b/src/task_info.rs @@ -1,6 +1,7 @@ //! This module roughly corresponds to `mach/task_info.h`. use crate::message::{audit_token_t, security_token_t}; +use crate::policy::policy_t; use crate::time_value::time_value_t; use crate::vm_statistics::{vm_extmod_statistics_data_t, vm_purgeable_info}; use crate::vm_types::{integer_t, mach_vm_address_t, mach_vm_size_t, natural_t, vm_size_t}; @@ -43,7 +44,6 @@ 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; -pub type policy_t = libc::c_int; #[repr(C, packed(4))] #[derive(Copy, Clone, Debug, Default, Hash, PartialOrd, PartialEq, Eq, Ord)] diff --git a/src/task_special_ports.rs b/src/task_special_ports.rs new file mode 100644 index 0000000..ebac4c8 --- /dev/null +++ b/src/task_special_ports.rs @@ -0,0 +1,79 @@ +//! This module corresponds to `mach/task_special_ports.h`. + +use crate::kern_return::kern_return_t; +use crate::mach_types::task_t; +use crate::port::mach_port_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; +pub const TASK_INSPECT_PORT: task_special_port_t = 5; +pub const TASK_READ_PORT: task_special_port_t = 6; +pub const TASK_ACCESS_PORT: task_special_port_t = 9; +pub const TASK_DEBUG_CONTROL_PORT: task_special_port_t = 10; +pub const TASK_RESOURCE_NOTIFY_PORT: task_special_port_t = 11; + +pub const TASK_MAX_SPECIAL_PORT: task_special_port_t = TASK_RESOURCE_NOTIFY_PORT; + +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn task_get_kernel_port(task: task_t, port: *mut mach_port_t) -> kern_return_t { + unsafe { crate::task::task_get_special_port(task, TASK_KERNEL_PORT, port) } +} + +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn task_set_kernel_port(task: task_t, port: mach_port_t) -> kern_return_t { + unsafe { crate::task::task_set_special_port(task, TASK_KERNEL_PORT, port) } +} + +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn task_get_host_port(task: task_t, port: *mut mach_port_t) -> kern_return_t { + unsafe { crate::task::task_get_special_port(task, TASK_HOST_PORT, port) } +} + +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn task_set_host_port(task: task_t, port: mach_port_t) -> kern_return_t { + unsafe { crate::task::task_set_special_port(task, TASK_HOST_PORT, port) } +} + +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn task_get_bootstrap_port(task: task_t, port: *mut mach_port_t) -> kern_return_t { + unsafe { crate::task::task_get_special_port(task, TASK_BOOTSTRAP_PORT, port) } +} + +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn task_set_bootstrap_port(task: task_t, port: mach_port_t) -> kern_return_t { + unsafe { crate::task::task_set_special_port(task, TASK_BOOTSTRAP_PORT, port) } +} + +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn task_get_debug_control_port(task: task_t, port: *mut mach_port_t) -> kern_return_t { + unsafe { crate::task::task_get_special_port(task, TASK_DEBUG_CONTROL_PORT, port) } +} + +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn task_set_task_debug_control_port(task: task_t, port: mach_port_t) -> kern_return_t { + unsafe { crate::task::task_set_special_port(task, TASK_DEBUG_CONTROL_PORT, port) } +} + +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn task_get_task_access_port(task: task_t, port: *mut mach_port_t) -> kern_return_t { + unsafe { crate::task::task_get_special_port(task, TASK_ACCESS_PORT, port) } +} + +#[inline] +#[allow(clippy::missing_safety_doc)] +pub unsafe fn task_set_task_access_port(task: task_t, port: mach_port_t) -> kern_return_t { + unsafe { crate::task::task_set_special_port(task, TASK_ACCESS_PORT, port) } +} diff --git a/src/thread_special_ports.rs b/src/thread_special_ports.rs new file mode 100644 index 0000000..52cf856 --- /dev/null +++ b/src/thread_special_ports.rs @@ -0,0 +1,6 @@ +//! This module corresponds to `mach/thread_special_ports.h`. + +pub const THREAD_KERNEL_PORT: libc::c_int = 1; +pub const THREAD_INSPECT_PORT: libc::c_int = 2; +pub const THREAD_READ_PORT: libc::c_int = 3; +pub const THREAD_MAX_SPECIAL_PORT: libc::c_int = THREAD_READ_PORT; diff --git a/src/thread_state.rs b/src/thread_state.rs new file mode 100644 index 0000000..85ffe59 --- /dev/null +++ b/src/thread_state.rs @@ -0,0 +1,13 @@ +//! This module corresponds to `mach/thread_state.h`. + +use crate::kern_return::kern_return_t; +use crate::mach_types::thread_t; + +unsafe extern "C" { + pub fn thread_get_register_pointer_values( + thread: thread_t, + sp: *mut libc::uintptr_t, + length: *mut libc::size_t, + values: *mut libc::uintptr_t, + ) -> kern_return_t; +} diff --git a/src/thread_switch.rs b/src/thread_switch.rs new file mode 100644 index 0000000..270c424 --- /dev/null +++ b/src/thread_switch.rs @@ -0,0 +1,5 @@ +//! This module corresponds to `mach/thread_switch.h`. + +pub const SWITCH_OPTION_NONE: libc::c_int = 0; +pub const SWITCH_OPTION_DEPRESS: libc::c_int = 1; +pub const SWITCH_OPTION_WAIT: libc::c_int = 2;