Support big-endian hosts with GuestType (#2383)
The GuestType trait is used to access data elements in guest memory. According to the WebAssembly spec, those are always stored in little-endian byte order, even on big-endian hosts. Accessing such elements on big-endian hosts therefore requires byte swapping. Fixed by adding from_le_bytes / to_le_bytes.
This commit is contained in:
@@ -88,7 +88,7 @@ macro_rules! primitives {
|
|||||||
if ptr.mem().is_borrowed(region) {
|
if ptr.mem().is_borrowed(region) {
|
||||||
return Err(GuestError::PtrBorrowed(region));
|
return Err(GuestError::PtrBorrowed(region));
|
||||||
}
|
}
|
||||||
Ok(unsafe { *host_ptr.cast::<Self>() })
|
Ok(unsafe { <$i>::from_le_bytes(*host_ptr.cast::<[u8; mem::size_of::<Self>()]>()) })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -108,7 +108,7 @@ macro_rules! primitives {
|
|||||||
return Err(GuestError::PtrBorrowed(region));
|
return Err(GuestError::PtrBorrowed(region));
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
*host_ptr.cast::<Self>() = val;
|
*host_ptr.cast::<[u8; mem::size_of::<Self>()]>() = <$i>::to_le_bytes(val);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user