-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the syscall handler for SYS_EXEC. This commit also provides the ability to specify a new root directory for the process. This is done because EXEC allows the parent process to specify the root directory of the new process. New threads automatically inherits its parent's root directory. Co-developed-by: Vijay Dhanraj <[email protected]> Signed-off-by: Peter Fang <[email protected]>
- Loading branch information
1 parent
f2f6522
commit 047d5de
Showing
8 changed files
with
52 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,12 @@ | |
// Author: Joerg Roedel <[email protected]> | ||
|
||
use super::obj::obj_close; | ||
use crate::task::{current_task_terminated, schedule}; | ||
use crate::address::VirtAddr; | ||
use crate::cpu::percpu::current_task; | ||
use crate::fs::find_dir; | ||
use crate::mm::guestmem::UserPtr; | ||
use crate::task::{current_task_terminated, exec_user, schedule}; | ||
use core::ffi::c_char; | ||
use syscall::SysCallError; | ||
|
||
pub fn sys_exit(exit_code: u32) -> ! { | ||
|
@@ -17,6 +22,18 @@ pub fn sys_exit(exit_code: u32) -> ! { | |
unreachable!("schedule() returned in sys_exit()"); | ||
} | ||
|
||
pub fn sys_exec(file: usize, root: usize, _flags: usize) -> Result<u64, SysCallError> { | ||
let user_file_ptr = UserPtr::<c_char>::new(VirtAddr::from(file)); | ||
let user_root_ptr = UserPtr::<c_char>::new(VirtAddr::from(root)); | ||
|
||
let file_str = user_file_ptr.read_c_string()?; | ||
let root_str = user_root_ptr.read_c_string()?; | ||
let real_root = find_dir(current_task().rootdir(), &root_str)?; | ||
let tid = exec_user(&file_str, real_root)?; | ||
|
||
Ok(tid.into()) | ||
} | ||
|
||
pub fn sys_close(obj_id: u32) -> Result<u64, SysCallError> { | ||
// According to syscall ABI/API spec, close always returns 0 even | ||
// if called with an invalid handle | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,16 @@ | |
// | ||
// Author: Joerg Roedel <[email protected]> | ||
|
||
extern crate alloc; | ||
|
||
use crate::address::{Address, VirtAddr}; | ||
use crate::error::SvsmError; | ||
use crate::fs::open; | ||
use crate::fs::{open, Directory}; | ||
use crate::mm::vm::VMFileMappingFlags; | ||
use crate::mm::USER_MEM_END; | ||
use crate::task::{create_user_task, current_task, schedule, TaskError}; | ||
use crate::types::PAGE_SIZE; | ||
use alloc::sync::Arc; | ||
use elf::{Elf64File, Elf64PhdrFlags}; | ||
|
||
fn convert_elf_phdr_flags(flags: Elf64PhdrFlags) -> VMFileMappingFlags { | ||
|
@@ -27,7 +30,7 @@ fn convert_elf_phdr_flags(flags: Elf64PhdrFlags) -> VMFileMappingFlags { | |
vm_flags | ||
} | ||
|
||
pub fn exec_user(binary: &str) -> Result<u32, SvsmError> { | ||
pub fn exec_user(binary: &str, root: Arc<dyn Directory>) -> Result<u32, SvsmError> { | ||
let fh = open(binary)?; | ||
let file_size = fh.size(); | ||
|
||
|
@@ -46,7 +49,7 @@ pub fn exec_user(binary: &str) -> Result<u32, SvsmError> { | |
let virt_base = alloc_info.range.vaddr_begin; | ||
let entry = elf_bin.get_entry(virt_base); | ||
|
||
let task = create_user_task(entry.try_into().unwrap())?; | ||
let task = create_user_task(entry.try_into().unwrap(), root)?; | ||
|
||
for seg in elf_bin.image_load_segment_iter(virt_base) { | ||
let virt_start = VirtAddr::from(seg.vaddr_range.vaddr_begin); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters