From 37b51462dcf26dc40ac5d7e82acdfd4cbe754157 Mon Sep 17 00:00:00 2001 From: Rubens Brandao Date: Wed, 10 Apr 2024 17:58:05 -0300 Subject: fix the array implementation using GAT --- rust/src/custombinaryview.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'rust/src/custombinaryview.rs') diff --git a/rust/src/custombinaryview.rs b/rust/src/custombinaryview.rs index 956be9bd..c69bad39 100644 --- a/rust/src/custombinaryview.rs +++ b/rust/src/custombinaryview.rs @@ -297,10 +297,12 @@ unsafe impl CoreOwnedArrayProvider for BinaryViewType { } } -unsafe impl<'a> CoreArrayWrapper<'a> for BinaryViewType { - type Wrapped = BinaryViewType; +unsafe impl CoreArrayWrapper for BinaryViewType { + // TODO there is nothing blocking the returned value from out-living the + // array, change it to &_ or Guard? + type Wrapped<'a> = BinaryViewType; - unsafe fn wrap_raw(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped { + unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { BinaryViewType(*raw) } } -- cgit v1.3.1 From f3c1a3cb3cbdd25d5f556d1ab770f8cbc29fd567 Mon Sep 17 00:00:00 2001 From: Rubens Brandao Date: Tue, 16 Apr 2024 17:03:20 -0300 Subject: add guard to array with unbound return types --- rust/src/custombinaryview.rs | 6 ++---- rust/src/downloadprovider.rs | 8 +++----- rust/src/references.rs | 8 +++----- rust/src/relocation.rs | 7 +++---- rust/src/types.rs | 2 -- 5 files changed, 11 insertions(+), 20 deletions(-) (limited to 'rust/src/custombinaryview.rs') diff --git a/rust/src/custombinaryview.rs b/rust/src/custombinaryview.rs index c69bad39..898102d6 100644 --- a/rust/src/custombinaryview.rs +++ b/rust/src/custombinaryview.rs @@ -298,12 +298,10 @@ unsafe impl CoreOwnedArrayProvider for BinaryViewType { } unsafe impl CoreArrayWrapper for BinaryViewType { - // TODO there is nothing blocking the returned value from out-living the - // array, change it to &_ or Guard? - type Wrapped<'a> = BinaryViewType; + type Wrapped<'a> = Guard<'a, BinaryViewType>; unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { - BinaryViewType(*raw) + Guard::new(BinaryViewType(*raw), &()) } } diff --git a/rust/src/downloadprovider.rs b/rust/src/downloadprovider.rs index cc243722..8334e0ce 100644 --- a/rust/src/downloadprovider.rs +++ b/rust/src/downloadprovider.rs @@ -1,5 +1,5 @@ use crate::rc::{ - Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Ref, RefCountable, + Array, CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref, RefCountable, }; use crate::settings::Settings; use crate::string::{BnStrCompatible, BnString}; @@ -72,12 +72,10 @@ unsafe impl CoreOwnedArrayProvider for DownloadProvider { } unsafe impl CoreArrayWrapper for DownloadProvider { - // TODO there is nothing blocking the returned value from out-living the - // array, change it to &_ or Guard? - type Wrapped<'a> = DownloadProvider; + type Wrapped<'a> = Guard<'a, DownloadProvider>; unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { - DownloadProvider::from_raw(*raw) + Guard::new(DownloadProvider::from_raw(*raw), &()) } } diff --git a/rust/src/references.rs b/rust/src/references.rs index a30f3f5e..8b4ebb87 100644 --- a/rust/src/references.rs +++ b/rust/src/references.rs @@ -1,6 +1,6 @@ use crate::architecture::CoreArchitecture; use crate::function::Function; -use crate::rc::{CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Ref}; +use crate::rc::{CoreArrayProvider, CoreArrayWrapper, CoreOwnedArrayProvider, Guard, Ref}; use binaryninjacore_sys::{BNFreeCodeReferences, BNFreeDataReferences, BNReferenceSource}; use std::mem::ManuallyDrop; @@ -65,12 +65,10 @@ unsafe impl CoreOwnedArrayProvider for CodeReference { } unsafe impl CoreArrayWrapper for CodeReference { - // TODO there is nothing blocking the returned value from out-living the - // array, change it to Guard? - type Wrapped<'a> = CodeReference; + type Wrapped<'a> = Guard<'a, CodeReference>; unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { - CodeReference::new(raw) + Guard::new(CodeReference::new(raw), &()) } } diff --git a/rust/src/relocation.rs b/rust/src/relocation.rs index 47ec2ac0..455f5a5a 100644 --- a/rust/src/relocation.rs +++ b/rust/src/relocation.rs @@ -1,3 +1,4 @@ +use crate::rc::Guard; use crate::string::BnStrCompatible; use crate::{ architecture::{Architecture, CoreArchitecture}, @@ -228,11 +229,9 @@ unsafe impl CoreOwnedArrayProvider for Relocation { } unsafe impl CoreArrayWrapper for Relocation { - // TODO there is nothing blocking the returned value from out-living the - // array, change it to &_ or Guard? - type Wrapped<'a> = Relocation; + type Wrapped<'a> = Guard<'a, Relocation>; unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { - Relocation(*raw) + Guard::new(Relocation(*raw), &()) } } diff --git a/rust/src/types.rs b/rust/src/types.rs index 43d48b3f..280d50fd 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -2501,7 +2501,6 @@ unsafe impl CoreArrayWrapper for NameAndType { type Wrapped<'a> = &'a NameAndType where S: 'a; unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { - // TODO this is not always valid, because the type is not transparent mem::transmute(raw) } } @@ -2549,7 +2548,6 @@ unsafe impl CoreArrayWrapper for DataVariable { type Wrapped<'a> = &'a DataVariable; unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { - // TODO this is not always valid, because the type is not transparent mem::transmute(raw) } } -- cgit v1.3.1