From 9043fe312851c9b32865ea9ac565792bf6665e4c Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 30 Dec 2023 20:34:16 +0100 Subject: [PATCH] Using dynamic imports also for the aligned buffer --- windows-projfs/src/aligned_buffer.rs | 31 +++++++++++++++++++--------- windows-projfs/src/fs.rs | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/windows-projfs/src/aligned_buffer.rs b/windows-projfs/src/aligned_buffer.rs index 969d0e0..f96a48e 100644 --- a/windows-projfs/src/aligned_buffer.rs +++ b/windows-projfs/src/aligned_buffer.rs @@ -1,23 +1,34 @@ -use std::ffi::c_void; - -use windows::Win32::Storage::ProjectedFileSystem::{ - PrjAllocateAlignedBuffer, - PrjFreeAlignedBuffer, - PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT, +use std::{ + ffi::c_void, + sync::Arc, }; +use windows::Win32::Storage::ProjectedFileSystem::PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT; + +use crate::library::ProjectedFSLibrary; + pub struct PrjAlignedBuffer { + library: Arc, + length: usize, raw_buffer: *mut c_void, } impl PrjAlignedBuffer { - pub fn allocate(context: PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT, length: usize) -> Option { - let raw_buffer = unsafe { PrjAllocateAlignedBuffer(context, length) }; + pub fn allocate( + library: Arc, + context: PRJ_NAMESPACE_VIRTUALIZATION_CONTEXT, + length: usize, + ) -> Option { + let raw_buffer = unsafe { library.prj_allocate_aligned_buffer(context, length) }; if raw_buffer.is_null() { None } else { - Some(Self { length, raw_buffer }) + Some(Self { + library, + length, + raw_buffer, + }) } } @@ -28,6 +39,6 @@ impl PrjAlignedBuffer { impl Drop for PrjAlignedBuffer { fn drop(&mut self) { - unsafe { PrjFreeAlignedBuffer(self.raw_buffer) }; + unsafe { self.library.prj_free_aligned_buffer(self.raw_buffer) }; } } diff --git a/windows-projfs/src/fs.rs b/windows-projfs/src/fs.rs index a04cce3..23938ef 100644 --- a/windows-projfs/src/fs.rs +++ b/windows-projfs/src/fs.rs @@ -593,6 +593,7 @@ mod native { }; let mut buffer = PrjAlignedBuffer::allocate( + context.library.clone(), callback_data.namespace_virtualization_context, chunk_length, )