Skip to content

Commit 9ed25b5

Browse files
chanddealexcrichton
authored andcommitted
(Pre)Add CONTEXT definition and init_frame for ARM (#184)
* Move to 0.3.6 and add ARM support * Update Cargo.toml * add init_frame for arm32 * use R11 as frame pointer for ARM init_frame * fix merge issue * add P/CONTEXT for ARM, without the union * update IMAGE_FILE_MACHINE_ARM to IMAGE_FILE_MACHINE_ARMNT * fix the union validation * undo winapi version bump * fix merge issues * fix aarch64 test error
1 parent b1c76e4 commit 9ed25b5

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/backtrace/dbghelp.rs

+13
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,16 @@ fn init_frame(frame: &mut Frame, ctx: &CONTEXT) -> WORD {
181181
frame.addr_frame_mut().Mode = AddrModeFlat;
182182
IMAGE_FILE_MACHINE_ARM64
183183
}
184+
185+
#[cfg(target_arch = "arm")]
186+
fn init_frame(frame: &mut Frame, ctx: &CONTEXT) -> WORD {
187+
frame.addr_pc_mut().Offset = ctx.Pc as u64;
188+
frame.addr_pc_mut().Mode = AddrModeFlat;
189+
frame.addr_stack_mut().Offset = ctx.Sp as u64;
190+
frame.addr_stack_mut().Mode = AddrModeFlat;
191+
unsafe {
192+
frame.addr_frame_mut().Offset = ctx.R11 as u64;
193+
}
194+
frame.addr_frame_mut().Mode = AddrModeFlat;
195+
IMAGE_FILE_MACHINE_ARMNT
196+
}

src/windows.rs

+52
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ ffi! {
309309
pub const IMAGE_FILE_MACHINE_ARM64: u16 = 43620;
310310
pub const IMAGE_FILE_MACHINE_AMD64: u16 = 34404;
311311
pub const IMAGE_FILE_MACHINE_I386: u16 = 332;
312+
pub const IMAGE_FILE_MACHINE_ARMNT: u16 = 452;
312313
pub const FILE_SHARE_READ: DWORD = 0x1;
313314
pub const FILE_SHARE_WRITE: DWORD = 0x2;
314315
pub const OPEN_EXISTING: DWORD = 0x3;
@@ -557,3 +558,54 @@ ffi! {
557558
pub struct FLOATING_SAVE_AREA {
558559
_Dummy: [u8; 512],
559560
}
561+
562+
#[cfg(target_arch = "arm")]
563+
ffi! {
564+
// #[repr(C)]
565+
// pub struct NEON128 {
566+
// pub Low: ULONG64,
567+
// pub High: LONG64,
568+
// }
569+
570+
// pub type PNEON128 = *mut NEON128;
571+
572+
#[repr(C)]
573+
pub struct CONTEXT_u {
574+
// pub Q: [NEON128; 16],
575+
pub D: [ULONG64; 32],
576+
// pub S: [DWORD; 32],
577+
}
578+
579+
pub const ARM_MAX_BREAKPOINTS: usize = 8;
580+
pub const ARM_MAX_WATCHPOINTS: usize = 1;
581+
582+
#[repr(C)]
583+
pub struct CONTEXT {
584+
pub ContextFlags: DWORD,
585+
pub R0: DWORD,
586+
pub R1: DWORD,
587+
pub R2: DWORD,
588+
pub R3: DWORD,
589+
pub R4: DWORD,
590+
pub R5: DWORD,
591+
pub R6: DWORD,
592+
pub R7: DWORD,
593+
pub R8: DWORD,
594+
pub R9: DWORD,
595+
pub R10: DWORD,
596+
pub R11: DWORD,
597+
pub R12: DWORD,
598+
pub Sp: DWORD,
599+
pub Lr: DWORD,
600+
pub Pc: DWORD,
601+
pub Cpsr: DWORD,
602+
pub Fpsrc: DWORD,
603+
pub Padding: DWORD,
604+
pub u: CONTEXT_u,
605+
pub Bvr: [DWORD; ARM_MAX_BREAKPOINTS],
606+
pub Bcr: [DWORD; ARM_MAX_BREAKPOINTS],
607+
pub Wvr: [DWORD; ARM_MAX_WATCHPOINTS],
608+
pub Wcr: [DWORD; ARM_MAX_WATCHPOINTS],
609+
pub Padding2: [DWORD; 2],
610+
}
611+
} // IFDEF(arm)

0 commit comments

Comments
 (0)