diff --git a/src/unwinder/arch/aarch64.rs b/src/unwinder/arch/aarch64.rs index 0df22a6..ed5ad08 100644 --- a/src/unwinder/arch/aarch64.rs +++ b/src/unwinder/arch/aarch64.rs @@ -2,6 +2,9 @@ use core::fmt; use core::ops; use gimli::{AArch64, Register}; +// Match DWARF_FRAME_REGISTERS in libgcc +pub const MAX_REG_RULES: usize = 97; + #[repr(C)] #[derive(Clone, Default)] pub struct Context { diff --git a/src/unwinder/arch/riscv64.rs b/src/unwinder/arch/riscv64.rs index 696bdcf..dcf7c9e 100644 --- a/src/unwinder/arch/riscv64.rs +++ b/src/unwinder/arch/riscv64.rs @@ -2,6 +2,9 @@ use core::fmt; use core::ops; use gimli::{Register, RiscV}; +// Match DWARF_FRAME_REGISTERS in libgcc +pub const MAX_REG_RULES: usize = 65; + #[repr(C)] #[derive(Clone, Default)] pub struct Context { diff --git a/src/unwinder/arch/x86.rs b/src/unwinder/arch/x86.rs index ec55416..f44fd75 100644 --- a/src/unwinder/arch/x86.rs +++ b/src/unwinder/arch/x86.rs @@ -2,6 +2,9 @@ use core::fmt; use core::ops; use gimli::{Register, X86}; +// Match DWARF_FRAME_REGISTERS in libgcc +pub const MAX_REG_RULES: usize = 17; + #[repr(C)] #[derive(Clone, Default)] pub struct Context { diff --git a/src/unwinder/arch/x86_64.rs b/src/unwinder/arch/x86_64.rs index 207e926..78bde82 100644 --- a/src/unwinder/arch/x86_64.rs +++ b/src/unwinder/arch/x86_64.rs @@ -2,6 +2,9 @@ use core::fmt; use core::ops; use gimli::{Register, X86_64}; +// Match DWARF_FRAME_REGISTERS in libgcc +pub const MAX_REG_RULES: usize = 17; + #[repr(C)] #[derive(Clone, Default)] pub struct Context { diff --git a/src/unwinder/frame.rs b/src/unwinder/frame.rs index 7bb0f36..792be6e 100644 --- a/src/unwinder/frame.rs +++ b/src/unwinder/frame.rs @@ -12,8 +12,21 @@ use crate::util::*; struct StoreOnStack; +// gimli's MSRV doesn't allow const generics, so we need to pick a supported array size. +const fn next_value(x: usize) -> usize { + let supported = [0, 1, 2, 3, 4, 8, 16, 32, 64, 128]; + let mut i = 0; + while i < supported.len() { + if supported[i] >= x { + return supported[i]; + } + i += 1; + } + 192 +} + impl gimli::UnwindContextStorage for StoreOnStack { - type Rules = [(Register, RegisterRule); 192]; + type Rules = [(Register, RegisterRule); next_value(MAX_REG_RULES)]; type Stack = [UnwindTableRow; 1]; }