wasmer_wasix/syscalls/wasi/
args_get.rs

1use super::*;
2use crate::syscalls::*;
3
4/// ### `args_get()`
5/// Read command-line argument data.
6/// The sizes of the buffers should match that returned by [`args_sizes_get()`](#args_sizes_get).
7/// Inputs:
8/// - `char **argv`
9///     A pointer to a buffer to write the argument pointers.
10/// - `char *argv_buf`
11///     A pointer to a buffer to write the argument string data.
12///
13#[instrument(level = "trace", skip_all, ret)]
14pub fn args_get<M: MemorySize>(
15    mut ctx: FunctionEnvMut<'_, WasiEnv>,
16    argv: WasmPtr<WasmPtr<u8, M>, M>,
17    argv_buf: WasmPtr<u8, M>,
18) -> Errno {
19    let env = ctx.data();
20    let (memory, mut state) = unsafe { env.get_memory_and_wasi_state(&ctx, 0) };
21
22    let args = state
23        .args
24        .lock()
25        .unwrap()
26        .iter()
27        .map(|a| a.as_bytes().to_vec())
28        .collect::<Vec<_>>();
29    let result = write_buffer_array(&memory, &args, argv, argv_buf);
30
31    debug!(
32        "args:\n{}",
33        state
34            .args
35            .lock()
36            .unwrap()
37            .iter()
38            .enumerate()
39            .map(|(i, v)| format!("{i:>20}: {v}"))
40            .collect::<Vec<String>>()
41            .join("\n")
42    );
43
44    result
45}