mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-30 10:33:31 +00:00
Refactor DentryMnt and fix some issues
Signed-off-by: Zhenchen Wang <m202372036@hust.edu.cn>
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
60fa4d104a
commit
8d18a12385
@ -12,7 +12,7 @@ use super::elf_file::Elf;
|
||||
use crate::{
|
||||
fs::{
|
||||
fs_resolver::{FsPath, FsResolver, AT_FDCWD},
|
||||
utils::{Dentry, DentryMnt},
|
||||
utils::DentryMnt,
|
||||
},
|
||||
prelude::*,
|
||||
process::{
|
||||
@ -93,7 +93,7 @@ fn lookup_and_parse_ldso(
|
||||
elf: &Elf,
|
||||
file_header: &[u8],
|
||||
fs_resolver: &FsResolver,
|
||||
) -> Result<(Arc<Dentry>, Elf)> {
|
||||
) -> Result<(Arc<DentryMnt>, Elf)> {
|
||||
let ldso_file = {
|
||||
let ldso_path = elf.ldso_path(file_header)?;
|
||||
let fs_path = FsPath::new(AT_FDCWD, &ldso_path)?;
|
||||
@ -101,14 +101,18 @@ fn lookup_and_parse_ldso(
|
||||
};
|
||||
let ldso_elf = {
|
||||
let mut buf = Box::new([0u8; PAGE_SIZE]);
|
||||
let inode = ldso_file.dentry().inode();
|
||||
let inode = ldso_file.inode();
|
||||
inode.read_at(0, &mut *buf)?;
|
||||
Elf::parse_elf(&*buf)?
|
||||
};
|
||||
Ok((ldso_file.dentry().clone(), ldso_elf))
|
||||
Ok((ldso_file.clone(), ldso_elf))
|
||||
}
|
||||
|
||||
fn load_ldso(root_vmar: &Vmar<Full>, ldso_file: &Dentry, ldso_elf: &Elf) -> Result<LdsoLoadInfo> {
|
||||
fn load_ldso(
|
||||
root_vmar: &Vmar<Full>,
|
||||
ldso_file: &DentryMnt,
|
||||
ldso_elf: &Elf,
|
||||
) -> Result<LdsoLoadInfo> {
|
||||
let map_addr = map_segment_vmos(ldso_elf, root_vmar, ldso_file)?;
|
||||
Ok(LdsoLoadInfo::new(
|
||||
ldso_elf.entry_point() + map_addr,
|
||||
@ -118,9 +122,9 @@ fn load_ldso(root_vmar: &Vmar<Full>, ldso_file: &Dentry, ldso_elf: &Elf) -> Resu
|
||||
|
||||
fn init_and_map_vmos(
|
||||
process_vm: &ProcessVm,
|
||||
ldso: Option<(Arc<Dentry>, Elf)>,
|
||||
ldso: Option<(Arc<DentryMnt>, Elf)>,
|
||||
parsed_elf: &Elf,
|
||||
elf_file: &Dentry,
|
||||
elf_file: &DentryMnt,
|
||||
) -> Result<(Vaddr, AuxVec)> {
|
||||
let root_vmar = process_vm.root_vmar();
|
||||
|
||||
@ -199,7 +203,7 @@ impl ElfLoadInfo {
|
||||
}
|
||||
|
||||
/// init vmo for each segment and then map segment to root vmar
|
||||
pub fn map_segment_vmos(elf: &Elf, root_vmar: &Vmar<Full>, elf_file: &Dentry) -> Result<Vaddr> {
|
||||
pub fn map_segment_vmos(elf: &Elf, root_vmar: &Vmar<Full>, elf_file: &DentryMnt) -> Result<Vaddr> {
|
||||
// all segments of the shared object must be mapped to a continuous vm range
|
||||
// to ensure the relative offset of each segment not changed.
|
||||
let base_addr = if elf.is_shared_object() {
|
||||
@ -288,7 +292,10 @@ fn map_segment_vmo(
|
||||
|
||||
/// Create VMO for each segment. Return the segment VMO and the size of
|
||||
/// additional anonymous mapping it needs.
|
||||
fn init_segment_vmo(program_header: &ProgramHeader64, elf_file: &Dentry) -> Result<(Vmo, usize)> {
|
||||
fn init_segment_vmo(
|
||||
program_header: &ProgramHeader64,
|
||||
elf_file: &DentryMnt,
|
||||
) -> Result<(Vmo, usize)> {
|
||||
trace!(
|
||||
"mem range = 0x{:x} - 0x{:x}, mem_size = 0x{:x}",
|
||||
program_header.virtual_addr,
|
||||
|
@ -11,7 +11,7 @@ use super::process_vm::ProcessVm;
|
||||
use crate::{
|
||||
fs::{
|
||||
fs_resolver::{FsPath, FsResolver, AT_FDCWD},
|
||||
utils::{Dentry, DentryMnt},
|
||||
utils::DentryMnt,
|
||||
},
|
||||
prelude::*,
|
||||
};
|
||||
@ -32,7 +32,7 @@ pub fn load_program_to_vm(
|
||||
recursion_limit: usize,
|
||||
) -> Result<(String, ElfLoadInfo)> {
|
||||
let abs_path = elf_file.abs_path();
|
||||
let inode = elf_file.dentry().inode();
|
||||
let inode = elf_file.inode();
|
||||
let file_header = {
|
||||
// read the first page of file header
|
||||
let mut file_header_buffer = Box::new([0u8; PAGE_SIZE]);
|
||||
@ -49,7 +49,7 @@ pub fn load_program_to_vm(
|
||||
let fs_path = FsPath::new(AT_FDCWD, &filename)?;
|
||||
fs_resolver.lookup(&fs_path)?
|
||||
};
|
||||
check_executable_file(interpreter.dentry())?;
|
||||
check_executable_file(&interpreter)?;
|
||||
return load_program_to_vm(
|
||||
process_vm,
|
||||
interpreter,
|
||||
@ -68,16 +68,16 @@ pub fn load_program_to_vm(
|
||||
Ok((abs_path, elf_load_info))
|
||||
}
|
||||
|
||||
pub fn check_executable_file(dentry: &Arc<Dentry>) -> Result<()> {
|
||||
if dentry.type_().is_directory() {
|
||||
pub fn check_executable_file(dentrymnt: &Arc<DentryMnt>) -> Result<()> {
|
||||
if dentrymnt.type_().is_directory() {
|
||||
return_errno_with_message!(Errno::EISDIR, "the file is a directory");
|
||||
}
|
||||
|
||||
if !dentry.type_().is_reguler_file() {
|
||||
if !dentrymnt.type_().is_reguler_file() {
|
||||
return_errno_with_message!(Errno::EACCES, "the dentry is not a regular file");
|
||||
}
|
||||
|
||||
if !dentry.mode()?.is_executable() {
|
||||
if !dentrymnt.mode()?.is_executable() {
|
||||
return_errno_with_message!(Errno::EACCES, "the dentry is not executable");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user