pub fn sys_exec(_path: &str, _args: &[&str]) -> SyscallResult<()>Expand description
Replace the current process image with a new program loaded from an ELF executable.
Loads the ELF binary at the given path, replaces the calling process’s
address space with the new program’s segments, and begins execution at the
ELF entry point. The process PID remains the same, but the virtual memory
layout, stack, and instruction pointer are all replaced.
Capabilities marked with the INHERIT flag are preserved across the exec
boundary; all other capabilities are dropped. File descriptors marked
close-on-exec are closed; remaining descriptors are inherited by the new
program image.
On success this function does not return to the caller because the process image has been replaced. On failure, the original process continues execution and an error is returned.
§Arguments
path- Absolute or relative path to the ELF executable to load. The path is resolved through the VFS and must point to a regular file with execute permission. Supports statically linked and dynamically linked ELF binaries (the dynamic linker is invoked automatically for the latter).args- Slice of string arguments to pass to the new program. These are placed on the new program’s initial stack and made available through the standardargc/argvmechanism. The first element is conventionally the program name.
§Returns
Ok(())- Never actually returned; on success the process image is replaced and execution continues at the new entry point.
§Errors
SyscallError::NotFound- The file atpathdoes not exist.SyscallError::PermissionDenied- The caller lacks execute permission on the file or lacks the required capability.SyscallError::InvalidArgument- The file is not a valid ELF binary, targets an incompatible architecture, orargsexceeds the maximum argument size (typically 2 MiB).SyscallError::OutOfMemory- Insufficient memory to load the new program segments.SyscallError::IoError- An I/O error occurred reading the executable.
§Examples
use veridian_kernel::pkg::sdk::syscall_api::{sys_exec, sys_exit, sys_fork, sys_wait};
let pid = sys_fork().expect("fork failed");
if pid == 0 {
// Child: replace image with /bin/ls
let result = sys_exec("/bin/ls", &["/bin/ls", "-l", "/home"]);
// If exec returns, it failed
sys_exit(1);
} else {
// Parent: wait for child to finish
let exit_code = sys_wait(pid).expect("wait failed");
}