From d552ae9beae6404c13548b98ec7a7ec4e6b3dd90 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Thu, 21 Jul 2022 15:24:16 -0400 Subject: [Rust API] Better name for this trait fn, more CC support --- rust/src/callingconvention.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'rust/src/callingconvention.rs') diff --git a/rust/src/callingconvention.rs b/rust/src/callingconvention.rs index 8e29a0b0..672b2c1b 100644 --- a/rust/src/callingconvention.rs +++ b/rust/src/callingconvention.rs @@ -24,7 +24,9 @@ use std::slice; use binaryninjacore_sys::*; use crate::architecture::{Architecture, ArchitectureExt, Register}; -use crate::rc::{Ref, RefCountable}; +use crate::rc::{ + CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref, RefCountable, +}; use crate::string::*; // TODO @@ -365,7 +367,7 @@ where ) } - let name = name.as_bytes_with_nul(); + let name = name.into_bytes_with_nul(); let raw = Box::into_raw(Box::new(CustomCallingConventionContext { raw_handle: ptr::null_mut(), cc: cc, @@ -438,6 +440,10 @@ impl CallingConvention { _arch: PhantomData, }) } + + pub fn name(&self) -> BnString { + unsafe { BnString::from_raw(BNGetCallingConventionName(self.handle)) } + } } impl Eq for CallingConvention {} @@ -580,6 +586,32 @@ unsafe impl RefCountable for CallingConvention { } } +impl CoreArrayProvider for CallingConvention { + type Raw = *mut BNCallingConvention; + type Context = A::Handle; +} + +unsafe impl CoreOwnedArrayProvider for CallingConvention { + unsafe fn free(raw: *mut *mut BNCallingConvention, count: usize, _content: &Self::Context) { + BNFreeCallingConventionList(raw, count); + } +} + +unsafe impl<'a, A: Architecture> CoreArrayWrapper<'a> for CallingConvention { + type Wrapped = Guard<'a, CallingConvention>; + + unsafe fn wrap_raw(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped { + Guard::new( + CallingConvention { + handle: *raw, + arch_handle: context.clone(), + _arch: Default::default(), + }, + context, + ) + } +} + pub struct ConventionBuilder { caller_saved_registers: Vec, _callee_saved_registers: Vec, -- cgit v1.3.1