diff --git a/Cargo.toml b/Cargo.toml index f77dc31f9d0..ed1cb8d4bb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -168,6 +168,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" 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..1b9b07c2e7b 100644 --- a/lib/virtual-net/src/host.rs +++ b/lib/virtual-net/src/host.rs @@ -10,6 +10,8 @@ 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; use tokio::runtime::Handle; @@ -62,6 +64,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 +98,8 @@ impl VirtualNetworking for LocalNetworking { if let Ok(p) = stream.peer_addr() { peer = p; } - Ok(Box::new(LocalTcpStream::new( - self.selector.clone(), - stream, - peer, - ))) + let socket = Box::new(LocalTcpStream::new(self.selector.clone(), stream, peer)); + Ok(socket) } async fn resolve( @@ -127,6 +128,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 +141,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 +251,66 @@ 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) + } + + #[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; + 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(()) + } + #[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; + 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 }) + } + #[cfg(target_os = "windows")] + fn dontroute(&self) -> Result { + Err(NetworkError::Unsupported) + } + 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/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, } diff --git a/lib/wasix/src/fs/mod.rs b/lib/wasix/src/fs/mod.rs index 51e49cc5e7e..6273de3e78a 100644 --- a/lib/wasix/src/fs/mod.rs +++ b/lib/wasix/src/fs/mod.rs @@ -456,9 +456,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() { @@ -468,14 +468,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/net/socket.rs b/lib/wasix/src/net/socket.rs index 0e836faf6fa..7f338478757 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,8 +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 { .. } => return Err(Errno::Inval), InodeSocketKind::UdpSocket { socket, .. } => match option { WasiSocketOption::Broadcast => { socket.set_broadcast(val).map_err(net_error_into_wasi_err)? @@ -610,11 +644,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 +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)? + } _ => return Err(Errno::Inval), }, InodeSocketKind::UdpSocket { socket, .. } => match option { diff --git a/lib/wasix/src/runtime/package_loader/builtin_loader.rs b/lib/wasix/src/runtime/package_loader/builtin_loader.rs index c559c030050..10833fd5b70 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 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, .. }) @@ -371,8 +375,7 @@ mod tests { } } - #[tokio::test] - 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()), @@ -421,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/filesystem_source.rs b/lib/wasix/src/runtime/resolver/filesystem_source.rs index 9be00fac897..c6c0f44d522 100644 --- a/lib/wasix/src/runtime/resolver/filesystem_source.rs +++ b/lib/wasix/src/runtime/resolver/filesystem_source.rs @@ -23,11 +23,18 @@ impl Source for FileSystemSource { _ => return Err(QueryError::Unsupported), }; - // FIXME: These two operations will block + #[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()))?; let url = crate::runtime::resolver::utils::url_from_file_path(&path) .ok_or_else(|| anyhow::anyhow!("Unable to turn \"{}\" into a URL", path.display()))?; diff --git a/lib/wasix/src/runtime/resolver/inputs.rs b/lib/wasix/src/runtime/resolver/inputs.rs index 8fb2b7f8cb7..a232c46c1bb 100644 --- a/lib/wasix/src/runtime/resolver/inputs.rs +++ b/lib/wasix/src/runtime/resolver/inputs.rs @@ -1,7 +1,7 @@ use std::{ fmt::{self, Display, Formatter}, fs::File, - io::{BufRead, BufReader}, + io::{BufRead, BufReader, Read}, path::{Path, PathBuf}, str::FromStr, }; @@ -344,7 +344,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 +371,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..dbac364402e 100644 --- a/lib/wasix/src/runtime/resolver/web_source.rs +++ b/lib/wasix/src/runtime/resolver/web_source.rs @@ -240,14 +240,21 @@ impl Source for WebSource { .await .context("Unable to get the locally cached file")?; - // FIXME: this will block + #[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()) .context("Unable to determine the package's metadata")?; @@ -447,8 +454,7 @@ mod tests { } } - #[tokio::test] - 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() @@ -472,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 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 + } - #[tokio::test] - async fn cache_hit() { + 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()); @@ -490,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 cache_hit() { + cache_hit_internal().await + } + #[cfg(target_arch = "wasm32")] + #[tokio::test()] + async fn cache_hit() { + cache_hit_internal().await + } - #[tokio::test] - async fn fall_back_to_stale_cache_if_request_fails() { + 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) @@ -513,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 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 + } - #[tokio::test] - async fn download_again_if_etag_is_different() { + 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(), @@ -549,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 + } } diff --git a/lib/wasix/src/state/env.rs b/lib/wasix/src/state/env.rs index 4b0a8f819f9..4a2b9df9389 100644 --- a/lib/wasix/src/state/env.rs +++ b/lib/wasix/src/state/env.rs @@ -1043,7 +1043,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:?}" ); }, 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/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/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 2f1fcefe05c..2c9a743afb0 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, @@ -385,13 +385,17 @@ 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.first().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/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 dc4ee8722d5..2646878bf01 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_open.rs b/lib/wasix/src/syscalls/wasix/sock_open.rs index c43688bc07b..508e9706d33 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, 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,