From 25f859b2f0627adba34c811226a338e27ff8da43 Mon Sep 17 00:00:00 2001 From: Peter Fang Date: Mon, 2 Sep 2024 18:32:37 +0800 Subject: [PATCH] syscall: Implement exec() Implement the EXEC syscall interface in user space. Co-developed-by: Vijay Dhanraj Signed-off-by: Peter Fang --- syscall/src/class0.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/syscall/src/class0.rs b/syscall/src/class0.rs index df23b6e87..5bc44004f 100644 --- a/syscall/src/class0.rs +++ b/syscall/src/class0.rs @@ -4,8 +4,9 @@ // // Author: Chuanxiao Dong -use super::call::syscall1; -use super::SYS_EXIT; +use super::call::{syscall1, syscall3, SysCallError}; +use super::{SYS_EXEC, SYS_EXIT}; +use core::ffi::CStr; pub fn exit(code: u32) -> ! { // SAFETY: SYS_EXIT is supported syscall number by the svsm kernel. @@ -14,3 +15,19 @@ pub fn exit(code: u32) -> ! { } unreachable!("Should never return from SYS_EXIT syscall"); } + +#[allow(dead_code)] +#[derive(Debug)] +pub struct Tid(u32); + +pub fn exec(file: &CStr, root: &CStr, flags: u32) -> Result { + unsafe { + syscall3( + SYS_EXEC, + file.as_ptr() as u64, + root.as_ptr() as u64, + u64::from(flags), + ) + .map(|ret| Tid(ret as u32)) + } +}