Skip to content

Commit

Permalink
Migrate cranelift-jit from winapi to windows-sys (#4363)
Browse files Browse the repository at this point in the history
* Migrate cranelift-jit from `winapi` to `windows-sys`

Following up on #4346, this migrates one more place in the tree from
winapi to windows-sys.
  • Loading branch information
sunfishcode authored Jul 1, 2022
1 parent ec83144 commit 64759f0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions cranelift/jit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ target-lexicon = "0.12"
memmap2 = { version = "0.2.1", optional = true }
log = { version = "0.4.6", default-features = false }

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["winbase", "memoryapi"] }
[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.36.0"
features = [
"Win32_Foundation",
"Win32_System_LibraryLoader",
"Win32_System_Memory",
]

[features]
selinux-fix = ['memmap2']
Expand Down
14 changes: 9 additions & 5 deletions cranelift/jit/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,10 @@ fn lookup_with_dlsym(name: &str) -> Option<*const u8> {

#[cfg(windows)]
fn lookup_with_dlsym(name: &str) -> Option<*const u8> {
use std::os::windows::io::RawHandle;
use windows_sys::Win32::Foundation::HINSTANCE;
use windows_sys::Win32::System::LibraryLoader;

const MSVCRT_DLL: &[u8] = b"msvcrt.dll\0";

let c_str = CString::new(name).unwrap();
Expand All @@ -899,15 +903,15 @@ fn lookup_with_dlsym(name: &str) -> Option<*const u8> {
// try to find the searched symbol in the currently running executable
ptr::null_mut(),
// try to find the searched symbol in local c runtime
winapi::um::libloaderapi::GetModuleHandleA(MSVCRT_DLL.as_ptr().cast::<i8>()),
LibraryLoader::GetModuleHandleA(MSVCRT_DLL.as_ptr()) as RawHandle,
];

for handle in &handles {
let addr = winapi::um::libloaderapi::GetProcAddress(*handle, c_str_ptr);
if addr.is_null() {
continue;
let addr = LibraryLoader::GetProcAddress(*handle as HINSTANCE, c_str_ptr.cast());
match addr {
None => continue,
Some(addr) => return Some(addr as *const u8),
}
return Some(addr as *const u8);
}

None
Expand Down
5 changes: 3 additions & 2 deletions cranelift/jit/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ impl PtrLen {

#[cfg(target_os = "windows")]
fn with_size(size: usize) -> io::Result<Self> {
use winapi::um::memoryapi::VirtualAlloc;
use winapi::um::winnt::{MEM_COMMIT, MEM_RESERVE, PAGE_READWRITE};
use windows_sys::Win32::System::Memory::{
VirtualAlloc, MEM_COMMIT, MEM_RESERVE, PAGE_READWRITE,
};

// VirtualAlloc always rounds up to the next multiple of the page size
let ptr = unsafe {
Expand Down

0 comments on commit 64759f0

Please sign in to comment.