Reduce needed register rules depending on targets

This commit is contained in:
Gary Guo 2021-10-12 18:30:39 +01:00
parent 6f4bf61efb
commit 6eb9fc4e0f
5 changed files with 26 additions and 1 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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<R: gimli::Reader> gimli::UnwindContextStorage<R> for StoreOnStack {
type Rules = [(Register, RegisterRule<R>); 192];
type Rules = [(Register, RegisterRule<R>); next_value(MAX_REG_RULES)];
type Stack = [UnwindTableRow<R, Self>; 1];
}