Skip to content

Commit

Permalink
Add mach-o/dyld.h items
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Jan 3, 2024
1 parent 1764622 commit 992a2c0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mach-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ fn main() {
.header("mach/vm_task.h")
.header("mach/vm_types.h");

cfg.header("mach-o/loader.h").header("mach-o/dyld.h");

// The below doesn't exist in Xcode 14:
if xcode < Xcode(14, 0) {
cfg.header("mach/lock_set.h");
Expand Down
16 changes: 16 additions & 0 deletions src/dyld.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! This module roughly corresponds to `mach-o/dyld.h`.
use loader::mach_header;

extern "C" {
pub fn _dyld_image_count() -> u32;
pub fn _dyld_get_image_header(image_index: u32) -> *const mach_header;
pub fn _dyld_get_image_vmaddr_slide(image_index: u32) -> ::libc::intptr_t;
pub fn _dyld_get_image_name(image_index: u32) -> *const ::libc::c_char;
pub fn _dyld_register_func_for_add_image(
callback: unsafe extern "C" fn(mh: *const mach_header, vmaddr_slide: ::libc::intptr_t),
);
pub fn _dyld_register_func_for_remove_image(
callback: unsafe extern "C" fn(mh: *const mach_header, vmaddr_slide: ::libc::intptr_t),
);
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ pub mod clock;
pub mod clock_priv;
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;
pub mod loader;
pub mod mach_init;
pub mod mach_port;
pub mod mach_time;
Expand Down
14 changes: 14 additions & 0 deletions src/loader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! This module roughly corresponds to `mach-o/loader.h`.
#[repr(C)]
#[allow(dead_code, non_snake_case)]
#[derive(Copy, Clone, Debug)]
pub struct mach_header {
pub magic: u32,
pub cputype: ::libc::cpu_type_t,
pub cpusubtype: ::libc::cpu_subtype_t,
pub filetype: u32,
pub ncmds: u32,
pub sizeofcmds: u32,
pub flags: u32,
}

0 comments on commit 992a2c0

Please sign in to comment.