MCPcopy Create free account
hub / github.com/WasmVM/WasmVM / proc_argv

Function proc_argv

host/sysenv/sys_proc.cpp:47–67  ·  view source on GitHub ↗

argv(idx:i32, buf_ptr, buf_len) -> i32

Source from the content-addressed store, hash-verified

45
46// argv(idx:i32, buf_ptr, buf_len) -> i32
47static std::vector<Value> proc_argv(Stack& stack) {
48 Frame& frame = stack.frames.top();
49 i32_t idx = std::get<i32_t>(frame.locals[0]);
50 i64_t buf_ptr = get_ptr(frame.locals[1]);
51 i64_t buf_len = get_ptr(frame.locals[2]);
52 if(idx < 0 || (size_t)idx >= wasmvm_args.size()) {
53 return {Value(i32_t(-EINVAL))};
54 }
55 const std::string& arg = wasmvm_args[(size_t)idx];
56 i64_t copy_len = std::min((i64_t)arg.size(), buf_len);
57 try {
58 mem_write(stack, buf_ptr, arg.data(), (size_t)copy_len);
59 if(copy_len < buf_len) {
60 byte_t nul = std::byte{0};
61 mem_write(stack, buf_ptr + copy_len, &nul, 1);
62 }
63 return {Value(i32_t(copy_len))};
64 } catch(...) {
65 return {Value(i32_t(-EFAULT))};
66 }
67}
68
69// getenv(name_ptr, name_len, buf_ptr, buf_len) -> i32
70static std::vector<Value> proc_getenv(Stack& stack) {

Callers

nothing calls this directly

Calls 3

get_ptrFunction · 0.85
ValueClass · 0.85
mem_writeFunction · 0.85

Tested by

no test coverage detected