Skip to content

Commit

Permalink
Add windows cache flush
Browse files Browse the repository at this point in the history
  • Loading branch information
Evian-Zhang committed Aug 8, 2024
1 parent c171346 commit c12de5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ libc = { version = "0.2", default-features = false }
mach2 = "0.4"

[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = "0.58", features = ["Win32_System_SystemInformation", "Win32_System_Memory"] }
windows = { version = "0.58", features = ["Win32_System_SystemInformation", "Win32_System_Memory", "Win32_System_Threading", "Win32_System_Diagnostics_Debug"] }

[dev-dependencies]
trybuild = "1"
6 changes: 6 additions & 0 deletions src/os/windows.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Windows-specific implementations
use windows::Win32::System::{
Diagnostics::Debug::FlushInstructionCache,
Memory::{VirtualProtect, PAGE_EXECUTE_READWRITE, PAGE_PROTECTION_FLAGS},
SystemInformation::{GetSystemInfo, SYSTEM_INFO},
Threading::GetCurrentProcess,
};

use crate::{code_manipulate::CodeManipulator, JumpEntry};
Expand Down Expand Up @@ -69,5 +71,9 @@ impl CodeManipulator for ArchCodeManipulator {
if res.is_err() {
panic!("Unable to restore code region to non-writable");
}
let res = unsafe { FlushInstructionCache(GetCurrentProcess(), Some(addr), L) };
if res.is_err() {
panic!("Failed to flush instruction cache");
}
}
}

0 comments on commit c12de5e

Please sign in to comment.