Skip to content

Commit f990fb0

Browse files
author
morphqdd
committed
feat(stdlib): run_envp_argv — execve with caller argv + envp
Lets callers pass an arbitrary-length argv (not just [prog, arg]) with a custom envp. Used by lake-house to forward manifest `flag` lines to lakec.
1 parent 42142e6 commit f990fb0

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

std/experimental/process.lake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,30 @@ pub run_envp is {
139139
}
140140
}
141141
}
142+
143+
// `run` with both a caller-supplied argv AND envp — each a raw
144+
// NULL-terminated `char**` (a buf filled via `rt_store`). `argv_ptr`
145+
// must already include argv[0] (the program path). Lets callers pass
146+
// an arbitrary number of CLI args (e.g. house manifest `flag` lines).
147+
pub run_envp_argv is {
148+
prog buf argv_ptr i64 envp_ptr i64 -> ret {atom i64} {
149+
let pc = cstr_of(prog)
150+
let pidfd = rt_clone3_pidfd(0)
151+
when pidfd < 0 {
152+
true -> { ret { :err 0 - pidfd } }
153+
false -> {
154+
when pidfd == 0 {
155+
true -> {
156+
rt_syscall(SYS_EXECVE addr(pc) argv_ptr envp_ptr 0 0 0)
157+
rt_syscall(SYS_EXIT 127 0 0 0 0 0)
158+
ret { :err 127 }
159+
}
160+
false -> {
161+
let result = wait_pidfd(pidfd)
162+
ret result
163+
}
164+
}
165+
}
166+
}
167+
}
168+
}

0 commit comments

Comments
 (0)