⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

sys_exec

Function sys_exec 

Source
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 standard argc/argv mechanism. 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

§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");
}