Skip to content

Commit

Permalink
Merge pull request #30 from gnzlbg/clock
Browse files Browse the repository at this point in the history
Add clock, dyld_kernel, and exception types
  • Loading branch information
gnzlbg authored Mar 3, 2018
2 parents 85c690a + c5316d4 commit eb5749a
Show file tree
Hide file tree
Showing 19 changed files with 556 additions and 132 deletions.
2 changes: 1 addition & 1 deletion ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -ex
echo "Running tests for target: ${TARGET}"
export RUST_BACKTRACE=1
export RUST_TEST_THREADS=1

export RUST_TEST_NOCAPTURE=1

if [[ $TARGET == *"ios"* ]]; then
export RUSTFLAGS='-C link-args=-mios-simulator-version-min=7.0'
Expand Down
2 changes: 1 addition & 1 deletion examples/dump_process_registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use mach::task::{task_resume, task_suspend, task_threads};
use mach::thread_act::{thread_get_state};
use mach::thread_status::{x86_THREAD_STATE64};
use mach::traps::{mach_task_self, task_for_pid};
use mach::types::{task_t, thread_act_array_t};
use mach::mach_types::{task_t, thread_act_array_t};

use std::io::prelude::*;

Expand Down
141 changes: 120 additions & 21 deletions mach-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,95 @@ fn main() {
let mut cfg = ctest::TestGenerator::new();

// Include the header files where the C APIs are defined
cfg.header("mach/mach.h")
.header("mach/clock_types.h")
.header("mach/i386/boolean.h")
cfg.header("mach/boolean.h")
.header("bootstrap.h")
.header("mach/bootstrap.h")
.header("mach/clock.h")
.header("mach/clock_priv.h")
.header("mach/clock_reply.h")
.header("mach/clock_types.h");

if xcode >= Xcode(8, 0) {
cfg.header("mach/dyld_kernel.h");
}

cfg.header("mach/error.h")
.header("mach/exc.h")
.header("mach/exception.h")
.header("mach/exception_types.h")
.header("mach/host_info.h")
.header("mach/host_notify.h")
.header("mach/host_priv.h")
.header("mach/host_reboot.h")
.header("mach/host_security.h")
.header("mach/host_special_ports.h")
.header("mach/kern_return.h")
.header("mach/i386/kern_return.h")
.header("mach/kmod.h")
.header("mach/lock_set.h")
.header("mach/mach.h")
.header("mach/mach_error.h")
.header("mach/mach_host.h")
.header("mach/mach_init.h")
.header("mach/mach_interface.h")
.header("mach/mach_param.h")
.header("mach/mach_port.h")
.header("mach/mach_syscalls.h")
.header("mach/mach_time.h")
.header("mach/mach_traps.h")
.header("mach/mach_types.h")
.header("mach/mach_vm.h")
.header("mach/mach_voucher.h")
.header("mach/mach_voucher_types.h")
.header("mach/machine.h")
.header("mach/memory_object_types.h")
.header("mach/message.h")
.header("mach/ndr.h")
.header("mach/notify.h")
.header("mach/policy.h")
.header("mach/port.h")
.header("mach/mach_init.h")
.header("mach/i386/_structs.h")
//.header("mach/task.defs")
.header("mach/port_obj.h")
.header("mach/processor.h")
.header("mach/processor_info.h")
.header("mach/processor_set.h")
.header("mach/rpc.h")
.header("mach/sdt.h")
.header("mach/semaphore.h")
.header("mach/shared_region.h")
.header("mach/std_types.h")
.header("mach/sync.h")
.header("mach/sync_policy.h")
.header("mach/task.h")
.header("mach/task_info.h")
// .header("mach/task_inspect.h");
.header("mach/task_policy.h")
.header("mach/task_special_ports.h")
.header("mach/thread_act.h")
//.header("mach/thread_act.defs")
.header("mach/thread_status.h")
.header("mach/mach_traps.h")
.header("mach/mach_types.h")
.header("mach/mach_vm.h")
//.header("mach/mach_vm.defs.")
.header("mach/thread_info.h")
.header("mach/thread_policy.h")
.header("mach/thread_special_ports.h");

if xcode >= Xcode(7, 0) {
cfg.header("mach/thread_state.h");
}

cfg.header("mach/thread_status.h")
.header("mach/thread_switch.h")
.header("mach/time_value.h")
.header("mach/vm_attributes.h")
.header("mach/vm_behavior.h")
.header("mach/vm_inherit.h")
.header("mach/vm_map.h")
.header("mach/vm_page_size.h")
.header("mach/vm_param.h")
.header("mach/vm_prot.h")
.header("mach/vm_purgable.h")
.header("mach/vm_region.h")
.header("mach/vm_statistics.h")
.header("mach/vm_sync.h")
.header("mach/i386/vm_types.h")
.header("bootstrap.h");
.header("mach/vm_task.h")
.header("mach/vm_types.h");

cfg.skip_struct(|s| {
cfg.skip_struct(move |s| {
match s {
// TODO: this type is a bitfield and must be verified by hand
"mach_msg_port_descriptor_t" |
Expand All @@ -94,12 +149,19 @@ fn main() {
"vm_region_submap_info_64" |
"vm_region_submap_short_info_64" |
"mach_vm_read_entry"
=> true,
=> true,

// These are not available in previous MacOSX versions:
"dyld_kernel_image_info" |
"dyld_kernel_process_info" |
"fsid" |
"fsobj_id"
if xcode < Xcode(8, 0) => true,
_ => false,
}
});

cfg.skip_type(|s| {
cfg.skip_type(move |s| {
match s {
// FIXME: this type is not exposed in /usr/include/mach
// but seems to be exposed in
Expand All @@ -111,7 +173,17 @@ fn main() {
"vm_region_submap_info_data_64_t"|
"vm_region_submap_short_info_data_64_t" |
"mach_vm_read_entry_t"
=> true,
=> true,

// These are not available in previous MacOSX versions
"dyld_kernel_image_info_t" |
"dyld_kernel_process_info_t" |
"dyld_kernel_image_info_array_t" |
"uuid_t" |
"fsid_t" |
"fsobj_id_t"
if xcode < Xcode(8, 0) => true,

_ => false,
}
});
Expand All @@ -129,6 +201,8 @@ fn main() {

cfg.skip_const(move |s| {
match s {
// Available only in MacOSX >= 10.13
"EXC_CORPSE_VARIANT_BIT" => true,
// Used to have a value of 11 until MacOSX 10.8 and changed to a
// value of 13 in MacOSX 10.9 ~ Xcode 6.4
"VM_REGION_EXTENDED_INFO"
Expand All @@ -138,6 +212,10 @@ fn main() {
if xcode < Xcode(7, 3) => true,
// Removed after MacOSX 10.6 (does not appear in MacOSX 10.7)
"VM_PROT_TRUSTED" if xcode > Xcode(4, 3) => true,
// Added after MacOSX 10.9 ~ Xcode 6.4
"EXC_CORPSE_NOTIFY" |
"EXC_MASK_CORPSE_NOTIFY"
if xcode <= Xcode(7, 0) => true,
_ => false,
}
});
Expand All @@ -153,14 +231,29 @@ fn main() {
"mach_timespec_t" |
"ipc_port_t" |
"vm_statistics_data_t" |
"fsid_t" |
"fsobj_id_t" |
"dyld_kernel_image_info_t" |
"dyld_kernel_process_info_t" |

// array types:
"vm_region_info_data_t" |
"mach_vm_read_entry_t" |
"name_t" |
"cmd_t" |
"name_array_t" |
"bootstrap_status_array_t" |
"bootstrap_property_array_t" |
"bool_array_t" |
"uuid_t" |

// pointer types:
"clock_attr_t" |
"dyld_kernel_image_info_array_t" |
"memory_object_fault_info_t" |
"exception_data_t" |
"exception_flavor_array_t" |
"exception_mask_array_t" |
"exception_port_arrary_t" |
"exception_handler_array_t" |
"thread_state_t" |
Expand All @@ -170,6 +263,9 @@ fn main() {
"thread_act_port_array_t" |
"ledger_array_t" |
"ledger_port_array_t" |
"mach_exception_data_t" |
"exception_behavior_array_t" |
"exception_port_array_t" |
"task_info_t" |
"task_array_t" |
"task_port_array_t" |
Expand Down Expand Up @@ -207,8 +303,6 @@ fn main() {
});

cfg.type_name(|ty, is_struct| match ty {
// struct foo in Rust should translate to foo_ in C:
"mach_timespec" => format!("{}_t", ty),
// struct foo in Rust should translate to struct foo in C:
"vm_region_basic_info_64"
| "vm_region_basic_info"
Expand All @@ -220,6 +314,11 @@ fn main() {
| "vm_page_info_basic"
| "vm_statistics"
| "task_dyld_info"
| "fsid"
| "fsobj_id"
| "dyld_kernel_image_info"
| "dyld_kernel_process_info"
| "mach_timespec"
| "mach_vm_read_entry" => format!("struct {}", ty),
_ if is_struct => format!("{}", ty),
_ => ty.to_string(),
Expand Down
17 changes: 8 additions & 9 deletions mach-test/test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ extern crate mach;

use mach::boolean::*;
use mach::bootstrap::*;
use mach::clock::*;
use mach::clock_priv::*;
use mach::clock_reply::*;
use mach::clock_types::*;
use mach::dyld_kernel::*;
use mach::exc::*;
use mach::exception_types::*;
use mach::kern_return::*;
use mach::mach_port::*;
// FIXME: mach::mach_types is not used,
// can probably be removed:
#[allow(unused_imports)]
use mach::mach_types::*;
use mach::memory_object_types::*;
use mach::message::*;
Expand All @@ -21,7 +24,6 @@ use mach::task_info::*;
use mach::thread_act::*;
use mach::thread_status::*;
use mach::traps::*;
use mach::types::*;
use mach::vm::*;
use mach::vm_attributes::*;
use mach::vm_behavior::*;
Expand All @@ -36,10 +38,7 @@ use mach::vm_statistics::*;
use mach::vm_sync::*;
use mach::vm_types::*;

// FIXME: exported by mach::types and mach::mach_types
use mach::types::task_name_t;

// FIXME: these types are not re-exported by mach::types but they are required.
use libc::{c_int, c_uchar, c_uint, clock_t};
// These types are not re-exported by mach::types but they are required.
use libc::{c_int, c_ulonglong, c_uchar, c_uint, clock_t};

include!(concat!(env!("OUT_DIR"), "/all.rs"));
65 changes: 62 additions & 3 deletions src/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,73 @@
//! This module corresponds to `bootstrap.h`
use boolean::boolean_t;
use kern_return::{kern_return_t};
use libc;
use port::{mach_port_t};

pub const BOOTSTRAP_MAX_NAME_LEN: libc::c_uint = 128;
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,
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;
}
24 changes: 24 additions & 0 deletions src/clock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! This module roughly corresponds to `mach/clock.h`.
pub const clock_MSG_COUNT: ::libc::c_uint = 3;

use mach_types::{clock_serv_t, clock_reply_t};
use clock_types::{mach_timespec_t, clock_flavor_t, clock_attr_t, alarm_type_t};
use kern_return::kern_return_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;
}
Loading

0 comments on commit eb5749a

Please sign in to comment.