From 05b5015999a8c1102473bcfedf52af1888c9bb32 Mon Sep 17 00:00:00 2001 From: Johnathan Sharratt Date: Wed, 12 Jul 2023 23:28:28 +1000 Subject: [PATCH 01/13] Fixed an issue where the socket address family was being corrupted due to padding fields being incorrect used. --- lib/wasi-types/src/types.rs | 3 +++ lib/wasi-types/src/wasi/bindings.rs | 2 +- lib/wasix/src/net/mod.rs | 16 ++++++++++++++-- lib/wasix/src/net/socket.rs | 6 ++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/wasi-types/src/types.rs b/lib/wasi-types/src/types.rs index d836a7bdc64..f080c8265b2 100644 --- a/lib/wasi-types/src/types.rs +++ b/lib/wasi-types/src/types.rs @@ -233,6 +233,7 @@ pub mod net { #[repr(C)] pub struct __wasi_addr_t { pub tag: Addressfamily, + pub _padding: u8, pub u: __wasi_addr_u, } @@ -246,6 +247,7 @@ pub mod net { #[repr(C)] pub struct __wasi_addr_port_t { pub tag: Addressfamily, + pub _padding: u8, pub u: __wasi_addr_port_u, } @@ -259,6 +261,7 @@ pub mod net { #[repr(C)] pub struct __wasi_cidr_t { pub tag: Addressfamily, + pub _padding: u8, pub u: __wasi_cidr_u, } diff --git a/lib/wasi-types/src/wasi/bindings.rs b/lib/wasi-types/src/wasi/bindings.rs index ab3d60e8736..009996793b0 100644 --- a/lib/wasi-types/src/wasi/bindings.rs +++ b/lib/wasi-types/src/wasi/bindings.rs @@ -1060,7 +1060,7 @@ impl core::fmt::Debug for Streamsecurity { } } } -#[repr(u16)] +#[repr(u8)] #[derive(Clone, Copy, PartialEq, Eq)] pub enum Addressfamily { Unspec, diff --git a/lib/wasix/src/net/mod.rs b/lib/wasix/src/net/mod.rs index 0a1ade30d8b..a59d71508cf 100644 --- a/lib/wasix/src/net/mod.rs +++ b/lib/wasix/src/net/mod.rs @@ -69,6 +69,7 @@ pub fn write_ip( let o = ip.octets(); __wasi_addr_t { tag: Addressfamily::Inet4, + _padding: 0, u: __wasi_addr_u { octs: [o[0], o[1], o[2], o[3], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], }, @@ -78,6 +79,7 @@ pub fn write_ip( let o = ip.octets(); __wasi_addr_t { tag: Addressfamily::Inet6, + _padding: 0, u: __wasi_addr_u { octs: o }, } } @@ -131,6 +133,7 @@ pub(crate) fn write_cidr( let o = ip.octets(); __wasi_cidr_t { tag: Addressfamily::Inet4, + _padding: 0, u: __wasi_cidr_u { octs: [ o[0], o[1], o[2], o[3], p, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -142,6 +145,7 @@ pub(crate) fn write_cidr( let o = ip.octets(); __wasi_cidr_t { tag: Addressfamily::Inet6, + _padding: 0, u: __wasi_cidr_u { octs: [ o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], o[10], o[11], @@ -163,7 +167,6 @@ pub(crate) fn read_ip_port( ) -> Result<(IpAddr, u16), Errno> { let addr_ptr = ptr.deref(memory); let addr = addr_ptr.read().map_err(crate::mem_error_to_wasi)?; - let o = addr.u.octs; Ok(match addr.tag { Addressfamily::Inet4 => { @@ -183,7 +186,10 @@ pub(crate) fn read_ip_port( u16::from_ne_bytes([o[0], o[1]]), ) } - _ => return Err(Errno::Inval), + _ => { + tracing::debug!("invalid address family ({})", addr.tag as u8); + return Err(Errno::Inval); + } }) } @@ -200,6 +206,7 @@ pub(crate) fn write_ip_port( let o = ip.octets(); __wasi_addr_port_t { tag: Addressfamily::Inet4, + _padding: 0, u: __wasi_addr_port_u { octs: [ p[0], p[1], o[0], o[1], o[2], o[3], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -211,6 +218,7 @@ pub(crate) fn write_ip_port( let o = ip.octets(); __wasi_addr_port_t { tag: Addressfamily::Inet6, + _padding: 0, u: __wasi_addr_port_u { octs: [ p[0], p[1], o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], @@ -292,6 +300,7 @@ pub(crate) fn write_route( let o = ip.octets(); __wasi_cidr_t { tag: Addressfamily::Inet4, + _padding: 0, u: __wasi_cidr_u { octs: [ o[0], o[1], o[2], o[3], p, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -303,6 +312,7 @@ pub(crate) fn write_route( let o = ip.octets(); __wasi_cidr_t { tag: Addressfamily::Inet6, + _padding: 0, u: __wasi_cidr_u { octs: [ o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], o[10], @@ -318,6 +328,7 @@ pub(crate) fn write_route( let o = ip.octets(); __wasi_addr_t { tag: Addressfamily::Inet4, + _padding: 0, u: __wasi_addr_u { octs: [o[0], o[1], o[2], o[3], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], }, @@ -327,6 +338,7 @@ pub(crate) fn write_route( let o = ip.octets(); __wasi_addr_t { tag: Addressfamily::Inet6, + _padding: 0, u: __wasi_addr_u { octs: o }, } } diff --git a/lib/wasix/src/net/socket.rs b/lib/wasix/src/net/socket.rs index ba2787ac396..7c90f01979b 100644 --- a/lib/wasix/src/net/socket.rs +++ b/lib/wasix/src/net/socket.rs @@ -214,11 +214,17 @@ impl InodeSocket { match *family { Addressfamily::Inet4 => { if !set_addr.is_ipv4() { + tracing::debug!( + "IP address is the wrong type IPv4 ({set_addr}) vs IPv6 family" + ); return Err(Errno::Inval); } } Addressfamily::Inet6 => { if !set_addr.is_ipv6() { + tracing::debug!( + "IP address is the wrong type IPv6 ({set_addr}) vs IPv4 family" + ); return Err(Errno::Inval); } } From 3a1e28cdc5de2a6dd7d9dd0269d9077137aa526f Mon Sep 17 00:00:00 2001 From: Johnathan Sharratt Date: Mon, 14 Aug 2023 07:29:14 +1000 Subject: [PATCH 02/13] Added a comment --- lib/wasi-types/src/types.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/wasi-types/src/types.rs b/lib/wasi-types/src/types.rs index f080c8265b2..ccfadd4e429 100644 --- a/lib/wasi-types/src/types.rs +++ b/lib/wasi-types/src/types.rs @@ -233,6 +233,7 @@ pub mod net { #[repr(C)] pub struct __wasi_addr_t { pub tag: Addressfamily, + // C will add a padding byte here which must be set to zero otherwise the tag will corrupt pub _padding: u8, pub u: __wasi_addr_u, } @@ -247,6 +248,7 @@ pub mod net { #[repr(C)] pub struct __wasi_addr_port_t { pub tag: Addressfamily, + // C will add a padding byte here which must be set to zero otherwise the tag will corrupt pub _padding: u8, pub u: __wasi_addr_port_u, } @@ -261,6 +263,7 @@ pub mod net { #[repr(C)] pub struct __wasi_cidr_t { pub tag: Addressfamily, + // C will add a padding byte here which must be set to zero otherwise the tag will corrupt pub _padding: u8, pub u: __wasi_cidr_u, } From cb74bea9aa5018c0074a37dfcad68b38ecfd8cdf Mon Sep 17 00:00:00 2001 From: Johnathan Sharratt Date: Fri, 25 Aug 2023 11:51:11 +1000 Subject: [PATCH 03/13] Faster compiles for debug by using release version of cranelift --- Cargo.toml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 433a869de63..3effe8e97cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -160,6 +160,22 @@ coverage = [] #[profile.release] #debug = true +# Enable optimizations for a few crates, even for debug builds. +# This greatly speeds up using debug builds, because these crates are extremely +# slow without optimizations. +[profile.dev.package.cranelift-codegen] +opt-level = 3 +[profile.dev.package.regalloc2] +opt-level = 3 +[profile.dev.package.wasmparser] +opt-level = 3 +[profile.dev.package.rkyv] +opt-level = 3 +[profile.dev.package.wasmer-types] +opt-level = 3 +[profile.dev.package.weezl] +opt-level = 3 + [[bench]] name = "static_and_dynamic_functions" harness = false From 6cf37b9dc8714d63cde34ca6ba430fc474cb59b0 Mon Sep 17 00:00:00 2001 From: Johnathan Sharratt Date: Sat, 26 Aug 2023 18:59:24 +1000 Subject: [PATCH 04/13] Added additional fixes for some missing parts of sockets --- lib/virtual-io/src/selector.rs | 30 +++++----- lib/virtual-net/src/client.rs | 30 ++++++++++ lib/virtual-net/src/host.rs | 60 ++++++++++++++++++- lib/virtual-net/src/lib.rs | 18 ++++++ lib/virtual-net/src/meta.rs | 14 +++++ lib/virtual-net/src/server.rs | 40 +++++++++++++ lib/wasix/src/net/socket.rs | 44 +++++++++++++- lib/wasix/src/syscalls/wasi/clock_time_get.rs | 2 +- lib/wasix/src/syscalls/wasi/poll_oneoff.rs | 14 ++++- lib/wasix/src/syscalls/wasix/sock_open.rs | 18 ++++++ 10 files changed, 250 insertions(+), 20 deletions(-) diff --git a/lib/virtual-io/src/selector.rs b/lib/virtual-io/src/selector.rs index cd4304b46f3..1fae9637a4c 100644 --- a/lib/virtual-io/src/selector.rs +++ b/lib/virtual-io/src/selector.rs @@ -89,23 +89,25 @@ impl Selector { return; } - let interest = if event.is_readable() { - InterestType::Readable - } else if event.is_writable() { - InterestType::Writable - } else if event.is_read_closed() || event.is_write_closed() { - InterestType::Closed - } else if event.is_error() { - InterestType::Error - } else { - continue; - }; - tracing::trace!(token = ?token, interest = ?interest, "host epoll"); - // Otherwise this is a waker we need to wake let s = event.token().0 as *mut HandlerWrapper; let mut handler = ManuallyDrop::new(unsafe { Box::from_raw(s) }); - handler.0.interest(interest); + if event.is_readable() { + tracing::trace!(token = ?token, interest = ?InterestType::Readable, "host epoll"); + handler.0.interest(InterestType::Readable); + } + if event.is_writable() { + tracing::trace!(token = ?token, interest = ?InterestType::Writable, "host epoll"); + handler.0.interest(InterestType::Writable); + } + if event.is_read_closed() || event.is_write_closed() { + tracing::trace!(token = ?token, interest = ?InterestType::Closed, "host epoll"); + handler.0.interest(InterestType::Closed); + } + if event.is_error() { + tracing::trace!(token = ?token, interest = ?InterestType::Error, "host epoll"); + handler.0.interest(InterestType::Error); + } } } } diff --git a/lib/virtual-net/src/client.rs b/lib/virtual-net/src/client.rs index 375985f1c54..29ee9cdf1f4 100644 --- a/lib/virtual-net/src/client.rs +++ b/lib/virtual-net/src/client.rs @@ -1370,6 +1370,36 @@ impl VirtualTcpSocket for RemoteSocket { } } + fn set_keepalive(&mut self, keep_alive: bool) -> Result<()> { + self.io_socket_fire_and_forget(RequestType::SetKeepAlive(keep_alive)) + } + + fn keepalive(&self) -> Result { + match InlineWaker::block_on(self.io_socket(RequestType::GetKeepAlive)) { + ResponseType::Err(err) => Err(err), + ResponseType::Flag(val) => Ok(val), + res => { + tracing::debug!("invalid response to get nodelay request - {res:?}"); + Err(NetworkError::IOError) + } + } + } + + fn set_dontroute(&mut self, dont_route: bool) -> Result<()> { + self.io_socket_fire_and_forget(RequestType::SetDontRoute(dont_route)) + } + + fn dontroute(&self) -> Result { + match InlineWaker::block_on(self.io_socket(RequestType::GetDontRoute)) { + ResponseType::Err(err) => Err(err), + ResponseType::Flag(val) => Ok(val), + res => { + tracing::debug!("invalid response to get nodelay request - {res:?}"); + Err(NetworkError::IOError) + } + } + } + fn addr_peer(&self) -> Result { match InlineWaker::block_on(self.io_socket(RequestType::GetAddrPeer)) { ResponseType::Err(err) => Err(err), diff --git a/lib/virtual-net/src/host.rs b/lib/virtual-net/src/host.rs index 50205bf3970..7617d3e29b8 100644 --- a/lib/virtual-net/src/host.rs +++ b/lib/virtual-net/src/host.rs @@ -10,6 +10,7 @@ use derivative::Derivative; use std::io::{Read, Write}; use std::mem::MaybeUninit; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}; +use std::os::fd::AsRawFd; use std::sync::Arc; use std::time::Duration; use tokio::runtime::Handle; @@ -62,6 +63,8 @@ impl VirtualNetworking for LocalNetworking { stream: mio::net::TcpListener::from_std(sock), selector: self.selector.clone(), handler_guard: None, + no_delay: None, + keep_alive: None, }) }) .map_err(io_err_into_net_error)?; @@ -94,11 +97,12 @@ impl VirtualNetworking for LocalNetworking { if let Ok(p) = stream.peer_addr() { peer = p; } - Ok(Box::new(LocalTcpStream::new( + let socket = Box::new(LocalTcpStream::new( self.selector.clone(), stream, peer, - ))) + )); + Ok(socket) } async fn resolve( @@ -127,6 +131,8 @@ pub struct LocalTcpListener { stream: mio::net::TcpListener, selector: Arc, handler_guard: Option, + no_delay: Option, + keep_alive: Option, } impl VirtualTcpListener for LocalTcpListener { @@ -138,6 +144,12 @@ impl VirtualTcpListener for LocalTcpListener { .ok(); let mut socket = LocalTcpStream::new(self.selector.clone(), stream, addr); socket.set_first_handler_writeable(); + if let Some(no_delay) = self.no_delay { + socket.set_nodelay(no_delay).ok(); + } + if let Some(keep_alive) = self.keep_alive { + socket.set_keepalive(keep_alive).ok(); + } Ok((Box::new(socket), addr)) } Err(NetworkError::WouldBlock) => Err(NetworkError::WouldBlock), @@ -242,6 +254,50 @@ impl VirtualTcpSocket for LocalTcpStream { self.stream.nodelay().map_err(io_err_into_net_error) } + fn set_keepalive(&mut self, keepalive: bool) -> Result<()> { + socket2::SockRef::from(&self.stream) + .set_keepalive(true) + .map_err(io_err_into_net_error)?; + Ok(()) + } + + fn keepalive(&self) -> Result { + let ret = socket2::SockRef::from(&self.stream) + .keepalive() + .map_err(io_err_into_net_error)?; + Ok(ret) + } + + fn set_dontroute(&mut self, val: bool) -> Result<()> { + let val = val as libc::c_int; + let payload = &val as *const libc::c_int as *const libc::c_void; + let err = unsafe { + libc::setsockopt(self.stream.as_raw_fd(), libc::SOL_SOCKET, + libc::SO_DONTROUTE, + payload, + std::mem::size_of::() as libc::socklen_t) + }; + if err == -1 { + return Err(io_err_into_net_error(std::io::Error::last_os_error())); + } + Ok(()) + } + + fn dontroute(&self) -> Result { + let mut payload: MaybeUninit = MaybeUninit::uninit(); + let mut len = std::mem::size_of::() as libc::socklen_t; + let err = unsafe { + libc::getsockopt(self.stream.as_raw_fd(), libc::SOL_SOCKET, + libc::SO_DONTROUTE, + payload.as_mut_ptr().cast(), + &mut len) + }; + if err == -1 { + return Err(io_err_into_net_error(std::io::Error::last_os_error())); + } + Ok(unsafe { payload.assume_init() != 0 }) + } + fn addr_peer(&self) -> Result { Ok(self.addr) } diff --git a/lib/virtual-net/src/lib.rs b/lib/virtual-net/src/lib.rs index dbc59d04ac8..4d5b2e3220b 100644 --- a/lib/virtual-net/src/lib.rs +++ b/lib/virtual-net/src/lib.rs @@ -573,6 +573,24 @@ pub trait VirtualTcpSocket: VirtualConnectedSocket + fmt::Debug + Send + Sync + /// latency but increases encapsulation overhead. fn nodelay(&self) -> Result; + /// When KEEP_ALIVE is set the connection will periodically send + /// an empty data packet to the server to make sure the connection + /// stays alive. + fn set_keepalive(&mut self, keepalive: bool) -> Result<()>; + + /// Indicates if the KEEP_ALIVE flag is set which means that the + /// socket will periodically send an empty data packet to keep + /// the connection alive. + fn keepalive(&self) -> Result; + + /// When DONT_ROUTE is set the packet will be sent directly + /// to the interface without passing through the routing logic. + fn set_dontroute(&mut self, keepalive: bool) -> Result<()>; + + /// Indicates if the packet will pass straight through to + /// the interface bypassing the routing logic. + fn dontroute(&self) -> Result; + /// Returns the address (IP and Port) of the peer socket that this /// is conencted to fn addr_peer(&self) -> Result; diff --git a/lib/virtual-net/src/meta.rs b/lib/virtual-net/src/meta.rs index c275254eeb8..8744f0af9ca 100644 --- a/lib/virtual-net/src/meta.rs +++ b/lib/virtual-net/src/meta.rs @@ -172,6 +172,20 @@ pub enum RequestType { /// is immediately sent to the peer without waiting. This reduces /// latency but increases encapsulation overhead. GetNoDelay, + /// When KEEP_ALIVE is set the connection will periodically send + /// an empty data packet to the server to make sure the connection + /// stays alive. + SetKeepAlive(bool), + /// Indicates if the KEEP_ALIVE flag is set which means that the + /// socket will periodically send an empty data packet to keep + /// the connection alive. + GetKeepAlive, + /// When DONT_ROUTE is set the packet will be sent directly + /// to the interface without passing through the routing logic. + SetDontRoute(bool), + /// Indicates if the packet will pass straight through to + /// the interface bypassing the routing logic. + GetDontRoute, /// Shuts down either the READER or WRITER sides of the socket /// connection. Shutdown(Shutdown), diff --git a/lib/virtual-net/src/server.rs b/lib/virtual-net/src/server.rs index 840addac83a..7168f80ebf5 100644 --- a/lib/virtual-net/src/server.rs +++ b/lib/virtual-net/src/server.rs @@ -1034,6 +1034,46 @@ impl RemoteNetworkingServerDriver { socket_id, req_id, ), + RequestType::SetKeepAlive(val) => self.process_inner_noop( + move |socket| match socket { + RemoteAdapterSocket::TcpSocket(s) => s.set_keepalive(val), + _ => Err(NetworkError::Unsupported), + }, + socket_id, + req_id, + ), + RequestType::GetKeepAlive => self.process_inner( + move |socket| match socket { + RemoteAdapterSocket::TcpSocket(s) => s.keepalive(), + _ => Err(NetworkError::Unsupported), + }, + |ret| match ret { + Ok(flag) => ResponseType::Flag(flag), + Err(err) => ResponseType::Err(err), + }, + socket_id, + req_id, + ), + RequestType::SetDontRoute(val) => self.process_inner_noop( + move |socket| match socket { + RemoteAdapterSocket::TcpSocket(s) => s.set_dontroute(val), + _ => Err(NetworkError::Unsupported), + }, + socket_id, + req_id, + ), + RequestType::GetDontRoute => self.process_inner( + move |socket| match socket { + RemoteAdapterSocket::TcpSocket(s) => s.dontroute(), + _ => Err(NetworkError::Unsupported), + }, + |ret| match ret { + Ok(flag) => ResponseType::Flag(flag), + Err(err) => ResponseType::Err(err), + }, + socket_id, + req_id, + ), RequestType::Shutdown(shutdown) => self.process_inner_noop( move |socket| match socket { RemoteAdapterSocket::TcpSocket(s) => s.shutdown(match shutdown { diff --git a/lib/wasix/src/net/socket.rs b/lib/wasix/src/net/socket.rs index 0e836faf6fa..60f73906270 100644 --- a/lib/wasix/src/net/socket.rs +++ b/lib/wasix/src/net/socket.rs @@ -45,6 +45,9 @@ pub enum InodeSocketKind { only_v6: bool, reuse_port: bool, reuse_addr: bool, + no_delay: Option, + keep_alive: Option, + dont_route: Option, send_buf_size: Option, recv_buf_size: Option, write_timeout: Option, @@ -437,12 +440,18 @@ impl InodeSocket { addr, write_timeout, read_timeout, + no_delay, + keep_alive, + dont_route, .. } => { new_write_timeout = *write_timeout; new_read_timeout = *read_timeout; match *ty { Socktype::Stream => { + let no_delay = *no_delay; + let keep_alive = *keep_alive; + let dont_route = *dont_route; let addr = match addr { Some(a) => *a, None => { @@ -453,7 +462,19 @@ impl InodeSocket { SocketAddr::new(ip, 0) } }; - net.connect_tcp(addr, peer) + Box::pin(async move { + let mut ret = net.connect_tcp(addr, peer).await?; + if let Some(no_delay) = no_delay { + ret.set_nodelay(no_delay).ok(); + } + if let Some(keep_alive) = keep_alive { + ret.set_keepalive(keep_alive).ok(); + } + if let Some(dont_route) = dont_route { + ret.set_dontroute(dont_route).ok(); + } + Ok(ret) + }) } Socktype::Dgram => return Err(Errno::Inval), _ => return Err(Errno::Notsup), @@ -565,12 +586,18 @@ impl InodeSocket { only_v6, reuse_port, reuse_addr, + no_delay, + keep_alive, + dont_route, .. } => { match option { WasiSocketOption::OnlyV6 => *only_v6 = val, WasiSocketOption::ReusePort => *reuse_port = val, WasiSocketOption::ReuseAddr => *reuse_addr = val, + WasiSocketOption::NoDelay => *no_delay = Some(val), + WasiSocketOption::KeepAlive => *keep_alive = Some(val), + WasiSocketOption::DontRoute => *dont_route = Some(val), _ => return Err(Errno::Inval), }; } @@ -584,6 +611,15 @@ impl InodeSocket { WasiSocketOption::NoDelay => { socket.set_nodelay(val).map_err(net_error_into_wasi_err)? } + WasiSocketOption::KeepAlive => { + socket.set_keepalive(val).map_err(net_error_into_wasi_err)? + } + WasiSocketOption::DontRoute => { + socket.set_dontroute(val).map_err(net_error_into_wasi_err)? + } + _ => return Err(Errno::Inval), + }, + InodeSocketKind::TcpListener { .. } => match option { _ => return Err(Errno::Inval), }, InodeSocketKind::UdpSocket { socket, .. } => match option { @@ -610,11 +646,15 @@ impl InodeSocket { only_v6, reuse_port, reuse_addr, + no_delay, + keep_alive, .. } => match option { WasiSocketOption::OnlyV6 => *only_v6, WasiSocketOption::ReusePort => *reuse_port, WasiSocketOption::ReuseAddr => *reuse_addr, + WasiSocketOption::NoDelay => no_delay.unwrap_or_default(), + WasiSocketOption::KeepAlive => keep_alive.unwrap_or_default(), _ => return Err(Errno::Inval), }, InodeSocketKind::Raw(sock) => match option { @@ -625,6 +665,8 @@ impl InodeSocket { }, InodeSocketKind::TcpStream { socket, .. } => match option { WasiSocketOption::NoDelay => socket.nodelay().map_err(net_error_into_wasi_err)?, + WasiSocketOption::KeepAlive => socket.keepalive().map_err(net_error_into_wasi_err)?, + WasiSocketOption::DontRoute => socket.dontroute().map_err(net_error_into_wasi_err)?, _ => return Err(Errno::Inval), }, InodeSocketKind::UdpSocket { socket, .. } => match option { diff --git a/lib/wasix/src/syscalls/wasi/clock_time_get.rs b/lib/wasix/src/syscalls/wasi/clock_time_get.rs index 45c0e7683fb..4d704026401 100644 --- a/lib/wasix/src/syscalls/wasi/clock_time_get.rs +++ b/lib/wasix/src/syscalls/wasi/clock_time_get.rs @@ -11,7 +11,7 @@ use crate::syscalls::*; /// Output: /// - `Timestamp *time` /// The value of the clock in nanoseconds -#[instrument(level = "trace", skip_all, fields(?clock_id, %precision), ret)] +//#[instrument(level = "trace", skip_all, fields(?clock_id, %precision), ret)] pub fn clock_time_get( ctx: FunctionEnvMut<'_, WasiEnv>, clock_id: Snapshot0Clockid, diff --git a/lib/wasix/src/syscalls/wasi/poll_oneoff.rs b/lib/wasix/src/syscalls/wasi/poll_oneoff.rs index 2f1fcefe05c..a3d203f7896 100644 --- a/lib/wasix/src/syscalls/wasi/poll_oneoff.rs +++ b/lib/wasix/src/syscalls/wasi/poll_oneoff.rs @@ -385,13 +385,23 @@ where match events { Ok(evts) => { // If its a timeout then return an event for it - Span::current().record("seen", evts.len()); + if evts.len() == 1 { + Span::current().record("seen", &format!( + "{:?}", + evts.iter().next().unwrap() + )); + } else { + Span::current().record("seen", &format!( + "trigger_cnt=({})", + evts.len() + )); + } // Process the events process_events(ctx, evts) } Err(Errno::Timedout) => { - // The timeout has triggerred so lets add that event + // The timeout has triggered so lets add that event if clock_subs.is_empty() { tracing::warn!("triggered_timeout (without any clock subscriptions)",); } diff --git a/lib/wasix/src/syscalls/wasix/sock_open.rs b/lib/wasix/src/syscalls/wasix/sock_open.rs index c43688bc07b..49868174482 100644 --- a/lib/wasix/src/syscalls/wasix/sock_open.rs +++ b/lib/wasix/src/syscalls/wasix/sock_open.rs @@ -31,6 +31,21 @@ pub fn sock_open( let env = ctx.data(); let (memory, state, inodes) = unsafe { env.get_memory_and_wasi_state_and_inodes(&ctx, 0) }; + // only certain combinations are supported + match pt { + SockProto::Tcp => { + if ty != Socktype::Stream { + return Errno::Notsup; + } + }, + SockProto::Udp => { + if ty != Socktype::Dgram { + return Errno::Notsup; + } + }, + _ => { } + } + let kind = match ty { Socktype::Stream | Socktype::Dgram => Kind::Socket { socket: InodeSocket::new(InodeSocketKind::PreSocket { @@ -41,6 +56,9 @@ pub fn sock_open( only_v6: false, reuse_port: false, reuse_addr: false, + no_delay: None, + keep_alive: None, + dont_route: None, send_buf_size: None, recv_buf_size: None, write_timeout: None, From 7885976b14748d9db4017118f6094e51a95c7cd7 Mon Sep 17 00:00:00 2001 From: Johnathan Sharratt Date: Tue, 29 Aug 2023 16:11:34 +1000 Subject: [PATCH 05/13] Fixed a blocking issue inside an async and added sha256 caching of webc files --- .../runtime/package_loader/builtin_loader.rs | 2 +- .../src/runtime/resolver/filesystem_source.rs | 5 ++-- lib/wasix/src/runtime/resolver/inputs.rs | 25 +++++++++++++++---- lib/wasix/src/runtime/resolver/web_source.rs | 5 ++-- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/wasix/src/runtime/package_loader/builtin_loader.rs b/lib/wasix/src/runtime/package_loader/builtin_loader.rs index c559c030050..0f70b4c4356 100644 --- a/lib/wasix/src/runtime/package_loader/builtin_loader.rs +++ b/lib/wasix/src/runtime/package_loader/builtin_loader.rs @@ -239,7 +239,7 @@ impl FileSystemCache { async fn lookup(&self, hash: &WebcHash) -> Result, Error> { let path = self.path(hash); - match Container::from_disk(&path) { + match tokio::task::block_in_place(|| Container::from_disk(&path)) { Ok(c) => Ok(Some(c)), Err(ContainerError::Open { error, .. }) | Err(ContainerError::Read { error, .. }) diff --git a/lib/wasix/src/runtime/resolver/filesystem_source.rs b/lib/wasix/src/runtime/resolver/filesystem_source.rs index 9be00fac897..56deefcaf2e 100644 --- a/lib/wasix/src/runtime/resolver/filesystem_source.rs +++ b/lib/wasix/src/runtime/resolver/filesystem_source.rs @@ -23,10 +23,9 @@ impl Source for FileSystemSource { _ => return Err(QueryError::Unsupported), }; - // FIXME: These two operations will block - let webc_sha256 = WebcHash::for_file(&path) + let webc_sha256 = tokio::task::block_in_place(|| WebcHash::for_file(&path)) .with_context(|| format!("Unable to hash \"{}\"", path.display()))?; - let container = Container::from_disk(&path) + let container = tokio::task::block_in_place(|| Container::from_disk(&path)) .with_context(|| format!("Unable to parse \"{}\"", path.display()))?; let url = crate::runtime::resolver::utils::url_from_file_path(&path) diff --git a/lib/wasix/src/runtime/resolver/inputs.rs b/lib/wasix/src/runtime/resolver/inputs.rs index 8fb2b7f8cb7..8a80964269f 100644 --- a/lib/wasix/src/runtime/resolver/inputs.rs +++ b/lib/wasix/src/runtime/resolver/inputs.rs @@ -1,9 +1,7 @@ use std::{ fmt::{self, Display, Formatter}, - fs::File, - io::{BufRead, BufReader}, path::{Path, PathBuf}, - str::FromStr, + str::FromStr, fs::File, io::{BufReader, BufRead, Read}, }; use anyhow::{Context, Error}; @@ -344,7 +342,19 @@ impl WebcHash { Ok(Self(hash)) } - pub fn for_file(path: impl AsRef) -> Result { + pub fn for_file(path: &PathBuf) -> Result { + // check for a hash at the file location + let path_hash = path.join(".sha256"); + if let Ok(mut file) = File::open(&path_hash) { + let mut hash = Vec::new(); + if let Ok(amt) = file.read_to_end(&mut hash) { + if amt == 32 { + return Ok(WebcHash::from_bytes(hash[0..32].try_into().unwrap())); + } + } + } + + // compute the hash let mut hasher = Sha256::default(); let mut reader = BufReader::new(File::open(path)?); @@ -359,7 +369,12 @@ impl WebcHash { } let hash = hasher.finalize().into(); - Ok(WebcHash::from_bytes(hash)) + + // write the cache of the hash to the file system + std::fs::write(path_hash, hash).ok(); + let hash = WebcHash::from_bytes(hash); + + Ok(hash) } /// Generate a new [`WebcHash`] based on the SHA-256 hash of some bytes. diff --git a/lib/wasix/src/runtime/resolver/web_source.rs b/lib/wasix/src/runtime/resolver/web_source.rs index c5234368114..e93fa3b7e84 100644 --- a/lib/wasix/src/runtime/resolver/web_source.rs +++ b/lib/wasix/src/runtime/resolver/web_source.rs @@ -240,13 +240,12 @@ impl Source for WebSource { .await .context("Unable to get the locally cached file")?; - // FIXME: this will block - let webc_sha256 = WebcHash::for_file(&local_path) + let webc_sha256 = tokio::task::block_in_place(|| WebcHash::for_file(&local_path)) .with_context(|| format!("Unable to hash \"{}\"", local_path.display()))?; // Note: We want to use Container::from_disk() rather than the bytes // our HTTP client gave us because then we can use memory-mapped files - let container = Container::from_disk(&local_path) + let container = tokio::task::block_in_place(|| Container::from_disk(&local_path)) .with_context(|| format!("Unable to load \"{}\"", local_path.display()))?; let pkg = PackageInfo::from_manifest(container.manifest()) .context("Unable to determine the package's metadata")?; From ee7fd9d8c032725d50bd9465605e0b40fde9e0a1 Mon Sep 17 00:00:00 2001 From: Johnathan Sharratt Date: Sat, 2 Sep 2023 04:55:19 +1000 Subject: [PATCH 06/13] Faster checksums for debug --- Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 3effe8e97cf..c757c545a7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -175,6 +175,10 @@ opt-level = 3 opt-level = 3 [profile.dev.package.weezl] opt-level = 3 +[profile.dev.package.sha256] +opt-level = 3 +[profile.dev.package.digest] +opt-level = 3 [[bench]] name = "static_and_dynamic_functions" From 53149e632f237548eb25fa83febbe5414b3ae586 Mon Sep 17 00:00:00 2001 From: Johnathan Sharratt Date: Sat, 2 Sep 2023 18:48:16 +1000 Subject: [PATCH 07/13] Removed error messages when a WASI instance shuts down and doing cleanups in parallel --- lib/wasix/src/fs/mod.rs | 25 +++++++++++-------- lib/wasix/src/syscalls/legacy/snapshot0.rs | 2 +- lib/wasix/src/syscalls/wasi/fd_close.rs | 2 +- lib/wasix/src/syscalls/wasi/fd_datasync.rs | 2 +- .../src/syscalls/wasi/fd_fdstat_set_flags.rs | 2 +- lib/wasix/src/syscalls/wasi/fd_read.rs | 4 +-- lib/wasix/src/syscalls/wasi/fd_write.rs | 4 +-- lib/wasix/src/syscalls/wasi/poll_oneoff.rs | 2 +- lib/wasix/src/syscalls/wasi/proc_raise.rs | 2 +- .../src/syscalls/wasix/callback_signal.rs | 2 +- lib/wasix/src/syscalls/wasix/epoll_create.rs | 2 +- lib/wasix/src/syscalls/wasix/epoll_ctl.rs | 2 +- lib/wasix/src/syscalls/wasix/epoll_wait.rs | 2 +- lib/wasix/src/syscalls/wasix/futex_wait.rs | 2 +- lib/wasix/src/syscalls/wasix/port_addr_add.rs | 2 +- .../src/syscalls/wasix/port_addr_clear.rs | 2 +- .../src/syscalls/wasix/port_addr_list.rs | 2 +- .../src/syscalls/wasix/port_addr_remove.rs | 2 +- lib/wasix/src/syscalls/wasix/port_bridge.rs | 2 +- .../src/syscalls/wasix/port_dhcp_acquire.rs | 2 +- .../src/syscalls/wasix/port_gateway_set.rs | 2 +- lib/wasix/src/syscalls/wasix/port_mac.rs | 2 +- .../src/syscalls/wasix/port_route_add.rs | 2 +- .../src/syscalls/wasix/port_route_clear.rs | 2 +- .../src/syscalls/wasix/port_route_list.rs | 2 +- .../src/syscalls/wasix/port_route_remove.rs | 2 +- lib/wasix/src/syscalls/wasix/port_unbridge.rs | 2 +- lib/wasix/src/syscalls/wasix/proc_fork.rs | 2 +- lib/wasix/src/syscalls/wasix/proc_join.rs | 2 +- lib/wasix/src/syscalls/wasix/proc_signal.rs | 2 +- lib/wasix/src/syscalls/wasix/proc_spawn.rs | 2 +- lib/wasix/src/syscalls/wasix/resolve.rs | 2 +- lib/wasix/src/syscalls/wasix/sched_yield.rs | 2 +- lib/wasix/src/syscalls/wasix/sock_accept.rs | 4 +-- lib/wasix/src/syscalls/wasix/sock_recv.rs | 2 +- .../src/syscalls/wasix/sock_recv_from.rs | 2 +- lib/wasix/src/syscalls/wasix/sock_send.rs | 2 +- .../src/syscalls/wasix/sock_send_file.rs | 2 +- lib/wasix/src/syscalls/wasix/sock_send_to.rs | 2 +- .../src/syscalls/wasix/stack_checkpoint.rs | 2 +- lib/wasix/src/syscalls/wasix/stack_restore.rs | 2 +- lib/wasix/src/syscalls/wasix/thread_join.rs | 2 +- lib/wasix/src/syscalls/wasix/thread_signal.rs | 2 +- lib/wasix/src/syscalls/wasix/thread_sleep.rs | 2 +- 44 files changed, 60 insertions(+), 57 deletions(-) diff --git a/lib/wasix/src/fs/mod.rs b/lib/wasix/src/fs/mod.rs index f57f753c95f..59ad1ec1dfb 100644 --- a/lib/wasix/src/fs/mod.rs +++ b/lib/wasix/src/fs/mod.rs @@ -453,9 +453,9 @@ impl WasiFs { pub async fn close_all(&self) { // TODO: this should close all uniquely owned files instead of just flushing. - // Make sure the STDOUT and STDERR are explicitely flushed - self.flush(__WASI_STDOUT_FILENO).await.ok(); - self.flush(__WASI_STDERR_FILENO).await.ok(); + if let Ok(mut map) = self.fd_map.write() { + map.clear(); + } let to_close = { if let Ok(map) = self.fd_map.read() { @@ -465,14 +465,17 @@ impl WasiFs { } }; - for fd in to_close { - self.flush(fd).await.ok(); - self.close_fd(fd).ok(); - } - - if let Ok(mut map) = self.fd_map.write() { - map.clear(); - } + let _ = tokio::join!( + // Make sure the STDOUT and STDERR are explicitely flushed + self.flush(__WASI_STDOUT_FILENO), + self.flush(__WASI_STDERR_FILENO), + async { + for fd in to_close { + self.flush(fd).await.ok(); + self.close_fd(fd).ok(); + } + } + ); } /// Will conditionally union the binary file system with this one diff --git a/lib/wasix/src/syscalls/legacy/snapshot0.rs b/lib/wasix/src/syscalls/legacy/snapshot0.rs index f5b1caf1b95..215c99602f0 100644 --- a/lib/wasix/src/syscalls/legacy/snapshot0.rs +++ b/lib/wasix/src/syscalls/legacy/snapshot0.rs @@ -69,7 +69,7 @@ pub fn fd_seek( /// Wrapper around `syscalls::poll_oneoff` with extra logic to add the removed /// userdata field back -#[instrument(level = "trace", skip_all, fields(timeout_ms = field::Empty, fd_guards = field::Empty, seen = field::Empty), ret, err)] +#[instrument(level = "trace", skip_all, fields(timeout_ms = field::Empty, fd_guards = field::Empty, seen = field::Empty), ret)] pub fn poll_oneoff( mut ctx: FunctionEnvMut, in_: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasi/fd_close.rs b/lib/wasix/src/syscalls/wasi/fd_close.rs index c66d878ae03..6c217ec36e3 100644 --- a/lib/wasix/src/syscalls/wasi/fd_close.rs +++ b/lib/wasix/src/syscalls/wasi/fd_close.rs @@ -12,7 +12,7 @@ use crate::syscalls::*; /// If `fd` is a directory /// - `Errno::Badf` /// If `fd` is invalid or not open -#[instrument(level = "debug", skip_all, fields(pid = ctx.data().process.pid().raw(), %fd), ret, err)] +#[instrument(level = "debug", skip_all, fields(pid = ctx.data().process.pid().raw(), %fd), ret)] pub fn fd_close(mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Result { wasi_try_ok!(WasiEnv::process_signals_and_exit(&mut ctx)?); diff --git a/lib/wasix/src/syscalls/wasi/fd_datasync.rs b/lib/wasix/src/syscalls/wasi/fd_datasync.rs index a76dff86d8a..75523059cd3 100644 --- a/lib/wasix/src/syscalls/wasi/fd_datasync.rs +++ b/lib/wasix/src/syscalls/wasi/fd_datasync.rs @@ -6,7 +6,7 @@ use crate::syscalls::*; /// Inputs: /// - `Fd fd` /// The file descriptor to sync -#[instrument(level = "debug", skip_all, fields(%fd), ret, err)] +#[instrument(level = "debug", skip_all, fields(%fd), ret)] pub fn fd_datasync(mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Result { wasi_try_ok!(WasiEnv::process_signals_and_exit(&mut ctx)?); diff --git a/lib/wasix/src/syscalls/wasi/fd_fdstat_set_flags.rs b/lib/wasix/src/syscalls/wasi/fd_fdstat_set_flags.rs index 67c055a500d..7ee8790a721 100644 --- a/lib/wasix/src/syscalls/wasi/fd_fdstat_set_flags.rs +++ b/lib/wasix/src/syscalls/wasi/fd_fdstat_set_flags.rs @@ -8,7 +8,7 @@ use crate::syscalls::*; /// The file descriptor to apply the new flags to /// - `Fdflags flags` /// The flags to apply to `fd` -#[instrument(level = "debug", skip_all, fields(%fd), ret, err)] +#[instrument(level = "debug", skip_all, fields(%fd), ret)] pub fn fd_fdstat_set_flags( mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, diff --git a/lib/wasix/src/syscalls/wasi/fd_read.rs b/lib/wasix/src/syscalls/wasi/fd_read.rs index ddb7ca3ea4b..ae28f3d7acf 100644 --- a/lib/wasix/src/syscalls/wasi/fd_read.rs +++ b/lib/wasix/src/syscalls/wasi/fd_read.rs @@ -18,7 +18,7 @@ use crate::{fs::NotificationInner, net::socket::TimeType, syscalls::*}; /// - `u32 *nread` /// Number of bytes read /// -#[instrument(level = "trace", skip_all, fields(%fd, nread = field::Empty), ret, err)] +#[instrument(level = "trace", skip_all, fields(%fd, nread = field::Empty), ret)] pub fn fd_read( mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, @@ -57,7 +57,7 @@ pub fn fd_read( /// Output: /// - `size_t nread` /// The number of bytes read -#[instrument(level = "trace", skip_all, fields(%fd, %offset, ?nread), ret, err)] +#[instrument(level = "trace", skip_all, fields(%fd, %offset, ?nread), ret)] pub fn fd_pread( mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, diff --git a/lib/wasix/src/syscalls/wasi/fd_write.rs b/lib/wasix/src/syscalls/wasi/fd_write.rs index 99efcf2af4b..e60ba61ae25 100644 --- a/lib/wasix/src/syscalls/wasi/fd_write.rs +++ b/lib/wasix/src/syscalls/wasi/fd_write.rs @@ -17,7 +17,7 @@ use crate::{net::socket::TimeType, syscalls::*}; /// Number of bytes written /// Errors: /// -#[instrument(level = "trace", skip_all, fields(%fd, nwritten = field::Empty), ret, err)] +#[instrument(level = "trace", skip_all, fields(%fd, nwritten = field::Empty), ret)] pub fn fd_write( mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, @@ -51,7 +51,7 @@ pub fn fd_write( /// Output: /// - `u32 *nwritten` /// Number of bytes written -#[instrument(level = "trace", skip_all, fields(%fd, %offset, nwritten = field::Empty), ret, err)] +#[instrument(level = "trace", skip_all, fields(%fd, %offset, nwritten = field::Empty), ret)] pub fn fd_pwrite( mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd, diff --git a/lib/wasix/src/syscalls/wasi/poll_oneoff.rs b/lib/wasix/src/syscalls/wasi/poll_oneoff.rs index a3d203f7896..bb90198a510 100644 --- a/lib/wasix/src/syscalls/wasi/poll_oneoff.rs +++ b/lib/wasix/src/syscalls/wasi/poll_oneoff.rs @@ -54,7 +54,7 @@ impl EventResult { /// Output: /// - `u32 nevents` /// The number of events seen -#[instrument(level = "trace", skip_all, fields(timeout_ms = field::Empty, fd_guards = field::Empty, seen = field::Empty), ret, err)] +#[instrument(level = "trace", skip_all, fields(timeout_ms = field::Empty, fd_guards = field::Empty, seen = field::Empty), ret)] pub fn poll_oneoff( mut ctx: FunctionEnvMut<'_, WasiEnv>, in_: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasi/proc_raise.rs b/lib/wasix/src/syscalls/wasi/proc_raise.rs index b21850f543e..6cd8cdf9f0f 100644 --- a/lib/wasix/src/syscalls/wasi/proc_raise.rs +++ b/lib/wasix/src/syscalls/wasi/proc_raise.rs @@ -7,7 +7,7 @@ use crate::syscalls::*; /// Inputs: /// - `Signal` /// Signal to be raised for this process -#[instrument(level = "debug", skip_all, fields(sig), ret, err)] +#[instrument(level = "debug", skip_all, fields(sig), ret)] pub fn proc_raise(mut ctx: FunctionEnvMut<'_, WasiEnv>, sig: Signal) -> Result { let env = ctx.data(); env.process.signal_process(sig); diff --git a/lib/wasix/src/syscalls/wasix/callback_signal.rs b/lib/wasix/src/syscalls/wasix/callback_signal.rs index eb5e1239e42..e5dcb802039 100644 --- a/lib/wasix/src/syscalls/wasix/callback_signal.rs +++ b/lib/wasix/src/syscalls/wasix/callback_signal.rs @@ -7,7 +7,7 @@ use crate::syscalls::*; /// ### Parameters /// /// * `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)] +#[instrument(level = "trace", skip_all, fields(name = field::Empty, funct_is_some = field::Empty), ret)] pub fn callback_signal( mut ctx: FunctionEnvMut<'_, WasiEnv>, name: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasix/epoll_create.rs b/lib/wasix/src/syscalls/wasix/epoll_create.rs index f7c626b2b27..9296f41792e 100644 --- a/lib/wasix/src/syscalls/wasix/epoll_create.rs +++ b/lib/wasix/src/syscalls/wasix/epoll_create.rs @@ -13,7 +13,7 @@ use tokio::sync::Mutex as AsyncMutex; /// ### `epoll_create()` /// Create an epoll interest list -#[instrument(level = "trace", skip_all, fields(timeout_ms = field::Empty, fd_guards = field::Empty, seen = field::Empty), ret, err)] +#[instrument(level = "trace", skip_all, fields(timeout_ms = field::Empty, fd_guards = field::Empty, seen = field::Empty), ret)] pub fn epoll_create( mut ctx: FunctionEnvMut<'_, WasiEnv>, ret_fd: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasix/epoll_ctl.rs b/lib/wasix/src/syscalls/wasix/epoll_ctl.rs index bbec212fbd4..4df7aebe9af 100644 --- a/lib/wasix/src/syscalls/wasix/epoll_ctl.rs +++ b/lib/wasix/src/syscalls/wasix/epoll_ctl.rs @@ -26,7 +26,7 @@ use crate::{ /// Output: /// - `Fd fd` /// The new file handle that is used to modify or wait on the interest list -#[instrument(level = "trace", skip_all, fields(timeout_ms = field::Empty, fd_guards = field::Empty, seen = field::Empty, fd), ret, err)] +#[instrument(level = "trace", skip_all, fields(timeout_ms = field::Empty, fd_guards = field::Empty, seen = field::Empty, fd), ret)] pub fn epoll_ctl( mut ctx: FunctionEnvMut<'_, WasiEnv>, epfd: WasiFd, diff --git a/lib/wasix/src/syscalls/wasix/epoll_wait.rs b/lib/wasix/src/syscalls/wasix/epoll_wait.rs index 55cba1f6021..37c7dc75671 100644 --- a/lib/wasix/src/syscalls/wasix/epoll_wait.rs +++ b/lib/wasix/src/syscalls/wasix/epoll_wait.rs @@ -15,7 +15,7 @@ const TIMEOUT_FOREVER: u64 = u64::MAX; /// ### `epoll_wait()` /// Wait for an I/O event on an epoll file descriptor -#[instrument(level = "trace", skip_all, fields(timeout_ms = field::Empty, fd_guards = field::Empty, seen = field::Empty), ret, err)] +#[instrument(level = "trace", skip_all, fields(timeout_ms = field::Empty, fd_guards = field::Empty, seen = field::Empty), ret)] pub fn epoll_wait<'a, M: MemorySize + 'static>( mut ctx: FunctionEnvMut<'a, WasiEnv>, epfd: WasiFd, diff --git a/lib/wasix/src/syscalls/wasix/futex_wait.rs b/lib/wasix/src/syscalls/wasix/futex_wait.rs index e54ebebab28..a66889289e9 100644 --- a/lib/wasix/src/syscalls/wasix/futex_wait.rs +++ b/lib/wasix/src/syscalls/wasix/futex_wait.rs @@ -70,7 +70,7 @@ impl Drop for FutexPoller { /// * `futex` - Memory location that holds the value that will be checked /// * `expected` - Expected value that should be currently held at the memory location /// * `timeout` - Timeout should the futex not be triggered in the allocated time -#[instrument(level = "trace", skip_all, fields(futex_idx = field::Empty, poller_idx = field::Empty, %expected, timeout = field::Empty, woken = field::Empty), err)] +#[instrument(level = "trace", skip_all, fields(futex_idx = field::Empty, poller_idx = field::Empty, %expected, timeout = field::Empty, woken = field::Empty))] pub fn futex_wait( ctx: FunctionEnvMut<'_, WasiEnv>, futex_ptr: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasix/port_addr_add.rs b/lib/wasix/src/syscalls/wasix/port_addr_add.rs index ce4633957d5..5feabed467b 100644 --- a/lib/wasix/src/syscalls/wasix/port_addr_add.rs +++ b/lib/wasix/src/syscalls/wasix/port_addr_add.rs @@ -7,7 +7,7 @@ use crate::syscalls::*; /// ## Parameters /// /// * `addr` - Address to be added -#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret, err)] +#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret)] pub fn port_addr_add( mut ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_cidr_t, M>, diff --git a/lib/wasix/src/syscalls/wasix/port_addr_clear.rs b/lib/wasix/src/syscalls/wasix/port_addr_clear.rs index 73afbe7577e..a1fec934330 100644 --- a/lib/wasix/src/syscalls/wasix/port_addr_clear.rs +++ b/lib/wasix/src/syscalls/wasix/port_addr_clear.rs @@ -3,7 +3,7 @@ use crate::syscalls::*; /// ### `port_addr_clear()` /// Clears all the addresses on the local port -#[instrument(level = "debug", skip_all, ret, err)] +#[instrument(level = "debug", skip_all, ret)] pub fn port_addr_clear(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result { let env = ctx.data(); let net = env.net().clone(); diff --git a/lib/wasix/src/syscalls/wasix/port_addr_list.rs b/lib/wasix/src/syscalls/wasix/port_addr_list.rs index c3147e9f052..54390855415 100644 --- a/lib/wasix/src/syscalls/wasix/port_addr_list.rs +++ b/lib/wasix/src/syscalls/wasix/port_addr_list.rs @@ -14,7 +14,7 @@ use crate::syscalls::*; /// ## Return /// /// The number of addresses returned. -#[instrument(level = "debug", skip_all, fields(naddrs = field::Empty), ret, err)] +#[instrument(level = "debug", skip_all, fields(naddrs = field::Empty), ret)] pub fn port_addr_list( mut ctx: FunctionEnvMut<'_, WasiEnv>, addrs_ptr: WasmPtr<__wasi_cidr_t, M>, diff --git a/lib/wasix/src/syscalls/wasix/port_addr_remove.rs b/lib/wasix/src/syscalls/wasix/port_addr_remove.rs index ef48d647953..accae6cba6f 100644 --- a/lib/wasix/src/syscalls/wasix/port_addr_remove.rs +++ b/lib/wasix/src/syscalls/wasix/port_addr_remove.rs @@ -7,7 +7,7 @@ use crate::syscalls::*; /// ## Parameters /// /// * `addr` - Address to be removed -#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret, err)] +#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret)] pub fn port_addr_remove( mut ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, diff --git a/lib/wasix/src/syscalls/wasix/port_bridge.rs b/lib/wasix/src/syscalls/wasix/port_bridge.rs index 28aa712bf46..1a428af3c24 100644 --- a/lib/wasix/src/syscalls/wasix/port_bridge.rs +++ b/lib/wasix/src/syscalls/wasix/port_bridge.rs @@ -9,7 +9,7 @@ use crate::syscalls::*; /// * `network` - Fully qualified identifier for the network /// * `token` - Access token used to authenticate with the network /// * `security` - Level of encryption to encapsulate the network connection with -#[instrument(level = "debug", skip_all, fields(network = field::Empty, ?security), ret, err)] +#[instrument(level = "debug", skip_all, fields(network = field::Empty, ?security), ret)] pub fn port_bridge( mut ctx: FunctionEnvMut<'_, WasiEnv>, network: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasix/port_dhcp_acquire.rs b/lib/wasix/src/syscalls/wasix/port_dhcp_acquire.rs index 38fcf3b01f9..3a7a534ee73 100644 --- a/lib/wasix/src/syscalls/wasix/port_dhcp_acquire.rs +++ b/lib/wasix/src/syscalls/wasix/port_dhcp_acquire.rs @@ -3,7 +3,7 @@ use crate::syscalls::*; /// ### `port_dhcp_acquire()` /// Acquires a set of IP addresses using DHCP -#[instrument(level = "debug", skip_all, ret, err)] +#[instrument(level = "debug", skip_all, ret)] pub fn port_dhcp_acquire(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result { let env = ctx.data(); let net = env.net().clone(); diff --git a/lib/wasix/src/syscalls/wasix/port_gateway_set.rs b/lib/wasix/src/syscalls/wasix/port_gateway_set.rs index 5a4cfdc4198..0c9136a4af3 100644 --- a/lib/wasix/src/syscalls/wasix/port_gateway_set.rs +++ b/lib/wasix/src/syscalls/wasix/port_gateway_set.rs @@ -7,7 +7,7 @@ use crate::syscalls::*; /// ## Parameters /// /// * `addr` - Address of the default gateway -#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret, err)] +#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret)] pub fn port_gateway_set( mut ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, diff --git a/lib/wasix/src/syscalls/wasix/port_mac.rs b/lib/wasix/src/syscalls/wasix/port_mac.rs index 15de5612b19..93b13c544c9 100644 --- a/lib/wasix/src/syscalls/wasix/port_mac.rs +++ b/lib/wasix/src/syscalls/wasix/port_mac.rs @@ -3,7 +3,7 @@ use crate::syscalls::*; /// ### `port_mac()` /// Returns the MAC address of the local port -#[instrument(level = "debug", skip_all, fields(max = field::Empty), ret, err)] +#[instrument(level = "debug", skip_all, fields(max = field::Empty), ret)] pub fn port_mac( mut ctx: FunctionEnvMut<'_, WasiEnv>, ret_mac: WasmPtr<__wasi_hardwareaddress_t, M>, diff --git a/lib/wasix/src/syscalls/wasix/port_route_add.rs b/lib/wasix/src/syscalls/wasix/port_route_add.rs index 9e3ee6e4c88..ccad1ca5a3f 100644 --- a/lib/wasix/src/syscalls/wasix/port_route_add.rs +++ b/lib/wasix/src/syscalls/wasix/port_route_add.rs @@ -3,7 +3,7 @@ use crate::syscalls::*; /// ### `port_route_add()` /// Adds a new route to the local port -#[instrument(level = "debug", skip_all, fields(cidr = field::Empty, via_router = field::Empty), ret, err)] +#[instrument(level = "debug", skip_all, fields(cidr = field::Empty, via_router = field::Empty), ret)] pub fn port_route_add( mut ctx: FunctionEnvMut<'_, WasiEnv>, cidr: WasmPtr<__wasi_cidr_t, M>, diff --git a/lib/wasix/src/syscalls/wasix/port_route_clear.rs b/lib/wasix/src/syscalls/wasix/port_route_clear.rs index cd853f929de..ba2ea4ab04a 100644 --- a/lib/wasix/src/syscalls/wasix/port_route_clear.rs +++ b/lib/wasix/src/syscalls/wasix/port_route_clear.rs @@ -3,7 +3,7 @@ use crate::syscalls::*; /// ### `port_route_clear()` /// Clears all the routes in the local port -#[instrument(level = "debug", skip_all, ret, err)] +#[instrument(level = "debug", skip_all, ret)] pub fn port_route_clear(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result { let env = ctx.data(); let net = env.net().clone(); diff --git a/lib/wasix/src/syscalls/wasix/port_route_list.rs b/lib/wasix/src/syscalls/wasix/port_route_list.rs index c237a610e5d..31b0ee397de 100644 --- a/lib/wasix/src/syscalls/wasix/port_route_list.rs +++ b/lib/wasix/src/syscalls/wasix/port_route_list.rs @@ -10,7 +10,7 @@ use crate::syscalls::*; /// ## Parameters /// /// * `routes` - The buffer where routes will be stored -#[instrument(level = "debug", skip_all, fields(nroutes = field::Empty, max_routes = field::Empty), ret, err)] +#[instrument(level = "debug", skip_all, fields(nroutes = field::Empty, max_routes = field::Empty), ret)] pub fn port_route_list( mut ctx: FunctionEnvMut<'_, WasiEnv>, routes_ptr: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasix/port_route_remove.rs b/lib/wasix/src/syscalls/wasix/port_route_remove.rs index 3ab127e9e4d..46e1b9d2335 100644 --- a/lib/wasix/src/syscalls/wasix/port_route_remove.rs +++ b/lib/wasix/src/syscalls/wasix/port_route_remove.rs @@ -3,7 +3,7 @@ use crate::syscalls::*; /// ### `port_route_remove()` /// Removes an existing route from the local port -#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret, err)] +#[instrument(level = "debug", skip_all, fields(ip = field::Empty), ret)] pub fn port_route_remove( mut ctx: FunctionEnvMut<'_, WasiEnv>, ip: WasmPtr<__wasi_addr_t, M>, diff --git a/lib/wasix/src/syscalls/wasix/port_unbridge.rs b/lib/wasix/src/syscalls/wasix/port_unbridge.rs index 5d2120fa789..6cc4085a2a6 100644 --- a/lib/wasix/src/syscalls/wasix/port_unbridge.rs +++ b/lib/wasix/src/syscalls/wasix/port_unbridge.rs @@ -3,7 +3,7 @@ use crate::syscalls::*; /// ### `port_unbridge()` /// Disconnects from a remote network -#[instrument(level = "debug", skip_all, ret, err)] +#[instrument(level = "debug", skip_all, ret)] pub fn port_unbridge(mut ctx: FunctionEnvMut<'_, WasiEnv>) -> Result { let env = ctx.data(); let net = env.net().clone(); diff --git a/lib/wasix/src/syscalls/wasix/proc_fork.rs b/lib/wasix/src/syscalls/wasix/proc_fork.rs index 2f916a330e7..8a2571f73ac 100644 --- a/lib/wasix/src/syscalls/wasix/proc_fork.rs +++ b/lib/wasix/src/syscalls/wasix/proc_fork.rs @@ -19,7 +19,7 @@ pub(crate) struct ForkResult { /// Forks the current process into a new subprocess. If the function /// 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. -#[instrument(level = "debug", skip_all, fields(pid = ctx.data().process.pid().raw()), ret, err)] +#[instrument(level = "debug", skip_all, fields(pid = ctx.data().process.pid().raw()), ret)] pub fn proc_fork( mut ctx: FunctionEnvMut<'_, WasiEnv>, mut copy_memory: Bool, diff --git a/lib/wasix/src/syscalls/wasix/proc_join.rs b/lib/wasix/src/syscalls/wasix/proc_join.rs index 50e43452904..2300a6c685f 100644 --- a/lib/wasix/src/syscalls/wasix/proc_join.rs +++ b/lib/wasix/src/syscalls/wasix/proc_join.rs @@ -20,7 +20,7 @@ enum JoinStatusResult { /// ## Parameters /// /// * `pid` - Handle of the child process to wait on -//#[instrument(level = "trace", skip_all, fields(pid = ctx.data().process.pid().raw()), ret, err)] +//#[instrument(level = "trace", skip_all, fields(pid = ctx.data().process.pid().raw()), ret)] pub fn proc_join( ctx: FunctionEnvMut<'_, WasiEnv>, pid_ptr: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasix/proc_signal.rs b/lib/wasix/src/syscalls/wasix/proc_signal.rs index 0af18956081..5cb8bf8cb5a 100644 --- a/lib/wasix/src/syscalls/wasix/proc_signal.rs +++ b/lib/wasix/src/syscalls/wasix/proc_signal.rs @@ -8,7 +8,7 @@ use crate::syscalls::*; /// /// * `pid` - Handle of the child process to wait on /// * `sig` - Signal to send the child process -#[instrument(level = "trace", skip_all, fields(%pid, ?sig), ret, err)] +#[instrument(level = "trace", skip_all, fields(%pid, ?sig), ret)] pub fn proc_signal( mut ctx: FunctionEnvMut<'_, WasiEnv>, pid: Pid, diff --git a/lib/wasix/src/syscalls/wasix/proc_spawn.rs b/lib/wasix/src/syscalls/wasix/proc_spawn.rs index 552d75ba5a2..539600193c8 100644 --- a/lib/wasix/src/syscalls/wasix/proc_spawn.rs +++ b/lib/wasix/src/syscalls/wasix/proc_spawn.rs @@ -23,7 +23,7 @@ use crate::syscalls::*; /// ## Return /// /// 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)] +#[instrument(level = "debug", skip_all, fields(name = field::Empty, working_dir = field::Empty), ret)] pub fn proc_spawn( mut ctx: FunctionEnvMut<'_, WasiEnv>, name: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasix/resolve.rs b/lib/wasix/src/syscalls/wasix/resolve.rs index 775e78c198c..2e40e6e6829 100644 --- a/lib/wasix/src/syscalls/wasix/resolve.rs +++ b/lib/wasix/src/syscalls/wasix/resolve.rs @@ -19,7 +19,7 @@ use crate::syscalls::*; /// ## Return /// /// The number of IP addresses returned during the DNS resolution. -#[instrument(level = "debug", skip_all, fields(host = field::Empty, %port), ret, err)] +#[instrument(level = "debug", skip_all, fields(host = field::Empty, %port), ret)] pub fn resolve( mut ctx: FunctionEnvMut<'_, WasiEnv>, host: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasix/sched_yield.rs b/lib/wasix/src/syscalls/wasix/sched_yield.rs index d6745761c6f..b6b3a363f34 100644 --- a/lib/wasix/src/syscalls/wasix/sched_yield.rs +++ b/lib/wasix/src/syscalls/wasix/sched_yield.rs @@ -3,7 +3,7 @@ use crate::syscalls::*; /// ### `sched_yield()` /// Yields execution of the thread -#[instrument(level = "trace", skip_all, ret, err)] +#[instrument(level = "trace", skip_all, ret)] pub fn sched_yield( mut ctx: FunctionEnvMut<'_, WasiEnv>, ) -> Result { diff --git a/lib/wasix/src/syscalls/wasix/sock_accept.rs b/lib/wasix/src/syscalls/wasix/sock_accept.rs index e97875b213e..3a9910fa3d4 100644 --- a/lib/wasix/src/syscalls/wasix/sock_accept.rs +++ b/lib/wasix/src/syscalls/wasix/sock_accept.rs @@ -15,7 +15,7 @@ use crate::{net::socket::TimeType, syscalls::*}; /// ## Return /// /// New socket connection -#[instrument(level = "debug", skip_all, fields(%sock, fd = field::Empty), ret, err)] +#[instrument(level = "debug", skip_all, fields(%sock, fd = field::Empty), ret)] pub fn sock_accept( mut ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, @@ -49,7 +49,7 @@ pub fn sock_accept( /// ## Return /// /// New socket connection -#[instrument(level = "debug", skip_all, fields(%sock, fd = field::Empty), ret, err)] +#[instrument(level = "debug", skip_all, fields(%sock, fd = field::Empty), ret)] pub fn sock_accept_v2( mut ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, diff --git a/lib/wasix/src/syscalls/wasix/sock_recv.rs b/lib/wasix/src/syscalls/wasix/sock_recv.rs index 04972edf4aa..c0d025c4a12 100644 --- a/lib/wasix/src/syscalls/wasix/sock_recv.rs +++ b/lib/wasix/src/syscalls/wasix/sock_recv.rs @@ -16,7 +16,7 @@ use crate::{net::socket::TimeType, syscalls::*}; /// ## Return /// /// Number of bytes stored in ri_data and message flags. -#[instrument(level = "trace", skip_all, fields(%sock, nread = field::Empty), ret, err)] +#[instrument(level = "trace", skip_all, fields(%sock, nread = field::Empty), ret)] pub fn sock_recv( mut ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, diff --git a/lib/wasix/src/syscalls/wasix/sock_recv_from.rs b/lib/wasix/src/syscalls/wasix/sock_recv_from.rs index 8ac2aee8320..17df5bab3cc 100644 --- a/lib/wasix/src/syscalls/wasix/sock_recv_from.rs +++ b/lib/wasix/src/syscalls/wasix/sock_recv_from.rs @@ -16,7 +16,7 @@ use crate::{net::socket::TimeType, syscalls::*}; /// ## Return /// /// Number of bytes stored in ri_data and message flags. -#[instrument(level = "trace", skip_all, fields(%sock, nread = field::Empty, peer = field::Empty), ret, err)] +#[instrument(level = "trace", skip_all, fields(%sock, nread = field::Empty, peer = field::Empty), ret)] pub fn sock_recv_from( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, diff --git a/lib/wasix/src/syscalls/wasix/sock_send.rs b/lib/wasix/src/syscalls/wasix/sock_send.rs index aba5246261b..be28e8290da 100644 --- a/lib/wasix/src/syscalls/wasix/sock_send.rs +++ b/lib/wasix/src/syscalls/wasix/sock_send.rs @@ -16,7 +16,7 @@ use crate::{net::socket::TimeType, syscalls::*}; /// ## Return /// /// Number of bytes transmitted. -#[instrument(level = "trace", skip_all, fields(%sock, nsent = field::Empty), ret, err)] +#[instrument(level = "trace", skip_all, fields(%sock, nsent = field::Empty), ret)] pub fn sock_send( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, diff --git a/lib/wasix/src/syscalls/wasix/sock_send_file.rs b/lib/wasix/src/syscalls/wasix/sock_send_file.rs index d29f48d4644..253cc1f095b 100644 --- a/lib/wasix/src/syscalls/wasix/sock_send_file.rs +++ b/lib/wasix/src/syscalls/wasix/sock_send_file.rs @@ -15,7 +15,7 @@ use crate::{net::socket::TimeType, syscalls::*, WasiInodes}; /// ## Return /// /// Number of bytes transmitted. -#[instrument(level = "debug", skip_all, fields(%sock, %in_fd, %offset, %count, nsent = field::Empty), ret, err)] +#[instrument(level = "debug", skip_all, fields(%sock, %in_fd, %offset, %count, nsent = field::Empty), ret)] pub fn sock_send_file( mut ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, diff --git a/lib/wasix/src/syscalls/wasix/sock_send_to.rs b/lib/wasix/src/syscalls/wasix/sock_send_to.rs index bf5ef1ea513..7a345bb8504 100644 --- a/lib/wasix/src/syscalls/wasix/sock_send_to.rs +++ b/lib/wasix/src/syscalls/wasix/sock_send_to.rs @@ -17,7 +17,7 @@ use crate::{net::socket::TimeType, syscalls::*}; /// ## Return /// /// Number of bytes transmitted. -#[instrument(level = "trace", skip_all, fields(%sock, ?addr, nsent = field::Empty), ret, err)] +#[instrument(level = "trace", skip_all, fields(%sock, ?addr, nsent = field::Empty), ret)] pub fn sock_send_to( ctx: FunctionEnvMut<'_, WasiEnv>, sock: WasiFd, diff --git a/lib/wasix/src/syscalls/wasix/stack_checkpoint.rs b/lib/wasix/src/syscalls/wasix/stack_checkpoint.rs index 250d191117b..b6d4b52b64e 100644 --- a/lib/wasix/src/syscalls/wasix/stack_checkpoint.rs +++ b/lib/wasix/src/syscalls/wasix/stack_checkpoint.rs @@ -4,7 +4,7 @@ use crate::syscalls::*; /// ### `stack_checkpoint()` /// Creates a snapshot of the current stack which allows it to be restored /// later using its stack hash. -#[instrument(level = "trace", skip_all, ret, err)] +#[instrument(level = "trace", skip_all, ret)] pub fn stack_checkpoint( mut ctx: FunctionEnvMut<'_, WasiEnv>, snapshot_ptr: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasix/stack_restore.rs b/lib/wasix/src/syscalls/wasix/stack_restore.rs index aae443f43b5..4335af0b3c4 100644 --- a/lib/wasix/src/syscalls/wasix/stack_restore.rs +++ b/lib/wasix/src/syscalls/wasix/stack_restore.rs @@ -8,7 +8,7 @@ use crate::syscalls::*; /// ## Parameters /// /// * `snapshot_ptr` - Contains a previously made snapshot -#[instrument(level = "trace", skip_all, ret, err)] +#[instrument(level = "trace", skip_all, ret)] pub fn stack_restore( mut ctx: FunctionEnvMut<'_, WasiEnv>, snapshot_ptr: WasmPtr, diff --git a/lib/wasix/src/syscalls/wasix/thread_join.rs b/lib/wasix/src/syscalls/wasix/thread_join.rs index 6bbb850c4f5..20d4a13d48d 100644 --- a/lib/wasix/src/syscalls/wasix/thread_join.rs +++ b/lib/wasix/src/syscalls/wasix/thread_join.rs @@ -10,7 +10,7 @@ use crate::syscalls::*; /// ## Parameters /// /// * `tid` - Handle of the thread to wait on -//#[instrument(level = "debug", skip_all, fields(%join_tid), ret, err)] +//#[instrument(level = "debug", skip_all, fields(%join_tid), ret)] pub fn thread_join( ctx: FunctionEnvMut<'_, WasiEnv>, join_tid: Tid, diff --git a/lib/wasix/src/syscalls/wasix/thread_signal.rs b/lib/wasix/src/syscalls/wasix/thread_signal.rs index cea9d4caeea..87000502c11 100644 --- a/lib/wasix/src/syscalls/wasix/thread_signal.rs +++ b/lib/wasix/src/syscalls/wasix/thread_signal.rs @@ -7,7 +7,7 @@ use crate::syscalls::*; /// Inputs: /// - `Signal` /// Signal to be raised for this process -#[instrument(level = "debug", skip_all, fields(%tid, ?sig), ret, err)] +#[instrument(level = "debug", skip_all, fields(%tid, ?sig), ret)] pub fn thread_signal( mut ctx: FunctionEnvMut<'_, WasiEnv>, tid: Tid, diff --git a/lib/wasix/src/syscalls/wasix/thread_sleep.rs b/lib/wasix/src/syscalls/wasix/thread_sleep.rs index 9f692a8ab50..5157a8befd5 100644 --- a/lib/wasix/src/syscalls/wasix/thread_sleep.rs +++ b/lib/wasix/src/syscalls/wasix/thread_sleep.rs @@ -9,7 +9,7 @@ use crate::syscalls::*; /// ## Parameters /// /// * `duration` - Amount of time that the thread should sleep -#[instrument(level = "debug", skip_all, fields(%duration), ret, err)] +#[instrument(level = "debug", skip_all, fields(%duration), ret)] pub fn thread_sleep( mut ctx: FunctionEnvMut<'_, WasiEnv>, duration: Timestamp, From 93b7bd10f5bca8ef95c5cbd5c2276a298e523fd7 Mon Sep 17 00:00:00 2001 From: Johnathan Sharratt Date: Sat, 2 Sep 2023 18:56:31 +1000 Subject: [PATCH 08/13] Reduced the logging level on WasiEnv cleanup code --- lib/wasix/src/state/env.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wasix/src/state/env.rs b/lib/wasix/src/state/env.rs index d0dbd1652c6..44854c3703d 100644 --- a/lib/wasix/src/state/env.rs +++ b/lib/wasix/src/state/env.rs @@ -1037,7 +1037,7 @@ impl WasiEnv { // Perform the clean operation using the asynchronous runtime tokio::select! { _ = timeout => { - tracing::warn!( + tracing::debug!( "WasiEnv::cleanup has timed out after {CLEANUP_TIMEOUT:?}" ); }, From 44c4215d0d8f8c63a413a813871670fd48b7d6ad Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 6 Sep 2023 10:55:59 +0200 Subject: [PATCH 09/13] Fixed linter --- lib/virtual-net/src/host.rs | 28 ++++++++++++---------- lib/wasix/src/net/socket.rs | 12 ++++++---- lib/wasix/src/runtime/resolver/inputs.rs | 4 +++- lib/wasix/src/syscalls/wasi/poll_oneoff.rs | 10 ++------ lib/wasix/src/syscalls/wasix/sock_open.rs | 6 ++--- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib/virtual-net/src/host.rs b/lib/virtual-net/src/host.rs index 7617d3e29b8..4c44c42ebfb 100644 --- a/lib/virtual-net/src/host.rs +++ b/lib/virtual-net/src/host.rs @@ -97,11 +97,7 @@ impl VirtualNetworking for LocalNetworking { if let Ok(p) = stream.peer_addr() { peer = p; } - let socket = Box::new(LocalTcpStream::new( - self.selector.clone(), - stream, - peer, - )); + let socket = Box::new(LocalTcpStream::new(self.selector.clone(), stream, peer)); Ok(socket) } @@ -272,10 +268,13 @@ impl VirtualTcpSocket for LocalTcpStream { let val = val as libc::c_int; let payload = &val as *const libc::c_int as *const libc::c_void; let err = unsafe { - libc::setsockopt(self.stream.as_raw_fd(), libc::SOL_SOCKET, - libc::SO_DONTROUTE, - payload, - std::mem::size_of::() as libc::socklen_t) + libc::setsockopt( + self.stream.as_raw_fd(), + libc::SOL_SOCKET, + libc::SO_DONTROUTE, + payload, + std::mem::size_of::() as libc::socklen_t, + ) }; if err == -1 { return Err(io_err_into_net_error(std::io::Error::last_os_error())); @@ -287,10 +286,13 @@ impl VirtualTcpSocket for LocalTcpStream { let mut payload: MaybeUninit = MaybeUninit::uninit(); let mut len = std::mem::size_of::() as libc::socklen_t; let err = unsafe { - libc::getsockopt(self.stream.as_raw_fd(), libc::SOL_SOCKET, - libc::SO_DONTROUTE, - payload.as_mut_ptr().cast(), - &mut len) + libc::getsockopt( + self.stream.as_raw_fd(), + libc::SOL_SOCKET, + libc::SO_DONTROUTE, + payload.as_mut_ptr().cast(), + &mut len, + ) }; if err == -1 { return Err(io_err_into_net_error(std::io::Error::last_os_error())); diff --git a/lib/wasix/src/net/socket.rs b/lib/wasix/src/net/socket.rs index 60f73906270..7f338478757 100644 --- a/lib/wasix/src/net/socket.rs +++ b/lib/wasix/src/net/socket.rs @@ -619,9 +619,7 @@ impl InodeSocket { } _ => return Err(Errno::Inval), }, - InodeSocketKind::TcpListener { .. } => match option { - _ => return Err(Errno::Inval), - }, + InodeSocketKind::TcpListener { .. } => return Err(Errno::Inval), InodeSocketKind::UdpSocket { socket, .. } => match option { WasiSocketOption::Broadcast => { socket.set_broadcast(val).map_err(net_error_into_wasi_err)? @@ -665,8 +663,12 @@ impl InodeSocket { }, InodeSocketKind::TcpStream { socket, .. } => match option { WasiSocketOption::NoDelay => socket.nodelay().map_err(net_error_into_wasi_err)?, - WasiSocketOption::KeepAlive => socket.keepalive().map_err(net_error_into_wasi_err)?, - WasiSocketOption::DontRoute => socket.dontroute().map_err(net_error_into_wasi_err)?, + WasiSocketOption::KeepAlive => { + socket.keepalive().map_err(net_error_into_wasi_err)? + } + WasiSocketOption::DontRoute => { + socket.dontroute().map_err(net_error_into_wasi_err)? + } _ => return Err(Errno::Inval), }, InodeSocketKind::UdpSocket { socket, .. } => match option { diff --git a/lib/wasix/src/runtime/resolver/inputs.rs b/lib/wasix/src/runtime/resolver/inputs.rs index 8a80964269f..a232c46c1bb 100644 --- a/lib/wasix/src/runtime/resolver/inputs.rs +++ b/lib/wasix/src/runtime/resolver/inputs.rs @@ -1,7 +1,9 @@ use std::{ fmt::{self, Display, Formatter}, + fs::File, + io::{BufRead, BufReader, Read}, path::{Path, PathBuf}, - str::FromStr, fs::File, io::{BufReader, BufRead, Read}, + str::FromStr, }; use anyhow::{Context, Error}; diff --git a/lib/wasix/src/syscalls/wasi/poll_oneoff.rs b/lib/wasix/src/syscalls/wasi/poll_oneoff.rs index bb90198a510..2c9a743afb0 100644 --- a/lib/wasix/src/syscalls/wasi/poll_oneoff.rs +++ b/lib/wasix/src/syscalls/wasi/poll_oneoff.rs @@ -386,15 +386,9 @@ where Ok(evts) => { // If its a timeout then return an event for it if evts.len() == 1 { - Span::current().record("seen", &format!( - "{:?}", - evts.iter().next().unwrap() - )); + Span::current().record("seen", &format!("{:?}", evts.first().unwrap())); } else { - Span::current().record("seen", &format!( - "trigger_cnt=({})", - evts.len() - )); + Span::current().record("seen", &format!("trigger_cnt=({})", evts.len())); } // Process the events diff --git a/lib/wasix/src/syscalls/wasix/sock_open.rs b/lib/wasix/src/syscalls/wasix/sock_open.rs index 49868174482..508e9706d33 100644 --- a/lib/wasix/src/syscalls/wasix/sock_open.rs +++ b/lib/wasix/src/syscalls/wasix/sock_open.rs @@ -37,13 +37,13 @@ pub fn sock_open( if ty != Socktype::Stream { return Errno::Notsup; } - }, + } SockProto::Udp => { if ty != Socktype::Dgram { return Errno::Notsup; } - }, - _ => { } + } + _ => {} } let kind = match ty { From 6706926d13c8e38edb1f1fdddba844a9d14ad3dd Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 6 Sep 2023 12:04:13 +0200 Subject: [PATCH 10/13] This should fix the wasi-web build --- lib/wasix/src/runtime/package_loader/builtin_loader.rs | 6 +++++- lib/wasix/src/runtime/resolver/filesystem_source.rs | 8 ++++++++ lib/wasix/src/runtime/resolver/web_source.rs | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/wasix/src/runtime/package_loader/builtin_loader.rs b/lib/wasix/src/runtime/package_loader/builtin_loader.rs index 0f70b4c4356..7cd7c5f5c08 100644 --- a/lib/wasix/src/runtime/package_loader/builtin_loader.rs +++ b/lib/wasix/src/runtime/package_loader/builtin_loader.rs @@ -239,7 +239,11 @@ impl FileSystemCache { async fn lookup(&self, hash: &WebcHash) -> Result, Error> { let path = self.path(hash); - match tokio::task::block_in_place(|| Container::from_disk(&path)) { + #[cfg(target_arch = "wasm32")] + let container = Container::from_disk(&path); + #[cfg(not(target_arch = "wasm32"))] + let container = tokio::task::block_in_place(|| Container::from_disk(&path)); + match container { Ok(c) => Ok(Some(c)), Err(ContainerError::Open { error, .. }) | Err(ContainerError::Read { error, .. }) diff --git a/lib/wasix/src/runtime/resolver/filesystem_source.rs b/lib/wasix/src/runtime/resolver/filesystem_source.rs index 56deefcaf2e..c6c0f44d522 100644 --- a/lib/wasix/src/runtime/resolver/filesystem_source.rs +++ b/lib/wasix/src/runtime/resolver/filesystem_source.rs @@ -23,8 +23,16 @@ impl Source for FileSystemSource { _ => return Err(QueryError::Unsupported), }; + #[cfg(target_arch = "wasm32")] + let webc_sha256 = WebcHash::for_file(&path) + .with_context(|| format!("Unable to hash \"{}\"", path.display()))?; + #[cfg(not(target_arch = "wasm32"))] let webc_sha256 = tokio::task::block_in_place(|| WebcHash::for_file(&path)) .with_context(|| format!("Unable to hash \"{}\"", path.display()))?; + #[cfg(target_arch = "wasm32")] + let container = Container::from_disk(&path) + .with_context(|| format!("Unable to parse \"{}\"", path.display()))?; + #[cfg(not(target_arch = "wasm32"))] let container = tokio::task::block_in_place(|| Container::from_disk(&path)) .with_context(|| format!("Unable to parse \"{}\"", path.display()))?; diff --git a/lib/wasix/src/runtime/resolver/web_source.rs b/lib/wasix/src/runtime/resolver/web_source.rs index e93fa3b7e84..bc06c722847 100644 --- a/lib/wasix/src/runtime/resolver/web_source.rs +++ b/lib/wasix/src/runtime/resolver/web_source.rs @@ -240,11 +240,19 @@ impl Source for WebSource { .await .context("Unable to get the locally cached file")?; + #[cfg(target_arch = "wasm32")] + let webc_sha256 = WebcHash::for_file(&local_path) + .with_context(|| format!("Unable to hash \"{}\"", local_path.display()))?; + #[cfg(not(target_arch = "wasm32"))] let webc_sha256 = tokio::task::block_in_place(|| WebcHash::for_file(&local_path)) .with_context(|| format!("Unable to hash \"{}\"", local_path.display()))?; // Note: We want to use Container::from_disk() rather than the bytes // our HTTP client gave us because then we can use memory-mapped files + #[cfg(target_arch = "wasm32")] + let container = Container::from_disk(&local_path) + .with_context(|| format!("Unable to load \"{}\"", local_path.display()))?; + #[cfg(not(target_arch = "wasm32"))] let container = tokio::task::block_in_place(|| Container::from_disk(&local_path)) .with_context(|| format!("Unable to load \"{}\"", local_path.display()))?; let pkg = PackageInfo::from_manifest(container.manifest()) From 5f0ac41d3c21eed53b0db9c56dbcf18de48bf7f7 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 6 Sep 2023 12:47:56 +0200 Subject: [PATCH 11/13] This should fix the Widnows build --- lib/virtual-net/src/host.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/virtual-net/src/host.rs b/lib/virtual-net/src/host.rs index 4c44c42ebfb..1b9b07c2e7b 100644 --- a/lib/virtual-net/src/host.rs +++ b/lib/virtual-net/src/host.rs @@ -10,6 +10,7 @@ use derivative::Derivative; use std::io::{Read, Write}; use std::mem::MaybeUninit; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}; +#[cfg(not(target_os = "windows"))] use std::os::fd::AsRawFd; use std::sync::Arc; use std::time::Duration; @@ -264,6 +265,7 @@ impl VirtualTcpSocket for LocalTcpStream { Ok(ret) } + #[cfg(not(target_os = "windows"))] fn set_dontroute(&mut self, val: bool) -> Result<()> { let val = val as libc::c_int; let payload = &val as *const libc::c_int as *const libc::c_void; @@ -281,7 +283,12 @@ impl VirtualTcpSocket for LocalTcpStream { } Ok(()) } + #[cfg(target_os = "windows")] + fn set_dontroute(&mut self, val: bool) -> Result<()> { + Err(NetworkError::Unsupported) + } + #[cfg(not(target_os = "windows"))] fn dontroute(&self) -> Result { let mut payload: MaybeUninit = MaybeUninit::uninit(); let mut len = std::mem::size_of::() as libc::socklen_t; @@ -299,6 +306,10 @@ impl VirtualTcpSocket for LocalTcpStream { } Ok(unsafe { payload.assume_init() != 0 }) } + #[cfg(target_os = "windows")] + fn dontroute(&self) -> Result { + Err(NetworkError::Unsupported) + } fn addr_peer(&self) -> Result { Ok(self.addr) From 152da45aa4044fe3e41cbd8d065639e72b9bb17c Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 6 Sep 2023 14:45:51 +0200 Subject: [PATCH 12/13] This should fix the tests failling because of the lack of tockio multi threaded runtime --- lib/wasix/src/runtime/package_loader/builtin_loader.rs | 2 +- lib/wasix/src/runtime/resolver/web_source.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/wasix/src/runtime/package_loader/builtin_loader.rs b/lib/wasix/src/runtime/package_loader/builtin_loader.rs index 7cd7c5f5c08..dc8d19e7adf 100644 --- a/lib/wasix/src/runtime/package_loader/builtin_loader.rs +++ b/lib/wasix/src/runtime/package_loader/builtin_loader.rs @@ -375,7 +375,7 @@ mod tests { } } - #[tokio::test] + #[tokio::test(flavor = "multi_thread")] async fn cache_misses_will_trigger_a_download() { let temp = TempDir::new().unwrap(); let client = Arc::new(DummyClient::with_responses([HttpResponse { diff --git a/lib/wasix/src/runtime/resolver/web_source.rs b/lib/wasix/src/runtime/resolver/web_source.rs index bc06c722847..0e78049dade 100644 --- a/lib/wasix/src/runtime/resolver/web_source.rs +++ b/lib/wasix/src/runtime/resolver/web_source.rs @@ -454,7 +454,7 @@ mod tests { } } - #[tokio::test] + #[tokio::test(flavor = "multi_thread")] async fn empty_cache_does_a_full_download() { let dummy_etag = "This is an etag"; let temp = TempDir::new().unwrap(); @@ -480,7 +480,7 @@ mod tests { assert_eq!(std::fs::read(path).unwrap(), PYTHON); } - #[tokio::test] + #[tokio::test(flavor = "multi_thread")] async fn cache_hit() { let temp = TempDir::new().unwrap(); let client = Arc::new(DummyClient::with_responses([])); @@ -498,7 +498,7 @@ mod tests { assert_eq!(client.requests.lock().unwrap().len(), 0); } - #[tokio::test] + #[tokio::test(flavor = "multi_thread")] async fn fall_back_to_stale_cache_if_request_fails() { let temp = TempDir::new().unwrap(); let client = Arc::new(DummyClient::with_responses([ResponseBuilder::new() @@ -521,7 +521,7 @@ mod tests { assert!(!python_path.with_extension("etag").exists()); } - #[tokio::test] + #[tokio::test(flavor = "multi_thread")] async fn download_again_if_etag_is_different() { let temp = TempDir::new().unwrap(); let client = Arc::new(DummyClient::with_responses([ From a829872f7c828dae8522273e4f7dc54a2db5c903 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 6 Sep 2023 15:51:29 +0200 Subject: [PATCH 13/13] This should fix test-js --- .../runtime/package_loader/builtin_loader.rs | 15 +++++- lib/wasix/src/runtime/resolver/web_source.rs | 52 ++++++++++++++++--- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/lib/wasix/src/runtime/package_loader/builtin_loader.rs b/lib/wasix/src/runtime/package_loader/builtin_loader.rs index dc8d19e7adf..10833fd5b70 100644 --- a/lib/wasix/src/runtime/package_loader/builtin_loader.rs +++ b/lib/wasix/src/runtime/package_loader/builtin_loader.rs @@ -375,8 +375,7 @@ mod tests { } } - #[tokio::test(flavor = "multi_thread")] - async fn cache_misses_will_trigger_a_download() { + async fn cache_misses_will_trigger_a_download_internal() { let temp = TempDir::new().unwrap(); let client = Arc::new(DummyClient::with_responses([HttpResponse { body: Some(PYTHON.to_vec()), @@ -425,4 +424,16 @@ mod tests { let in_memory = loader.in_memory.0.read().unwrap(); assert!(in_memory.contains_key(&summary.dist.webc_sha256)); } + + #[cfg(not(target_arch = "wasm32"))] + #[tokio::test(flavor = "multi_thread")] + async fn cache_misses_will_trigger_a_download() { + cache_misses_will_trigger_a_download_internal().await + } + + #[cfg(target_arch = "wasm32")] + #[tokio::test()] + async fn cache_misses_will_trigger_a_download() { + cache_misses_will_trigger_a_download_internal().await + } } diff --git a/lib/wasix/src/runtime/resolver/web_source.rs b/lib/wasix/src/runtime/resolver/web_source.rs index 0e78049dade..dbac364402e 100644 --- a/lib/wasix/src/runtime/resolver/web_source.rs +++ b/lib/wasix/src/runtime/resolver/web_source.rs @@ -454,8 +454,7 @@ mod tests { } } - #[tokio::test(flavor = "multi_thread")] - async fn empty_cache_does_a_full_download() { + async fn empty_cache_does_a_full_download_internal() { let dummy_etag = "This is an etag"; let temp = TempDir::new().unwrap(); let client = DummyClient::with_responses([ResponseBuilder::new() @@ -479,9 +478,18 @@ mod tests { assert_eq!(std::fs::read_to_string(etag_path).unwrap(), dummy_etag); assert_eq!(std::fs::read(path).unwrap(), PYTHON); } - + #[cfg(not(target_arch = "wasm32"))] #[tokio::test(flavor = "multi_thread")] - async fn cache_hit() { + async fn empty_cache_does_a_full_download() { + empty_cache_does_a_full_download_internal().await + } + #[cfg(target_arch = "wasm32")] + #[tokio::test()] + async fn empty_cache_does_a_full_download() { + empty_cache_does_a_full_download_internal().await + } + + async fn cache_hit_internal() { let temp = TempDir::new().unwrap(); let client = Arc::new(DummyClient::with_responses([])); let source = WebSource::new(temp.path(), client.clone()); @@ -497,9 +505,18 @@ mod tests { // And no requests were sent assert_eq!(client.requests.lock().unwrap().len(), 0); } - + #[cfg(not(target_arch = "wasm32"))] #[tokio::test(flavor = "multi_thread")] - async fn fall_back_to_stale_cache_if_request_fails() { + async fn cache_hit() { + cache_hit_internal().await + } + #[cfg(target_arch = "wasm32")] + #[tokio::test()] + async fn cache_hit() { + cache_hit_internal().await + } + + async fn fall_back_to_stale_cache_if_request_fails_internal() { let temp = TempDir::new().unwrap(); let client = Arc::new(DummyClient::with_responses([ResponseBuilder::new() .with_status(StatusCode::INTERNAL_SERVER_ERROR) @@ -520,9 +537,18 @@ mod tests { // The etag file wasn't written assert!(!python_path.with_extension("etag").exists()); } - + #[cfg(not(target_arch = "wasm32"))] #[tokio::test(flavor = "multi_thread")] - async fn download_again_if_etag_is_different() { + async fn fall_back_to_stale_cache_if_request_fails() { + fall_back_to_stale_cache_if_request_fails_internal().await + } + #[cfg(target_arch = "wasm32")] + #[tokio::test()] + async fn fall_back_to_stale_cache_if_request_fails() { + fall_back_to_stale_cache_if_request_fails_internal().await + } + + async fn download_again_if_etag_is_different_internal() { let temp = TempDir::new().unwrap(); let client = Arc::new(DummyClient::with_responses([ ResponseBuilder::new().with_etag("coreutils").build(), @@ -556,4 +582,14 @@ mod tests { "coreutils" ); } + #[cfg(not(target_arch = "wasm32"))] + #[tokio::test(flavor = "multi_thread")] + async fn download_again_if_etag_is_different() { + download_again_if_etag_is_different_internal().await + } + #[cfg(target_arch = "wasm32")] + #[tokio::test()] + async fn download_again_if_etag_is_different() { + download_again_if_etag_is_different_internal().await + } }