Update WASI to cap-std 0.25 and windows-sys. (#4302)
This updates to rustix 0.35.6, and updates wasi-common to use cap-std 0.25 and windows-sys (instead of winapi). Changes include: - Better error code mappings on Windows. - Fixes undefined references to `utimensat` on Darwin. - Fixes undefined references to `preadv64` and `pwritev64` on Android. - Updates to io-lifetimes 0.7, which matches the io_safety API in Rust. - y2038 bug fixes for 32-bit platforms
This commit is contained in:
@@ -333,7 +333,7 @@ impl MemoryImageSlot {
|
||||
// mprotect the relevant region.
|
||||
self.set_protection(
|
||||
self.cur_size..size_bytes,
|
||||
rustix::io::MprotectFlags::READ | rustix::io::MprotectFlags::WRITE,
|
||||
rustix::mm::MprotectFlags::READ | rustix::mm::MprotectFlags::WRITE,
|
||||
)?;
|
||||
self.cur_size = size_bytes;
|
||||
|
||||
@@ -386,7 +386,7 @@ impl MemoryImageSlot {
|
||||
.map_err(|e| InstantiationError::Resource(e.into()))?;
|
||||
self.set_protection(
|
||||
0..initial_size_bytes,
|
||||
rustix::io::MprotectFlags::READ | rustix::io::MprotectFlags::WRITE,
|
||||
rustix::mm::MprotectFlags::READ | rustix::mm::MprotectFlags::WRITE,
|
||||
)
|
||||
.map_err(|e| InstantiationError::Resource(e.into()))?;
|
||||
} else if initial_size_bytes < self.initial_size {
|
||||
@@ -409,7 +409,7 @@ impl MemoryImageSlot {
|
||||
// mprotect(NONE) the zone from the first to the second.
|
||||
self.set_protection(
|
||||
initial_size_bytes..self.initial_size,
|
||||
rustix::io::MprotectFlags::empty(),
|
||||
rustix::mm::MprotectFlags::empty(),
|
||||
)
|
||||
.map_err(|e| InstantiationError::Resource(e.into()))?;
|
||||
} else if initial_size_bytes > self.initial_size {
|
||||
@@ -420,7 +420,7 @@ impl MemoryImageSlot {
|
||||
// made visible as zeros.
|
||||
self.set_protection(
|
||||
self.initial_size..initial_size_bytes,
|
||||
rustix::io::MprotectFlags::READ | rustix::io::MprotectFlags::WRITE,
|
||||
rustix::mm::MprotectFlags::READ | rustix::mm::MprotectFlags::WRITE,
|
||||
)
|
||||
.map_err(|e| InstantiationError::Resource(e.into()))?;
|
||||
} else {
|
||||
@@ -444,11 +444,11 @@ impl MemoryImageSlot {
|
||||
);
|
||||
if image.len > 0 {
|
||||
unsafe {
|
||||
let ptr = rustix::io::mmap(
|
||||
let ptr = rustix::mm::mmap(
|
||||
(self.base + image.linear_memory_offset) as *mut c_void,
|
||||
image.len,
|
||||
rustix::io::ProtFlags::READ | rustix::io::ProtFlags::WRITE,
|
||||
rustix::io::MapFlags::PRIVATE | rustix::io::MapFlags::FIXED,
|
||||
rustix::mm::ProtFlags::READ | rustix::mm::ProtFlags::WRITE,
|
||||
rustix::mm::MapFlags::PRIVATE | rustix::mm::MapFlags::FIXED,
|
||||
image.fd.as_file(),
|
||||
image.fd_offset,
|
||||
)
|
||||
@@ -477,10 +477,10 @@ impl MemoryImageSlot {
|
||||
// semantics we want for reuse between instances, so it's all we
|
||||
// need to do.
|
||||
unsafe {
|
||||
rustix::io::madvise(
|
||||
rustix::mm::madvise(
|
||||
self.base as *mut c_void,
|
||||
self.cur_size,
|
||||
rustix::io::Advice::LinuxDontNeed,
|
||||
rustix::mm::Advice::LinuxDontNeed,
|
||||
)?;
|
||||
}
|
||||
} else {
|
||||
@@ -499,20 +499,20 @@ impl MemoryImageSlot {
|
||||
// mprotect the initial heap region beyond the initial heap size back to PROT_NONE.
|
||||
self.set_protection(
|
||||
self.initial_size..self.cur_size,
|
||||
rustix::io::MprotectFlags::empty(),
|
||||
rustix::mm::MprotectFlags::empty(),
|
||||
)?;
|
||||
self.cur_size = self.initial_size;
|
||||
self.dirty = false;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_protection(&self, range: Range<usize>, flags: rustix::io::MprotectFlags) -> Result<()> {
|
||||
fn set_protection(&self, range: Range<usize>, flags: rustix::mm::MprotectFlags) -> Result<()> {
|
||||
assert!(range.start <= range.end);
|
||||
assert!(range.end <= self.static_size);
|
||||
let mprotect_start = self.base.checked_add(range.start).unwrap();
|
||||
if range.len() > 0 {
|
||||
unsafe {
|
||||
rustix::io::mprotect(mprotect_start as *mut _, range.len(), flags)?;
|
||||
rustix::mm::mprotect(mprotect_start as *mut _, range.len(), flags)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -532,11 +532,11 @@ impl MemoryImageSlot {
|
||||
/// inaccessible. Used both during instantiate and during drop.
|
||||
fn reset_with_anon_memory(&self) -> Result<()> {
|
||||
unsafe {
|
||||
let ptr = rustix::io::mmap_anonymous(
|
||||
let ptr = rustix::mm::mmap_anonymous(
|
||||
self.base as *mut c_void,
|
||||
self.static_size,
|
||||
rustix::io::ProtFlags::empty(),
|
||||
rustix::io::MapFlags::PRIVATE | rustix::io::MapFlags::FIXED,
|
||||
rustix::mm::ProtFlags::empty(),
|
||||
rustix::mm::MapFlags::PRIVATE | rustix::mm::MapFlags::FIXED,
|
||||
)?;
|
||||
assert_eq!(ptr as usize, self.base);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ fn decommit(addr: *mut u8, len: usize, protect: bool) -> Result<()> {
|
||||
}
|
||||
|
||||
// On Linux, this is enough to cause the kernel to initialize the pages to 0 on next access
|
||||
rustix::io::madvise(addr as _, len, rustix::io::Advice::LinuxDontNeed)
|
||||
rustix::mm::madvise(addr as _, len, rustix::mm::Advice::LinuxDontNeed)
|
||||
.context("madvise failed to decommit: {}")?;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,15 @@ fn decommit(addr: *mut u8, len: usize, protect: bool) -> Result<()> {
|
||||
// The new mapping will be to the CoW zero page, so this effectively
|
||||
// zeroes the pages.
|
||||
unsafe {
|
||||
rustix::io::mmap_anonymous(
|
||||
rustix::mm::mmap_anonymous(
|
||||
addr as _,
|
||||
len,
|
||||
if protect {
|
||||
rustix::io::ProtFlags::empty()
|
||||
rustix::mm::ProtFlags::empty()
|
||||
} else {
|
||||
rustix::io::ProtFlags::READ | rustix::io::ProtFlags::WRITE
|
||||
rustix::mm::ProtFlags::READ | rustix::mm::ProtFlags::WRITE
|
||||
},
|
||||
rustix::io::MapFlags::PRIVATE | rustix::io::MapFlags::FIXED,
|
||||
rustix::mm::MapFlags::PRIVATE | rustix::mm::MapFlags::FIXED,
|
||||
)
|
||||
.context("mmap failed to remap pages: {}")?;
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ impl Mmap {
|
||||
.len();
|
||||
let len = usize::try_from(len).map_err(|_| anyhow!("file too large to map"))?;
|
||||
let ptr = unsafe {
|
||||
rustix::io::mmap(
|
||||
rustix::mm::mmap(
|
||||
ptr::null_mut(),
|
||||
len,
|
||||
rustix::io::ProtFlags::READ,
|
||||
rustix::io::MapFlags::PRIVATE,
|
||||
rustix::mm::ProtFlags::READ,
|
||||
rustix::mm::MapFlags::PRIVATE,
|
||||
&file,
|
||||
0,
|
||||
)
|
||||
@@ -171,11 +171,11 @@ impl Mmap {
|
||||
Ok(if accessible_size == mapping_size {
|
||||
// Allocate a single read-write region at once.
|
||||
let ptr = unsafe {
|
||||
rustix::io::mmap_anonymous(
|
||||
rustix::mm::mmap_anonymous(
|
||||
ptr::null_mut(),
|
||||
mapping_size,
|
||||
rustix::io::ProtFlags::READ | rustix::io::ProtFlags::WRITE,
|
||||
rustix::io::MapFlags::PRIVATE,
|
||||
rustix::mm::ProtFlags::READ | rustix::mm::ProtFlags::WRITE,
|
||||
rustix::mm::MapFlags::PRIVATE,
|
||||
)
|
||||
.context(format!("mmap failed to allocate {:#x} bytes", mapping_size))?
|
||||
};
|
||||
@@ -188,11 +188,11 @@ impl Mmap {
|
||||
} else {
|
||||
// Reserve the mapping size.
|
||||
let ptr = unsafe {
|
||||
rustix::io::mmap_anonymous(
|
||||
rustix::mm::mmap_anonymous(
|
||||
ptr::null_mut(),
|
||||
mapping_size,
|
||||
rustix::io::ProtFlags::empty(),
|
||||
rustix::io::MapFlags::PRIVATE,
|
||||
rustix::mm::ProtFlags::empty(),
|
||||
rustix::mm::MapFlags::PRIVATE,
|
||||
)
|
||||
.context(format!("mmap failed to allocate {:#x} bytes", mapping_size))?
|
||||
};
|
||||
@@ -430,7 +430,7 @@ impl Drop for Mmap {
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn drop(&mut self) {
|
||||
if self.len != 0 {
|
||||
unsafe { rustix::io::munmap(self.ptr as *mut std::ffi::c_void, self.len) }
|
||||
unsafe { rustix::mm::munmap(self.ptr as *mut std::ffi::c_void, self.len) }
|
||||
.expect("munmap failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,21 +295,21 @@ pub fn lazy_per_thread_init() -> Result<(), Box<Trap>> {
|
||||
let guard_size = page_size;
|
||||
let alloc_size = guard_size + MIN_STACK_SIZE;
|
||||
|
||||
let ptr = rustix::io::mmap_anonymous(
|
||||
let ptr = rustix::mm::mmap_anonymous(
|
||||
null_mut(),
|
||||
alloc_size,
|
||||
rustix::io::ProtFlags::empty(),
|
||||
rustix::io::MapFlags::PRIVATE,
|
||||
rustix::mm::ProtFlags::empty(),
|
||||
rustix::mm::MapFlags::PRIVATE,
|
||||
)
|
||||
.map_err(|_| Box::new(Trap::oom()))?;
|
||||
|
||||
// Prepare the stack with readable/writable memory and then register it
|
||||
// with `sigaltstack`.
|
||||
let stack_ptr = (ptr as usize + guard_size) as *mut std::ffi::c_void;
|
||||
rustix::io::mprotect(
|
||||
rustix::mm::mprotect(
|
||||
stack_ptr,
|
||||
MIN_STACK_SIZE,
|
||||
rustix::io::MprotectFlags::READ | rustix::io::MprotectFlags::WRITE,
|
||||
rustix::mm::MprotectFlags::READ | rustix::mm::MprotectFlags::WRITE,
|
||||
)
|
||||
.expect("mprotect to configure memory for sigaltstack failed");
|
||||
let new_stack = libc::stack_t {
|
||||
@@ -335,7 +335,7 @@ pub fn lazy_per_thread_init() -> Result<(), Box<Trap>> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
// Deallocate the stack memory.
|
||||
let r = rustix::io::munmap(self.mmap_ptr, self.mmap_size);
|
||||
let r = rustix::mm::munmap(self.mmap_ptr, self.mmap_size);
|
||||
debug_assert!(r.is_ok(), "munmap failed during thread shutdown");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user