Skip to content

Commit

Permalink
Fixed: MSVC Build on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Sep 9, 2023
1 parent 6eaf5a5 commit b3174fa
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src-rust/src/utilities/icache_clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
);
}
}

0 comments on commit b3174fa

Please sign in to comment.