Skip to content

Commit 63be15d

Browse files
john-sharratttheduke
authored andcommitted
Fixed another issue on the javascript compilation
1 parent 674f0d0 commit 63be15d

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

lib/vm/src/mmap.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Mmap {
6767
pub fn accessible_reserved(
6868
mut accessible_size: usize,
6969
mapping_size: usize,
70-
backing_file: Option<std::fs::File>,
70+
mut backing_file: Option<std::fs::File>,
7171
memory_type: MmapType,
7272
) -> Result<Self, String> {
7373
use std::os::fd::IntoRawFd;
@@ -76,14 +76,27 @@ impl Mmap {
7676
assert_le!(accessible_size, mapping_size);
7777
assert_eq!(mapping_size & (page_size - 1), 0);
7878
assert_eq!(accessible_size & (page_size - 1), 0);
79-
let memory_fd = backing_file.map_or(-1, |fd| fd.into_raw_fd());
8079

8180
// Mmap may return EINVAL if the size is zero, so just
8281
// special-case that.
8382
if mapping_size == 0 {
8483
return Ok(Self::new());
8584
}
8685

86+
// If there is a backing file, reise the file so that its at least
87+
// `mapping_size` bytes.
88+
if let Some(backing_file) = &mut backing_file {
89+
let len = backing_file.metadata().map_err(|e| e.to_string())?.len() as usize;
90+
if len < mapping_size {
91+
backing_file
92+
.set_len(mapping_size as u64)
93+
.map_err(|e| e.to_string())?;
94+
}
95+
accessible_size = accessible_size.max(len).min(mapping_size);
96+
}
97+
98+
let memory_fd = backing_file.map_or(-1, |fd| fd.into_raw_fd());
99+
87100
// Compute the flags
88101
let mut flags = match memory_fd {
89102
fd if fd < 0 => libc::MAP_ANON,
@@ -94,18 +107,6 @@ impl Mmap {
94107
MmapType::Shared => libc::MAP_SHARED,
95108
};
96109

97-
// Resize the file so that its size is at least `mapping_size`.
98-
if memory_fd != -1 {
99-
let len = unsafe { libc::lseek(memory_fd, 0, libc::SEEK_END) };
100-
if len < mapping_size as i64 {
101-
let r = unsafe { libc::ftruncate64(memory_fd, mapping_size as libc::off64_t) };
102-
if r != 0 {
103-
return Err(io::Error::last_os_error().to_string());
104-
}
105-
}
106-
accessible_size = accessible_size.max(len as usize).min(mapping_size);
107-
}
108-
109110
Ok(if accessible_size == mapping_size {
110111
// Allocate a single read-write region at once.
111112
let ptr = unsafe {

0 commit comments

Comments
 (0)