Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libafl_frida: Allow compilation for iOS #1023

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libafl_frida/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// build.rs

fn main() {
cc::Build::new().file("src/gettls.c").compile("libgettls.a");
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
if target_os != "ios" {
cc::Build::new().file("src/gettls.c").compile("libgettls.a");
}

// Force linking against libc++
#[cfg(unix)]
Expand Down
14 changes: 14 additions & 0 deletions libafl_frida/src/asan/asan_rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern "C" {
fn __register_frame(begin: *mut c_void);
}

#[cfg(not(target_os = "ios"))]
extern "C" {
fn tls_ptr() -> *const c_void;
}
Expand Down Expand Up @@ -390,6 +391,7 @@ impl AsanRuntime {
/// Register the current thread with the runtime, implementing shadow memory for its stack and
/// tls mappings.
#[allow(clippy::unused_self)]
#[cfg(not(target_os = "ios"))]
pub fn register_thread(&mut self) {
let (stack_start, stack_end) = Self::current_stack();
self.allocator
Expand All @@ -403,6 +405,17 @@ impl AsanRuntime {
);
}

/// Register the current thread with the runtime, implementing shadow memory for its stack mapping.
#[allow(clippy::unused_self)]
#[cfg(target_os = "ios")]
pub fn register_thread(&mut self) {
let (stack_start, stack_end) = Self::current_stack();
self.allocator
.map_shadow_for_region(stack_start, stack_end, true);

println!("registering thread with stack {stack_start:x}:{stack_end:x}");
}

/// Get the maximum stack size for the current stack
#[must_use]
#[cfg(target_vendor = "apple")]
Expand Down Expand Up @@ -470,6 +483,7 @@ impl AsanRuntime {

/// Determine the tls start, end for the currently running thread
#[must_use]
#[cfg(not(target_os = "ios"))]
fn current_tls() -> (usize, usize) {
let tls_address = unsafe { tls_ptr() } as usize;

Expand Down