mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 13:18:20 +00:00
Implemented functionality needed for WASIX and Networking within Web Assembly
- Introduced the virtual BUS interface used for RPC between web assembly apps - Introduced the virtual networking interface used to implement networking for web assembly apps - Implemented a local implementation of the virtual networking (available behind the feature toggle 'host-net' on the 'wasi' package) - Fixed up some of the examples from the wasmer3 branch - Refactored the WASI implementations so they support wasm64-wasi - WASIX is behind its own namespaces for both 32bit and 64bit implementations - Fixed the wasi_pipes unit test which was using internals that are no longer exposed - instead made the pipes clonable
This commit is contained in:
committed by
Manos Pitsidianakis
parent
7c532813e7
commit
62de9c5aad
@@ -10,7 +10,7 @@ use std::{
|
||||
string::FromUtf8Error,
|
||||
};
|
||||
use thiserror::Error;
|
||||
use wasmer_types::ValueType;
|
||||
use wasmer_types::{MemorySize, ValueType};
|
||||
|
||||
/// Error for invalid [`Memory`] access.
|
||||
#[derive(Clone, Copy, Debug, Error)]
|
||||
@@ -85,6 +85,13 @@ impl<'a, T: ValueType> WasmRef<'a, T> {
|
||||
WasmPtr::new(self.offset)
|
||||
}
|
||||
|
||||
/// Get a `WasmPtr` fror this `WasmRef`.
|
||||
#[inline]
|
||||
pub fn as_ptr<M: MemorySize>(self) -> WasmPtr<T, M> {
|
||||
let offset: M::Offset = self.offset.try_into().map_err(|_| "invalid offset into memory").unwrap();
|
||||
WasmPtr::<T, M>::new(offset)
|
||||
}
|
||||
|
||||
/// Get a reference to the Wasm memory backing this reference.
|
||||
#[inline]
|
||||
pub fn memory(self) -> &'a Memory {
|
||||
|
||||
@@ -4,53 +4,11 @@ use std::convert::TryFrom;
|
||||
use std::{fmt, marker::PhantomData, mem};
|
||||
use wasmer_types::{NativeWasmType, ValueType};
|
||||
|
||||
/// Trait for the `Memory32` and `Memory64` marker types.
|
||||
///
|
||||
/// This allows code to be generic over 32-bit and 64-bit memories.
|
||||
pub unsafe trait MemorySize {
|
||||
/// Type used to represent an offset into a memory. This is `u32` or `u64`.
|
||||
type Offset: Copy + Into<u64> + TryFrom<u64>;
|
||||
pub use wasmer_types::MemorySize;
|
||||
|
||||
/// Type used to pass this value as an argument or return value for a Wasm function.
|
||||
type Native: NativeWasmType;
|
||||
pub use wasmer_types::Memory32;
|
||||
|
||||
/// Zero value used for `WasmPtr::is_null`.
|
||||
const ZERO: Self::Offset;
|
||||
|
||||
/// Convert an `Offset` to a `Native`.
|
||||
fn offset_to_native(offset: Self::Offset) -> Self::Native;
|
||||
|
||||
/// Convert a `Native` to an `Offset`.
|
||||
fn native_to_offset(native: Self::Native) -> Self::Offset;
|
||||
}
|
||||
|
||||
/// Marker trait for 32-bit memories.
|
||||
pub struct Memory32;
|
||||
unsafe impl MemorySize for Memory32 {
|
||||
type Offset = u32;
|
||||
type Native = i32;
|
||||
const ZERO: Self::Offset = 0;
|
||||
fn offset_to_native(offset: Self::Offset) -> Self::Native {
|
||||
offset as Self::Native
|
||||
}
|
||||
fn native_to_offset(native: Self::Native) -> Self::Offset {
|
||||
native as Self::Offset
|
||||
}
|
||||
}
|
||||
|
||||
/// Marker trait for 64-bit memories.
|
||||
pub struct Memory64;
|
||||
unsafe impl MemorySize for Memory64 {
|
||||
type Offset = u64;
|
||||
type Native = i64;
|
||||
const ZERO: Self::Offset = 0;
|
||||
fn offset_to_native(offset: Self::Offset) -> Self::Native {
|
||||
offset as Self::Native
|
||||
}
|
||||
fn native_to_offset(native: Self::Native) -> Self::Offset {
|
||||
native as Self::Offset
|
||||
}
|
||||
}
|
||||
pub use wasmer_types::Memory64;
|
||||
|
||||
/// Alias for `WasmPtr<T, Memory64>.
|
||||
pub type WasmPtr64<T> = WasmPtr<T, Memory64>;
|
||||
|
||||
Reference in New Issue
Block a user