wasmer_wasix/syscalls/wasix/
port_bridge.rs1use super::*;
2use crate::syscalls::*;
3
4#[instrument(level = "trace", skip_all, fields(network = field::Empty, ?security), ret)]
13pub fn port_bridge<M: MemorySize>(
14 mut ctx: FunctionEnvMut<'_, WasiEnv>,
15 network: WasmPtr<u8, M>,
16 network_len: M::Offset,
17 token: WasmPtr<u8, M>,
18 token_len: M::Offset,
19 security: Streamsecurity,
20) -> Result<Errno, WasiError> {
21 WasiEnv::do_pending_operations(&mut ctx)?;
22
23 let env = ctx.data();
24 let memory = unsafe { env.memory_view(&ctx) };
25
26 let network = unsafe { get_input_str_ok!(&memory, network, network_len) };
27 Span::current().record("network", network.as_str());
28
29 let token = unsafe { get_input_str_ok!(&memory, token, token_len) };
30 let security = match security {
31 Streamsecurity::Unencrypted => StreamSecurity::Unencrypted,
32 Streamsecurity::AnyEncryption => StreamSecurity::AnyEncyption,
33 Streamsecurity::ClassicEncryption => StreamSecurity::ClassicEncryption,
34 Streamsecurity::DoubleEncryption => StreamSecurity::DoubleEncryption,
35 _ => return Ok(Errno::Inval),
36 };
37
38 wasi_try_ok!(port_bridge_internal(
39 &mut ctx,
40 network.as_str(),
41 token.as_str(),
42 security
43 )?);
44
45 #[cfg(feature = "journal")]
46 if ctx.data().enable_journal {
47 JournalEffector::save_port_bridge(&mut ctx, network, token, security).map_err(|err| {
48 tracing::error!("failed to save port_bridge event - {}", err);
49 WasiError::Exit(ExitCode::from(Errno::Fault))
50 })?;
51 }
52
53 Ok(Errno::Success)
54}
55
56pub(crate) fn port_bridge_internal(
57 ctx: &mut FunctionEnvMut<'_, WasiEnv>,
58 network: &str,
59 token: &str,
60 security: StreamSecurity,
61) -> Result<Result<(), Errno>, WasiError> {
62 let env = ctx.data();
63
64 let net = env.net().clone();
65 wasi_try_ok_ok!(__asyncify(ctx, None, async move {
66 net.bridge(network, token, security)
67 .await
68 .map_err(net_error_into_wasi_err)
69 })?);
70 Ok(Ok(()))
71}