Conversation
|
Thanks for taking the time and looking into implementing this, I know it's not an easy task. There's some changes I'll need you to make before I can really consider a full review of this though. As far as disassembler, we obviously need a new disassembler to support arm64, but if there doesn't exist a pure rust one that supports arm, we still need to keep iced-x86 for x86. I don't love splitting dependencies, but this library already has some inherit unsafety due to the nature of what it's doing. I don't want to introduce FFI layers that don't have rust's safety guarantees. We swapped out udis with iced-x86 for a similar reason in #41. So keep x86 using iced-x86 and you can still use capstone if there's no good arm64 disassembly rust libraries to handle it (one day we'll hopefully have a more developed library out there to replace capstone with, like we did iced-x86) Also, keep changes unrelated to arm64 support to a minimum. There are large code diffs just for adding support, so all the extra warning changes updates and style changes makes a big diff bigger and harder for me to review. If this was a small change, I'd be a lot more open to little warning fixes. I don't have a whole lot of time to look into some of the more specific implementation details, but I'll try to look at it when I can. |
|
Understood, I would try to refactor the PR to a minimum. |
A very early stage in dev arm64 support to impl #57
Summary
This PR adds full ARM64 support for both Linux and macOS (Apple Silicon), making retour a truly cross-platform detouring library.
Changes
New Architecture Support
src/arch/arm64/module with ARM64-specific implementations:patcher.rs- Function patching using 16-byte absolute jumps (LDR X16 + BR X16)trampoline.rs- Trampoline generation with PC-relative instruction handling (ADR, ADRP, LDR literal)thunk.rs- Code generation for jumps, calls, and conditional branchesmeta.rs- Architecture constants (128MB detour range)Disassembler Migration
iced-x86withcapstonefor cross-platform disassemblysrc/arch/disasm/abstraction layer supporting x86, x86_64, and ARM64OwnedInsnmacOS ARM64 W^X Compliance
MAP_JITflagpthread_jit_write_protect_np()mach_vm_protectwithVM_PROT_COPY__TEXT,__detour_patchsection to avoid executing from pages being modifiedCI Updates
aarch64-unknown-linux-gnutarget (native ARM64 runner)aarch64-apple-darwintarget (macOS ARM64)Code Quality
# Safetydocumentation to unsafe functionsBreaking Changes
None - public API unchanged.
Platform Notes
On macOS ARM64, due to strict W^X enforcement:
MAP_JIT(may need JIT entitlement for hardened runtime apps)__TEXT,__detour_patchsection