Skip to content

Commit

Permalink
syscall: Implement exec()
Browse files Browse the repository at this point in the history
Implement the EXEC syscall interface in user space.

Co-developed-by: Vijay Dhanraj <[email protected]>
Signed-off-by: Peter Fang <[email protected]>
  • Loading branch information
peterfang authored and vijaydhanraj committed Oct 27, 2024
1 parent 047d5de commit 25f859b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions syscall/src/class0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
//
// Author: Chuanxiao Dong <[email protected]>

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.
Expand All @@ -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<Tid, SysCallError> {
unsafe {
syscall3(
SYS_EXEC,
file.as_ptr() as u64,
root.as_ptr() as u64,
u64::from(flags),
)
.map(|ret| Tid(ret as u32))
}
}

0 comments on commit 25f859b

Please sign in to comment.