diff --git a/Cargo.lock b/Cargo.lock index 33610f2c0dd..f0139620867 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6461,7 +6461,7 @@ dependencies = [ "wasmer-vm", "wasmparser 0.121.2", "wat", - "winapi 0.3.9", + "windows-sys 0.59.0", ] [[package]] @@ -6725,7 +6725,7 @@ dependencies = [ "wasmer-types", "wasmer-vm", "wasmparser 0.121.2", - "winapi 0.3.9", + "windows-sys 0.59.0", "xxhash-rust", ] @@ -7096,7 +7096,7 @@ dependencies = [ "thiserror", "tracing", "wasmer-types", - "winapi 0.3.9", + "windows-sys 0.59.0", ] [[package]] @@ -7181,7 +7181,7 @@ dependencies = [ "web-sys", "webc", "weezl", - "winapi 0.3.9", + "windows-sys 0.59.0", "xxhash-rust", ] @@ -7552,6 +7552,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index 628d75ae50e..22e42a37014 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -56,7 +56,7 @@ wasmparser = { workspace = true, default-features = false, optional = true } # - Mandatory dependencies for `sys` on Windows. [target.'cfg(all(not(target_arch = "wasm32"), target_os = "windows"))'.dependencies] -winapi = "0.3" +windows-sys = "0.59" # - Development Dependencies for `sys`. [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] wat = "1.0" diff --git a/lib/compiler/Cargo.toml b/lib/compiler/Cargo.toml index ce9d426d611..8d122d08b90 100644 --- a/lib/compiler/Cargo.toml +++ b/lib/compiler/Cargo.toml @@ -44,7 +44,7 @@ wasmer-vm = { path = "../vm", version = "=4.3.5" } region = { version = "3.0" } [target.'cfg(target_os = "windows")'.dependencies] -winapi = { version = "0.3", features = ["winnt", "impl-default"] } +windows-sys = { version = "0.59", features = ["Win32_System_Diagnostics_Debug"] } [features] default = ["std"] diff --git a/lib/compiler/src/engine/unwind/windows_x64.rs b/lib/compiler/src/engine/unwind/windows_x64.rs index 115d7233ee2..9ef4a9840e3 100644 --- a/lib/compiler/src/engine/unwind/windows_x64.rs +++ b/lib/compiler/src/engine/unwind/windows_x64.rs @@ -4,12 +4,14 @@ //! Module for Windows x64 ABI unwind registry. use std::collections::HashMap; use wasmer_types::CompiledFunctionUnwindInfoReference; -use winapi::um::winnt; +use windows_sys::Win32::System::Diagnostics::Debug::{ + RtlAddFunctionTable, RtlDeleteFunctionTable, IMAGE_RUNTIME_FUNCTION_ENTRY, +}; /// Represents a registry of function unwind information for Windows x64 ABI. pub struct UnwindRegistry { // A hashmap mapping the baseaddress with the registered runtime functions - functions: HashMap>, + functions: HashMap>, published: bool, } @@ -39,16 +41,14 @@ impl UnwindRegistry { _ => return Err("unsupported unwind information".to_string()), }; - let mut entry = winnt::RUNTIME_FUNCTION::default(); + let mut entry: IMAGE_RUNTIME_FUNCTION_ENTRY = unsafe { std::mem::zeroed() }; entry.BeginAddress = func_start; entry.EndAddress = func_start + func_len; // The unwind information should be immediately following the function // with padding for 4 byte alignment - unsafe { - *entry.u.UnwindInfoAddress_mut() = (entry.EndAddress + 3) & !3; - } + entry.Anonymous.UnwindInfoAddress = (entry.EndAddress + 3) & !3; let entries = self.functions.entry(base_address).or_insert_with(Vec::new); entries.push(entry); @@ -73,7 +73,7 @@ impl UnwindRegistry { "function table allocation was not aligned" ); unsafe { - if winnt::RtlAddFunctionTable( + if RtlAddFunctionTable( functions.as_mut_ptr(), functions.len() as u32, *base_address as u64, @@ -94,7 +94,7 @@ impl Drop for UnwindRegistry { if self.published { unsafe { for functions in self.functions.values_mut() { - winnt::RtlDeleteFunctionTable(functions.as_mut_ptr()); + RtlDeleteFunctionTable(functions.as_mut_ptr()); } } } diff --git a/lib/vm/Cargo.toml b/lib/vm/Cargo.toml index 5ad15978a4a..a89893b7e40 100644 --- a/lib/vm/Cargo.toml +++ b/lib/vm/Cargo.toml @@ -38,7 +38,7 @@ crossbeam-queue = "0.3.8" mach2 = "0.4.2" [target.'cfg(target_os = "windows")'.dependencies] -winapi = { version = "0.3", features = ["winbase", "memoryapi", "errhandlingapi"] } +windows-sys = { version = "0.59", features = ["Win32_System_Diagnostics_Debug", "Win32_System_Threading", "Win32_System_Kernel", "Win32_System_Memory"] } [build-dependencies] cc = "1.0" diff --git a/lib/vm/src/mmap.rs b/lib/vm/src/mmap.rs index 6d1ce905494..e08f49dc1e9 100644 --- a/lib/vm/src/mmap.rs +++ b/lib/vm/src/mmap.rs @@ -192,8 +192,9 @@ impl Mmap { _backing_file: Option, _memory_type: MmapType, ) -> Result { - use winapi::um::memoryapi::VirtualAlloc; - use winapi::um::winnt::{MEM_COMMIT, MEM_RESERVE, PAGE_NOACCESS, PAGE_READWRITE}; + use windows_sys::Win32::System::Memory::{ + VirtualAlloc, MEM_COMMIT, MEM_RESERVE, PAGE_NOACCESS, PAGE_READWRITE, + }; let page_size = region::page::size(); assert_le!(accessible_size, mapping_size); @@ -272,9 +273,8 @@ impl Mmap { /// `self`'s reserved memory. #[cfg(target_os = "windows")] pub fn make_accessible(&mut self, start: usize, len: usize) -> Result<(), String> { - use winapi::ctypes::c_void; - use winapi::um::memoryapi::VirtualAlloc; - use winapi::um::winnt::{MEM_COMMIT, PAGE_READWRITE}; + use std::ffi::c_void; + use windows_sys::Win32::System::Memory::{VirtualAlloc, MEM_COMMIT, PAGE_READWRITE}; let page_size = region::page::size(); assert_eq!(start & (page_size - 1), 0); assert_eq!(len & (page_size - 1), 0); @@ -396,9 +396,8 @@ impl Drop for Mmap { #[cfg(target_os = "windows")] fn drop(&mut self) { if self.len() != 0 { - use winapi::ctypes::c_void; - use winapi::um::memoryapi::VirtualFree; - use winapi::um::winnt::MEM_RELEASE; + use std::ffi::c_void; + use windows_sys::Win32::System::Memory::{VirtualFree, MEM_RELEASE}; let r = unsafe { VirtualFree(self.ptr as *mut c_void, 0, MEM_RELEASE) }; assert_ne!(r, 0); } diff --git a/lib/vm/src/trap/traphandlers.rs b/lib/vm/src/trap/traphandlers.rs index aa40a0df6b8..4ce892db0a0 100644 --- a/lib/vm/src/trap/traphandlers.rs +++ b/lib/vm/src/trap/traphandlers.rs @@ -84,7 +84,7 @@ cfg_if::cfg_if! { pub type TrapHandlerFn<'a> = dyn Fn(libc::c_int, *const libc::siginfo_t, *const libc::c_void) -> bool + Send + Sync + 'a; } else if #[cfg(target_os = "windows")] { /// Function which may handle custom signals while processing traps. - pub type TrapHandlerFn<'a> = dyn Fn(winapi::um::winnt::PEXCEPTION_POINTERS) -> bool + Send + Sync + 'a; + pub type TrapHandlerFn<'a> = dyn Fn(*mut windows_sys::Win32::System::Diagnostics::Debug::EXCEPTION_POINTERS) -> bool + Send + Sync + 'a; } } @@ -465,10 +465,20 @@ cfg_if::cfg_if! { }; } } else if #[cfg(target_os = "windows")] { - use winapi::um::errhandlingapi::*; - use winapi::um::winnt::*; - use winapi::um::minwinbase::*; - use winapi::vc::excpt::*; + use windows_sys::Win32::System::Diagnostics::Debug::{ + AddVectoredExceptionHandler, + CONTEXT, + EXCEPTION_CONTINUE_EXECUTION, + EXCEPTION_CONTINUE_SEARCH, + EXCEPTION_POINTERS, + }; + use windows_sys::Win32::Foundation::{ + EXCEPTION_ACCESS_VIOLATION, + EXCEPTION_ILLEGAL_INSTRUCTION, + EXCEPTION_INT_DIVIDE_BY_ZERO, + EXCEPTION_INT_OVERFLOW, + EXCEPTION_STACK_OVERFLOW, + }; unsafe fn platform_init() { // our trap handler needs to go first, so that we can recover from @@ -480,8 +490,8 @@ cfg_if::cfg_if! { } unsafe extern "system" fn exception_handler( - exception_info: PEXCEPTION_POINTERS - ) -> LONG { + exception_info: *mut EXCEPTION_POINTERS + ) -> i32 { // Check the kind of exception, since we only handle a subset within // wasm code. If anything else happens we want to defer to whatever // the rest of the system wants to do for this exception. @@ -993,7 +1003,7 @@ pub fn lazy_per_thread_init() -> Result<(), Trap> { // We need additional space on the stack to handle stack overflow // exceptions. Rust's initialization code sets this to 0x5000 but this // seems to be insufficient in practice. - use winapi::um::processthreadsapi::SetThreadStackGuarantee; + use windows_sys::Win32::System::Threading::SetThreadStackGuarantee; if unsafe { SetThreadStackGuarantee(&mut 0x10000) } == 0 { panic!("failed to set thread stack guarantee"); } diff --git a/lib/wasix/Cargo.toml b/lib/wasix/Cargo.toml index ccd0447a264..3a5f3e0dbce 100644 --- a/lib/wasix/Cargo.toml +++ b/lib/wasix/Cargo.toml @@ -57,7 +57,7 @@ async-trait = { version = "^0.1" } urlencoding = { version = "^2" } serde_derive = { version = "^1" } serde_json = { version = "^1" } -serde_yaml.workspace = true +serde_yaml.workspace = true weezl = { version = "^0.1" } hex = { version = "^0.4" } linked_hash_set = { version = "0.1" } @@ -124,7 +124,7 @@ libc.workspace = true termios = { version = "0.3" } [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3", features = ["sysinfoapi"] } +windows-sys = { version = "0.59", features = ["Win32_System_SystemInformation"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] terminal_size = { version = "0.3.0" } diff --git a/lib/wasix/src/syscalls/windows.rs b/lib/wasix/src/syscalls/windows.rs index a1481d4cb21..8cfe208acd6 100644 --- a/lib/wasix/src/syscalls/windows.rs +++ b/lib/wasix/src/syscalls/windows.rs @@ -30,7 +30,8 @@ pub fn platform_clock_time_get( ) -> Result { let nanos = match clock_id { wasi::Snapshot0Clockid::Monotonic => { - let tick_ms = unsafe { winapi::um::sysinfoapi::GetTickCount64() }; + let tick_ms = + unsafe { windows_sys::Win32::System::SystemInformation::GetTickCount64() }; tick_ms * 1_000_000 } wasi::Snapshot0Clockid::Realtime => {