From ea82d201e7efb2065d0cea459bea0fcda1985762 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Tue, 19 May 2026 20:01:42 -0400 Subject: Refactor calling convention Rust API to allow default implementations Also implements the new calling convention APIs in Rust --- arch/riscv/src/lib.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'arch') diff --git a/arch/riscv/src/lib.rs b/arch/riscv/src/lib.rs index 3537a082..8504abe6 100644 --- a/arch/riscv/src/lib.rs +++ b/arch/riscv/src/lib.rs @@ -14,7 +14,9 @@ use binaryninja::{ UnusedRegisterStack, }, binary_view::{BinaryView, BinaryViewType}, - calling_convention::{register_calling_convention, CallingConvention, ConventionBuilder}, + calling_convention::{ + register_calling_convention, CallingConvention, ConventionBuilder, CoreCallingConvention, + }, disassembly::{InstructionTextToken, InstructionTextTokenKind}, function::Function, function_recognizer::FunctionRecognizer, @@ -2755,12 +2757,22 @@ impl AsRef for RiscVELFRelocationHa } struct RiscVCC { + core: CoreCallingConvention, _dis: PhantomData, } impl RiscVCC { - fn new() -> Self { - RiscVCC { _dis: PhantomData } + fn new(core: CoreCallingConvention) -> Self { + RiscVCC { + core, + _dis: PhantomData, + } + } +} + +impl AsRef for RiscVCC { + fn as_ref(&self) -> &CoreCallingConvention { + &self.core } } @@ -3087,17 +3099,13 @@ pub extern "C" fn CorePluginInit() -> bool { arch32.register_function_recognizer(RiscVELFPLTRecognizer); arch64.register_function_recognizer(RiscVELFPLTRecognizer); - let cc32 = register_calling_convention( - arch32, - "default", - RiscVCC::>::new(), - ); + let cc32 = register_calling_convention(arch32, "default", |core| { + RiscVCC::>::new(core) + }); arch32.set_default_calling_convention(&cc32); - let cc64 = register_calling_convention( - arch64, - "default", - RiscVCC::>::new(), - ); + let cc64 = register_calling_convention(arch64, "default", |core| { + RiscVCC::>::new(core) + }); arch64.set_default_calling_convention(&cc64); if let Some(bvt) = BinaryViewType::by_name("ELF") { -- cgit v1.3.1