From b3174fae942254cf03882ceae83d0d32e8492870 Mon Sep 17 00:00:00 2001 From: sewer56 Date: Sat, 9 Sep 2023 20:49:24 +0100 Subject: [PATCH] Fixed: MSVC Build on Windows --- src-rust/src/utilities/icache_clear.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src-rust/src/utilities/icache_clear.rs b/src-rust/src/utilities/icache_clear.rs index 53f7534..b3b4aeb 100644 --- a/src-rust/src/utilities/icache_clear.rs +++ b/src-rust/src/utilities/icache_clear.rs @@ -13,6 +13,7 @@ extern "C" { /// # Remarks /// /// This function is provided by LLVM. It might not work in non-LLVM backends. +#[cfg(not(target_os = "windows"))] // MSVC fix pub fn clear_instruction_cache(start: *mut u8, end: *mut u8) { unsafe { __clear_cache( @@ -21,3 +22,24 @@ pub fn clear_instruction_cache(start: *mut u8, end: *mut u8) { ) } } + +/// Clears the instruction cache for the specified range. +/// +/// # Arguments +/// +/// * `start` - The start address of the range to clear. +/// * `end` - The end address of the range to clear. +#[cfg(target_os = "windows")] // MSVC fix +pub fn clear_instruction_cache(start: *mut u8, end: *mut u8) { + use windows::Win32::System::{ + Diagnostics::Debug::FlushInstructionCache, Threading::GetCurrentProcess, + }; + + unsafe { + FlushInstructionCache( + GetCurrentProcess(), + Some(start as *const std::ffi::c_void), + end as usize - start as usize, + ); + } +}