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

Remove the Architecture Handle #5318

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
39 changes: 16 additions & 23 deletions arch/riscv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,11 @@ impl<D: RiscVDisassembler> architecture::Intrinsic for RiscVIntrinsic<D> {
}

struct RiscVArch<D: 'static + RiscVDisassembler + Send + Sync> {
handle: CoreArchitecture,
custom_handle: CustomArchitectureHandle<RiscVArch<D>>,
handle: &'static CoreArchitecture,
_dis: PhantomData<D>,
}

impl<D: 'static + RiscVDisassembler + Send + Sync> architecture::Architecture for RiscVArch<D> {
type Handle = CustomArchitectureHandle<Self>;

type RegisterInfo = Register<D>;
type Register = Register<D>;
type RegisterStackInfo = UnusedRegisterStackInfo<Self::Register>;
Expand Down Expand Up @@ -674,7 +671,7 @@ impl<D: 'static + RiscVDisassembler + Send + Sync> architecture::Architecture fo
self.max_instr_len()
}

fn associated_arch_by_addr(&self, _addr: &mut u64) -> CoreArchitecture {
fn associated_arch_by_addr(&self, _addr: &mut u64) -> &'static CoreArchitecture {
self.handle
}

Expand Down Expand Up @@ -2140,8 +2137,8 @@ impl<D: 'static + RiscVDisassembler + Send + Sync> architecture::Architecture fo
true
}

fn handle(&self) -> CustomArchitectureHandle<Self> {
self.custom_handle
fn core(&self) -> &'static CoreArchitecture {
self.handle
}
}

Expand Down Expand Up @@ -2868,22 +2865,18 @@ pub extern "C" fn CorePluginInit() -> bool {
binaryninja::logger::init(log::LevelFilter::Trace).expect("Failed to set up logging");

use riscv_dis::{RiscVIMACDisassembler, Rv32GRegs, Rv64GRegs};
let arch32 =
architecture::register_architecture("rv32gc", |custom_handle, core_arch| RiscVArch::<
RiscVIMACDisassembler<Rv32GRegs>,
> {
handle: core_arch,
custom_handle,
_dis: PhantomData,
});
let arch64 =
architecture::register_architecture("rv64gc", |custom_handle, core_arch| RiscVArch::<
RiscVIMACDisassembler<Rv64GRegs>,
> {
handle: core_arch,
custom_handle,
_dis: PhantomData,
});
let arch32 = architecture::register_architecture("rv32gc", |core_arch| RiscVArch::<
RiscVIMACDisassembler<Rv32GRegs>,
> {
handle: core_arch,
_dis: PhantomData,
});
let arch64 = architecture::register_architecture("rv64gc", |core_arch| RiscVArch::<
RiscVIMACDisassembler<Rv64GRegs>,
> {
handle: core_arch,
_dis: PhantomData,
});

arch32.register_relocation_handler("ELF", |custom_handle, core_handler| {
RiscVELFRelocationHandler::<RiscVIMACDisassembler<Rv32GRegs>> {
Expand Down
2 changes: 1 addition & 1 deletion rust/examples/pdb-ng/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct PDBParserInstance<'a, S: Source<'a> + 'a> {
/// Parent binary view (usually during BinaryView::Finalize)
pub(crate) bv: &'a BinaryView,
/// Default arch of self.bv
pub(crate) arch: CoreArchitecture,
pub(crate) arch: &'static CoreArchitecture,
/// Default calling convention for self.arch
pub(crate) default_cc: Ref<CallingConvention<CoreArchitecture>>,
/// Thiscall calling convention for self.bv, or default_cc if we can't find one
Expand Down
24 changes: 12 additions & 12 deletions rust/examples/pdb-ng/src/type_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,31 +700,31 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
// TODO: Pointer suffix is not exposed
match data.indirection {
Some(Indirection::Near16) => Ok(Some(Box::new(ParsedType::Bare(Type::pointer(
&self.arch,
self.arch,
base.as_ref(),
))))),
Some(Indirection::Far16) => Ok(Some(Box::new(ParsedType::Bare(Type::pointer(
&self.arch,
self.arch,
base.as_ref(),
))))),
Some(Indirection::Huge16) => Ok(Some(Box::new(ParsedType::Bare(Type::pointer(
&self.arch,
self.arch,
base.as_ref(),
))))),
Some(Indirection::Near32) => Ok(Some(Box::new(ParsedType::Bare(Type::pointer(
&self.arch,
self.arch,
base.as_ref(),
))))),
Some(Indirection::Far32) => Ok(Some(Box::new(ParsedType::Bare(Type::pointer(
&self.arch,
self.arch,
base.as_ref(),
))))),
Some(Indirection::Near64) => Ok(Some(Box::new(ParsedType::Bare(Type::pointer(
&self.arch,
self.arch,
base.as_ref(),
))))),
Some(Indirection::Near128) => Ok(Some(Box::new(ParsedType::Bare(Type::pointer(
&self.arch,
self.arch,
base.as_ref(),
))))),
None => Ok(Some(Box::new(ParsedType::Bare(base)))),
Expand Down Expand Up @@ -1102,7 +1102,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
for (offset, (name, method)) in virt_methods {
vt.insert(
&Conf::new(
Type::pointer(&self.arch, &Conf::new(method.method_type, max_confidence())),
Type::pointer(self.arch, &Conf::new(method.method_type, max_confidence())),
max_confidence(),
),
&name,
Expand All @@ -1127,7 +1127,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
self.named_types.insert(vt_name.clone(), vt_type.clone());

let vt_pointer = Type::pointer(
&self.arch,
self.arch,
&Conf::new(
Type::named_type_from_type(&QualifiedName::from(vt_name), vt_type.as_ref()),
max_confidence(),
Expand Down Expand Up @@ -1245,7 +1245,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
// Return UDT??
// This probably means the return value got pushed to the stack
fancy_return_type = Type::pointer(
&self.arch,
self.arch,
&Conf::new(return_type.clone(), max_confidence()),
);
fancy_arguments.insert(
Expand Down Expand Up @@ -1528,7 +1528,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {
if return_stacky {
// Stack return via a pointer in the first parameter
fancy_return_type =
Conf::new(Type::pointer(&self.arch, &return_type), max_confidence());
Conf::new(Type::pointer(self.arch, &return_type), max_confidence());
fancy_arguments.insert(
0,
FunctionParameter::new(fancy_return_type.clone(), "__return".to_string(), None),
Expand Down Expand Up @@ -1583,7 +1583,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> {

if let Some(base) = base {
Ok(Some(Box::new(ParsedType::Bare(Type::pointer(
&self.arch,
self.arch,
base.as_ref(),
)))))
} else {
Expand Down
Loading
Loading