Skip to content

Commit 3623501

Browse files
authored
sys/miri: fix Mmap::from_file to seek to start of file. (#12572)
The constructor takes a `&File` but `&File` still allows mutation of the underlying state, e.g., the seek position. It turns out that this matters when we try to `Mmap::from_file` more than once, e.g. when enabling guest debugging and thus mapping private copies of code. No test yet as this will be covered by upcoming miri coverage of guest debugging.
1 parent 282546d commit 3623501

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

  • crates/wasmtime/src/runtime/vm/sys/miri

crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::runtime::vm::sys::vm::MemoryImageSource;
1010
use crate::runtime::vm::{HostAlignedByteCount, SendSyncPtr};
1111
use std::alloc::{self, Layout};
1212
use std::fs::File;
13-
use std::io::Read;
13+
use std::io::{Read, Seek, SeekFrom};
1414
use std::ops::Range;
1515
use std::path::Path;
1616
use std::ptr::NonNull;
@@ -63,6 +63,7 @@ impl Mmap {
6363
// Read the file and copy it in to a fresh "mmap" to have allocation for
6464
// an mmap only in one location.
6565
let mut dst = Vec::new();
66+
file.seek(SeekFrom::Start(0))?;
6667
file.read_to_end(&mut dst)?;
6768
let count = HostAlignedByteCount::new_rounded_up(dst.len())?;
6869
let result = Mmap::new(count)?;

0 commit comments

Comments
 (0)