Skip to content

Commit

Permalink
Fix windows compile
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Dec 2, 2024
1 parent 9d41294 commit 6b26585
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub fn open_file_for_mmap(path: &Path) -> Result<File> {
.access_mode(FILE_GENERIC_READ | FILE_GENERIC_EXECUTE)
.share_mode(FILE_SHARE_READ)
.open(path)
.err2anyhow()
.context("failed to open file")
}

Expand Down Expand Up @@ -85,7 +84,6 @@ impl Mmap {
unsafe {
let len = file
.metadata()
.err2anyhow()
.context("failed to get file metadata")?
.len();
let len = usize::try_from(len).map_err(|_| anyhow!("file too large to map"))?;
Expand All @@ -105,8 +103,7 @@ impl Mmap {
ptr::null(),
);
if mapping == INVALID_HANDLE_VALUE {
return Err(io::Error::last_os_error().into_anyhow())
.context("failed to create file mapping");
return Err(io::Error::last_os_error()).context("failed to create file mapping");
}

// Create a view for the entire file using all our requisite
Expand All @@ -123,8 +120,7 @@ impl Mmap {
let err = io::Error::last_os_error();
CloseHandle(mapping);
if ptr.is_null() {
return Err(err.into_anyhow())
.context(format!("failed to create map view of {:#x} bytes", len));
return Err(err).context(format!("failed to create map view of {:#x} bytes", len));
}

let memory = std::ptr::slice_from_raw_parts_mut(ptr.cast(), len);
Expand All @@ -138,7 +134,7 @@ impl Mmap {
// remove the execute bit)
let mut old = 0;
if VirtualProtect(ret.as_mut_ptr().cast(), ret.len(), PAGE_WRITECOPY, &mut old) == 0 {
return Err(io::Error::last_os_error().into_anyhow())
return Err(io::Error::last_os_error())
.context("failed change pages to `PAGE_READONLY`");
}

Expand Down

0 comments on commit 6b26585

Please sign in to comment.