diff options
| author | Glenn Smith <glenn@vector35.com> | 2022-07-21 15:24:16 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2022-09-29 21:02:22 -0400 |
| commit | d552ae9beae6404c13548b98ec7a7ec4e6b3dd90 (patch) | |
| tree | 00a2696b2a3a33b1ac5bb058801fdea9f1a38c03 /rust/src/callingconvention.rs | |
| parent | 2e18783a2f6e29c225d177e8a0fb866a9c9d85df (diff) | |
[Rust API] Better name for this trait fn, more CC support
Diffstat (limited to 'rust/src/callingconvention.rs')
| -rw-r--r-- | rust/src/callingconvention.rs | 36 |
1 files changed, 34 insertions, 2 deletions
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<A: Architecture> CallingConvention<A> { _arch: PhantomData, }) } + + pub fn name(&self) -> BnString { + unsafe { BnString::from_raw(BNGetCallingConventionName(self.handle)) } + } } impl<A: Architecture> Eq for CallingConvention<A> {} @@ -580,6 +586,32 @@ unsafe impl<A: Architecture> RefCountable for CallingConvention<A> { } } +impl<A: Architecture> CoreArrayProvider for CallingConvention<A> { + type Raw = *mut BNCallingConvention; + type Context = A::Handle; +} + +unsafe impl<A: Architecture> CoreOwnedArrayProvider for CallingConvention<A> { + unsafe fn free(raw: *mut *mut BNCallingConvention, count: usize, _content: &Self::Context) { + BNFreeCallingConventionList(raw, count); + } +} + +unsafe impl<'a, A: Architecture> CoreArrayWrapper<'a> for CallingConvention<A> { + type Wrapped = Guard<'a, CallingConvention<A>>; + + 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<A: Architecture> { caller_saved_registers: Vec<A::Register>, _callee_saved_registers: Vec<A::Register>, |
