mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-12 13:28:49 +00:00
Improvements to the tracing and logging in wasmer
- Now using the fmt subscriber for improved formatting - Using spans on all syscalls - Added recorded fields on the spans instead trace and debug macros - Adding timing on all syscall
This commit is contained in:
committed by
Christoph Herzog
parent
6d33d57e6e
commit
6dde2831a0
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -4890,6 +4890,8 @@ dependencies = [
|
|||||||
"time 0.3.20",
|
"time 0.3.20",
|
||||||
"tldextract",
|
"tldextract",
|
||||||
"toml",
|
"toml",
|
||||||
|
"tracing",
|
||||||
|
"tracing-subscriber 0.3.16",
|
||||||
"unix_mode",
|
"unix_mode",
|
||||||
"url",
|
"url",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::{any::Any, marker::PhantomData};
|
use std::{any::Any, fmt::Debug, marker::PhantomData};
|
||||||
|
|
||||||
use crate::vm::VMFunctionEnvironment;
|
use crate::vm::VMFunctionEnvironment;
|
||||||
|
|
||||||
@@ -102,6 +102,12 @@ pub struct FunctionEnvMut<'a, T: 'a> {
|
|||||||
pub(crate) func_env: FunctionEnv<T>,
|
pub(crate) func_env: FunctionEnv<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, T> Debug for FunctionEnvMut<'a, T> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "env_mut")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Send + 'static> FunctionEnvMut<'_, T> {
|
impl<T: Send + 'static> FunctionEnvMut<'_, T> {
|
||||||
/// Returns a reference to the host state in this function environement.
|
/// Returns a reference to the host state in this function environement.
|
||||||
pub fn data(&self) -> &T {
|
pub fn data(&self) -> &T {
|
||||||
|
|||||||
@@ -278,11 +278,6 @@ impl<T: ValueType, M: MemorySize> Eq for WasmPtr<T, M> {}
|
|||||||
|
|
||||||
impl<T: ValueType, M: MemorySize> fmt::Debug for WasmPtr<T, M> {
|
impl<T: ValueType, M: MemorySize> fmt::Debug for WasmPtr<T, M> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(
|
write!(f, "{}(@{})", std::any::type_name::<T>(), self.offset.into())
|
||||||
f,
|
|
||||||
"WasmPtr(offset: {}, pointer: {:#x})",
|
|
||||||
self.offset.into(),
|
|
||||||
self.offset.into()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ pathdiff = "0.2.1"
|
|||||||
sha2 = "0.10.6"
|
sha2 = "0.10.6"
|
||||||
object = "0.30.0"
|
object = "0.30.0"
|
||||||
wasm-coredump-builder = { version = "0.1.11" }
|
wasm-coredump-builder = { version = "0.1.11" }
|
||||||
|
tracing = { version = "0.1", optional = true }
|
||||||
|
tracing-subscriber = { version = "0.3", features = [ "env-filter", "fmt" ], optional = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
chrono = { version = "^0.4", default-features = false, features = [ "std", "clock" ] }
|
chrono = { version = "^0.4", default-features = false, features = [ "std", "clock" ] }
|
||||||
@@ -111,6 +113,7 @@ default = [
|
|||||||
"wasmer-artifact-create",
|
"wasmer-artifact-create",
|
||||||
"static-artifact-create",
|
"static-artifact-create",
|
||||||
"webc_runner",
|
"webc_runner",
|
||||||
|
"tracing"
|
||||||
]
|
]
|
||||||
cache = ["wasmer-cache"]
|
cache = ["wasmer-cache"]
|
||||||
cache-blake3-pure = ["wasmer-cache/blake3-pure"]
|
cache-blake3-pure = ["wasmer-cache/blake3-pure"]
|
||||||
@@ -167,6 +170,7 @@ debug = ["fern", "wasmer-wasi/logging"]
|
|||||||
disable-all-logging = ["wasmer-wasi/disable-all-logging", "log/release_max_level_off"]
|
disable-all-logging = ["wasmer-wasi/disable-all-logging", "log/release_max_level_off"]
|
||||||
headless = []
|
headless = []
|
||||||
headless-minimal = ["headless", "disable-all-logging", "wasi"]
|
headless-minimal = ["headless", "disable-all-logging", "wasi"]
|
||||||
|
tracing = [ "dep:tracing", "tracing-subscriber" ]
|
||||||
|
|
||||||
# Optional
|
# Optional
|
||||||
enable-serde = [
|
enable-serde = [
|
||||||
|
|||||||
@@ -1,4 +1,36 @@
|
|||||||
//! Logging functions for the debug feature.
|
//! Logging functions for the debug feature.
|
||||||
|
|
||||||
|
/// Subroutine to instantiate the loggers
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
pub fn set_up_logging(verbose: u8) -> Result<(), String> {
|
||||||
|
use tracing_subscriber::prelude::*;
|
||||||
|
use tracing_subscriber::{fmt, EnvFilter};
|
||||||
|
|
||||||
|
let fmt_layer = fmt::layer()
|
||||||
|
.with_target(false)
|
||||||
|
.with_span_events(fmt::format::FmtSpan::CLOSE)
|
||||||
|
.with_thread_ids(true)
|
||||||
|
.compact();
|
||||||
|
|
||||||
|
let filter_layer = EnvFilter::try_from_default_env()
|
||||||
|
.or_else(|_| match verbose {
|
||||||
|
1 => EnvFilter::try_new("debug"),
|
||||||
|
_ => EnvFilter::try_new("trace"),
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
tracing_subscriber::registry()
|
||||||
|
.with(filter_layer)
|
||||||
|
.with(fmt_layer)
|
||||||
|
.init();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Subroutine to instantiate the loggers
|
||||||
|
#[deprecated("please use the tracing feature instead")]
|
||||||
|
#[cfg(not(feature = "tracing"))]
|
||||||
|
pub fn set_up_logging(verbose: u8) -> Result<(), String> {
|
||||||
use crate::utils::wasmer_should_print_color;
|
use crate::utils::wasmer_should_print_color;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use fern::colors::{Color, ColoredLevelConfig};
|
use fern::colors::{Color, ColoredLevelConfig};
|
||||||
@@ -7,8 +39,6 @@ use std::time;
|
|||||||
/// The debug level
|
/// The debug level
|
||||||
pub type DebugLevel = log::LevelFilter;
|
pub type DebugLevel = log::LevelFilter;
|
||||||
|
|
||||||
/// Subroutine to instantiate the loggers
|
|
||||||
pub fn set_up_logging(verbose: u8) -> Result<(), String> {
|
|
||||||
let colors_line = ColoredLevelConfig::new()
|
let colors_line = ColoredLevelConfig::new()
|
||||||
.error(Color::Red)
|
.error(Color::Red)
|
||||||
.warn(Color::Yellow)
|
.warn(Color::Yellow)
|
||||||
|
|||||||
@@ -417,11 +417,7 @@ impl Errno {
|
|||||||
}
|
}
|
||||||
impl core::fmt::Debug for Errno {
|
impl core::fmt::Debug for Errno {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
f.debug_struct("Errno")
|
write!(f, "Errno::{}", &self.name())
|
||||||
.field("code", &(*self as i32))
|
|
||||||
.field("name", &self.name())
|
|
||||||
.field("message", &self.message())
|
|
||||||
.finish()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl core::fmt::Display for Errno {
|
impl core::fmt::Display for Errno {
|
||||||
@@ -528,11 +524,7 @@ impl BusErrno {
|
|||||||
}
|
}
|
||||||
impl core::fmt::Debug for BusErrno {
|
impl core::fmt::Debug for BusErrno {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
f.debug_struct("BusErrno")
|
write!(f, "BusErrno::{}", &self.name())
|
||||||
.field("code", &(*self as i32))
|
|
||||||
.field("name", &self.name())
|
|
||||||
.field("message", &self.message())
|
|
||||||
.finish()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl core::fmt::Display for BusErrno {
|
impl core::fmt::Display for BusErrno {
|
||||||
@@ -2166,6 +2158,14 @@ impl core::fmt::Debug for Bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl core::fmt::Display for Bool {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
match self {
|
||||||
|
Bool::False => write!(f, "false"),
|
||||||
|
Bool::True => write!(f, "true"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct OptionTimestamp {
|
pub struct OptionTimestamp {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
tracing = "0.1"
|
tracing = { version = "0.1" }
|
||||||
getrandom = "0.2"
|
getrandom = "0.2"
|
||||||
wasmer-wasi-types = { path = "../wasi-types", version = "=3.2.0-alpha.1" }
|
wasmer-wasi-types = { path = "../wasi-types", version = "=3.2.0-alpha.1" }
|
||||||
wasmer-types = { path = "../types", version = "=3.2.0-alpha.1", default-features = false }
|
wasmer-types = { path = "../types", version = "=3.2.0-alpha.1", default-features = false }
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Represents the ID of a sub-process
|
/// Represents the ID of a sub-process
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct WasiProcessId(u32);
|
pub struct WasiProcessId(u32);
|
||||||
|
|
||||||
impl WasiProcessId {
|
impl WasiProcessId {
|
||||||
@@ -67,6 +67,12 @@ impl std::fmt::Display for WasiProcessId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Debug for WasiProcessId {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a process running within the compute state
|
/// Represents a process running within the compute state
|
||||||
// TODO: fields should be private and only accessed via methods.
|
// TODO: fields should be private and only accessed via methods.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Represents the ID of a WASI thread
|
/// Represents the ID of a WASI thread
|
||||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct WasiThreadId(u32);
|
pub struct WasiThreadId(u32);
|
||||||
|
|
||||||
impl WasiThreadId {
|
impl WasiThreadId {
|
||||||
@@ -67,6 +67,12 @@ impl std::fmt::Display for WasiThreadId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Debug for WasiThreadId {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents a linked list of stack snapshots
|
/// Represents a linked list of stack snapshots
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct ThreadSnapshot {
|
struct ThreadSnapshot {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use tracing::{field, instrument, trace_span};
|
||||||
use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr};
|
use wasmer::{AsStoreMut, FunctionEnvMut, WasmPtr};
|
||||||
use wasmer_wasi_types::wasi::{
|
use wasmer_wasi_types::wasi::{
|
||||||
Errno, Event, EventFdReadwrite, Eventrwflags, Eventtype, Fd, Filesize, Filestat, Filetype,
|
Errno, Event, EventFdReadwrite, Eventrwflags, Eventtype, Fd, Filesize, Filestat, Filetype,
|
||||||
@@ -20,6 +21,7 @@ use crate::{
|
|||||||
/// WARNING: this function involves saving, clobbering, and restoring unrelated
|
/// WARNING: this function involves saving, clobbering, and restoring unrelated
|
||||||
/// Wasm memory. If the memory clobbered by the current syscall is also used by
|
/// Wasm memory. If the memory clobbered by the current syscall is also used by
|
||||||
/// that syscall, then it may break.
|
/// that syscall, then it may break.
|
||||||
|
#[instrument(level = "debug", skip_all, ret)]
|
||||||
pub fn fd_filestat_get(
|
pub fn fd_filestat_get(
|
||||||
mut ctx: FunctionEnvMut<WasiEnv>,
|
mut ctx: FunctionEnvMut<WasiEnv>,
|
||||||
fd: Fd,
|
fd: Fd,
|
||||||
@@ -72,6 +74,7 @@ pub fn fd_filestat_get(
|
|||||||
|
|
||||||
/// Wrapper around `syscalls::path_filestat_get` with extra logic to handle the size
|
/// Wrapper around `syscalls::path_filestat_get` with extra logic to handle the size
|
||||||
/// difference of `wasi_filestat_t`
|
/// difference of `wasi_filestat_t`
|
||||||
|
#[instrument(level = "debug", skip_all, ret)]
|
||||||
pub fn path_filestat_get(
|
pub fn path_filestat_get(
|
||||||
mut ctx: FunctionEnvMut<WasiEnv>,
|
mut ctx: FunctionEnvMut<WasiEnv>,
|
||||||
fd: Fd,
|
fd: Fd,
|
||||||
@@ -115,6 +118,7 @@ pub fn path_filestat_get(
|
|||||||
|
|
||||||
/// Wrapper around `syscalls::fd_seek` with extra logic to remap the values
|
/// Wrapper around `syscalls::fd_seek` with extra logic to remap the values
|
||||||
/// of `Whence`
|
/// of `Whence`
|
||||||
|
#[instrument(level = "debug", skip_all, ret)]
|
||||||
pub fn fd_seek(
|
pub fn fd_seek(
|
||||||
ctx: FunctionEnvMut<WasiEnv>,
|
ctx: FunctionEnvMut<WasiEnv>,
|
||||||
fd: Fd,
|
fd: Fd,
|
||||||
@@ -132,6 +136,7 @@ pub fn fd_seek(
|
|||||||
|
|
||||||
/// Wrapper around `syscalls::poll_oneoff` with extra logic to add the removed
|
/// Wrapper around `syscalls::poll_oneoff` with extra logic to add the removed
|
||||||
/// userdata field back
|
/// userdata field back
|
||||||
|
#[instrument(level = "trace", skip_all, fields(timeout_ns = field::Empty, fd_guards = field::Empty, seen = field::Empty), ret, err)]
|
||||||
pub fn poll_oneoff(
|
pub fn poll_oneoff(
|
||||||
mut ctx: FunctionEnvMut<WasiEnv>,
|
mut ctx: FunctionEnvMut<WasiEnv>,
|
||||||
in_: WasmPtr<Snapshot0Subscription, Memory32>,
|
in_: WasmPtr<Snapshot0Subscription, Memory32>,
|
||||||
@@ -157,12 +162,7 @@ pub fn poll_oneoff(
|
|||||||
let triggered_events = match triggered_events {
|
let triggered_events = match triggered_events {
|
||||||
Ok(a) => a,
|
Ok(a) => a,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
tracing::trace!(
|
tracing::trace!(err = err as u16);
|
||||||
"wasi[{}:{}]::poll_oneoff0 errno={}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
err
|
|
||||||
);
|
|
||||||
return Ok(err);
|
return Ok(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ pub mod wasix;
|
|||||||
|
|
||||||
use bytes::{Buf, BufMut};
|
use bytes::{Buf, BufMut};
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
|
use tracing::instrument;
|
||||||
pub use wasi::*;
|
pub use wasi::*;
|
||||||
pub use wasix::*;
|
pub use wasix::*;
|
||||||
|
|
||||||
@@ -664,7 +665,6 @@ pub(crate) fn write_buffer_array<M: MemorySize>(
|
|||||||
|
|
||||||
let mut current_buffer_offset = 0usize;
|
let mut current_buffer_offset = 0usize;
|
||||||
for ((i, sub_buffer), ptr) in from.iter().enumerate().zip(ptrs.iter()) {
|
for ((i, sub_buffer), ptr) in from.iter().enumerate().zip(ptrs.iter()) {
|
||||||
trace!("ptr: {:?}, subbuffer: {:?}", ptr, sub_buffer);
|
|
||||||
let mut buf_offset = buffer.offset();
|
let mut buf_offset = buffer.offset();
|
||||||
buf_offset += wasi_try!(to_offset::<M>(current_buffer_offset));
|
buf_offset += wasi_try!(to_offset::<M>(current_buffer_offset));
|
||||||
let new_ptr = WasmPtr::new(buf_offset);
|
let new_ptr = WasmPtr::new(buf_offset);
|
||||||
@@ -935,6 +935,7 @@ where
|
|||||||
Ok(Errno::Success)
|
Ok(Errno::Success)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip_all, fields(memory_stack_len = memory_stack.len(), rewind_stack_len = rewind_stack.len(), store_data_len = store_data.len()))]
|
||||||
#[must_use = "the action must be passed to the call loop"]
|
#[must_use = "the action must be passed to the call loop"]
|
||||||
pub(crate) fn rewind<M: MemorySize>(
|
pub(crate) fn rewind<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
@@ -942,15 +943,6 @@ pub(crate) fn rewind<M: MemorySize>(
|
|||||||
rewind_stack: Bytes,
|
rewind_stack: Bytes,
|
||||||
store_data: Bytes,
|
store_data: Bytes,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::rewinding (memory_stack_size={}, rewind_size={}, store_data={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
memory_stack.len(),
|
|
||||||
rewind_stack.len(),
|
|
||||||
store_data.len()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Store the memory stack so that it can be restored later
|
// Store the memory stack so that it can be restored later
|
||||||
super::REWIND.with(|cell| cell.replace(Some(memory_stack)));
|
super::REWIND.with(|cell| cell.replace(Some(memory_stack)));
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ use crate::syscalls::*;
|
|||||||
/// - `char *argv_buf`
|
/// - `char *argv_buf`
|
||||||
/// A pointer to a buffer to write the argument string data.
|
/// A pointer to a buffer to write the argument string data.
|
||||||
///
|
///
|
||||||
|
#[instrument(level = "debug", skip_all, ret)]
|
||||||
pub fn args_get<M: MemorySize>(
|
pub fn args_get<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
argv: WasmPtr<WasmPtr<u8, M>, M>,
|
argv: WasmPtr<WasmPtr<u8, M>, M>,
|
||||||
argv_buf: WasmPtr<u8, M>,
|
argv_buf: WasmPtr<u8, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!("wasi[{}:{}]::args_get", ctx.data().pid(), ctx.data().tid());
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ pub fn args_get<M: MemorySize>(
|
|||||||
let result = write_buffer_array(&memory, &args, argv, argv_buf);
|
let result = write_buffer_array(&memory, &args, argv, argv_buf);
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"=> args:\n{}",
|
"args:\n{}",
|
||||||
state
|
state
|
||||||
.args
|
.args
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -8,16 +8,12 @@ use crate::syscalls::*;
|
|||||||
/// The number of arguments.
|
/// The number of arguments.
|
||||||
/// - `size_t *argv_buf_size`
|
/// - `size_t *argv_buf_size`
|
||||||
/// The size of the argument string data.
|
/// The size of the argument string data.
|
||||||
|
#[instrument(level = "debug", skip_all, ret)]
|
||||||
pub fn args_sizes_get<M: MemorySize>(
|
pub fn args_sizes_get<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
argc: WasmPtr<M::Offset, M>,
|
argc: WasmPtr<M::Offset, M>,
|
||||||
argv_buf_size: WasmPtr<M::Offset, M>,
|
argv_buf_size: WasmPtr<M::Offset, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::args_sizes_get",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
|
|
||||||
@@ -31,7 +27,7 @@ pub fn args_sizes_get<M: MemorySize>(
|
|||||||
wasi_try_mem!(argc.write(argc_val));
|
wasi_try_mem!(argc.write(argc_val));
|
||||||
wasi_try_mem!(argv_buf_size.write(argv_buf_size_val));
|
wasi_try_mem!(argv_buf_size.write(argv_buf_size_val));
|
||||||
|
|
||||||
debug!("=> argc={}, argv_buf_size={}", argc_val, argv_buf_size_val);
|
debug!("argc={}, argv_buf_size={}", argc_val, argv_buf_size_val);
|
||||||
|
|
||||||
Errno::Success
|
Errno::Success
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,16 +9,12 @@ use crate::syscalls::*;
|
|||||||
/// Output:
|
/// Output:
|
||||||
/// - `Timestamp *resolution`
|
/// - `Timestamp *resolution`
|
||||||
/// The resolution of the clock in nanoseconds
|
/// The resolution of the clock in nanoseconds
|
||||||
|
#[instrument(level = "trace", skip_all, ret)]
|
||||||
pub fn clock_res_get<M: MemorySize>(
|
pub fn clock_res_get<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
clock_id: Snapshot0Clockid,
|
clock_id: Snapshot0Clockid,
|
||||||
resolution: WasmPtr<Timestamp, M>,
|
resolution: WasmPtr<Timestamp, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::clock_res_get",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
|
|||||||
@@ -11,18 +11,13 @@ use crate::syscalls::*;
|
|||||||
/// Output:
|
/// Output:
|
||||||
/// - `Timestamp *time`
|
/// - `Timestamp *time`
|
||||||
/// The value of the clock in nanoseconds
|
/// The value of the clock in nanoseconds
|
||||||
|
#[instrument(level = "trace", skip_all, fields(clock_id, precision), ret)]
|
||||||
pub fn clock_time_get<M: MemorySize>(
|
pub fn clock_time_get<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
clock_id: Snapshot0Clockid,
|
clock_id: Snapshot0Clockid,
|
||||||
precision: Timestamp,
|
precision: Timestamp,
|
||||||
time: WasmPtr<Timestamp, M>,
|
time: WasmPtr<Timestamp, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
/*
|
|
||||||
debug!(
|
|
||||||
"wasi::clock_time_get clock_id: {}, precision: {}",
|
|
||||||
clock_id as u8, precision
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
@@ -34,13 +29,5 @@ pub fn clock_time_get<M: MemorySize>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
wasi_try_mem!(time.write(&memory, t_out as Timestamp));
|
wasi_try_mem!(time.write(&memory, t_out as Timestamp));
|
||||||
|
|
||||||
/*
|
|
||||||
trace!(
|
|
||||||
"time: {} => {}",
|
|
||||||
wasi_try_mem!(time.deref(&memory).read()),
|
|
||||||
result
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
Errno::Success
|
Errno::Success
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,16 +8,12 @@ use crate::syscalls::*;
|
|||||||
/// The ID of the clock to query
|
/// The ID of the clock to query
|
||||||
/// - `Timestamp *time`
|
/// - `Timestamp *time`
|
||||||
/// The value of the clock in nanoseconds
|
/// The value of the clock in nanoseconds
|
||||||
|
#[instrument(level = "trace", skip_all, fields(clock_id, time), ret)]
|
||||||
pub fn clock_time_set<M: MemorySize>(
|
pub fn clock_time_set<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
clock_id: Snapshot0Clockid,
|
clock_id: Snapshot0Clockid,
|
||||||
time: Timestamp,
|
time: Timestamp,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
trace!(
|
|
||||||
"wasi::clock_time_set clock_id: {:?}, time: {}",
|
|
||||||
clock_id,
|
|
||||||
time
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
@@ -30,6 +26,5 @@ pub fn clock_time_set<M: MemorySize>(
|
|||||||
|
|
||||||
let mut guard = env.state.clock_offset.lock().unwrap();
|
let mut guard = env.state.clock_offset.lock().unwrap();
|
||||||
guard.insert(clock_id, t_offset);
|
guard.insert(clock_id, t_offset);
|
||||||
|
|
||||||
Errno::Success
|
Errno::Success
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,18 +9,14 @@ use crate::syscalls::*;
|
|||||||
/// A pointer to a buffer to write the environment variable pointers.
|
/// A pointer to a buffer to write the environment variable pointers.
|
||||||
/// - `char *environ_buf`
|
/// - `char *environ_buf`
|
||||||
/// A pointer to a buffer to write the environment variable string data.
|
/// A pointer to a buffer to write the environment variable string data.
|
||||||
|
#[instrument(level = "debug", skip_all, ret)]
|
||||||
pub fn environ_get<M: MemorySize>(
|
pub fn environ_get<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
environ: WasmPtr<WasmPtr<u8, M>, M>,
|
environ: WasmPtr<WasmPtr<u8, M>, M>,
|
||||||
environ_buf: WasmPtr<u8, M>,
|
environ_buf: WasmPtr<u8, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi::environ_get. Environ: {:?}, environ_buf: {:?}",
|
|
||||||
environ, environ_buf
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
trace!(" -> State envs: {:?}", state.envs);
|
|
||||||
|
|
||||||
write_buffer_array(&memory, &*state.envs, environ, environ_buf)
|
write_buffer_array(&memory, &*state.envs, environ, environ_buf)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,16 +8,12 @@ use crate::syscalls::*;
|
|||||||
/// The number of environment variables.
|
/// The number of environment variables.
|
||||||
/// - `size_t *environ_buf_size`
|
/// - `size_t *environ_buf_size`
|
||||||
/// The size of the environment variable string data.
|
/// The size of the environment variable string data.
|
||||||
|
#[instrument(level = "trace", skip_all, ret)]
|
||||||
pub fn environ_sizes_get<M: MemorySize>(
|
pub fn environ_sizes_get<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
environ_count: WasmPtr<M::Offset, M>,
|
environ_count: WasmPtr<M::Offset, M>,
|
||||||
environ_buf_size: WasmPtr<M::Offset, M>,
|
environ_buf_size: WasmPtr<M::Offset, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::environ_sizes_get",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
|
|
||||||
@@ -32,9 +28,8 @@ pub fn environ_sizes_get<M: MemorySize>(
|
|||||||
wasi_try_mem!(environ_buf_size.write(env_buf_size));
|
wasi_try_mem!(environ_buf_size.write(env_buf_size));
|
||||||
|
|
||||||
trace!(
|
trace!(
|
||||||
"env_var_count: {}, env_buf_size: {}",
|
%env_var_count,
|
||||||
env_var_count,
|
%env_buf_size
|
||||||
env_buf_size
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Errno::Success
|
Errno::Success
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use crate::syscalls::*;
|
|||||||
/// The length from the offset to which the advice applies
|
/// The length from the offset to which the advice applies
|
||||||
/// - `__wasi_advice_t advice`
|
/// - `__wasi_advice_t advice`
|
||||||
/// The advice to give
|
/// The advice to give
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd, offset, len, advice), ret)]
|
||||||
pub fn fd_advise(
|
pub fn fd_advise(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -19,13 +20,6 @@ pub fn fd_advise(
|
|||||||
len: Filesize,
|
len: Filesize,
|
||||||
advice: Advice,
|
advice: Advice,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::fd_advise: fd={}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd
|
|
||||||
);
|
|
||||||
|
|
||||||
// this is used for our own benefit, so just returning success is a valid
|
// this is used for our own benefit, so just returning success is a valid
|
||||||
// implementation for now
|
// implementation for now
|
||||||
Errno::Success
|
Errno::Success
|
||||||
|
|||||||
@@ -10,17 +10,13 @@ use crate::syscalls::*;
|
|||||||
/// The offset from the start marking the beginning of the allocation
|
/// The offset from the start marking the beginning of the allocation
|
||||||
/// - `Filesize len`
|
/// - `Filesize len`
|
||||||
/// The length from the offset marking the end of the allocation
|
/// The length from the offset marking the end of the allocation
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd, offset, len), ret)]
|
||||||
pub fn fd_allocate(
|
pub fn fd_allocate(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
offset: Filesize,
|
offset: Filesize,
|
||||||
len: Filesize,
|
len: Filesize,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::fd_allocate",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
let fd_entry = wasi_try!(state.fs.get_fd(fd));
|
let fd_entry = wasi_try!(state.fs.get_fd(fd));
|
||||||
@@ -52,7 +48,7 @@ pub fn fd_allocate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
inode.stat.write().unwrap().st_size = new_size;
|
inode.stat.write().unwrap().st_size = new_size;
|
||||||
debug!("New file size: {}", new_size);
|
debug!(%new_size);
|
||||||
|
|
||||||
Errno::Success
|
Errno::Success
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,14 +12,8 @@ use crate::syscalls::*;
|
|||||||
/// If `fd` is a directory
|
/// If `fd` is a directory
|
||||||
/// - `Errno::Badf`
|
/// - `Errno::Badf`
|
||||||
/// If `fd` is invalid or not open
|
/// If `fd` is invalid or not open
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd), ret, err)]
|
||||||
pub fn fd_close(mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Result<Errno, WasiError> {
|
pub fn fd_close(mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::fd_close: fd={}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd
|
|
||||||
);
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
wasi_try_ok!(state.fs.close_fd(fd));
|
wasi_try_ok!(state.fs.close_fd(fd));
|
||||||
|
|||||||
@@ -6,12 +6,8 @@ use crate::syscalls::*;
|
|||||||
/// Inputs:
|
/// Inputs:
|
||||||
/// - `Fd fd`
|
/// - `Fd fd`
|
||||||
/// The file descriptor to sync
|
/// The file descriptor to sync
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd), ret, err)]
|
||||||
pub fn fd_datasync(mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Result<Errno, WasiError> {
|
pub fn fd_datasync(mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::fd_datasync",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let state = env.state.clone();
|
let state = env.state.clone();
|
||||||
let fd_entry = wasi_try_ok!(state.fs.get_fd(fd));
|
let fd_entry = wasi_try_ok!(state.fs.get_fd(fd));
|
||||||
|
|||||||
@@ -9,17 +9,17 @@ use crate::syscalls::*;
|
|||||||
/// Outputs:
|
/// Outputs:
|
||||||
/// - `Fd fd`
|
/// - `Fd fd`
|
||||||
/// The new file handle that is a duplicate of the original
|
/// The new file handle that is a duplicate of the original
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd, ret_fd = field::Empty), ret)]
|
||||||
pub fn fd_dup<M: MemorySize>(
|
pub fn fd_dup<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
ret_fd: WasmPtr<WasiFd, M>,
|
ret_fd: WasmPtr<WasiFd, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!("wasi[{}:{}]::fd_dup", ctx.data().pid(), ctx.data().tid());
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (memory, state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
let fd = wasi_try!(state.fs.clone_fd(fd));
|
let fd = wasi_try!(state.fs.clone_fd(fd));
|
||||||
|
|
||||||
|
Span::current().record("ret_fd", fd);
|
||||||
wasi_try_mem!(ret_fd.write(&memory, fd));
|
wasi_try_mem!(ret_fd.write(&memory, fd));
|
||||||
|
|
||||||
Errno::Success
|
Errno::Success
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ use crate::{fs::NotificationInner, syscalls::*};
|
|||||||
|
|
||||||
/// ### `fd_event()`
|
/// ### `fd_event()`
|
||||||
/// Creates a file handle for event notifications
|
/// Creates a file handle for event notifications
|
||||||
|
#[instrument(level = "debug", skip_all, fields(initial_val, ret_fd = field::Empty), ret)]
|
||||||
pub fn fd_event<M: MemorySize>(
|
pub fn fd_event<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
initial_val: u64,
|
initial_val: u64,
|
||||||
flags: EventFdFlags,
|
flags: EventFdFlags,
|
||||||
ret_fd: WasmPtr<WasiFd, M>,
|
ret_fd: WasmPtr<WasiFd, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!("wasi[{}:{}]::fd_event", ctx.data().pid(), ctx.data().tid());
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, state, mut inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, state, mut inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
|
|
||||||
@@ -32,12 +31,7 @@ pub fn fd_event<M: MemorySize>(
|
|||||||
.fs
|
.fs
|
||||||
.create_fd(rights, rights, Fdflags::empty(), 0, inode));
|
.create_fd(rights, rights, Fdflags::empty(), 0, inode));
|
||||||
|
|
||||||
trace!(
|
Span::current().record("ret_fd", fd);
|
||||||
"wasi[{}:{}]::fd_event - event notifications created (fd={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd
|
|
||||||
);
|
|
||||||
wasi_try_mem!(ret_fd.write(&memory, fd));
|
wasi_try_mem!(ret_fd.write(&memory, fd));
|
||||||
|
|
||||||
Errno::Success
|
Errno::Success
|
||||||
|
|||||||
@@ -9,18 +9,12 @@ use crate::syscalls::*;
|
|||||||
/// Output:
|
/// Output:
|
||||||
/// - `Fdstat *buf`
|
/// - `Fdstat *buf`
|
||||||
/// The location where the metadata will be written
|
/// The location where the metadata will be written
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd), ret)]
|
||||||
pub fn fd_fdstat_get<M: MemorySize>(
|
pub fn fd_fdstat_get<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
buf_ptr: WasmPtr<Fdstat, M>,
|
buf_ptr: WasmPtr<Fdstat, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::fd_fdstat_get: fd={}, buf_ptr={}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd,
|
|
||||||
buf_ptr.offset()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
let stat = wasi_try!(state.fs.fdstat(fd));
|
let stat = wasi_try!(state.fs.fdstat(fd));
|
||||||
|
|||||||
@@ -8,19 +8,12 @@ use crate::syscalls::*;
|
|||||||
/// The file descriptor to apply the new flags to
|
/// The file descriptor to apply the new flags to
|
||||||
/// - `Fdflags flags`
|
/// - `Fdflags flags`
|
||||||
/// The flags to apply to `fd`
|
/// The flags to apply to `fd`
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd), ret, err)]
|
||||||
pub fn fd_fdstat_set_flags(
|
pub fn fd_fdstat_set_flags(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
flags: Fdflags,
|
flags: Fdflags,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::fd_fdstat_set_flags (fd={}, flags={:?})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd,
|
|
||||||
flags
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (_, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (_, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
@@ -29,13 +22,6 @@ pub fn fd_fdstat_set_flags(
|
|||||||
let inode = fd_entry.inode.clone();
|
let inode = fd_entry.inode.clone();
|
||||||
|
|
||||||
if !fd_entry.rights.contains(Rights::FD_FDSTAT_SET_FLAGS) {
|
if !fd_entry.rights.contains(Rights::FD_FDSTAT_SET_FLAGS) {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::fd_fdstat_set_flags (fd={}, flags={:?}) - access denied",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd,
|
|
||||||
flags
|
|
||||||
);
|
|
||||||
return Ok(Errno::Access);
|
return Ok(Errno::Access);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,17 +10,13 @@ use crate::syscalls::*;
|
|||||||
/// The rights to apply to `fd`
|
/// The rights to apply to `fd`
|
||||||
/// - `Rights fs_rights_inheriting`
|
/// - `Rights fs_rights_inheriting`
|
||||||
/// The inheriting rights to apply to `fd`
|
/// The inheriting rights to apply to `fd`
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd), ret)]
|
||||||
pub fn fd_fdstat_set_rights(
|
pub fn fd_fdstat_set_rights(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
fs_rights_base: Rights,
|
fs_rights_base: Rights,
|
||||||
fs_rights_inheriting: Rights,
|
fs_rights_inheriting: Rights,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::fd_fdstat_set_rights",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
let mut fd_map = state.fs.fd_map.write().unwrap();
|
let mut fd_map = state.fs.fd_map.write().unwrap();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use crate::syscalls::*;
|
|||||||
/// Output:
|
/// Output:
|
||||||
/// - `Filestat *buf`
|
/// - `Filestat *buf`
|
||||||
/// Where the metadata from `fd` will be written
|
/// Where the metadata from `fd` will be written
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd), ret)]
|
||||||
pub fn fd_filestat_get<M: MemorySize>(
|
pub fn fd_filestat_get<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -30,11 +31,6 @@ pub(crate) fn fd_filestat_get_internal<M: MemorySize>(
|
|||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
buf: WasmPtr<Filestat, M>,
|
buf: WasmPtr<Filestat, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::fd_filestat_get: fd={fd}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
let fd_entry = wasi_try!(state.fs.get_fd(fd));
|
let fd_entry = wasi_try!(state.fs.get_fd(fd));
|
||||||
|
|||||||
@@ -8,16 +8,12 @@ use crate::syscalls::*;
|
|||||||
/// File descriptor to adjust
|
/// File descriptor to adjust
|
||||||
/// - `Filesize st_size`
|
/// - `Filesize st_size`
|
||||||
/// New size that `fd` will be set to
|
/// New size that `fd` will be set to
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd, st_size), ret)]
|
||||||
pub fn fd_filestat_set_size(
|
pub fn fd_filestat_set_size(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
st_size: Filesize,
|
st_size: Filesize,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::fd_filestat_set_size",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
let fd_entry = wasi_try!(state.fs.get_fd(fd));
|
let fd_entry = wasi_try!(state.fs.get_fd(fd));
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use crate::syscalls::*;
|
|||||||
/// Last modified time
|
/// Last modified time
|
||||||
/// - `Fstflags fst_flags`
|
/// - `Fstflags fst_flags`
|
||||||
/// Bit-vector for controlling which times get set
|
/// Bit-vector for controlling which times get set
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd, st_atim, st_mtim), ret)]
|
||||||
pub fn fd_filestat_set_times(
|
pub fn fd_filestat_set_times(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -17,11 +18,6 @@ pub fn fd_filestat_set_times(
|
|||||||
st_mtim: Timestamp,
|
st_mtim: Timestamp,
|
||||||
fst_flags: Fstflags,
|
fst_flags: Fstflags,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::fd_filestat_set_times",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
let fd_entry = wasi_try!(state.fs.get_fd(fd));
|
let fd_entry = wasi_try!(state.fs.get_fd(fd));
|
||||||
|
|||||||
@@ -1,22 +1,17 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::syscalls::*;
|
use crate::syscalls::*;
|
||||||
|
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd, path = field::Empty), ret)]
|
||||||
pub fn fd_prestat_dir_name<M: MemorySize>(
|
pub fn fd_prestat_dir_name<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
path: WasmPtr<u8, M>,
|
path: WasmPtr<u8, M>,
|
||||||
path_len: M::Offset,
|
path_len: M::Offset,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::fd_prestat_dir_name: fd={}, path_len={}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd,
|
|
||||||
path_len
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
let path_chars = wasi_try_mem!(path.slice(&memory, path_len));
|
let path_chars = wasi_try_mem!(path.slice(&memory, path_len));
|
||||||
|
Span::current().record("path", get_input_str!(&memory, path, path_len).as_str());
|
||||||
|
|
||||||
let inode = wasi_try!(state.fs.get_fd_inode(fd));
|
let inode = wasi_try!(state.fs.get_fd_inode(fd));
|
||||||
|
|
||||||
|
|||||||
@@ -9,27 +9,17 @@ use crate::syscalls::*;
|
|||||||
/// Output:
|
/// Output:
|
||||||
/// - `__wasi_prestat *buf`
|
/// - `__wasi_prestat *buf`
|
||||||
/// Where the metadata will be written
|
/// Where the metadata will be written
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd), ret)]
|
||||||
pub fn fd_prestat_get<M: MemorySize>(
|
pub fn fd_prestat_get<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
buf: WasmPtr<Prestat, M>,
|
buf: WasmPtr<Prestat, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::fd_prestat_get: fd={}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
|
|
||||||
let prestat_ptr = buf.deref(&memory);
|
let prestat_ptr = buf.deref(&memory);
|
||||||
wasi_try_mem!(
|
wasi_try_mem!(prestat_ptr.write(wasi_try!(state.fs.prestat_fd(fd))));
|
||||||
prestat_ptr.write(wasi_try!(state.fs.prestat_fd(fd).map_err(|code| {
|
|
||||||
debug!("fd_prestat_get failed (fd={}) - errno={}", fd, code);
|
|
||||||
code
|
|
||||||
})))
|
|
||||||
);
|
|
||||||
|
|
||||||
Errno::Success
|
Errno::Success
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use crate::{fs::NotificationInner, syscalls::*};
|
|||||||
/// - `u32 *nread`
|
/// - `u32 *nread`
|
||||||
/// Number of bytes read
|
/// Number of bytes read
|
||||||
///
|
///
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd, nread = field::Empty), ret, err)]
|
||||||
pub fn fd_read<M: MemorySize>(
|
pub fn fd_read<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -41,29 +42,13 @@ pub fn fd_read<M: MemorySize>(
|
|||||||
|
|
||||||
let mut ret = Errno::Success;
|
let mut ret = Errno::Success;
|
||||||
let bytes_read = match res {
|
let bytes_read = match res {
|
||||||
Ok(bytes_read) => {
|
Ok(bytes_read) => bytes_read,
|
||||||
trace!(
|
|
||||||
%fd,
|
|
||||||
%bytes_read,
|
|
||||||
"wasi[{}:{}]::fd_read",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
);
|
|
||||||
bytes_read
|
|
||||||
}
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let read_err = err.name();
|
|
||||||
trace!(
|
|
||||||
%fd,
|
|
||||||
%read_err,
|
|
||||||
"wasi[{}:{}]::fd_read",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
);
|
|
||||||
ret = err;
|
ret = err;
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Span::current().record("nread", bytes_read);
|
||||||
|
|
||||||
let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| Errno::Overflow));
|
let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| Errno::Overflow));
|
||||||
|
|
||||||
@@ -93,6 +78,7 @@ pub fn fd_read<M: MemorySize>(
|
|||||||
/// Output:
|
/// Output:
|
||||||
/// - `size_t nread`
|
/// - `size_t nread`
|
||||||
/// The number of bytes read
|
/// The number of bytes read
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd, offset, nread), ret, err)]
|
||||||
pub fn fd_pread<M: MemorySize>(
|
pub fn fd_pread<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -108,33 +94,13 @@ pub fn fd_pread<M: MemorySize>(
|
|||||||
|
|
||||||
let mut ret = Errno::Success;
|
let mut ret = Errno::Success;
|
||||||
let bytes_read = match res {
|
let bytes_read = match res {
|
||||||
Ok(bytes_read) => {
|
Ok(bytes_read) => bytes_read,
|
||||||
trace!(
|
|
||||||
%fd,
|
|
||||||
%offset,
|
|
||||||
%bytes_read,
|
|
||||||
"wasi[{}:{}]::fd_pread - {:?}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
ret
|
|
||||||
);
|
|
||||||
bytes_read
|
|
||||||
}
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let read_err = err.name();
|
|
||||||
trace!(
|
|
||||||
%fd,
|
|
||||||
%offset,
|
|
||||||
%read_err,
|
|
||||||
"wasi[{}:{}]::fd_pread - {:?}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
ret
|
|
||||||
);
|
|
||||||
ret = err;
|
ret = err;
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Span::current().record("nread", bytes_read);
|
||||||
|
|
||||||
let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| Errno::Overflow));
|
let bytes_read: M::Offset = wasi_try_ok!(bytes_read.try_into().map_err(|_| Errno::Overflow));
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use crate::syscalls::*;
|
|||||||
/// - `u32 *bufused`
|
/// - `u32 *bufused`
|
||||||
/// The Number of bytes stored in `buf`; if less than `buf_len` then entire
|
/// The Number of bytes stored in `buf`; if less than `buf_len` then entire
|
||||||
/// directory has been read
|
/// directory has been read
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd), ret)]
|
||||||
pub fn fd_readdir<M: MemorySize>(
|
pub fn fd_readdir<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -24,11 +25,6 @@ pub fn fd_readdir<M: MemorySize>(
|
|||||||
cookie: Dircookie,
|
cookie: Dircookie,
|
||||||
bufused: WasmPtr<M::Offset, M>,
|
bufused: WasmPtr<M::Offset, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::fd_readdir",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
// TODO: figure out how this is supposed to work;
|
// TODO: figure out how this is supposed to work;
|
||||||
@@ -44,7 +40,7 @@ pub fn fd_readdir<M: MemorySize>(
|
|||||||
let guard = working_dir.inode.read();
|
let guard = working_dir.inode.read();
|
||||||
match guard.deref() {
|
match guard.deref() {
|
||||||
Kind::Dir { path, entries, .. } => {
|
Kind::Dir { path, entries, .. } => {
|
||||||
debug!("Reading dir {:?}", path);
|
trace!("reading dir {:?}", path);
|
||||||
// TODO: refactor this code
|
// TODO: refactor this code
|
||||||
// we need to support multiple calls,
|
// we need to support multiple calls,
|
||||||
// simple and obviously correct implementation for now:
|
// simple and obviously correct implementation for now:
|
||||||
@@ -56,7 +52,7 @@ pub fn fd_readdir<M: MemorySize>(
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|entry| {
|
.map(|entry| {
|
||||||
let filename = entry.file_name().to_string_lossy().to_string();
|
let filename = entry.file_name().to_string_lossy().to_string();
|
||||||
debug!("Getting file: {:?}", filename);
|
trace!("getting file: {:?}", filename);
|
||||||
let filetype = virtual_file_type_to_wasi_file_type(
|
let filetype = virtual_file_type_to_wasi_file_type(
|
||||||
entry.file_type().map_err(fs_error_into_wasi_err)?,
|
entry.file_type().map_err(fs_error_into_wasi_err)?,
|
||||||
);
|
);
|
||||||
@@ -79,7 +75,7 @@ pub fn fd_readdir<M: MemorySize>(
|
|||||||
entry_vec
|
entry_vec
|
||||||
}
|
}
|
||||||
Kind::Root { entries } => {
|
Kind::Root { entries } => {
|
||||||
debug!("Reading root");
|
trace!("reading root");
|
||||||
let sorted_entries = {
|
let sorted_entries = {
|
||||||
let mut entry_vec: Vec<(String, InodeGuard)> = entries
|
let mut entry_vec: Vec<(String, InodeGuard)> = entries
|
||||||
.iter()
|
.iter()
|
||||||
@@ -108,7 +104,7 @@ pub fn fd_readdir<M: MemorySize>(
|
|||||||
for (entry_path_str, wasi_file_type, ino) in entries.iter().skip(cookie as usize) {
|
for (entry_path_str, wasi_file_type, ino) in entries.iter().skip(cookie as usize) {
|
||||||
cur_cookie += 1;
|
cur_cookie += 1;
|
||||||
let namlen = entry_path_str.len();
|
let namlen = entry_path_str.len();
|
||||||
debug!("Returning dirent for {}", entry_path_str);
|
trace!("returning dirent for {}", entry_path_str);
|
||||||
let dirent = Dirent {
|
let dirent = Dirent {
|
||||||
d_next: cur_cookie,
|
d_next: cur_cookie,
|
||||||
d_ino: *ino,
|
d_ino: *ino,
|
||||||
|
|||||||
@@ -8,14 +8,8 @@ use crate::syscalls::*;
|
|||||||
/// File descriptor to copy
|
/// File descriptor to copy
|
||||||
/// - `Fd to`
|
/// - `Fd to`
|
||||||
/// Location to copy file descriptor to
|
/// Location to copy file descriptor to
|
||||||
|
#[instrument(level = "debug", skip_all, fields(from, to), ret)]
|
||||||
pub fn fd_renumber(ctx: FunctionEnvMut<'_, WasiEnv>, from: WasiFd, to: WasiFd) -> Errno {
|
pub fn fd_renumber(ctx: FunctionEnvMut<'_, WasiEnv>, from: WasiFd, to: WasiFd) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::fd_renumber(from={}, to={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
from,
|
|
||||||
to
|
|
||||||
);
|
|
||||||
if from == to {
|
if from == to {
|
||||||
return Errno::Success;
|
return Errno::Success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use crate::syscalls::*;
|
|||||||
/// Output:
|
/// Output:
|
||||||
/// - `Filesize *fd`
|
/// - `Filesize *fd`
|
||||||
/// The new offset relative to the start of the file
|
/// The new offset relative to the start of the file
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd, offset, whence), ret)]
|
||||||
pub fn fd_seek<M: MemorySize>(
|
pub fn fd_seek<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -20,15 +21,6 @@ pub fn fd_seek<M: MemorySize>(
|
|||||||
whence: Whence,
|
whence: Whence,
|
||||||
newoffset: WasmPtr<Filesize, M>,
|
newoffset: WasmPtr<Filesize, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::fd_seek: fd={}, offset={} from={:?}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd,
|
|
||||||
offset,
|
|
||||||
whence,
|
|
||||||
);
|
|
||||||
|
|
||||||
wasi_try_ok!(WasiEnv::process_signals_and_exit(&mut ctx)?);
|
wasi_try_ok!(WasiEnv::process_signals_and_exit(&mut ctx)?);
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
@@ -123,11 +115,7 @@ pub fn fd_seek<M: MemorySize>(
|
|||||||
wasi_try_mem_ok!(new_offset_ref.write(new_offset));
|
wasi_try_mem_ok!(new_offset_ref.write(new_offset));
|
||||||
|
|
||||||
trace!(
|
trace!(
|
||||||
"wasi[{}:{}]::fd_seek: fd={}, new_offset={}",
|
%new_offset,
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd,
|
|
||||||
new_offset,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(Errno::Success)
|
Ok(Errno::Success)
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ use crate::syscalls::*;
|
|||||||
/// TODO: figure out which errors this should return
|
/// TODO: figure out which errors this should return
|
||||||
/// - `Errno::Perm`
|
/// - `Errno::Perm`
|
||||||
/// - `Errno::Notcapable`
|
/// - `Errno::Notcapable`
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd), ret)]
|
||||||
pub fn fd_sync(mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Result<Errno, WasiError> {
|
pub fn fd_sync(mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Result<Errno, WasiError> {
|
||||||
debug!("wasi[{}:{}]::fd_sync", ctx.data().pid(), ctx.data().tid());
|
|
||||||
debug!("=> fd={}", fd);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (_, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
let fd_entry = wasi_try_ok!(state.fs.get_fd(fd));
|
let fd_entry = wasi_try_ok!(state.fs.get_fd(fd));
|
||||||
|
|||||||
@@ -9,13 +9,12 @@ use crate::syscalls::*;
|
|||||||
/// Output:
|
/// Output:
|
||||||
/// - `Filesize *offset`
|
/// - `Filesize *offset`
|
||||||
/// The offset of `fd` relative to the start of the file
|
/// The offset of `fd` relative to the start of the file
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd, offset = field::Empty), ret)]
|
||||||
pub fn fd_tell<M: MemorySize>(
|
pub fn fd_tell<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
offset: WasmPtr<Filesize, M>,
|
offset: WasmPtr<Filesize, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!("wasi::fd_tell");
|
|
||||||
debug!("wasi[{}:{}]::fd_tell", ctx.data().pid(), ctx.data().tid());
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
let offset_ref = offset.deref(&memory);
|
let offset_ref = offset.deref(&memory);
|
||||||
@@ -26,7 +25,9 @@ pub fn fd_tell<M: MemorySize>(
|
|||||||
return Errno::Access;
|
return Errno::Access;
|
||||||
}
|
}
|
||||||
|
|
||||||
wasi_try_mem!(offset_ref.write(fd_entry.offset.load(Ordering::Acquire)));
|
let offset = fd_entry.offset.load(Ordering::Acquire);
|
||||||
|
Span::current().record("offset", offset);
|
||||||
|
wasi_try_mem!(offset_ref.write(offset));
|
||||||
|
|
||||||
Errno::Success
|
Errno::Success
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use crate::syscalls::*;
|
|||||||
/// Number of bytes written
|
/// Number of bytes written
|
||||||
/// Errors:
|
/// Errors:
|
||||||
///
|
///
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd, nwritten = field::Empty), ret, err)]
|
||||||
pub fn fd_write<M: MemorySize>(
|
pub fn fd_write<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -22,13 +23,6 @@ pub fn fd_write<M: MemorySize>(
|
|||||||
iovs_len: M::Offset,
|
iovs_len: M::Offset,
|
||||||
nwritten: WasmPtr<M::Offset, M>,
|
nwritten: WasmPtr<M::Offset, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::fd_write: fd={}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd,
|
|
||||||
);
|
|
||||||
|
|
||||||
let offset = {
|
let offset = {
|
||||||
let mut env = ctx.data();
|
let mut env = ctx.data();
|
||||||
let state = env.state.clone();
|
let state = env.state.clone();
|
||||||
@@ -55,6 +49,7 @@ pub fn fd_write<M: MemorySize>(
|
|||||||
/// Output:
|
/// Output:
|
||||||
/// - `u32 *nwritten`
|
/// - `u32 *nwritten`
|
||||||
/// Number of bytes written
|
/// Number of bytes written
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd, offset, nwritten = field::Empty), ret, err)]
|
||||||
pub fn fd_pwrite<M: MemorySize>(
|
pub fn fd_pwrite<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -63,14 +58,6 @@ pub fn fd_pwrite<M: MemorySize>(
|
|||||||
offset: Filesize,
|
offset: Filesize,
|
||||||
nwritten: WasmPtr<M::Offset, M>,
|
nwritten: WasmPtr<M::Offset, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::fd_pwrite (fd={}, offset={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd,
|
|
||||||
offset,
|
|
||||||
);
|
|
||||||
|
|
||||||
fd_write_internal::<M>(ctx, fd, iovs, iovs_len, offset as usize, nwritten, false)
|
fd_write_internal::<M>(ctx, fd, iovs, iovs_len, offset as usize, nwritten, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,6 +247,7 @@ fn fd_write_internal<M: MemorySize>(
|
|||||||
}
|
}
|
||||||
bytes_written
|
bytes_written
|
||||||
};
|
};
|
||||||
|
Span::current().record("nwritten", bytes_written);
|
||||||
|
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
let nwritten_ref = nwritten.deref(&memory);
|
let nwritten_ref = nwritten.deref(&memory);
|
||||||
|
|||||||
@@ -83,3 +83,5 @@ pub use poll_oneoff::*;
|
|||||||
pub use proc_exit::*;
|
pub use proc_exit::*;
|
||||||
pub use proc_raise::*;
|
pub use proc_raise::*;
|
||||||
pub use random_get::*;
|
pub use random_get::*;
|
||||||
|
|
||||||
|
use tracing::{debug_span, field, instrument, trace_span, Span};
|
||||||
|
|||||||
@@ -14,17 +14,13 @@ use crate::syscalls::*;
|
|||||||
/// Required Rights:
|
/// Required Rights:
|
||||||
/// - Rights::PATH_CREATE_DIRECTORY
|
/// - Rights::PATH_CREATE_DIRECTORY
|
||||||
/// This right must be set on the directory that the file is created in (TODO: verify that this is true)
|
/// This right must be set on the directory that the file is created in (TODO: verify that this is true)
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd, path = field::Empty), ret)]
|
||||||
pub fn path_create_directory<M: MemorySize>(
|
pub fn path_create_directory<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
path: WasmPtr<u8, M>,
|
path: WasmPtr<u8, M>,
|
||||||
path_len: M::Offset,
|
path_len: M::Offset,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::path_create_directory",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
|
|
||||||
@@ -39,16 +35,13 @@ pub fn path_create_directory<M: MemorySize>(
|
|||||||
return Errno::Access;
|
return Errno::Access;
|
||||||
}
|
}
|
||||||
let mut path_string = unsafe { get_input_str!(&memory, path, path_len) };
|
let mut path_string = unsafe { get_input_str!(&memory, path, path_len) };
|
||||||
debug!("=> fd: {}, path: {}", fd, &path_string);
|
Span::current().record("path", path_string.as_str());
|
||||||
|
|
||||||
// Convert relative paths into absolute paths
|
// Convert relative paths into absolute paths
|
||||||
if path_string.starts_with("./") {
|
if path_string.starts_with("./") {
|
||||||
path_string = ctx.data().state.fs.relative_path_to_absolute(path_string);
|
path_string = ctx.data().state.fs.relative_path_to_absolute(path_string);
|
||||||
trace!(
|
trace!(
|
||||||
"wasi[{}:{}]::rel_to_abs (name={}))",
|
%path_string
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
path_string
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,12 +59,8 @@ pub fn path_create_directory<M: MemorySize>(
|
|||||||
return Errno::Inval;
|
return Errno::Inval;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Looking at components {:?}", &path_vec);
|
|
||||||
|
|
||||||
let mut cur_dir_inode = working_dir.inode;
|
let mut cur_dir_inode = working_dir.inode;
|
||||||
for comp in &path_vec {
|
for comp in &path_vec {
|
||||||
debug!("Creating dir {}", comp);
|
|
||||||
|
|
||||||
let processing_cur_dir_inode = cur_dir_inode.clone();
|
let processing_cur_dir_inode = cur_dir_inode.clone();
|
||||||
let mut guard = processing_cur_dir_inode.write();
|
let mut guard = processing_cur_dir_inode.write();
|
||||||
match guard.deref_mut() {
|
match guard.deref_mut() {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use crate::syscalls::*;
|
|||||||
/// Output:
|
/// Output:
|
||||||
/// - `__wasi_file_stat_t *buf`
|
/// - `__wasi_file_stat_t *buf`
|
||||||
/// The location where the metadata will be stored
|
/// The location where the metadata will be stored
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd, path = field::Empty))]
|
||||||
pub fn path_filestat_get<M: MemorySize>(
|
pub fn path_filestat_get<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -27,24 +28,12 @@ pub fn path_filestat_get<M: MemorySize>(
|
|||||||
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
|
|
||||||
let mut path_string = unsafe { get_input_str!(&memory, path, path_len) };
|
let mut path_string = unsafe { get_input_str!(&memory, path, path_len) };
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::path_filestat_get (fd={}, path={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd,
|
|
||||||
path_string
|
|
||||||
);
|
|
||||||
|
|
||||||
// Convert relative paths into absolute paths
|
// Convert relative paths into absolute paths
|
||||||
if path_string.starts_with("./") {
|
if path_string.starts_with("./") {
|
||||||
path_string = ctx.data().state.fs.relative_path_to_absolute(path_string);
|
path_string = ctx.data().state.fs.relative_path_to_absolute(path_string);
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::rel_to_abs (name={}))",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
path_string
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
Span::current().record("path", path_string.as_str());
|
||||||
|
|
||||||
let stat = wasi_try!(path_filestat_get_internal(
|
let stat = wasi_try!(path_filestat_get_internal(
|
||||||
&memory,
|
&memory,
|
||||||
@@ -87,8 +76,6 @@ pub(crate) fn path_filestat_get_internal(
|
|||||||
if !root_dir.rights.contains(Rights::PATH_FILESTAT_GET) {
|
if !root_dir.rights.contains(Rights::PATH_FILESTAT_GET) {
|
||||||
return Err(Errno::Access);
|
return Err(Errno::Access);
|
||||||
}
|
}
|
||||||
debug!("=> base_fd: {}, path: {}", fd, path_string);
|
|
||||||
|
|
||||||
let file_inode = state.fs.get_inode_at_path(
|
let file_inode = state.fs.get_inode_at_path(
|
||||||
inodes,
|
inodes,
|
||||||
fd,
|
fd,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use crate::syscalls::*;
|
|||||||
/// The timestamp that the last modified time attribute is set to
|
/// The timestamp that the last modified time attribute is set to
|
||||||
/// - `Fstflags fst_flags`
|
/// - `Fstflags fst_flags`
|
||||||
/// A bitmask controlling which attributes are set
|
/// A bitmask controlling which attributes are set
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd, path = field::Empty, st_atim, st_mtim), ret)]
|
||||||
pub fn path_filestat_set_times<M: MemorySize>(
|
pub fn path_filestat_set_times<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -28,11 +29,6 @@ pub fn path_filestat_set_times<M: MemorySize>(
|
|||||||
st_mtim: Timestamp,
|
st_mtim: Timestamp,
|
||||||
fst_flags: Fstflags,
|
fst_flags: Fstflags,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::path_filestat_set_times",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
let fd_entry = wasi_try!(state.fs.get_fd(fd));
|
let fd_entry = wasi_try!(state.fs.get_fd(fd));
|
||||||
@@ -47,16 +43,13 @@ pub fn path_filestat_set_times<M: MemorySize>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut path_string = unsafe { get_input_str!(&memory, path, path_len) };
|
let mut path_string = unsafe { get_input_str!(&memory, path, path_len) };
|
||||||
debug!("=> base_fd: {}, path: {}", fd, &path_string);
|
Span::current().record("path", path_string.as_str());
|
||||||
|
|
||||||
// Convert relative paths into absolute paths
|
// Convert relative paths into absolute paths
|
||||||
if path_string.starts_with("./") {
|
if path_string.starts_with("./") {
|
||||||
path_string = ctx.data().state.fs.relative_path_to_absolute(path_string);
|
path_string = ctx.data().state.fs.relative_path_to_absolute(path_string);
|
||||||
trace!(
|
trace!(
|
||||||
"wasi[{}:{}]::rel_to_abs (name={}))",
|
%path_string
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
path_string
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use crate::syscalls::*;
|
|||||||
/// String containing the new file path
|
/// String containing the new file path
|
||||||
/// - `u32 old_path_len`
|
/// - `u32 old_path_len`
|
||||||
/// Length of the `new_path` string
|
/// Length of the `new_path` string
|
||||||
|
#[instrument(level = "debug", skip_all, fields(old_fd, new_fd, old_path = field::Empty, new_path = field::Empty, follow_symlinks = false), ret)]
|
||||||
pub fn path_link<M: MemorySize>(
|
pub fn path_link<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
old_fd: WasiFd,
|
old_fd: WasiFd,
|
||||||
@@ -28,20 +29,17 @@ pub fn path_link<M: MemorySize>(
|
|||||||
new_path: WasmPtr<u8, M>,
|
new_path: WasmPtr<u8, M>,
|
||||||
new_path_len: M::Offset,
|
new_path_len: M::Offset,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!("wasi[{}:{}]::path_link", ctx.data().pid(), ctx.data().tid());
|
|
||||||
if old_flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 {
|
if old_flags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 {
|
||||||
debug!(" - will follow symlinks when opening path");
|
Span::current().record("follow_symlinks", true);
|
||||||
}
|
}
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
let mut old_path_str = unsafe { get_input_str!(&memory, old_path, old_path_len) };
|
let mut old_path_str = unsafe { get_input_str!(&memory, old_path, old_path_len) };
|
||||||
|
Span::current().record("old_path", old_path_str.as_str());
|
||||||
let mut new_path_str = unsafe { get_input_str!(&memory, new_path, new_path_len) };
|
let mut new_path_str = unsafe { get_input_str!(&memory, new_path, new_path_len) };
|
||||||
|
Span::current().record("new_path", new_path_str.as_str());
|
||||||
let source_fd = wasi_try!(state.fs.get_fd(old_fd));
|
let source_fd = wasi_try!(state.fs.get_fd(old_fd));
|
||||||
let target_fd = wasi_try!(state.fs.get_fd(new_fd));
|
let target_fd = wasi_try!(state.fs.get_fd(new_fd));
|
||||||
debug!(
|
|
||||||
"=> source_fd: {}, source_path: {}, target_fd: {}, target_path: {}",
|
|
||||||
old_fd, &old_path_str, new_fd, new_path_str
|
|
||||||
);
|
|
||||||
|
|
||||||
if !source_fd.rights.contains(Rights::PATH_LINK_SOURCE)
|
if !source_fd.rights.contains(Rights::PATH_LINK_SOURCE)
|
||||||
|| !target_fd.rights.contains(Rights::PATH_LINK_TARGET)
|
|| !target_fd.rights.contains(Rights::PATH_LINK_TARGET)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ use crate::syscalls::*;
|
|||||||
/// The new file descriptor
|
/// The new file descriptor
|
||||||
/// Possible Errors:
|
/// Possible Errors:
|
||||||
/// - `Errno::Access`, `Errno::Badf`, `Errno::Fault`, `Errno::Fbig?`, `Errno::Inval`, `Errno::Io`, `Errno::Loop`, `Errno::Mfile`, `Errno::Nametoolong?`, `Errno::Nfile`, `Errno::Noent`, `Errno::Notdir`, `Errno::Rofs`, and `Errno::Notcapable`
|
/// - `Errno::Access`, `Errno::Badf`, `Errno::Fault`, `Errno::Fbig?`, `Errno::Inval`, `Errno::Io`, `Errno::Loop`, `Errno::Mfile`, `Errno::Nametoolong?`, `Errno::Nfile`, `Errno::Noent`, `Errno::Notdir`, `Errno::Rofs`, and `Errno::Notcapable`
|
||||||
|
#[instrument(level = "debug", skip_all, fields(dirfd, path = field::Empty, follow_symlinks = false, ret_fd = field::Empty), ret)]
|
||||||
pub fn path_open<M: MemorySize>(
|
pub fn path_open<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
dirfd: WasiFd,
|
dirfd: WasiFd,
|
||||||
@@ -37,9 +38,8 @@ pub fn path_open<M: MemorySize>(
|
|||||||
fs_flags: Fdflags,
|
fs_flags: Fdflags,
|
||||||
fd: WasmPtr<WasiFd, M>,
|
fd: WasmPtr<WasiFd, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!("wasi[{}:{}]::path_open", ctx.data().pid(), ctx.data().tid());
|
|
||||||
if dirflags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 {
|
if dirflags & __WASI_LOOKUP_SYMLINK_FOLLOW != 0 {
|
||||||
debug!(" - will follow symlinks when opening path");
|
Span::current().record("follow_symlinks", true);
|
||||||
}
|
}
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state, mut inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, mut inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
@@ -66,18 +66,15 @@ pub fn path_open<M: MemorySize>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut path_string = unsafe { get_input_str!(&memory, path, path_len) };
|
let mut path_string = unsafe { get_input_str!(&memory, path, path_len) };
|
||||||
|
Span::current().record("path", path_string.as_str());
|
||||||
|
|
||||||
// Convert relative paths into absolute paths
|
// Convert relative paths into absolute paths
|
||||||
if path_string.starts_with("./") {
|
if path_string.starts_with("./") {
|
||||||
path_string = ctx.data().state.fs.relative_path_to_absolute(path_string);
|
path_string = ctx.data().state.fs.relative_path_to_absolute(path_string);
|
||||||
trace!(
|
trace!(
|
||||||
"wasi[{}:{}]::rel_to_abs (name={}))",
|
%path_string
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
path_string
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
debug!("=> path_open(): dirfd: {}, path: {}", dirfd, &path_string);
|
|
||||||
|
|
||||||
let path_arg = std::path::PathBuf::from(&path_string);
|
let path_arg = std::path::PathBuf::from(&path_string);
|
||||||
let maybe_inode = state.fs.get_inode_at_path(
|
let maybe_inode = state.fs.get_inode_at_path(
|
||||||
@@ -200,11 +197,7 @@ pub fn path_open<M: MemorySize>(
|
|||||||
// nothing bad happens
|
// nothing bad happens
|
||||||
let dup_fd = wasi_try!(state.fs.clone_fd(fd));
|
let dup_fd = wasi_try!(state.fs.clone_fd(fd));
|
||||||
trace!(
|
trace!(
|
||||||
"wasi[{}:{}]::path_open [special_fd] (dup_fd: {}->{})",
|
%dup_fd
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd,
|
|
||||||
dup_fd
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// some special files will return a constant FD rather than
|
// some special files will return a constant FD rather than
|
||||||
@@ -237,12 +230,10 @@ pub fn path_open<M: MemorySize>(
|
|||||||
inode
|
inode
|
||||||
} else {
|
} else {
|
||||||
// less-happy path, we have to try to create the file
|
// less-happy path, we have to try to create the file
|
||||||
debug!("Maybe creating file");
|
|
||||||
if o_flags.contains(Oflags::CREATE) {
|
if o_flags.contains(Oflags::CREATE) {
|
||||||
if o_flags.contains(Oflags::DIRECTORY) {
|
if o_flags.contains(Oflags::DIRECTORY) {
|
||||||
return Errno::Notdir;
|
return Errno::Notdir;
|
||||||
}
|
}
|
||||||
debug!("Creating file");
|
|
||||||
// strip end file name
|
// strip end file name
|
||||||
|
|
||||||
let (parent_inode, new_entity_name) = wasi_try!(state.fs.get_parent_inode_at_path(
|
let (parent_inode, new_entity_name) = wasi_try!(state.fs.get_parent_inode_at_path(
|
||||||
@@ -289,12 +280,9 @@ pub fn path_open<M: MemorySize>(
|
|||||||
open_flags |= Fd::TRUNCATE;
|
open_flags |= Fd::TRUNCATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(wasi_try!(open_options.open(&new_file_host_path).map_err(
|
Some(wasi_try!(open_options
|
||||||
|e| {
|
.open(&new_file_host_path)
|
||||||
debug!("Error opening file {}", e);
|
.map_err(|e| { fs_error_into_wasi_err(e) })))
|
||||||
fs_error_into_wasi_err(e)
|
|
||||||
}
|
|
||||||
)))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_inode = {
|
let new_inode = {
|
||||||
@@ -334,13 +322,8 @@ pub fn path_open<M: MemorySize>(
|
|||||||
inode
|
inode
|
||||||
));
|
));
|
||||||
|
|
||||||
wasi_try_mem!(fd_ref.write(out_fd));
|
Span::current().record("ret_fd", out_fd);
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::path_open returning fd {}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
out_fd
|
|
||||||
);
|
|
||||||
|
|
||||||
|
wasi_try_mem!(fd_ref.write(out_fd));
|
||||||
Errno::Success
|
Errno::Success
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use crate::syscalls::*;
|
|||||||
/// Pointer to characters containing the path that the symlink points to
|
/// Pointer to characters containing the path that the symlink points to
|
||||||
/// - `u32 buf_used`
|
/// - `u32 buf_used`
|
||||||
/// The number of bytes written to `buf`
|
/// The number of bytes written to `buf`
|
||||||
|
#[instrument(level = "debug", skip_all, fields(dir_fd, path = field::Empty), ret)]
|
||||||
pub fn path_readlink<M: MemorySize>(
|
pub fn path_readlink<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
dir_fd: WasiFd,
|
dir_fd: WasiFd,
|
||||||
@@ -26,11 +27,6 @@ pub fn path_readlink<M: MemorySize>(
|
|||||||
buf_len: M::Offset,
|
buf_len: M::Offset,
|
||||||
buf_used: WasmPtr<M::Offset, M>,
|
buf_used: WasmPtr<M::Offset, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::path_readlink",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
|
|
||||||
@@ -39,15 +35,13 @@ pub fn path_readlink<M: MemorySize>(
|
|||||||
return Errno::Access;
|
return Errno::Access;
|
||||||
}
|
}
|
||||||
let mut path_str = unsafe { get_input_str!(&memory, path, path_len) };
|
let mut path_str = unsafe { get_input_str!(&memory, path, path_len) };
|
||||||
|
Span::current().record("path", path_str.as_str());
|
||||||
|
|
||||||
// Convert relative paths into absolute paths
|
// Convert relative paths into absolute paths
|
||||||
if path_str.starts_with("./") {
|
if path_str.starts_with("./") {
|
||||||
path_str = ctx.data().state.fs.relative_path_to_absolute(path_str);
|
path_str = ctx.data().state.fs.relative_path_to_absolute(path_str);
|
||||||
trace!(
|
trace!(
|
||||||
"wasi[{}:{}]::rel_to_abs (name={}))",
|
%path_str
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
path_str
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +51,6 @@ pub fn path_readlink<M: MemorySize>(
|
|||||||
let guard = inode.read();
|
let guard = inode.read();
|
||||||
if let Kind::Symlink { relative_path, .. } = guard.deref() {
|
if let Kind::Symlink { relative_path, .. } = guard.deref() {
|
||||||
let rel_path_str = relative_path.to_string_lossy();
|
let rel_path_str = relative_path.to_string_lossy();
|
||||||
debug!("Result => {:?}", rel_path_str);
|
|
||||||
let buf_len: u64 = buf_len.into();
|
let buf_len: u64 = buf_len.into();
|
||||||
let bytes = rel_path_str.bytes();
|
let bytes = rel_path_str.bytes();
|
||||||
if bytes.len() as u64 >= buf_len {
|
if bytes.len() as u64 >= buf_len {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use super::*;
|
|||||||
use crate::syscalls::*;
|
use crate::syscalls::*;
|
||||||
|
|
||||||
/// Returns Errno::Notemtpy if directory is not empty
|
/// Returns Errno::Notemtpy if directory is not empty
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd, path = field::Empty), ret)]
|
||||||
pub fn path_remove_directory<M: MemorySize>(
|
pub fn path_remove_directory<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
@@ -9,25 +10,18 @@ pub fn path_remove_directory<M: MemorySize>(
|
|||||||
path_len: M::Offset,
|
path_len: M::Offset,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
// TODO check if fd is a dir, ensure it's within sandbox, etc.
|
// TODO check if fd is a dir, ensure it's within sandbox, etc.
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::path_remove_directory",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
|
|
||||||
let base_dir = wasi_try!(state.fs.get_fd(fd));
|
let base_dir = wasi_try!(state.fs.get_fd(fd));
|
||||||
let mut path_str = unsafe { get_input_str!(&memory, path, path_len) };
|
let mut path_str = unsafe { get_input_str!(&memory, path, path_len) };
|
||||||
|
Span::current().record("path", path_str.as_str());
|
||||||
|
|
||||||
// Convert relative paths into absolute paths
|
// Convert relative paths into absolute paths
|
||||||
if path_str.starts_with("./") {
|
if path_str.starts_with("./") {
|
||||||
path_str = ctx.data().state.fs.relative_path_to_absolute(path_str);
|
path_str = ctx.data().state.fs.relative_path_to_absolute(path_str);
|
||||||
trace!(
|
trace!(
|
||||||
"wasi[{}:{}]::rel_to_abs (name={}))",
|
%path_str
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
path_str
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use crate::syscalls::*;
|
|||||||
/// Pointer to UTF8 bytes, the new file name
|
/// Pointer to UTF8 bytes, the new file name
|
||||||
/// - `u32 new_path_len`
|
/// - `u32 new_path_len`
|
||||||
/// The number of bytes to read from `new_path`
|
/// The number of bytes to read from `new_path`
|
||||||
|
#[instrument(level = "debug", skip_all, fields(old_fd, new_fd, old_path = field::Empty, new_path = field::Empty), ret)]
|
||||||
pub fn path_rename<M: MemorySize>(
|
pub fn path_rename<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
old_fd: WasiFd,
|
old_fd: WasiFd,
|
||||||
@@ -25,19 +26,16 @@ pub fn path_rename<M: MemorySize>(
|
|||||||
new_path: WasmPtr<u8, M>,
|
new_path: WasmPtr<u8, M>,
|
||||||
new_path_len: M::Offset,
|
new_path_len: M::Offset,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi::path_rename: old_fd = {}, new_fd = {}",
|
|
||||||
old_fd, new_fd
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
let mut source_str = unsafe { get_input_str!(&memory, old_path, old_path_len) };
|
let mut source_str = unsafe { get_input_str!(&memory, old_path, old_path_len) };
|
||||||
|
Span::current().record("old_path", source_str.as_str());
|
||||||
source_str = ctx.data().state.fs.relative_path_to_absolute(source_str);
|
source_str = ctx.data().state.fs.relative_path_to_absolute(source_str);
|
||||||
let source_path = std::path::Path::new(&source_str);
|
let source_path = std::path::Path::new(&source_str);
|
||||||
let mut target_str = unsafe { get_input_str!(&memory, new_path, new_path_len) };
|
let mut target_str = unsafe { get_input_str!(&memory, new_path, new_path_len) };
|
||||||
|
Span::current().record("new_path", target_str.as_str());
|
||||||
target_str = ctx.data().state.fs.relative_path_to_absolute(target_str);
|
target_str = ctx.data().state.fs.relative_path_to_absolute(target_str);
|
||||||
let target_path = std::path::Path::new(&target_str);
|
let target_path = std::path::Path::new(&target_str);
|
||||||
debug!("=> rename from {} to {}", &source_str, &target_str);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let source_fd = wasi_try!(state.fs.get_fd(old_fd));
|
let source_fd = wasi_try!(state.fs.get_fd(old_fd));
|
||||||
@@ -87,7 +85,7 @@ pub fn path_rename<M: MemorySize>(
|
|||||||
return Errno::Inval
|
return Errno::Inval
|
||||||
}
|
}
|
||||||
Kind::Symlink { .. } | Kind::File { .. } | Kind::Buffer { .. } => {
|
Kind::Symlink { .. } | Kind::File { .. } | Kind::Buffer { .. } => {
|
||||||
error!("Fatal internal logic error: parent of inode is not a directory");
|
debug!("fatal internal logic error: parent of inode is not a directory");
|
||||||
return Errno::Inval;
|
return Errno::Inval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,7 +102,7 @@ pub fn path_rename<M: MemorySize>(
|
|||||||
return Errno::Inval
|
return Errno::Inval
|
||||||
}
|
}
|
||||||
Kind::Symlink { .. } | Kind::File { .. } | Kind::Buffer { .. } => {
|
Kind::Symlink { .. } | Kind::File { .. } | Kind::Buffer { .. } => {
|
||||||
error!("Fatal internal logic error: parent of inode is not a directory");
|
debug!("fatal internal logic error: parent of inode is not a directory");
|
||||||
return Errno::Inval;
|
return Errno::Inval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,7 +173,7 @@ pub fn path_rename<M: MemorySize>(
|
|||||||
let result = entries.insert(target_entry_name, source_entry);
|
let result = entries.insert(target_entry_name, source_entry);
|
||||||
assert!(
|
assert!(
|
||||||
result.is_none(),
|
result.is_none(),
|
||||||
"Fatal error: race condition on filesystem detected or internal logic error"
|
"fatal error: race condition on filesystem detected or internal logic error"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use crate::syscalls::*;
|
|||||||
/// Array of UTF-8 bytes representing the target path
|
/// Array of UTF-8 bytes representing the target path
|
||||||
/// - `u32 new_path_len`
|
/// - `u32 new_path_len`
|
||||||
/// The number of bytes to read from `new_path`
|
/// The number of bytes to read from `new_path`
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd, old_path = field::Empty, new_path = field::Empty), ret)]
|
||||||
pub fn path_symlink<M: MemorySize>(
|
pub fn path_symlink<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
old_path: WasmPtr<u8, M>,
|
old_path: WasmPtr<u8, M>,
|
||||||
@@ -22,15 +23,12 @@ pub fn path_symlink<M: MemorySize>(
|
|||||||
new_path: WasmPtr<u8, M>,
|
new_path: WasmPtr<u8, M>,
|
||||||
new_path_len: M::Offset,
|
new_path_len: M::Offset,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::path_symlink",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
let mut old_path_str = unsafe { get_input_str!(&memory, old_path, old_path_len) };
|
let mut old_path_str = unsafe { get_input_str!(&memory, old_path, old_path_len) };
|
||||||
|
Span::current().record("old_path", old_path_str.as_str());
|
||||||
let mut new_path_str = unsafe { get_input_str!(&memory, new_path, new_path_len) };
|
let mut new_path_str = unsafe { get_input_str!(&memory, new_path, new_path_len) };
|
||||||
|
Span::current().record("new_path", new_path_str.as_str());
|
||||||
old_path_str = ctx.data().state.fs.relative_path_to_absolute(old_path_str);
|
old_path_str = ctx.data().state.fs.relative_path_to_absolute(old_path_str);
|
||||||
new_path_str = ctx.data().state.fs.relative_path_to_absolute(new_path_str);
|
new_path_str = ctx.data().state.fs.relative_path_to_absolute(new_path_str);
|
||||||
let base_fd = wasi_try!(state.fs.get_fd(fd));
|
let base_fd = wasi_try!(state.fs.get_fd(fd));
|
||||||
@@ -83,11 +81,6 @@ pub fn path_symlink<M: MemorySize>(
|
|||||||
relative_path.push("..");
|
relative_path.push("..");
|
||||||
}
|
}
|
||||||
relative_path.push(source_path);
|
relative_path.push(source_path);
|
||||||
debug!(
|
|
||||||
"Symlinking {} to {}",
|
|
||||||
new_path_str,
|
|
||||||
relative_path.to_string_lossy()
|
|
||||||
);
|
|
||||||
|
|
||||||
let kind = Kind::Symlink {
|
let kind = Kind::Symlink {
|
||||||
base_po_dir: fd,
|
base_po_dir: fd,
|
||||||
|
|||||||
@@ -10,17 +10,13 @@ use crate::syscalls::*;
|
|||||||
/// Array of UTF-8 bytes representing the path
|
/// Array of UTF-8 bytes representing the path
|
||||||
/// - `u32 path_len`
|
/// - `u32 path_len`
|
||||||
/// The number of bytes in the `path` array
|
/// The number of bytes in the `path` array
|
||||||
|
#[instrument(level = "debug", skip_all, fields(fd, path = field::Empty), ret)]
|
||||||
pub fn path_unlink_file<M: MemorySize>(
|
pub fn path_unlink_file<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
fd: WasiFd,
|
fd: WasiFd,
|
||||||
path: WasmPtr<u8, M>,
|
path: WasmPtr<u8, M>,
|
||||||
path_len: M::Offset,
|
path_len: M::Offset,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::path_unlink_file",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
|
|
||||||
@@ -29,17 +25,11 @@ pub fn path_unlink_file<M: MemorySize>(
|
|||||||
return Errno::Access;
|
return Errno::Access;
|
||||||
}
|
}
|
||||||
let mut path_str = unsafe { get_input_str!(&memory, path, path_len) };
|
let mut path_str = unsafe { get_input_str!(&memory, path, path_len) };
|
||||||
debug!("Requested file: {}", path_str);
|
Span::current().record("path", path_str.as_str());
|
||||||
|
|
||||||
// Convert relative paths into absolute paths
|
// Convert relative paths into absolute paths
|
||||||
if path_str.starts_with("./") {
|
if path_str.starts_with("./") {
|
||||||
path_str = ctx.data().state.fs.relative_path_to_absolute(path_str);
|
path_str = ctx.data().state.fs.relative_path_to_absolute(path_str);
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::rel_to_abs (name={}))",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
path_str
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let inode = wasi_try!(state.fs.get_inode_at_path(inodes, fd, &path_str, false));
|
let inode = wasi_try!(state.fs.get_inode_at_path(inodes, fd, &path_str, false));
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ use crate::{
|
|||||||
/// Output:
|
/// Output:
|
||||||
/// - `u32 nevents`
|
/// - `u32 nevents`
|
||||||
/// The number of events seen
|
/// The number of events seen
|
||||||
|
#[instrument(level = "trace", skip_all, fields(timeout_ns = field::Empty, fd_guards = field::Empty, seen = field::Empty), ret, err)]
|
||||||
pub fn poll_oneoff<M: MemorySize>(
|
pub fn poll_oneoff<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
in_: WasmPtr<Subscription, M>,
|
in_: WasmPtr<Subscription, M>,
|
||||||
@@ -49,12 +50,6 @@ pub fn poll_oneoff<M: MemorySize>(
|
|||||||
let triggered_events = match triggered_events {
|
let triggered_events = match triggered_events {
|
||||||
Ok(a) => a,
|
Ok(a) => a,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
tracing::trace!(
|
|
||||||
"wasi[{}:{}]::poll_oneoff errno={}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
err
|
|
||||||
);
|
|
||||||
return Ok(err);
|
return Ok(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -105,14 +100,7 @@ impl<'a> Future for PollBatch<'a> {
|
|||||||
Poll::Pending => {}
|
Poll::Pending => {}
|
||||||
Poll::Ready(e) => {
|
Poll::Ready(e) => {
|
||||||
for evt in e {
|
for evt in e {
|
||||||
tracing::trace!(
|
tracing::trace!(fd, userdata = evt.userdata, ty = evt.type_ as u8,);
|
||||||
"wasi[{}:{}]::poll_oneoff triggered_fd (fd={}, userdata={}, type={:?})",
|
|
||||||
pid,
|
|
||||||
tid,
|
|
||||||
fd,
|
|
||||||
evt.userdata,
|
|
||||||
evt.type_,
|
|
||||||
);
|
|
||||||
evts.push(evt);
|
evts.push(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,12 +137,6 @@ pub(crate) fn poll_oneoff_internal(
|
|||||||
// Determine if we are in silent polling mode
|
// Determine if we are in silent polling mode
|
||||||
let mut env = ctx.data();
|
let mut env = ctx.data();
|
||||||
let state = ctx.data().state.deref();
|
let state = ctx.data().state.deref();
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::poll_oneoff (nsubscriptions={})",
|
|
||||||
pid,
|
|
||||||
tid,
|
|
||||||
subs.len(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// These are used when we capture what clocks (timeouts) are being
|
// These are used when we capture what clocks (timeouts) are being
|
||||||
// subscribed too
|
// subscribed too
|
||||||
@@ -222,23 +204,14 @@ pub(crate) fn poll_oneoff_internal(
|
|||||||
// If the timeout duration is zero then this is an immediate check rather than
|
// If the timeout duration is zero then this is an immediate check rather than
|
||||||
// a sleep itself
|
// a sleep itself
|
||||||
if clock_info.timeout == 0 {
|
if clock_info.timeout == 0 {
|
||||||
tracing::trace!("wasi[{}:{}]::poll_oneoff nonblocking", pid, tid,);
|
|
||||||
time_to_sleep = Some(Duration::ZERO);
|
time_to_sleep = Some(Duration::ZERO);
|
||||||
} else {
|
} else {
|
||||||
tracing::trace!(
|
|
||||||
"wasi[{}:{}]::poll_oneoff clock_id={:?} (userdata={}, timeout={})",
|
|
||||||
pid,
|
|
||||||
tid,
|
|
||||||
clock_info.clock_id,
|
|
||||||
s.userdata,
|
|
||||||
clock_info.timeout
|
|
||||||
);
|
|
||||||
time_to_sleep = Some(Duration::from_nanos(clock_info.timeout));
|
time_to_sleep = Some(Duration::from_nanos(clock_info.timeout));
|
||||||
clock_subs.push((clock_info, s.userdata));
|
clock_subs.push((clock_info, s.userdata));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
error!("Polling not implemented for these clocks yet");
|
error!("polling not implemented for these clocks yet");
|
||||||
return Ok(Err(Errno::Inval));
|
return Ok(Err(Errno::Inval));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,33 +262,28 @@ pub(crate) fn poll_oneoff_internal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
tracing::trace!(
|
|
||||||
"wasi[{}:{}]::poll_oneoff wait_for_fd={} type={:?}",
|
|
||||||
pid,
|
|
||||||
tid,
|
|
||||||
fd,
|
|
||||||
wasi_file_ref
|
|
||||||
);
|
|
||||||
fd_guards.push(wasi_file_ref);
|
fd_guards.push(wasi_file_ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fd_guards.len() > 10 {
|
||||||
|
let small_list: Vec<_> = fd_guards.iter().take(10).collect();
|
||||||
|
tracing::Span::current().record("fd_guards", format!("{:?}...", small_list));
|
||||||
|
} else {
|
||||||
|
tracing::Span::current().record("fd_guards", format!("{:?}", fd_guards));
|
||||||
|
}
|
||||||
|
|
||||||
fd_guards
|
fd_guards
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(time_to_sleep) = time_to_sleep.as_ref() {
|
if let Some(time_to_sleep) = time_to_sleep.as_ref() {
|
||||||
if *time_to_sleep == Duration::ZERO {
|
if *time_to_sleep == Duration::ZERO {
|
||||||
tracing::trace!("wasi[{}:{}]::poll_oneoff non_blocking", pid, tid,);
|
Span::current().record("timeout_ns", "nonblocking");
|
||||||
} else {
|
} else {
|
||||||
tracing::trace!(
|
Span::current().record("timeout_ns", time_to_sleep.as_millis());
|
||||||
"wasi[{}:{}]::poll_oneoff wait_for_timeout={}",
|
|
||||||
pid,
|
|
||||||
tid,
|
|
||||||
time_to_sleep.as_millis()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tracing::trace!("wasi[{}:{}]::poll_oneoff wait_for_infinite", pid, tid,);
|
Span::current().record("timeout_ns", "infinite");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block polling the file descriptors
|
// Block polling the file descriptors
|
||||||
@@ -330,22 +298,13 @@ pub(crate) fn poll_oneoff_internal(
|
|||||||
match ret {
|
match ret {
|
||||||
Ok(evts) => {
|
Ok(evts) => {
|
||||||
// If its a timeout then return an event for it
|
// If its a timeout then return an event for it
|
||||||
tracing::trace!(
|
Span::current().record("seen", evts.len());
|
||||||
"wasi[{}:{}]::poll_oneoff seen={}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
evts.len()
|
|
||||||
);
|
|
||||||
Ok(Ok(evts))
|
Ok(Ok(evts))
|
||||||
}
|
}
|
||||||
Err(Errno::Timedout) => {
|
Err(Errno::Timedout) => {
|
||||||
// The timeout has triggerred so lets add that event
|
// The timeout has triggerred so lets add that event
|
||||||
if clock_subs.is_empty() && time_to_sleep != Some(Duration::ZERO) {
|
if clock_subs.is_empty() && time_to_sleep != Some(Duration::ZERO) {
|
||||||
tracing::warn!(
|
tracing::warn!("triggered_timeout (without any clock subscriptions)",);
|
||||||
"wasi[{}:{}]::poll_oneoff triggered_timeout (without any clock subscriptions)",
|
|
||||||
pid,
|
|
||||||
tid
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
let mut evts = Vec::new();
|
let mut evts = Vec::new();
|
||||||
for (clock_info, userdata) in clock_subs {
|
for (clock_info, userdata) in clock_subs {
|
||||||
@@ -355,12 +314,12 @@ pub(crate) fn poll_oneoff_internal(
|
|||||||
type_: Eventtype::Clock,
|
type_: Eventtype::Clock,
|
||||||
u: EventUnion { clock: 0 },
|
u: EventUnion { clock: 0 },
|
||||||
};
|
};
|
||||||
tracing::trace!(
|
Span::current().record(
|
||||||
"wasi[{}:{}]::poll_oneoff triggered_clock id={:?} (userdata={})",
|
"seen",
|
||||||
pid,
|
&format!(
|
||||||
tid,
|
"clock(id={},userdata={})",
|
||||||
clock_info.clock_id,
|
clock_info.clock_id as u32, evt.userdata
|
||||||
evt.userdata,
|
),
|
||||||
);
|
);
|
||||||
evts.push(evt);
|
evts.push(evt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,17 +8,11 @@ use crate::syscalls::*;
|
|||||||
/// Inputs:
|
/// Inputs:
|
||||||
/// - `ExitCode`
|
/// - `ExitCode`
|
||||||
/// Exit code to return to the operating system
|
/// Exit code to return to the operating system
|
||||||
|
#[instrument(level = "debug", skip_all, fields(code))]
|
||||||
pub fn proc_exit<M: MemorySize>(
|
pub fn proc_exit<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
code: ExitCode,
|
code: ExitCode,
|
||||||
) -> Result<(), WasiError> {
|
) -> Result<(), WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::proc_exit (code={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
code
|
|
||||||
);
|
|
||||||
|
|
||||||
// Set the exit code for this process
|
// Set the exit code for this process
|
||||||
ctx.data().thread.set_status_finished(Ok(code as u32));
|
ctx.data().thread.set_status_finished(Ok(code as u32));
|
||||||
|
|
||||||
@@ -44,7 +38,11 @@ pub fn proc_exit<M: MemorySize>(
|
|||||||
// Make sure its within the "active" part of the memory stack
|
// Make sure its within the "active" part of the memory stack
|
||||||
let offset = wasi_env.stack_base - pid_offset;
|
let offset = wasi_env.stack_base - pid_offset;
|
||||||
if offset as usize > memory_stack.len() {
|
if offset as usize > memory_stack.len() {
|
||||||
warn!("wasi[{}:{}]::vfork failed - the return value (pid) is outside of the active part of the memory stack ({} vs {})", ctx.data().pid(), ctx.data().tid(), offset, memory_stack.len());
|
warn!(
|
||||||
|
"fork failed - the return value (pid) is outside of the active part of the memory stack ({} vs {})",
|
||||||
|
offset,
|
||||||
|
memory_stack.len()
|
||||||
|
);
|
||||||
return Err(WasiError::Exit(Errno::Fault as u32));
|
return Err(WasiError::Exit(Errno::Fault as u32));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +53,9 @@ pub fn proc_exit<M: MemorySize>(
|
|||||||
let pbytes = &mut memory_stack[pstart..pend];
|
let pbytes = &mut memory_stack[pstart..pend];
|
||||||
pbytes.clone_from_slice(&val_bytes);
|
pbytes.clone_from_slice(&val_bytes);
|
||||||
} else {
|
} else {
|
||||||
warn!("wasi[{}:{}]::vfork failed - the return value (pid) is not being returned on the stack - which is not supported", ctx.data().pid(), ctx.data().tid());
|
warn!(
|
||||||
|
"fork failed - the return value (pid) is not being returned on the stack - which is not supported"
|
||||||
|
);
|
||||||
return Err(WasiError::Exit(Errno::Fault as u32));
|
return Err(WasiError::Exit(Errno::Fault as u32));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,8 @@ use crate::syscalls::*;
|
|||||||
/// Inputs:
|
/// Inputs:
|
||||||
/// - `Signal`
|
/// - `Signal`
|
||||||
/// Signal to be raised for this process
|
/// Signal to be raised for this process
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sig), ret, err)]
|
||||||
pub fn proc_raise(mut ctx: FunctionEnvMut<'_, WasiEnv>, sig: Signal) -> Result<Errno, WasiError> {
|
pub fn proc_raise(mut ctx: FunctionEnvMut<'_, WasiEnv>, sig: Signal) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::proc_raise (sig={:?})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sig
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
env.process.signal_process(sig);
|
env.process.signal_process(sig);
|
||||||
|
|
||||||
@@ -34,12 +29,6 @@ pub fn proc_raise_interval(
|
|||||||
interval: Timestamp,
|
interval: Timestamp,
|
||||||
repeat: Bool,
|
repeat: Bool,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::proc_raise_interval (sig={:?})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sig
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let interval = match interval {
|
let interval = match interval {
|
||||||
0 => None,
|
0 => None,
|
||||||
|
|||||||
@@ -8,17 +8,12 @@ use crate::syscalls::*;
|
|||||||
/// A pointer to a buffer where the random bytes will be written
|
/// A pointer to a buffer where the random bytes will be written
|
||||||
/// - `size_t buf_len`
|
/// - `size_t buf_len`
|
||||||
/// The number of bytes that will be written
|
/// The number of bytes that will be written
|
||||||
|
#[instrument(level = "trace", skip_all, fields(buf_len), ret)]
|
||||||
pub fn random_get<M: MemorySize>(
|
pub fn random_get<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
buf: WasmPtr<u8, M>,
|
buf: WasmPtr<u8, M>,
|
||||||
buf_len: M::Offset,
|
buf_len: M::Offset,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::random_get(buf_len={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
buf_len
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
let buf_len64: u64 = buf_len.into();
|
let buf_len64: u64 = buf_len.into();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::syscalls::*;
|
|||||||
/// ### Parameters
|
/// ### Parameters
|
||||||
///
|
///
|
||||||
/// * `name` - Name of the function that will be invoked
|
/// * `name` - Name of the function that will be invoked
|
||||||
|
#[instrument(level = "debug", skip_all, fields(name = field::Empty, funct_is_some = field::Empty), ret, err)]
|
||||||
pub fn callback_reactor<M: MemorySize>(
|
pub fn callback_reactor<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
name: WasmPtr<u8, M>,
|
name: WasmPtr<u8, M>,
|
||||||
@@ -15,12 +16,7 @@ pub fn callback_reactor<M: MemorySize>(
|
|||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
let name = unsafe { name.read_utf8_string(&memory, name_len)? };
|
let name = unsafe { name.read_utf8_string(&memory, name_len)? };
|
||||||
debug!(
|
Span::current().record("name", name.as_str());
|
||||||
"wasi[{}:{}]::callback_reactor (name={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
name
|
|
||||||
);
|
|
||||||
|
|
||||||
let funct = env
|
let funct = env
|
||||||
.inner()
|
.inner()
|
||||||
@@ -28,6 +24,7 @@ pub fn callback_reactor<M: MemorySize>(
|
|||||||
.exports
|
.exports
|
||||||
.get_typed_function(&ctx, &name)
|
.get_typed_function(&ctx, &name)
|
||||||
.ok();
|
.ok();
|
||||||
|
Span::current().record("funct_is_some", funct.is_some());
|
||||||
|
|
||||||
ctx.data_mut().inner_mut().react = funct;
|
ctx.data_mut().inner_mut().react = funct;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::syscalls::*;
|
|||||||
/// ### Parameters
|
/// ### Parameters
|
||||||
///
|
///
|
||||||
/// * `name` - Name of the function that will be invoked
|
/// * `name` - Name of the function that will be invoked
|
||||||
|
#[instrument(level = "trace", skip_all, fields(name = field::Empty, funct_is_some = field::Empty), ret, err)]
|
||||||
pub fn callback_signal<M: MemorySize>(
|
pub fn callback_signal<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
name: WasmPtr<u8, M>,
|
name: WasmPtr<u8, M>,
|
||||||
@@ -26,6 +27,7 @@ pub fn callback_signal<M: MemorySize>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Span::current().record("name", name.as_str());
|
||||||
|
|
||||||
let funct = env
|
let funct = env
|
||||||
.inner()
|
.inner()
|
||||||
@@ -33,13 +35,7 @@ pub fn callback_signal<M: MemorySize>(
|
|||||||
.exports
|
.exports
|
||||||
.get_typed_function(&ctx, &name)
|
.get_typed_function(&ctx, &name)
|
||||||
.ok();
|
.ok();
|
||||||
trace!(
|
Span::current().record("funct_is_some", funct.is_some());
|
||||||
"wasi[{}:{}]::callback_signal (name={}, found={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
name,
|
|
||||||
funct.is_some()
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let inner = ctx.data_mut().inner_mut();
|
let inner = ctx.data_mut().inner_mut();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::syscalls::*;
|
|||||||
/// ### Parameters
|
/// ### Parameters
|
||||||
///
|
///
|
||||||
/// * `name` - Name of the function that will be invoked
|
/// * `name` - Name of the function that will be invoked
|
||||||
|
#[instrument(level = "debug", skip_all, fields(name = field::Empty, funct_is_some = field::Empty), ret ,err)]
|
||||||
pub fn callback_thread<M: MemorySize>(
|
pub fn callback_thread<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
name: WasmPtr<u8, M>,
|
name: WasmPtr<u8, M>,
|
||||||
@@ -14,13 +15,9 @@ pub fn callback_thread<M: MemorySize>(
|
|||||||
) -> Result<(), MemoryAccessError> {
|
) -> Result<(), MemoryAccessError> {
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
let name = unsafe { name.read_utf8_string(&memory, name_len)? };
|
let name = unsafe { name.read_utf8_string(&memory, name_len)? };
|
||||||
debug!(
|
Span::current().record("name", name.as_str());
|
||||||
"wasi[{}:{}]::callback_spawn (name={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
name
|
|
||||||
);
|
|
||||||
|
|
||||||
let funct = env
|
let funct = env
|
||||||
.inner()
|
.inner()
|
||||||
@@ -28,6 +25,7 @@ pub fn callback_thread<M: MemorySize>(
|
|||||||
.exports
|
.exports
|
||||||
.get_typed_function(&ctx, &name)
|
.get_typed_function(&ctx, &name)
|
||||||
.ok();
|
.ok();
|
||||||
|
Span::current().record("funct_is_some", funct.is_some());
|
||||||
|
|
||||||
ctx.data_mut().inner_mut().thread_spawn = funct;
|
ctx.data_mut().inner_mut().thread_spawn = funct;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::syscalls::*;
|
|||||||
/// ### Parameters
|
/// ### Parameters
|
||||||
///
|
///
|
||||||
/// * `name` - Name of the function that will be invoked
|
/// * `name` - Name of the function that will be invoked
|
||||||
|
#[instrument(level = "debug", skip_all, fields(name = field::Empty, funct_is_some = field::Empty), ret, err)]
|
||||||
pub fn callback_thread_local_destroy<M: MemorySize>(
|
pub fn callback_thread_local_destroy<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
name: WasmPtr<u8, M>,
|
name: WasmPtr<u8, M>,
|
||||||
@@ -14,13 +15,9 @@ pub fn callback_thread_local_destroy<M: MemorySize>(
|
|||||||
) -> Result<(), MemoryAccessError> {
|
) -> Result<(), MemoryAccessError> {
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
let name = unsafe { name.read_utf8_string(&memory, name_len)? };
|
let name = unsafe { name.read_utf8_string(&memory, name_len)? };
|
||||||
debug!(
|
Span::current().record("name", name.as_str());
|
||||||
"wasi[{}:{}]::callback_thread_local_destroy (name={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
name
|
|
||||||
);
|
|
||||||
|
|
||||||
let funct = env
|
let funct = env
|
||||||
.inner()
|
.inner()
|
||||||
@@ -28,6 +25,7 @@ pub fn callback_thread_local_destroy<M: MemorySize>(
|
|||||||
.exports
|
.exports
|
||||||
.get_typed_function(&ctx, &name)
|
.get_typed_function(&ctx, &name)
|
||||||
.ok();
|
.ok();
|
||||||
|
Span::current().record("funct_is_some", funct.is_some());
|
||||||
|
|
||||||
ctx.data_mut().inner_mut().thread_local_destroy = funct;
|
ctx.data_mut().inner_mut().thread_local_destroy = funct;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::syscalls::*;
|
|||||||
|
|
||||||
/// ### `chdir()`
|
/// ### `chdir()`
|
||||||
/// Sets the current working directory
|
/// Sets the current working directory
|
||||||
|
#[instrument(level = "debug", skip_all, fields(name = field::Empty), ret)]
|
||||||
pub fn chdir<M: MemorySize>(
|
pub fn chdir<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
path: WasmPtr<u8, M>,
|
path: WasmPtr<u8, M>,
|
||||||
@@ -11,12 +12,7 @@ pub fn chdir<M: MemorySize>(
|
|||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
let (memory, mut state) = env.get_memory_and_wasi_state(&ctx, 0);
|
||||||
let path = unsafe { get_input_str!(&memory, path, path_len) };
|
let path = unsafe { get_input_str!(&memory, path, path_len) };
|
||||||
debug!(
|
Span::current().record("path", path.as_str());
|
||||||
"wasi[{}:{}]::chdir [{}]",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
path
|
|
||||||
);
|
|
||||||
|
|
||||||
// Check if the directory exists
|
// Check if the directory exists
|
||||||
if state.fs.root_fs.read_dir(Path::new(path.as_str())).is_err() {
|
if state.fs.root_fs.read_dir(Path::new(path.as_str())).is_err() {
|
||||||
|
|||||||
@@ -10,13 +10,12 @@ use crate::syscalls::*;
|
|||||||
/// First file handle that represents one end of the pipe
|
/// First file handle that represents one end of the pipe
|
||||||
/// - `Fd`
|
/// - `Fd`
|
||||||
/// Second file handle that represents the other end of the pipe
|
/// Second file handle that represents the other end of the pipe
|
||||||
|
#[instrument(level = "trace", skip_all, fields(fd1 = field::Empty, fd2 = field::Empty), ret)]
|
||||||
pub fn fd_pipe<M: MemorySize>(
|
pub fn fd_pipe<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
ro_fd1: WasmPtr<WasiFd, M>,
|
ro_fd1: WasmPtr<WasiFd, M>,
|
||||||
ro_fd2: WasmPtr<WasiFd, M>,
|
ro_fd2: WasmPtr<WasiFd, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
trace!("wasi[{}:{}]::fd_pipe", ctx.data().pid(), ctx.data().tid());
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
|
|
||||||
@@ -47,13 +46,7 @@ pub fn fd_pipe<M: MemorySize>(
|
|||||||
let fd2 = wasi_try!(state
|
let fd2 = wasi_try!(state
|
||||||
.fs
|
.fs
|
||||||
.create_fd(rights, rights, Fdflags::empty(), 0, inode2));
|
.create_fd(rights, rights, Fdflags::empty(), 0, inode2));
|
||||||
trace!(
|
Span::current().record("fd1", fd1).record("fd2", fd2);
|
||||||
"wasi[{}:{}]::fd_pipe (fd1={}, fd2={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd1,
|
|
||||||
fd2
|
|
||||||
);
|
|
||||||
|
|
||||||
wasi_try_mem!(ro_fd1.write(&memory, fd1));
|
wasi_try_mem!(ro_fd1.write(&memory, fd1));
|
||||||
wasi_try_mem!(ro_fd2.write(&memory, fd2));
|
wasi_try_mem!(ro_fd2.write(&memory, fd2));
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ where
|
|||||||
/// * `futex` - Memory location that holds the value that will be checked
|
/// * `futex` - Memory location that holds the value that will be checked
|
||||||
/// * `expected` - Expected value that should be currently held at the memory location
|
/// * `expected` - Expected value that should be currently held at the memory location
|
||||||
/// * `timeout` - Timeout should the futex not be triggered in the allocated time
|
/// * `timeout` - Timeout should the futex not be triggered in the allocated time
|
||||||
|
#[instrument(level = "trace", skip_all, fields(futex_idx = field::Empty, expected, timeout = field::Empty, woken = field::Empty), err)]
|
||||||
pub fn futex_wait<M: MemorySize>(
|
pub fn futex_wait<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
futex_ptr: WasmPtr<u32, M>,
|
futex_ptr: WasmPtr<u32, M>,
|
||||||
@@ -85,17 +86,11 @@ pub fn futex_wait<M: MemorySize>(
|
|||||||
OptionTag::Some => Some(Duration::from_nanos(timeout.u as u64)),
|
OptionTag::Some => Some(Duration::from_nanos(timeout.u as u64)),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
Span::current().record("timeout", &format!("{:?}", timeout));
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::futex_wait(offset={}, timeout={:?})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
futex_ptr.offset(),
|
|
||||||
timeout
|
|
||||||
);
|
|
||||||
|
|
||||||
let state = env.state.clone();
|
let state = env.state.clone();
|
||||||
let futex_idx: u64 = wasi_try_ok!(futex_ptr.offset().try_into().map_err(|_| Errno::Overflow));
|
let futex_idx: u64 = wasi_try_ok!(futex_ptr.offset().try_into().map_err(|_| Errno::Overflow));
|
||||||
|
Span::current().record("futex_idx", futex_idx);
|
||||||
|
|
||||||
// Create a poller which will register ourselves against
|
// Create a poller which will register ourselves against
|
||||||
// this futex event and check when it has changed
|
// this futex event and check when it has changed
|
||||||
@@ -121,6 +116,8 @@ pub fn futex_wait<M: MemorySize>(
|
|||||||
}
|
}
|
||||||
Ok(_) => Bool::True,
|
Ok(_) => Bool::True,
|
||||||
};
|
};
|
||||||
|
Span::current().record("woken", woken as u8);
|
||||||
|
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
let mut env = ctx.data();
|
let mut env = ctx.data();
|
||||||
wasi_try_mem_ok!(ret_woken.write(&memory, woken));
|
wasi_try_mem_ok!(ret_woken.write(&memory, woken));
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use crate::syscalls::*;
|
|||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
///
|
///
|
||||||
/// * `futex` - Memory location that holds a futex that others may be waiting on
|
/// * `futex` - Memory location that holds a futex that others may be waiting on
|
||||||
|
#[instrument(level = "trace", skip_all, fields(futex_idx = field::Empty, woken = field::Empty), ret)]
|
||||||
pub fn futex_wake<M: MemorySize>(
|
pub fn futex_wake<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
futex_ptr: WasmPtr<u32, M>,
|
futex_ptr: WasmPtr<u32, M>,
|
||||||
@@ -18,8 +19,9 @@ pub fn futex_wake<M: MemorySize>(
|
|||||||
let state = env.state.deref();
|
let state = env.state.deref();
|
||||||
|
|
||||||
let pointer: u64 = wasi_try!(futex_ptr.offset().try_into().map_err(|_| Errno::Overflow));
|
let pointer: u64 = wasi_try!(futex_ptr.offset().try_into().map_err(|_| Errno::Overflow));
|
||||||
let mut woken = false;
|
Span::current().record("futex_idx", pointer);
|
||||||
|
|
||||||
|
let mut woken = false;
|
||||||
let woken = {
|
let woken = {
|
||||||
let mut guard = state.futexs.lock().unwrap();
|
let mut guard = state.futexs.lock().unwrap();
|
||||||
if let Some(futex) = guard.get_mut(&pointer) {
|
if let Some(futex) = guard.get_mut(&pointer) {
|
||||||
@@ -34,22 +36,7 @@ pub fn futex_wake<M: MemorySize>(
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if woken {
|
Span::current().record("woken", woken);
|
||||||
trace!(
|
|
||||||
%woken,
|
|
||||||
"wasi[{}:{}]::futex_wake(offset={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
futex_ptr.offset()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::futex_wake(offset={}) - nothing waiting",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
futex_ptr.offset()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let woken = match woken {
|
let woken = match woken {
|
||||||
false => Bool::False,
|
false => Bool::False,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use crate::syscalls::*;
|
|||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
///
|
///
|
||||||
/// * `futex` - Memory location that holds a futex that others may be waiting on
|
/// * `futex` - Memory location that holds a futex that others may be waiting on
|
||||||
|
#[instrument(level = "trace", skip_all, fields(futex_idx = field::Empty, woken = field::Empty), ret)]
|
||||||
pub fn futex_wake_all<M: MemorySize>(
|
pub fn futex_wake_all<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
futex_ptr: WasmPtr<u32, M>,
|
futex_ptr: WasmPtr<u32, M>,
|
||||||
@@ -16,8 +17,9 @@ pub fn futex_wake_all<M: MemorySize>(
|
|||||||
let state = env.state.deref();
|
let state = env.state.deref();
|
||||||
|
|
||||||
let pointer: u64 = wasi_try!(futex_ptr.offset().try_into().map_err(|_| Errno::Overflow));
|
let pointer: u64 = wasi_try!(futex_ptr.offset().try_into().map_err(|_| Errno::Overflow));
|
||||||
let mut woken = false;
|
Span::current().record("futex_idx", pointer);
|
||||||
|
|
||||||
|
let mut woken = false;
|
||||||
let woken = {
|
let woken = {
|
||||||
let mut guard = state.futexs.lock().unwrap();
|
let mut guard = state.futexs.lock().unwrap();
|
||||||
if let Some(futex) = guard.remove(&pointer) {
|
if let Some(futex) = guard.remove(&pointer) {
|
||||||
@@ -27,22 +29,7 @@ pub fn futex_wake_all<M: MemorySize>(
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if woken {
|
Span::current().record("woken", woken);
|
||||||
trace!(
|
|
||||||
%woken,
|
|
||||||
"wasi[{}:{}]::futex_wake(offset={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
futex_ptr.offset()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::futex_wake(offset={}) - nothing waiting",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
futex_ptr.offset()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let woken = match woken {
|
let woken = match woken {
|
||||||
false => Bool::False,
|
false => Bool::False,
|
||||||
|
|||||||
@@ -5,26 +5,22 @@ use crate::syscalls::*;
|
|||||||
/// Returns the current working directory
|
/// Returns the current working directory
|
||||||
/// If the path exceeds the size of the buffer then this function
|
/// If the path exceeds the size of the buffer then this function
|
||||||
/// will fill the path_len with the needed size and return EOVERFLOW
|
/// will fill the path_len with the needed size and return EOVERFLOW
|
||||||
|
#[instrument(level = "debug", skip_all, fields(path = field::Empty, max_path_len = field::Empty), ret)]
|
||||||
pub fn getcwd<M: MemorySize>(
|
pub fn getcwd<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
path: WasmPtr<u8, M>,
|
path: WasmPtr<u8, M>,
|
||||||
path_len: WasmPtr<M::Offset, M>,
|
path_len: WasmPtr<M::Offset, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!("wasi[{}:{}]::getcwd", ctx.data().pid(), ctx.data().tid());
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
let (memory, mut state, inodes) = env.get_memory_and_wasi_state_and_inodes(&ctx, 0);
|
||||||
|
|
||||||
let (_, cur_dir) = wasi_try!(state.fs.get_current_dir(inodes, crate::VIRTUAL_ROOT_FD,));
|
let (_, cur_dir) = wasi_try!(state.fs.get_current_dir(inodes, crate::VIRTUAL_ROOT_FD,));
|
||||||
trace!(
|
Span::current().record("path", cur_dir.as_str());
|
||||||
"wasi[{}:{}]::getcwd(current_dir={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
cur_dir
|
|
||||||
);
|
|
||||||
|
|
||||||
let max_path_len = wasi_try_mem!(path_len.read(&memory));
|
let max_path_len = wasi_try_mem!(path_len.read(&memory));
|
||||||
let path_slice = wasi_try_mem!(path.slice(&memory, max_path_len));
|
let path_slice = wasi_try_mem!(path.slice(&memory, max_path_len));
|
||||||
let max_path_len: u64 = max_path_len.into();
|
let max_path_len: u64 = max_path_len.into();
|
||||||
|
Span::current().record("max_path_len", max_path_len);
|
||||||
|
|
||||||
let cur_dir = cur_dir.as_bytes();
|
let cur_dir = cur_dir.as_bytes();
|
||||||
wasi_try_mem!(path_len.write(&memory, wasi_try!(to_offset::<M>(cur_dir.len()))));
|
wasi_try_mem!(path_len.write(&memory, wasi_try!(to_offset::<M>(cur_dir.len()))));
|
||||||
|
|||||||
@@ -141,3 +141,5 @@ pub use thread_sleep::*;
|
|||||||
pub use thread_spawn::*;
|
pub use thread_spawn::*;
|
||||||
pub use tty_get::*;
|
pub use tty_get::*;
|
||||||
pub use tty_set::*;
|
pub use tty_set::*;
|
||||||
|
|
||||||
|
use tracing::{debug_span, field, instrument, trace_span, Span};
|
||||||
|
|||||||
@@ -7,18 +7,17 @@ use crate::syscalls::*;
|
|||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
///
|
///
|
||||||
/// * `addr` - Address to be added
|
/// * `addr` - Address to be added
|
||||||
|
#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret, err)]
|
||||||
pub fn port_addr_add<M: MemorySize>(
|
pub fn port_addr_add<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
ip: WasmPtr<__wasi_cidr_t, M>,
|
ip: WasmPtr<__wasi_cidr_t, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_addr_add",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
let cidr = wasi_try_ok!(crate::net::read_cidr(&memory, ip));
|
let cidr = wasi_try_ok!(crate::net::read_cidr(&memory, ip));
|
||||||
|
Span::current().record("ip", &format!("{:?}", cidr));
|
||||||
|
|
||||||
let net = env.net().clone();
|
let net = env.net().clone();
|
||||||
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
||||||
net.ip_add(cidr.ip, cidr.prefix)
|
net.ip_add(cidr.ip, cidr.prefix)
|
||||||
|
|||||||
@@ -3,12 +3,8 @@ use crate::syscalls::*;
|
|||||||
|
|
||||||
/// ### `port_addr_clear()`
|
/// ### `port_addr_clear()`
|
||||||
/// Clears all the addresses on the local port
|
/// Clears all the addresses on the local port
|
||||||
|
#[instrument(level = "debug", skip_all, ret, err)]
|
||||||
pub fn port_addr_clear(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
|
pub fn port_addr_clear(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_addr_clear",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let net = env.net().clone();
|
let net = env.net().clone();
|
||||||
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
||||||
|
|||||||
@@ -14,16 +14,12 @@ use crate::syscalls::*;
|
|||||||
/// ## Return
|
/// ## Return
|
||||||
///
|
///
|
||||||
/// The number of addresses returned.
|
/// The number of addresses returned.
|
||||||
|
#[instrument(level = "debug", skip_all, fields(naddrs = field::Empty)ret, err)]
|
||||||
pub fn port_addr_list<M: MemorySize>(
|
pub fn port_addr_list<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
addrs_ptr: WasmPtr<__wasi_cidr_t, M>,
|
addrs_ptr: WasmPtr<__wasi_cidr_t, M>,
|
||||||
naddrs_ptr: WasmPtr<M::Offset, M>,
|
naddrs_ptr: WasmPtr<M::Offset, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_addr_list",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let mut env = ctx.data();
|
let mut env = ctx.data();
|
||||||
let mut memory = env.memory_view(&ctx);
|
let mut memory = env.memory_view(&ctx);
|
||||||
let max_addrs = wasi_try_mem_ok!(naddrs_ptr.read(&memory));
|
let max_addrs = wasi_try_mem_ok!(naddrs_ptr.read(&memory));
|
||||||
@@ -35,6 +31,7 @@ pub fn port_addr_list<M: MemorySize>(
|
|||||||
})?);
|
})?);
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
Span::current().record("naddrs", addrs.len());
|
||||||
|
|
||||||
let addrs_len: M::Offset = wasi_try_ok!(addrs.len().try_into().map_err(|_| Errno::Overflow));
|
let addrs_len: M::Offset = wasi_try_ok!(addrs.len().try_into().map_err(|_| Errno::Overflow));
|
||||||
wasi_try_mem_ok!(naddrs_ptr.write(&memory, addrs_len));
|
wasi_try_mem_ok!(naddrs_ptr.write(&memory, addrs_len));
|
||||||
|
|||||||
@@ -7,18 +7,17 @@ use crate::syscalls::*;
|
|||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
///
|
///
|
||||||
/// * `addr` - Address to be removed
|
/// * `addr` - Address to be removed
|
||||||
|
#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret, err)]
|
||||||
pub fn port_addr_remove<M: MemorySize>(
|
pub fn port_addr_remove<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
ip: WasmPtr<__wasi_addr_t, M>,
|
ip: WasmPtr<__wasi_addr_t, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_addr_remove",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
let ip = wasi_try_ok!(crate::net::read_ip(&memory, ip));
|
let ip = wasi_try_ok!(crate::net::read_ip(&memory, ip));
|
||||||
|
Span::current().record("ip", &format!("{:?}", ip));
|
||||||
|
|
||||||
let net = env.net().clone();
|
let net = env.net().clone();
|
||||||
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
||||||
net.ip_remove(ip).map_err(net_error_into_wasi_err)
|
net.ip_remove(ip).map_err(net_error_into_wasi_err)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use crate::syscalls::*;
|
|||||||
/// * `network` - Fully qualified identifier for the network
|
/// * `network` - Fully qualified identifier for the network
|
||||||
/// * `token` - Access token used to authenticate with the network
|
/// * `token` - Access token used to authenticate with the network
|
||||||
/// * `security` - Level of encryption to encapsulate the network connection with
|
/// * `security` - Level of encryption to encapsulate the network connection with
|
||||||
|
#[instrument(level = "debug", skip_all, fields(network = field::Empty, security), ret, err)]
|
||||||
pub fn port_bridge<M: MemorySize>(
|
pub fn port_bridge<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
network: WasmPtr<u8, M>,
|
network: WasmPtr<u8, M>,
|
||||||
@@ -17,14 +18,12 @@ pub fn port_bridge<M: MemorySize>(
|
|||||||
token_len: M::Offset,
|
token_len: M::Offset,
|
||||||
security: Streamsecurity,
|
security: Streamsecurity,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_bridge",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
let network = unsafe { get_input_str_ok!(&memory, network, network_len) };
|
let network = unsafe { get_input_str_ok!(&memory, network, network_len) };
|
||||||
|
Span::current().record("network", network.as_str());
|
||||||
|
|
||||||
let token = unsafe { get_input_str_ok!(&memory, token, token_len) };
|
let token = unsafe { get_input_str_ok!(&memory, token, token_len) };
|
||||||
let security = match security {
|
let security = match security {
|
||||||
Streamsecurity::Unencrypted => StreamSecurity::Unencrypted,
|
Streamsecurity::Unencrypted => StreamSecurity::Unencrypted,
|
||||||
|
|||||||
@@ -3,12 +3,8 @@ use crate::syscalls::*;
|
|||||||
|
|
||||||
/// ### `port_dhcp_acquire()`
|
/// ### `port_dhcp_acquire()`
|
||||||
/// Acquires a set of IP addresses using DHCP
|
/// Acquires a set of IP addresses using DHCP
|
||||||
|
#[instrument(level = "debug", skip_all, ret, err)]
|
||||||
pub fn port_dhcp_acquire(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
|
pub fn port_dhcp_acquire(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_dhcp_acquire",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let net = env.net().clone();
|
let net = env.net().clone();
|
||||||
let tasks = env.tasks().clone();
|
let tasks = env.tasks().clone();
|
||||||
|
|||||||
@@ -7,18 +7,16 @@ use crate::syscalls::*;
|
|||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
///
|
///
|
||||||
/// * `addr` - Address of the default gateway
|
/// * `addr` - Address of the default gateway
|
||||||
|
#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret, err)]
|
||||||
pub fn port_gateway_set<M: MemorySize>(
|
pub fn port_gateway_set<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
ip: WasmPtr<__wasi_addr_t, M>,
|
ip: WasmPtr<__wasi_addr_t, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_gateway_set",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
let ip = wasi_try_ok!(crate::net::read_ip(&memory, ip));
|
let ip = wasi_try_ok!(crate::net::read_ip(&memory, ip));
|
||||||
|
Span::current().record("ip", &format!("{:?}", ip));
|
||||||
|
|
||||||
let net = env.net().clone();
|
let net = env.net().clone();
|
||||||
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ use crate::syscalls::*;
|
|||||||
|
|
||||||
/// ### `port_mac()`
|
/// ### `port_mac()`
|
||||||
/// Returns the MAC address of the local port
|
/// Returns the MAC address of the local port
|
||||||
|
#[instrument(level = "debug", skip_all, fields(max = field::Empty), ret, err)]
|
||||||
pub fn port_mac<M: MemorySize>(
|
pub fn port_mac<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
ret_mac: WasmPtr<__wasi_hardwareaddress_t, M>,
|
ret_mac: WasmPtr<__wasi_hardwareaddress_t, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!("wasi[{}:{}]::port_mac", ctx.data().pid(), ctx.data().tid());
|
|
||||||
let mut env = ctx.data();
|
let mut env = ctx.data();
|
||||||
let mut memory = env.memory_view(&ctx);
|
let mut memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
@@ -18,6 +18,8 @@ pub fn port_mac<M: MemorySize>(
|
|||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
|
Span::current().record("mac", hex::encode(mac.as_ref()).as_str());
|
||||||
|
|
||||||
let mac = __wasi_hardwareaddress_t { octs: mac };
|
let mac = __wasi_hardwareaddress_t { octs: mac };
|
||||||
wasi_try_mem_ok!(ret_mac.write(&memory, mac));
|
wasi_try_mem_ok!(ret_mac.write(&memory, mac));
|
||||||
Ok(Errno::Success)
|
Ok(Errno::Success)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::syscalls::*;
|
|||||||
|
|
||||||
/// ### `port_route_add()`
|
/// ### `port_route_add()`
|
||||||
/// Adds a new route to the local port
|
/// Adds a new route to the local port
|
||||||
|
#[instrument(level = "debug", skip_all, fields(cidr = field::Empty, via_router = field::Empty), ret, err)]
|
||||||
pub fn port_route_add<M: MemorySize>(
|
pub fn port_route_add<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
cidr: WasmPtr<__wasi_cidr_t, M>,
|
cidr: WasmPtr<__wasi_cidr_t, M>,
|
||||||
@@ -10,15 +11,15 @@ pub fn port_route_add<M: MemorySize>(
|
|||||||
preferred_until: WasmPtr<OptionTimestamp, M>,
|
preferred_until: WasmPtr<OptionTimestamp, M>,
|
||||||
expires_at: WasmPtr<OptionTimestamp, M>,
|
expires_at: WasmPtr<OptionTimestamp, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_route_add",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
let cidr = wasi_try_ok!(crate::net::read_cidr(&memory, cidr));
|
let cidr = wasi_try_ok!(crate::net::read_cidr(&memory, cidr));
|
||||||
|
Span::current().record("cidr", &format!("{:?}", cidr));
|
||||||
|
|
||||||
let via_router = wasi_try_ok!(crate::net::read_ip(&memory, via_router));
|
let via_router = wasi_try_ok!(crate::net::read_ip(&memory, via_router));
|
||||||
|
Span::current().record("via_router", &format!("{:?}", via_router));
|
||||||
|
|
||||||
let preferred_until = wasi_try_mem_ok!(preferred_until.read(&memory));
|
let preferred_until = wasi_try_mem_ok!(preferred_until.read(&memory));
|
||||||
let preferred_until = match preferred_until.tag {
|
let preferred_until = match preferred_until.tag {
|
||||||
OptionTag::None => None,
|
OptionTag::None => None,
|
||||||
|
|||||||
@@ -3,12 +3,8 @@ use crate::syscalls::*;
|
|||||||
|
|
||||||
/// ### `port_route_clear()`
|
/// ### `port_route_clear()`
|
||||||
/// Clears all the routes in the local port
|
/// Clears all the routes in the local port
|
||||||
|
#[instrument(level = "debug", skip_all, ret, err)]
|
||||||
pub fn port_route_clear(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
|
pub fn port_route_clear(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_route_clear",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let net = env.net().clone();
|
let net = env.net().clone();
|
||||||
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
||||||
|
|||||||
@@ -10,22 +10,19 @@ use crate::syscalls::*;
|
|||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
///
|
///
|
||||||
/// * `routes` - The buffer where routes will be stored
|
/// * `routes` - The buffer where routes will be stored
|
||||||
|
#[instrument(level = "debug", skip_all, fields(nroutes = field::Empty, max_routes = field::Empty), ret, err)]
|
||||||
pub fn port_route_list<M: MemorySize>(
|
pub fn port_route_list<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
routes_ptr: WasmPtr<Route, M>,
|
routes_ptr: WasmPtr<Route, M>,
|
||||||
nroutes_ptr: WasmPtr<M::Offset, M>,
|
nroutes_ptr: WasmPtr<M::Offset, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_route_list",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let mut env = ctx.data();
|
let mut env = ctx.data();
|
||||||
let mut memory = env.memory_view(&ctx);
|
let mut memory = env.memory_view(&ctx);
|
||||||
let ref_nroutes = nroutes_ptr.deref(&memory);
|
let ref_nroutes = nroutes_ptr.deref(&memory);
|
||||||
let max_routes: usize = wasi_try_ok!(wasi_try_mem_ok!(ref_nroutes.read())
|
let max_routes: usize = wasi_try_ok!(wasi_try_mem_ok!(ref_nroutes.read())
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|_| Errno::Inval));
|
.map_err(|_| Errno::Inval));
|
||||||
|
Span::current().record("max_routes", max_routes);
|
||||||
let ref_routes =
|
let ref_routes =
|
||||||
wasi_try_mem_ok!(routes_ptr.slice(&memory, wasi_try_ok!(to_offset::<M>(max_routes))));
|
wasi_try_mem_ok!(routes_ptr.slice(&memory, wasi_try_ok!(to_offset::<M>(max_routes))));
|
||||||
|
|
||||||
@@ -33,6 +30,8 @@ pub fn port_route_list<M: MemorySize>(
|
|||||||
let routes = wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
let routes = wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
||||||
net.route_list().map_err(net_error_into_wasi_err)
|
net.route_list().map_err(net_error_into_wasi_err)
|
||||||
})?);
|
})?);
|
||||||
|
Span::current().record("nroutes", routes.len());
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
|
|||||||
@@ -3,18 +3,16 @@ use crate::syscalls::*;
|
|||||||
|
|
||||||
/// ### `port_route_remove()`
|
/// ### `port_route_remove()`
|
||||||
/// Removes an existing route from the local port
|
/// Removes an existing route from the local port
|
||||||
|
#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret, err)]
|
||||||
pub fn port_route_remove<M: MemorySize>(
|
pub fn port_route_remove<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
ip: WasmPtr<__wasi_addr_t, M>,
|
ip: WasmPtr<__wasi_addr_t, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_route_remove",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
let ip = wasi_try_ok!(crate::net::read_ip(&memory, ip));
|
let ip = wasi_try_ok!(crate::net::read_ip(&memory, ip));
|
||||||
|
Span::current().record("ip", &format!("{:?}", ip));
|
||||||
|
|
||||||
let net = env.net().clone();
|
let net = env.net().clone();
|
||||||
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
wasi_try_ok!(__asyncify(&mut ctx, None, async {
|
||||||
|
|||||||
@@ -3,12 +3,8 @@ use crate::syscalls::*;
|
|||||||
|
|
||||||
/// ### `port_unbridge()`
|
/// ### `port_unbridge()`
|
||||||
/// Disconnects from a remote network
|
/// Disconnects from a remote network
|
||||||
|
#[instrument(level = "debug", skip_all, ret, err)]
|
||||||
pub fn port_unbridge(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
|
pub fn port_unbridge(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::port_unbridge",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let net = env.net().clone();
|
let net = env.net().clone();
|
||||||
wasi_try_ok!(__asyncify(&mut ctx, None, async move {
|
wasi_try_ok!(__asyncify(&mut ctx, None, async move {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use crate::{
|
|||||||
/// ## Return
|
/// ## Return
|
||||||
///
|
///
|
||||||
/// Returns a bus process id that can be used to invoke calls
|
/// Returns a bus process id that can be used to invoke calls
|
||||||
|
#[instrument(level = "debug", skip_all, fields(name = field::Empty, args_len), ret, err)]
|
||||||
pub fn proc_exec<M: MemorySize>(
|
pub fn proc_exec<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
name: WasmPtr<u8, M>,
|
name: WasmPtr<u8, M>,
|
||||||
@@ -27,13 +28,7 @@ pub fn proc_exec<M: MemorySize>(
|
|||||||
warn!("failed to execve as the name could not be read - {}", err);
|
warn!("failed to execve as the name could not be read - {}", err);
|
||||||
WasiError::Exit(Errno::Fault as ExitCode)
|
WasiError::Exit(Errno::Fault as ExitCode)
|
||||||
})?;
|
})?;
|
||||||
trace!(
|
Span::current().record("name", name.as_str());
|
||||||
"wasi[{}:{}]::proc_exec (name={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
name
|
|
||||||
);
|
|
||||||
|
|
||||||
let args = args.read_utf8_string(&memory, args_len).map_err(|err| {
|
let args = args.read_utf8_string(&memory, args_len).map_err(|err| {
|
||||||
warn!("failed to execve as the args could not be read - {}", err);
|
warn!("failed to execve as the args could not be read - {}", err);
|
||||||
WasiError::Exit(Errno::Fault as ExitCode)
|
WasiError::Exit(Errno::Fault as ExitCode)
|
||||||
@@ -47,13 +42,8 @@ pub fn proc_exec<M: MemorySize>(
|
|||||||
// Convert relative paths into absolute paths
|
// Convert relative paths into absolute paths
|
||||||
if name.starts_with("./") {
|
if name.starts_with("./") {
|
||||||
name = ctx.data().state.fs.relative_path_to_absolute(name);
|
name = ctx.data().state.fs.relative_path_to_absolute(name);
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::rel_to_abs (name={}))",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
name
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
trace!(name);
|
||||||
|
|
||||||
// Convert the preopen directories
|
// Convert the preopen directories
|
||||||
let preopen = ctx.data().state.preopen.clone();
|
let preopen = ctx.data().state.preopen.clone();
|
||||||
@@ -103,12 +93,7 @@ pub fn proc_exec<M: MemorySize>(
|
|||||||
Ok(a) => Some(a),
|
Ok(a) => Some(a),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if err != VirtualBusError::NotFound {
|
if err != VirtualBusError::NotFound {
|
||||||
error!(
|
error!("builtin failed - {}", err);
|
||||||
"wasi[{}:{}]::proc_exec - builtin failed - {}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_store = new_store.take().unwrap();
|
let new_store = new_store.take().unwrap();
|
||||||
@@ -149,21 +134,11 @@ pub fn proc_exec<M: MemorySize>(
|
|||||||
// exit code can be processed
|
// exit code can be processed
|
||||||
let process = match process {
|
let process = match process {
|
||||||
Some(a) => {
|
Some(a) => {
|
||||||
trace!(
|
trace!("spawned sub-process (pid={})", child_pid.raw());
|
||||||
"wasi[{}:{}]::spawned sub-process (pid={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
child_pid.raw()
|
|
||||||
);
|
|
||||||
a
|
a
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
debug!(
|
debug!("process failed with (err={})", err_exit_code);
|
||||||
"wasi[{}:{}]::process failed with (err={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
err_exit_code
|
|
||||||
);
|
|
||||||
OwnedTaskStatus::new(TaskStatus::Finished(Ok(err_exit_code))).handle()
|
OwnedTaskStatus::new(TaskStatus::Finished(Ok(err_exit_code))).handle()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -185,7 +160,11 @@ pub fn proc_exec<M: MemorySize>(
|
|||||||
// Make sure its within the "active" part of the memory stack
|
// Make sure its within the "active" part of the memory stack
|
||||||
let offset = stack_base - pid_offset;
|
let offset = stack_base - pid_offset;
|
||||||
if offset as usize > memory_stack.len() {
|
if offset as usize > memory_stack.len() {
|
||||||
warn!("vfork failed - the return value (pid) is outside of the active part of the memory stack ({} vs {})", offset, memory_stack.len());
|
warn!(
|
||||||
|
"vfork failed - the return value (pid) is outside of the active part of the memory stack ({} vs {})",
|
||||||
|
offset,
|
||||||
|
memory_stack.len()
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// Update the memory stack with the new PID
|
// Update the memory stack with the new PID
|
||||||
let val_bytes = child_pid.raw().to_ne_bytes();
|
let val_bytes = child_pid.raw().to_ne_bytes();
|
||||||
@@ -195,7 +174,9 @@ pub fn proc_exec<M: MemorySize>(
|
|||||||
pbytes.clone_from_slice(&val_bytes);
|
pbytes.clone_from_slice(&val_bytes);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!("vfork failed - the return value (pid) is not being returned on the stack - which is not supported");
|
warn!(
|
||||||
|
"vfork failed - the return value (pid) is not being returned on the stack - which is not supported",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jump back to the vfork point and current on execution
|
// Jump back to the vfork point and current on execution
|
||||||
@@ -245,12 +226,7 @@ pub fn proc_exec<M: MemorySize>(
|
|||||||
Ok(a) => Ok(Ok(a)),
|
Ok(a) => Ok(Ok(a)),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if err != VirtualBusError::NotFound {
|
if err != VirtualBusError::NotFound {
|
||||||
error!(
|
error!("builtin failed - {}", err);
|
||||||
"wasi[{}:{}]::proc_exec - builtin failed - {}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_store = new_store.take().unwrap();
|
let new_store = new_store.take().unwrap();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use wasmer::vm::VMMemory;
|
|||||||
/// Forks the current process into a new subprocess. If the function
|
/// Forks the current process into a new subprocess. If the function
|
||||||
/// returns a zero then its the new subprocess. If it returns a positive
|
/// returns a zero then its the new subprocess. If it returns a positive
|
||||||
/// number then its the current process and the $pid represents the child.
|
/// number then its the current process and the $pid represents the child.
|
||||||
|
#[instrument(level = "debug", skip_all, fields(copy_memory, pid = field::Empty), ret, err)]
|
||||||
pub fn proc_fork<M: MemorySize>(
|
pub fn proc_fork<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
mut copy_memory: Bool,
|
mut copy_memory: Bool,
|
||||||
@@ -15,39 +16,10 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
wasi_try_ok!(WasiEnv::process_signals_and_exit(&mut ctx)?);
|
wasi_try_ok!(WasiEnv::process_signals_and_exit(&mut ctx)?);
|
||||||
|
|
||||||
// If we were just restored then we need to return the value instead
|
// If we were just restored then we need to return the value instead
|
||||||
let fork_op = if copy_memory == Bool::True {
|
|
||||||
"fork"
|
|
||||||
} else {
|
|
||||||
"vfork"
|
|
||||||
};
|
|
||||||
if handle_rewind::<M>(&mut ctx) {
|
if handle_rewind::<M>(&mut ctx) {
|
||||||
let env = ctx.data();
|
|
||||||
let memory = env.memory_view(&ctx);
|
|
||||||
let ret_pid = wasi_try_mem_ok!(pid_ptr.read(&memory));
|
|
||||||
if ret_pid == 0 {
|
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::proc_{} - entering child",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fork_op
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::proc_{} - entering parent(child={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fork_op,
|
|
||||||
ret_pid
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return Ok(Errno::Success);
|
return Ok(Errno::Success);
|
||||||
}
|
}
|
||||||
trace!(
|
trace!("capturing",);
|
||||||
"wasi[{}:{}]::proc_{} - capturing",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fork_op
|
|
||||||
);
|
|
||||||
|
|
||||||
// Fork the environment which will copy all the open file handlers
|
// Fork the environment which will copy all the open file handlers
|
||||||
// and associate a new context but otherwise shares things like the
|
// and associate a new context but otherwise shares things like the
|
||||||
@@ -56,11 +28,7 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
let (mut child_env, mut child_handle) = match ctx.data().fork() {
|
let (mut child_env, mut child_handle) = match ctx.data().fork() {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!(
|
debug!("could not fork process: {err}");
|
||||||
pid=%ctx.data().pid(),
|
|
||||||
tid=%ctx.data().tid(),
|
|
||||||
"could not fork process: {err}"
|
|
||||||
);
|
|
||||||
// TODO: evaluate the appropriate error code, document it in the spec.
|
// TODO: evaluate the appropriate error code, document it in the spec.
|
||||||
return Ok(Errno::Perm);
|
return Ok(Errno::Perm);
|
||||||
}
|
}
|
||||||
@@ -119,10 +87,7 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
) {
|
) {
|
||||||
Errno::Success => OnCalledAction::InvokeAgain,
|
Errno::Success => OnCalledAction::InvokeAgain,
|
||||||
err => {
|
err => {
|
||||||
warn!(
|
warn!("failed - could not rewind the stack - errno={}", err);
|
||||||
"{} failed - could not rewind the stack - errno={}",
|
|
||||||
fork_op, err
|
|
||||||
);
|
|
||||||
OnCalledAction::Trap(Box::new(WasiError::Exit(Errno::Fault as u32)))
|
OnCalledAction::Trap(Box::new(WasiError::Exit(Errno::Fault as u32)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,6 +100,13 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
|
|
||||||
// Perform the unwind action
|
// Perform the unwind action
|
||||||
unwind::<M, _>(ctx, move |mut ctx, mut memory_stack, rewind_stack| {
|
unwind::<M, _>(ctx, move |mut ctx, mut memory_stack, rewind_stack| {
|
||||||
|
let span = debug_span!(
|
||||||
|
"unwind",
|
||||||
|
memory_stack_len = memory_stack.len(),
|
||||||
|
rewind_stack_len = rewind_stack.len()
|
||||||
|
);
|
||||||
|
let _span_guard = span.enter();
|
||||||
|
|
||||||
// Grab all the globals and serialize them
|
// Grab all the globals and serialize them
|
||||||
let store_data = crate::utils::store::capture_snapshot(&mut ctx.as_store_mut())
|
let store_data = crate::utils::store::capture_snapshot(&mut ctx.as_store_mut())
|
||||||
.serialize()
|
.serialize()
|
||||||
@@ -146,25 +118,13 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
let fork_memory: VMMemory = match env
|
let fork_memory: VMMemory = match env
|
||||||
.memory()
|
.memory()
|
||||||
.try_clone(&ctx)
|
.try_clone(&ctx)
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| MemoryError::Generic("the memory could not be cloned".to_string()))
|
||||||
error!(
|
|
||||||
"wasi[{}:{}]::{} failed - the memory could not be cloned",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fork_op
|
|
||||||
);
|
|
||||||
MemoryError::Generic("the memory could not be cloned".to_string())
|
|
||||||
})
|
|
||||||
.and_then(|mut memory| memory.duplicate())
|
.and_then(|mut memory| memory.duplicate())
|
||||||
{
|
{
|
||||||
Ok(memory) => memory.into(),
|
Ok(memory) => memory.into(),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!(
|
warn!(
|
||||||
"wasi[{}:{}]::{} failed - could not fork the memory - {}",
|
%err
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fork_op,
|
|
||||||
err
|
|
||||||
);
|
);
|
||||||
return OnCalledAction::Trap(Box::new(WasiError::Exit(Errno::Fault as u32)));
|
return OnCalledAction::Trap(Box::new(WasiError::Exit(Errno::Fault as u32)));
|
||||||
}
|
}
|
||||||
@@ -208,16 +168,13 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
import_object.define("env", "memory", memory.clone());
|
import_object.define("env", "memory", memory.clone());
|
||||||
memory
|
memory
|
||||||
} else {
|
} else {
|
||||||
error!(
|
error!("wasm instantiate failed - no memory supplied",);
|
||||||
"wasi[{}:{}]::wasm instantiate failed - no memory supplied",
|
|
||||||
pid, tid
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let instance = match Instance::new(&mut store, &module, &import_object) {
|
let instance = match Instance::new(&mut store, &module, &import_object) {
|
||||||
Ok(a) => a,
|
Ok(a) => a,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("wasi[{}:{}]::wasm instantiate error ({})", pid, tid, err);
|
error!("wasm instantiate error ({})", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -230,12 +187,7 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
|
|
||||||
// Rewind the stack and carry on
|
// Rewind the stack and carry on
|
||||||
{
|
{
|
||||||
trace!(
|
trace!("rewinding child");
|
||||||
"wasi[{}:{}]::{}: rewinding child",
|
|
||||||
ctx.data(&store).pid(),
|
|
||||||
ctx.data(&store).tid(),
|
|
||||||
fork_op
|
|
||||||
);
|
|
||||||
let ctx = ctx.env.clone().into_mut(&mut store);
|
let ctx = ctx.env.clone().into_mut(&mut store);
|
||||||
match rewind::<M>(
|
match rewind::<M>(
|
||||||
ctx,
|
ctx,
|
||||||
@@ -245,7 +197,10 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
) {
|
) {
|
||||||
Errno::Success => OnCalledAction::InvokeAgain,
|
Errno::Success => OnCalledAction::InvokeAgain,
|
||||||
err => {
|
err => {
|
||||||
warn!("wasi[{}:{}]::wasm rewind failed - could not rewind the stack - errno={}", pid, tid, err);
|
warn!(
|
||||||
|
"wasm rewind failed - could not rewind the stack - errno={}",
|
||||||
|
err
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -254,31 +209,15 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
// Invoke the start function
|
// Invoke the start function
|
||||||
let mut ret = Errno::Success;
|
let mut ret = Errno::Success;
|
||||||
if ctx.data(&store).thread.is_main() {
|
if ctx.data(&store).thread.is_main() {
|
||||||
trace!(
|
trace!("re-invoking main");
|
||||||
"wasi[{}:{}]::{}: re-invoking main",
|
|
||||||
ctx.data(&store).pid(),
|
|
||||||
ctx.data(&store).tid(),
|
|
||||||
fork_op
|
|
||||||
);
|
|
||||||
let start = ctx.data(&store).inner().start.clone().unwrap();
|
let start = ctx.data(&store).inner().start.clone().unwrap();
|
||||||
start.call(&mut store);
|
start.call(&mut store);
|
||||||
} else {
|
} else {
|
||||||
trace!(
|
trace!("re-invoking thread_spawn");
|
||||||
"wasi[{}:{}]::{}: re-invoking thread_spawn",
|
|
||||||
ctx.data(&store).pid(),
|
|
||||||
ctx.data(&store).tid(),
|
|
||||||
fork_op
|
|
||||||
);
|
|
||||||
let start = ctx.data(&store).inner().thread_spawn.clone().unwrap();
|
let start = ctx.data(&store).inner().thread_spawn.clone().unwrap();
|
||||||
start.call(&mut store, 0, 0);
|
start.call(&mut store, 0, 0);
|
||||||
}
|
}
|
||||||
trace!(
|
trace!("child exited (code = {})", ret);
|
||||||
"wasi[{}:{}]::proc_{} - child exited (code = {})",
|
|
||||||
ctx.data(&store).pid(),
|
|
||||||
ctx.data(&store).tid(),
|
|
||||||
fork_op,
|
|
||||||
ret
|
|
||||||
);
|
|
||||||
|
|
||||||
// Clean up the environment
|
// Clean up the environment
|
||||||
ctx.cleanup((&mut store), Some(ret as ExitCode));
|
ctx.cleanup((&mut store), Some(ret as ExitCode));
|
||||||
@@ -293,9 +232,7 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
.task_wasm(Box::new(task), store, module, spawn_type)
|
.task_wasm(Box::new(task), store, module, spawn_type)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
warn!(
|
warn!(
|
||||||
"wasi[{}:{}]::failed to fork as the process could not be spawned - {}",
|
"failed to fork as the process could not be spawned - {}",
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
err
|
err
|
||||||
@@ -308,12 +245,7 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
let process = OwnedTaskStatus::default();
|
let process = OwnedTaskStatus::default();
|
||||||
|
|
||||||
{
|
{
|
||||||
trace!(
|
trace!("spawned sub-process (pid={})", child_pid.raw());
|
||||||
"wasi[{}:{}]::spawned sub-process (pid={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
child_pid.raw()
|
|
||||||
);
|
|
||||||
let mut inner = ctx.data().process.write();
|
let mut inner = ctx.data().process.write();
|
||||||
inner.bus_processes.insert(child_pid, process.handle());
|
inner.bus_processes.insert(child_pid, process.handle());
|
||||||
}
|
}
|
||||||
@@ -325,7 +257,11 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
// Make sure its within the "active" part of the memory stack
|
// Make sure its within the "active" part of the memory stack
|
||||||
let offset = env.stack_base - pid_offset;
|
let offset = env.stack_base - pid_offset;
|
||||||
if offset as usize > memory_stack.len() {
|
if offset as usize > memory_stack.len() {
|
||||||
warn!("{} failed - the return value (pid) is outside of the active part of the memory stack ({} vs {})", fork_op, offset, memory_stack.len());
|
warn!(
|
||||||
|
"failed - the return value (pid) is outside of the active part of the memory stack ({} vs {})",
|
||||||
|
offset,
|
||||||
|
memory_stack.len()
|
||||||
|
);
|
||||||
return OnCalledAction::Trap(Box::new(WasiError::Exit(Errno::Fault as u32)));
|
return OnCalledAction::Trap(Box::new(WasiError::Exit(Errno::Fault as u32)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +272,9 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
let pbytes = &mut memory_stack[pstart..pend];
|
let pbytes = &mut memory_stack[pstart..pend];
|
||||||
pbytes.clone_from_slice(&val_bytes);
|
pbytes.clone_from_slice(&val_bytes);
|
||||||
} else {
|
} else {
|
||||||
warn!("{} failed - the return value (pid) is not being returned on the stack - which is not supported", fork_op);
|
warn!(
|
||||||
|
"failed - the return value (pid) is not being returned on the stack - which is not supported"
|
||||||
|
);
|
||||||
return OnCalledAction::Trap(Box::new(WasiError::Exit(Errno::Fault as u32)));
|
return OnCalledAction::Trap(Box::new(WasiError::Exit(Errno::Fault as u32)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,10 +287,7 @@ pub fn proc_fork<M: MemorySize>(
|
|||||||
) {
|
) {
|
||||||
Errno::Success => OnCalledAction::InvokeAgain,
|
Errno::Success => OnCalledAction::InvokeAgain,
|
||||||
err => {
|
err => {
|
||||||
warn!(
|
warn!("failed - could not rewind the stack - errno={}", err);
|
||||||
"{} failed - could not rewind the stack - errno={}",
|
|
||||||
fork_op, err
|
|
||||||
);
|
|
||||||
OnCalledAction::Trap(Box::new(WasiError::Exit(Errno::Fault as u32)))
|
OnCalledAction::Trap(Box::new(WasiError::Exit(Errno::Fault as u32)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ use crate::syscalls::*;
|
|||||||
|
|
||||||
/// ### `proc_id()`
|
/// ### `proc_id()`
|
||||||
/// Returns the handle of the current process
|
/// Returns the handle of the current process
|
||||||
|
#[instrument(level = "debug", skip_all, fields(pid = field::Empty), ret)]
|
||||||
pub fn proc_id<M: MemorySize>(ctx: FunctionEnvMut<'_, WasiEnv>, ret_pid: WasmPtr<Pid, M>) -> Errno {
|
pub fn proc_id<M: MemorySize>(ctx: FunctionEnvMut<'_, WasiEnv>, ret_pid: WasmPtr<Pid, M>) -> Errno {
|
||||||
debug!("wasi[{}:{}]::getpid", ctx.data().pid(), ctx.data().tid());
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|
||||||
let pid = env.process.pid();
|
let pid = env.process.pid();
|
||||||
|
Span::current().record("pid", pid.raw());
|
||||||
|
|
||||||
wasi_try_mem!(ret_pid.write(&memory, pid.raw() as Pid));
|
wasi_try_mem!(ret_pid.write(&memory, pid.raw() as Pid));
|
||||||
Errno::Success
|
Errno::Success
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use crate::syscalls::*;
|
|||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
///
|
///
|
||||||
/// * `pid` - Handle of the child process to wait on
|
/// * `pid` - Handle of the child process to wait on
|
||||||
|
#[instrument(level = "trace", skip_all, fields(filter_pid = field::Empty, ret_pid = field::Empty, exit_code = field::Empty), ret, err)]
|
||||||
pub fn proc_join<M: MemorySize>(
|
pub fn proc_join<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
pid_ptr: WasmPtr<Pid, M>,
|
pid_ptr: WasmPtr<Pid, M>,
|
||||||
@@ -17,12 +18,7 @@ pub fn proc_join<M: MemorySize>(
|
|||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
let pid = wasi_try_mem_ok!(pid_ptr.read(&memory));
|
let pid = wasi_try_mem_ok!(pid_ptr.read(&memory));
|
||||||
trace!(
|
Span::current().record("filter_pid", pid);
|
||||||
"wasi[{}:{}]::proc_join (pid={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
pid
|
|
||||||
);
|
|
||||||
|
|
||||||
// If the ID is maximum then it means wait for any of the children
|
// If the ID is maximum then it means wait for any of the children
|
||||||
if pid == u32::MAX {
|
if pid == u32::MAX {
|
||||||
@@ -35,23 +31,16 @@ pub fn proc_join<M: MemorySize>(
|
|||||||
)
|
)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
trace!(
|
trace!(
|
||||||
"wasi[{}:{}]::child join failed (pid={}) - {}",
|
%pid,
|
||||||
ctx.data().pid(),
|
%err
|
||||||
ctx.data().tid(),
|
|
||||||
pid,
|
|
||||||
err
|
|
||||||
);
|
);
|
||||||
err
|
err
|
||||||
})?);
|
})?);
|
||||||
return match child_exit {
|
return match child_exit {
|
||||||
Some((pid, exit_code)) => {
|
Some((pid, exit_code)) => {
|
||||||
trace!(
|
Span::current()
|
||||||
"wasi[{}:{}]::child ({}) exited with {}",
|
.record("ret_pid", pid.raw())
|
||||||
ctx.data().pid(),
|
.record("exit_code", exit_code);
|
||||||
ctx.data().tid(),
|
|
||||||
pid,
|
|
||||||
exit_code
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
wasi_try_mem_ok!(pid_ptr.write(&memory, pid.raw() as Pid));
|
wasi_try_mem_ok!(pid_ptr.write(&memory, pid.raw() as Pid));
|
||||||
@@ -59,11 +48,6 @@ pub fn proc_join<M: MemorySize>(
|
|||||||
Ok(Errno::Success)
|
Ok(Errno::Success)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::no children",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
wasi_try_mem_ok!(pid_ptr.write(&memory, -1i32 as Pid));
|
wasi_try_mem_ok!(pid_ptr.write(&memory, -1i32 as Pid));
|
||||||
@@ -84,16 +68,15 @@ pub fn proc_join<M: MemorySize>(
|
|||||||
})
|
})
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
trace!(
|
trace!(
|
||||||
"wasi[{}:{}]::child join failed (pid={}) - {}",
|
%pid,
|
||||||
ctx.data().pid(),
|
%err
|
||||||
ctx.data().tid(),
|
|
||||||
pid,
|
|
||||||
err
|
|
||||||
);
|
);
|
||||||
err
|
err
|
||||||
})?);
|
})?);
|
||||||
|
|
||||||
trace!("child ({}) exited with {}", pid.raw(), exit_code);
|
Span::current()
|
||||||
|
.record("ret_pid", pid.raw())
|
||||||
|
.record("exit_code", exit_code);
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let mut children = env.process.children.write().unwrap();
|
let mut children = env.process.children.write().unwrap();
|
||||||
children.retain(|a| *a != pid);
|
children.retain(|a| *a != pid);
|
||||||
@@ -103,10 +86,8 @@ pub fn proc_join<M: MemorySize>(
|
|||||||
return Ok(Errno::Success);
|
return Ok(Errno::Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!(
|
Span::current().record("ret_pid", pid.raw());
|
||||||
"process already terminated or not registered (pid={})",
|
|
||||||
pid.raw()
|
|
||||||
);
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
wasi_try_mem_ok!(exit_code_ptr.write(&memory, Errno::Child as ExitCode));
|
wasi_try_mem_ok!(exit_code_ptr.write(&memory, Errno::Child as ExitCode));
|
||||||
|
|||||||
@@ -3,21 +3,22 @@ use crate::syscalls::*;
|
|||||||
|
|
||||||
/// ### `proc_parent()`
|
/// ### `proc_parent()`
|
||||||
/// Returns the parent handle of the supplied process
|
/// Returns the parent handle of the supplied process
|
||||||
|
#[instrument(level = "debug", skip_all, fields(pid, parent = field::Empty), ret)]
|
||||||
pub fn proc_parent<M: MemorySize>(
|
pub fn proc_parent<M: MemorySize>(
|
||||||
ctx: FunctionEnvMut<'_, WasiEnv>,
|
ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
pid: Pid,
|
pid: Pid,
|
||||||
ret_parent: WasmPtr<Pid, M>,
|
ret_parent: WasmPtr<Pid, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!("wasi[{}:{}]::getppid", ctx.data().pid(), ctx.data().tid());
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let pid: WasiProcessId = pid.into();
|
let pid: WasiProcessId = pid.into();
|
||||||
if pid == env.process.pid() {
|
if pid == env.process.pid() {
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
Span::current().record("parent", env.process.ppid().raw());
|
||||||
wasi_try_mem!(ret_parent.write(&memory, env.process.ppid().raw() as Pid));
|
wasi_try_mem!(ret_parent.write(&memory, env.process.ppid().raw() as Pid));
|
||||||
Errno::Success
|
Errno::Success
|
||||||
} else if let Some(process) = env.control_plane.get_process(pid) {
|
} else if let Some(process) = env.control_plane.get_process(pid) {
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
Span::current().record("parent", process.pid().raw());
|
||||||
wasi_try_mem!(ret_parent.write(&memory, process.pid().raw() as Pid));
|
wasi_try_mem!(ret_parent.write(&memory, process.pid().raw() as Pid));
|
||||||
Errno::Success
|
Errno::Success
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -8,19 +8,12 @@ use crate::syscalls::*;
|
|||||||
///
|
///
|
||||||
/// * `pid` - Handle of the child process to wait on
|
/// * `pid` - Handle of the child process to wait on
|
||||||
/// * `sig` - Signal to send the child process
|
/// * `sig` - Signal to send the child process
|
||||||
|
#[instrument(level = "trace", skip_all, fields(pid, sig), ret, err)]
|
||||||
pub fn proc_signal<M: MemorySize>(
|
pub fn proc_signal<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
pid: Pid,
|
pid: Pid,
|
||||||
sig: Signal,
|
sig: Signal,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
trace!(
|
|
||||||
"wasi[{}:{}]::proc_signal(pid={}, sig={:?})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
pid,
|
|
||||||
sig
|
|
||||||
);
|
|
||||||
|
|
||||||
let process = {
|
let process = {
|
||||||
let pid: WasiProcessId = pid.into();
|
let pid: WasiProcessId = pid.into();
|
||||||
ctx.data().control_plane.get_process(pid)
|
ctx.data().control_plane.get_process(pid)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ use crate::syscalls::*;
|
|||||||
/// ## Return
|
/// ## Return
|
||||||
///
|
///
|
||||||
/// Returns a bus process id that can be used to invoke calls
|
/// Returns a bus process id that can be used to invoke calls
|
||||||
|
#[instrument(level = "debug", skip_all, fields(name = field::Empty, working_dir = field::Empty), ret, err)]
|
||||||
pub fn proc_spawn<M: MemorySize>(
|
pub fn proc_spawn<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
name: WasmPtr<u8, M>,
|
name: WasmPtr<u8, M>,
|
||||||
@@ -45,19 +46,13 @@ pub fn proc_spawn<M: MemorySize>(
|
|||||||
let args = unsafe { get_input_str_bus_ok!(&memory, args, args_len) };
|
let args = unsafe { get_input_str_bus_ok!(&memory, args, args_len) };
|
||||||
let preopen = unsafe { get_input_str_bus_ok!(&memory, preopen, preopen_len) };
|
let preopen = unsafe { get_input_str_bus_ok!(&memory, preopen, preopen_len) };
|
||||||
let working_dir = unsafe { get_input_str_bus_ok!(&memory, working_dir, working_dir_len) };
|
let working_dir = unsafe { get_input_str_bus_ok!(&memory, working_dir, working_dir_len) };
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::process_spawn (name={})",
|
Span::current()
|
||||||
ctx.data().pid(),
|
.record("name", name.as_str())
|
||||||
ctx.data().tid(),
|
.record("working_dir", working_dir.as_str());
|
||||||
name
|
|
||||||
);
|
|
||||||
|
|
||||||
if chroot == Bool::True {
|
if chroot == Bool::True {
|
||||||
warn!(
|
warn!("chroot is not currently supported",);
|
||||||
"wasi[{}:{}]::chroot is not currently supported",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid()
|
|
||||||
);
|
|
||||||
return Ok(BusErrno::Unsupported);
|
return Ok(BusErrno::Unsupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,9 +128,7 @@ pub fn proc_spawn_internal(
|
|||||||
if !preopen.is_empty() {
|
if !preopen.is_empty() {
|
||||||
for preopen in preopen {
|
for preopen in preopen {
|
||||||
warn!(
|
warn!(
|
||||||
"wasi[{}:{}]::preopens are not yet supported for spawned processes [{}]",
|
"preopens are not yet supported for spawned processes [{}]",
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
preopen
|
preopen
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -181,13 +174,7 @@ pub fn proc_spawn_internal(
|
|||||||
.create_fd_ext(rights, rights, Fdflags::empty(), 0, inode2, fd)
|
.create_fd_ext(rights, rights, Fdflags::empty(), 0, inode2, fd)
|
||||||
.map_err(|_| BusErrno::Internal)?;
|
.map_err(|_| BusErrno::Internal)?;
|
||||||
|
|
||||||
trace!(
|
trace!("fd_pipe (fd1={}, fd2={})", pipe, fd);
|
||||||
"wasi[{}:{}]::fd_pipe (fd1={}, fd2={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
pipe,
|
|
||||||
fd
|
|
||||||
);
|
|
||||||
Ok(OptionFd {
|
Ok(OptionFd {
|
||||||
tag: OptionTag::Some,
|
tag: OptionTag::Some,
|
||||||
fd: pipe,
|
fd: pipe,
|
||||||
@@ -234,12 +221,7 @@ pub fn proc_spawn_internal(
|
|||||||
Ok(a) => a,
|
Ok(a) => a,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if err != VirtualBusError::NotFound {
|
if err != VirtualBusError::NotFound {
|
||||||
error!(
|
error!("builtin failed - {}", err);
|
||||||
"wasi[{}:{}]::proc_spawn - builtin failed - {}",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// Now we actually spawn the process
|
// Now we actually spawn the process
|
||||||
let child_work =
|
let child_work =
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use crate::syscalls::*;
|
|||||||
/// ## Return
|
/// ## Return
|
||||||
///
|
///
|
||||||
/// The number of IP addresses returned during the DNS resolution.
|
/// The number of IP addresses returned during the DNS resolution.
|
||||||
|
#[instrument(level = "debug", skip_all, fields(host = field::Empty, port), ret, err)]
|
||||||
pub fn resolve<M: MemorySize>(
|
pub fn resolve<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
host: WasmPtr<u8, M>,
|
host: WasmPtr<u8, M>,
|
||||||
@@ -34,13 +35,7 @@ pub fn resolve<M: MemorySize>(
|
|||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
unsafe { get_input_str_ok!(&memory, host, host_len) }
|
unsafe { get_input_str_ok!(&memory, host, host_len) }
|
||||||
};
|
};
|
||||||
|
Span::current().record("host", host_str.as_str());
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::resolve (host={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
host_str
|
|
||||||
);
|
|
||||||
|
|
||||||
let port = if port > 0 { Some(port) } else { None };
|
let port = if port > 0 { Some(port) } else { None };
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::syscalls::*;
|
|||||||
|
|
||||||
/// ### `sched_yield()`
|
/// ### `sched_yield()`
|
||||||
/// Yields execution of the thread
|
/// Yields execution of the thread
|
||||||
|
#[instrument(level = "trace", skip_all, ret, err)]
|
||||||
pub fn sched_yield(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
|
pub fn sched_yield(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result<Errno, WasiError> {
|
||||||
//trace!("wasi[{}:{}]::sched_yield", ctx.data().pid(), ctx.data().tid());
|
//trace!("wasi[{}:{}]::sched_yield", ctx.data().pid(), ctx.data().tid());
|
||||||
thread_sleep_internal(ctx, 0)
|
thread_sleep_internal(ctx, 0)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use crate::syscalls::*;
|
|||||||
/// ## Return
|
/// ## Return
|
||||||
///
|
///
|
||||||
/// New socket connection
|
/// New socket connection
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock, fd = field::Empty), ret, err)]
|
||||||
pub fn sock_accept<M: MemorySize>(
|
pub fn sock_accept<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
@@ -20,14 +21,6 @@ pub fn sock_accept<M: MemorySize>(
|
|||||||
ro_fd: WasmPtr<WasiFd, M>,
|
ro_fd: WasmPtr<WasiFd, M>,
|
||||||
ro_addr: WasmPtr<__wasi_addr_port_t, M>,
|
ro_addr: WasmPtr<__wasi_addr_port_t, M>,
|
||||||
) -> Result<Errno, WasiError> {
|
) -> Result<Errno, WasiError> {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_accept (fd={}, flags={:?})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock,
|
|
||||||
fd_flags
|
|
||||||
);
|
|
||||||
|
|
||||||
wasi_try_ok!(WasiEnv::process_signals_and_exit(&mut ctx)?);
|
wasi_try_ok!(WasiEnv::process_signals_and_exit(&mut ctx)?);
|
||||||
|
|
||||||
let tasks = ctx.data().tasks().clone();
|
let tasks = ctx.data().tasks().clone();
|
||||||
@@ -72,13 +65,7 @@ pub fn sock_accept<M: MemorySize>(
|
|||||||
|
|
||||||
let rights = Rights::all_socket();
|
let rights = Rights::all_socket();
|
||||||
let fd = wasi_try_ok!(state.fs.create_fd(rights, rights, new_flags, 0, inode));
|
let fd = wasi_try_ok!(state.fs.create_fd(rights, rights, new_flags, 0, inode));
|
||||||
|
Span::current().record("fd", fd);
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_accept (ret=ESUCCESS, peer={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
fd
|
|
||||||
);
|
|
||||||
|
|
||||||
wasi_try_mem_ok!(ro_fd.write(&memory, fd));
|
wasi_try_mem_ok!(ro_fd.write(&memory, fd));
|
||||||
wasi_try_ok!(crate::net::write_ip_port(
|
wasi_try_ok!(crate::net::write_ip_port(
|
||||||
|
|||||||
@@ -12,24 +12,21 @@ use crate::syscalls::*;
|
|||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
///
|
///
|
||||||
/// * `fd` - Socket that the address is bound to
|
/// * `fd` - Socket that the address is bound to
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock, addr = field::Empty), ret)]
|
||||||
pub fn sock_addr_local<M: MemorySize>(
|
pub fn sock_addr_local<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
ret_addr: WasmPtr<__wasi_addr_port_t, M>,
|
ret_addr: WasmPtr<__wasi_addr_port_t, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_addr_local (fd={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock
|
|
||||||
);
|
|
||||||
|
|
||||||
let addr = wasi_try!(__sock_actor(
|
let addr = wasi_try!(__sock_actor(
|
||||||
&mut ctx,
|
&mut ctx,
|
||||||
sock,
|
sock,
|
||||||
Rights::empty(),
|
Rights::empty(),
|
||||||
|socket, _| socket.addr_local()
|
|socket, _| socket.addr_local()
|
||||||
));
|
));
|
||||||
|
|
||||||
|
Span::current().record("addr", &format!("{:?}", addr));
|
||||||
|
|
||||||
let memory = ctx.data().memory_view(&ctx);
|
let memory = ctx.data().memory_view(&ctx);
|
||||||
wasi_try!(crate::net::write_ip_port(
|
wasi_try!(crate::net::write_ip_port(
|
||||||
&memory,
|
&memory,
|
||||||
|
|||||||
@@ -12,24 +12,19 @@ use crate::syscalls::*;
|
|||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
///
|
///
|
||||||
/// * `fd` - Socket that the address is bound to
|
/// * `fd` - Socket that the address is bound to
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock, addr = field::Empty), ret)]
|
||||||
pub fn sock_addr_peer<M: MemorySize>(
|
pub fn sock_addr_peer<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
ro_addr: WasmPtr<__wasi_addr_port_t, M>,
|
ro_addr: WasmPtr<__wasi_addr_port_t, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_addr_peer (fd={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock
|
|
||||||
);
|
|
||||||
|
|
||||||
let addr = wasi_try!(__sock_actor(
|
let addr = wasi_try!(__sock_actor(
|
||||||
&mut ctx,
|
&mut ctx,
|
||||||
sock,
|
sock,
|
||||||
Rights::empty(),
|
Rights::empty(),
|
||||||
|socket, _| socket.addr_peer()
|
|socket, _| socket.addr_peer()
|
||||||
));
|
));
|
||||||
|
Span::current().record("addr", &format!("{:?}", addr));
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
|
|||||||
@@ -9,22 +9,18 @@ use crate::syscalls::*;
|
|||||||
///
|
///
|
||||||
/// * `fd` - File descriptor of the socket to be bind
|
/// * `fd` - File descriptor of the socket to be bind
|
||||||
/// * `addr` - Address to bind the socket to
|
/// * `addr` - Address to bind the socket to
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock, addr = field::Empty), ret)]
|
||||||
pub fn sock_bind<M: MemorySize>(
|
pub fn sock_bind<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
addr: WasmPtr<__wasi_addr_port_t, M>,
|
addr: WasmPtr<__wasi_addr_port_t, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_bind (fd={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock
|
|
||||||
);
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
let addr = wasi_try!(crate::net::read_ip_port(&memory, addr));
|
let addr = wasi_try!(crate::net::read_ip_port(&memory, addr));
|
||||||
let addr = SocketAddr::new(addr.0, addr.1);
|
let addr = SocketAddr::new(addr.0, addr.1);
|
||||||
|
Span::current().record("addr", &format!("{:?}", addr));
|
||||||
|
|
||||||
let net = env.net().clone();
|
let net = env.net().clone();
|
||||||
|
|
||||||
let tasks = ctx.data().tasks().clone();
|
let tasks = ctx.data().tasks().clone();
|
||||||
|
|||||||
@@ -13,23 +13,18 @@ use crate::syscalls::*;
|
|||||||
///
|
///
|
||||||
/// * `fd` - Socket descriptor
|
/// * `fd` - Socket descriptor
|
||||||
/// * `addr` - Address of the socket to connect to
|
/// * `addr` - Address of the socket to connect to
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock, addr = field::Empty), ret)]
|
||||||
pub fn sock_connect<M: MemorySize>(
|
pub fn sock_connect<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
addr: WasmPtr<__wasi_addr_port_t, M>,
|
addr: WasmPtr<__wasi_addr_port_t, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_connect (fd={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock
|
|
||||||
);
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let net = env.net().clone();
|
let net = env.net().clone();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
let addr = wasi_try!(crate::net::read_ip_port(&memory, addr));
|
let addr = wasi_try!(crate::net::read_ip_port(&memory, addr));
|
||||||
let addr = SocketAddr::new(addr.0, addr.1);
|
let addr = SocketAddr::new(addr.0, addr.1);
|
||||||
|
Span::current().record("addr", &format!("{:?}", addr));
|
||||||
|
|
||||||
let tasks = ctx.data().tasks().clone();
|
let tasks = ctx.data().tasks().clone();
|
||||||
wasi_try!(__sock_upgrade(
|
wasi_try!(__sock_upgrade(
|
||||||
|
|||||||
@@ -9,20 +9,13 @@ use crate::syscalls::*;
|
|||||||
///
|
///
|
||||||
/// * `fd` - Socket descriptor
|
/// * `fd` - Socket descriptor
|
||||||
/// * `sockopt` - Socket option to be retrieved
|
/// * `sockopt` - Socket option to be retrieved
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock, opt), ret)]
|
||||||
pub fn sock_get_opt_flag<M: MemorySize>(
|
pub fn sock_get_opt_flag<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
opt: Sockoption,
|
opt: Sockoption,
|
||||||
ret_flag: WasmPtr<Bool, M>,
|
ret_flag: WasmPtr<Bool, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_get_opt_flag(fd={}, ty={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock,
|
|
||||||
opt
|
|
||||||
);
|
|
||||||
|
|
||||||
let option: crate::net::socket::WasiSocketOption = opt.into();
|
let option: crate::net::socket::WasiSocketOption = opt.into();
|
||||||
let flag = wasi_try!(__sock_actor(
|
let flag = wasi_try!(__sock_actor(
|
||||||
&mut ctx,
|
&mut ctx,
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ use crate::syscalls::*;
|
|||||||
///
|
///
|
||||||
/// * `fd` - Socket descriptor
|
/// * `fd` - Socket descriptor
|
||||||
/// * `sockopt` - Socket option to be retrieved
|
/// * `sockopt` - Socket option to be retrieved
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock, opt), ret)]
|
||||||
pub fn sock_get_opt_size<M: MemorySize>(
|
pub fn sock_get_opt_size<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
opt: Sockoption,
|
opt: Sockoption,
|
||||||
ret_size: WasmPtr<Filesize, M>,
|
ret_size: WasmPtr<Filesize, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_get_opt_size(fd={}, ty={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock,
|
|
||||||
opt
|
|
||||||
);
|
|
||||||
let size = wasi_try!(__sock_actor(
|
let size = wasi_try!(__sock_actor(
|
||||||
&mut ctx,
|
&mut ctx,
|
||||||
sock,
|
sock,
|
||||||
|
|||||||
@@ -8,20 +8,13 @@ use crate::{net::socket::TimeType, syscalls::*};
|
|||||||
///
|
///
|
||||||
/// * `fd` - Socket descriptor
|
/// * `fd` - Socket descriptor
|
||||||
/// * `sockopt` - Socket option to be retrieved
|
/// * `sockopt` - Socket option to be retrieved
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock, opt), ret)]
|
||||||
pub fn sock_get_opt_time<M: MemorySize>(
|
pub fn sock_get_opt_time<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
opt: Sockoption,
|
opt: Sockoption,
|
||||||
ret_time: WasmPtr<OptionTimestamp, M>,
|
ret_time: WasmPtr<OptionTimestamp, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_get_opt_time(fd={}, ty={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock,
|
|
||||||
opt
|
|
||||||
);
|
|
||||||
|
|
||||||
let ty = match opt {
|
let ty = match opt {
|
||||||
Sockoption::RecvTimeout => TimeType::ReadTimeout,
|
Sockoption::RecvTimeout => TimeType::ReadTimeout,
|
||||||
Sockoption::SendTimeout => TimeType::WriteTimeout,
|
Sockoption::SendTimeout => TimeType::WriteTimeout,
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ use crate::syscalls::*;
|
|||||||
/// * `fd` - Socket descriptor
|
/// * `fd` - Socket descriptor
|
||||||
/// * `multiaddr` - Multicast group to joined
|
/// * `multiaddr` - Multicast group to joined
|
||||||
/// * `interface` - Interface that will join
|
/// * `interface` - Interface that will join
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock), ret)]
|
||||||
pub fn sock_join_multicast_v4<M: MemorySize>(
|
pub fn sock_join_multicast_v4<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
multiaddr: WasmPtr<__wasi_addr_ip4_t, M>,
|
multiaddr: WasmPtr<__wasi_addr_ip4_t, M>,
|
||||||
iface: WasmPtr<__wasi_addr_ip4_t, M>,
|
iface: WasmPtr<__wasi_addr_ip4_t, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_join_multicast_v4 (fd={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock
|
|
||||||
);
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
let multiaddr = wasi_try!(crate::net::read_ip_v4(&memory, multiaddr));
|
let multiaddr = wasi_try!(crate::net::read_ip_v4(&memory, multiaddr));
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ use crate::syscalls::*;
|
|||||||
/// * `fd` - Socket descriptor
|
/// * `fd` - Socket descriptor
|
||||||
/// * `multiaddr` - Multicast group to joined
|
/// * `multiaddr` - Multicast group to joined
|
||||||
/// * `interface` - Interface that will join
|
/// * `interface` - Interface that will join
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock, iface), ret)]
|
||||||
pub fn sock_join_multicast_v6<M: MemorySize>(
|
pub fn sock_join_multicast_v6<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
multiaddr: WasmPtr<__wasi_addr_ip6_t, M>,
|
multiaddr: WasmPtr<__wasi_addr_ip6_t, M>,
|
||||||
iface: u32,
|
iface: u32,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_join_multicast_v6 (fd={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock
|
|
||||||
);
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
let multiaddr = wasi_try!(crate::net::read_ip_v6(&memory, multiaddr));
|
let multiaddr = wasi_try!(crate::net::read_ip_v6(&memory, multiaddr));
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ use crate::syscalls::*;
|
|||||||
/// * `fd` - Socket descriptor
|
/// * `fd` - Socket descriptor
|
||||||
/// * `multiaddr` - Multicast group to leave
|
/// * `multiaddr` - Multicast group to leave
|
||||||
/// * `interface` - Interface that will left
|
/// * `interface` - Interface that will left
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock), ret)]
|
||||||
pub fn sock_leave_multicast_v4<M: MemorySize>(
|
pub fn sock_leave_multicast_v4<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
multiaddr: WasmPtr<__wasi_addr_ip4_t, M>,
|
multiaddr: WasmPtr<__wasi_addr_ip4_t, M>,
|
||||||
iface: WasmPtr<__wasi_addr_ip4_t, M>,
|
iface: WasmPtr<__wasi_addr_ip4_t, M>,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_leave_multicast_v4 (fd={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock
|
|
||||||
);
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
let multiaddr = wasi_try!(crate::net::read_ip_v4(&memory, multiaddr));
|
let multiaddr = wasi_try!(crate::net::read_ip_v4(&memory, multiaddr));
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ use crate::syscalls::*;
|
|||||||
/// * `fd` - Socket descriptor
|
/// * `fd` - Socket descriptor
|
||||||
/// * `multiaddr` - Multicast group to leave
|
/// * `multiaddr` - Multicast group to leave
|
||||||
/// * `interface` - Interface that will left
|
/// * `interface` - Interface that will left
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock, iface), ret)]
|
||||||
pub fn sock_leave_multicast_v6<M: MemorySize>(
|
pub fn sock_leave_multicast_v6<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
multiaddr: WasmPtr<__wasi_addr_ip6_t, M>,
|
multiaddr: WasmPtr<__wasi_addr_ip6_t, M>,
|
||||||
iface: u32,
|
iface: u32,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_leave_multicast_v6 (fd={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock
|
|
||||||
);
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let memory = env.memory_view(&ctx);
|
let memory = env.memory_view(&ctx);
|
||||||
let multiaddr = wasi_try!(crate::net::read_ip_v6(&memory, multiaddr));
|
let multiaddr = wasi_try!(crate::net::read_ip_v6(&memory, multiaddr));
|
||||||
|
|||||||
@@ -13,18 +13,12 @@ use crate::syscalls::*;
|
|||||||
///
|
///
|
||||||
/// * `fd` - File descriptor of the socket to be bind
|
/// * `fd` - File descriptor of the socket to be bind
|
||||||
/// * `backlog` - Maximum size of the queue for pending connections
|
/// * `backlog` - Maximum size of the queue for pending connections
|
||||||
|
#[instrument(level = "debug", skip_all, fields(sock, backlog), ret)]
|
||||||
pub fn sock_listen<M: MemorySize>(
|
pub fn sock_listen<M: MemorySize>(
|
||||||
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
mut ctx: FunctionEnvMut<'_, WasiEnv>,
|
||||||
sock: WasiFd,
|
sock: WasiFd,
|
||||||
backlog: M::Offset,
|
backlog: M::Offset,
|
||||||
) -> Errno {
|
) -> Errno {
|
||||||
debug!(
|
|
||||||
"wasi[{}:{}]::sock_listen (fd={})",
|
|
||||||
ctx.data().pid(),
|
|
||||||
ctx.data().tid(),
|
|
||||||
sock
|
|
||||||
);
|
|
||||||
|
|
||||||
let env = ctx.data();
|
let env = ctx.data();
|
||||||
let net = env.net().clone();
|
let net = env.net().clone();
|
||||||
let backlog: usize = wasi_try!(backlog.try_into().map_err(|_| Errno::Inval));
|
let backlog: usize = wasi_try!(backlog.try_into().map_err(|_| Errno::Inval));
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user