#[ensures(effects!(old(trace), trace))]
(ctx: &mut VmCtx, argv: u32, argv_buf: u32)
| 900 | #[ensures(trace_safe(trace, ctx))] |
| 901 | // #[ensures(effects!(old(trace), trace))] |
| 902 | pub fn wasi_args_get(ctx: &mut VmCtx, argv: u32, argv_buf: u32) -> RuntimeResult<()> { |
| 903 | // 1. copy argv_buffer |
| 904 | let argv_buf_len = ctx.arg_buffer.len() as u32; |
| 905 | ctx.copy_arg_buffer_to_sandbox(argv_buf, argv_buf_len)?; |
| 906 | // 2. copy in argv |
| 907 | let mut idx: usize = 0; |
| 908 | let mut start: u32 = 0; |
| 909 | let mut cursor: usize = 0; |
| 910 | while idx < ctx.arg_buffer.len() { |
| 911 | body_invariant!(ctx_safe(ctx)); |
| 912 | body_invariant!(trace_safe(trace, ctx)); |
| 913 | // We have found an argument either when we find a trailing space, or if we started an arg |
| 914 | // and ran out of space |
| 915 | if !ctx.fits_in_lin_mem_usize((argv as usize) + cursor, 8) { |
| 916 | return Err(Eoverflow); |
| 917 | } |
| 918 | |
| 919 | if ctx.arg_buffer[idx] == b'\0' { |
| 920 | while idx < ctx.arg_buffer.len() && ctx.arg_buffer[idx] == b'\0' { |
| 921 | idx += 1; |
| 922 | } // scan past multiple spaces |
| 923 | ctx.write_u32((argv as usize) + cursor, argv_buf + start); |
| 924 | cursor += 4; |
| 925 | start = idx as u32; |
| 926 | } |
| 927 | idx += 1; |
| 928 | |
| 929 | // we reached the end, so record the final arg |
| 930 | if idx >= ctx.arg_buffer.len() { |
| 931 | ctx.write_u32((argv as usize) + cursor, argv_buf + start); |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | let argc = ctx.argc; |
| 936 | // ensure the last entry is null |
| 937 | if !ctx.fits_in_lin_mem_usize((argv as usize) + argc * 4, 8) { |
| 938 | return Err(Eoverflow); |
| 939 | } |
| 940 | ctx.write_u32((argv as usize) + argc * 4, 0); |
| 941 | Ok(()) |
| 942 | } |
| 943 | |
| 944 | // https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#environ_get |
| 945 | #[with_ghost_var(trace: &mut Trace)] |
no test coverage detected