wasmer_wasix/syscalls/wasix/
tty_set.rs

1use super::*;
2use crate::{WasiTtyState, syscalls::*};
3
4/// ### `tty_set()`
5/// Updates the properties of the rect
6#[instrument(level = "trace", skip_all, ret)]
7pub fn tty_set<M: MemorySize>(
8    mut ctx: FunctionEnvMut<'_, WasiEnv>,
9    tty_state: WasmPtr<Tty, M>,
10) -> Result<Errno, WasiError> {
11    WasiEnv::do_pending_operations(&mut ctx)?;
12
13    let env = ctx.data();
14
15    let memory = unsafe { env.memory_view(&ctx) };
16    let state = wasi_try_mem_ok!(tty_state.read(&memory));
17    let echo = state.echo;
18    let line_buffered = state.line_buffered;
19    let line_feeds = true;
20    debug!(
21        %echo,
22        %line_buffered,
23        %line_feeds
24    );
25
26    let state = crate::os::tty::WasiTtyState {
27        cols: state.cols,
28        rows: state.rows,
29        width: state.width,
30        height: state.height,
31        stdin_tty: state.stdin_tty,
32        stdout_tty: state.stdout_tty,
33        stderr_tty: state.stderr_tty,
34        echo,
35        line_buffered,
36        line_feeds,
37    };
38
39    wasi_try_ok!({
40        #[allow(clippy::redundant_clone)]
41        tty_set_internal(&mut ctx, state.clone())
42    });
43    let env = ctx.data();
44
45    #[cfg(feature = "journal")]
46    if env.enable_journal {
47        JournalEffector::save_tty_set(&mut ctx, state).map_err(|err| {
48            tracing::error!("failed to save path symbolic link event - {}", err);
49            WasiError::Exit(ExitCode::from(Errno::Fault))
50        })?;
51    }
52
53    Ok(Errno::Success)
54}
55
56pub fn tty_set_internal(
57    ctx: &mut FunctionEnvMut<'_, WasiEnv>,
58    state: WasiTtyState,
59) -> Result<(), Errno> {
60    let env = ctx.data();
61    let bridge = if let Some(t) = env.runtime.tty() {
62        t
63    } else {
64        return Err(Errno::Notsup);
65    };
66    bridge.tty_set(state);
67
68    Ok(())
69}