mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-30 10:33:31 +00:00
Extract dentry.rs and mount.rs to path module, rename Dentry and DentryMnt and check usage of pub.
Signed-off-by: Zhenchen Wang <m202372036@hust.edu.cn>
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
8d18a12385
commit
8bcadee540
@ -12,7 +12,7 @@ use super::elf_file::Elf;
|
||||
use crate::{
|
||||
fs::{
|
||||
fs_resolver::{FsPath, FsResolver, AT_FDCWD},
|
||||
utils::DentryMnt,
|
||||
path::Dentry,
|
||||
},
|
||||
prelude::*,
|
||||
process::{
|
||||
@ -35,7 +35,7 @@ use crate::{
|
||||
pub fn load_elf_to_vm(
|
||||
process_vm: &ProcessVm,
|
||||
file_header: &[u8],
|
||||
elf_file: Arc<DentryMnt>,
|
||||
elf_file: Arc<Dentry>,
|
||||
fs_resolver: &FsResolver,
|
||||
argv: Vec<CString>,
|
||||
envp: Vec<CString>,
|
||||
@ -93,7 +93,7 @@ fn lookup_and_parse_ldso(
|
||||
elf: &Elf,
|
||||
file_header: &[u8],
|
||||
fs_resolver: &FsResolver,
|
||||
) -> Result<(Arc<DentryMnt>, Elf)> {
|
||||
) -> Result<(Arc<Dentry>, Elf)> {
|
||||
let ldso_file = {
|
||||
let ldso_path = elf.ldso_path(file_header)?;
|
||||
let fs_path = FsPath::new(AT_FDCWD, &ldso_path)?;
|
||||
@ -105,14 +105,10 @@ fn lookup_and_parse_ldso(
|
||||
inode.read_at(0, &mut *buf)?;
|
||||
Elf::parse_elf(&*buf)?
|
||||
};
|
||||
Ok((ldso_file.clone(), ldso_elf))
|
||||
Ok((ldso_file, ldso_elf))
|
||||
}
|
||||
|
||||
fn load_ldso(
|
||||
root_vmar: &Vmar<Full>,
|
||||
ldso_file: &DentryMnt,
|
||||
ldso_elf: &Elf,
|
||||
) -> Result<LdsoLoadInfo> {
|
||||
fn load_ldso(root_vmar: &Vmar<Full>, ldso_file: &Dentry, 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,
|
||||
@ -122,9 +118,9 @@ fn load_ldso(
|
||||
|
||||
fn init_and_map_vmos(
|
||||
process_vm: &ProcessVm,
|
||||
ldso: Option<(Arc<DentryMnt>, Elf)>,
|
||||
ldso: Option<(Arc<Dentry>, Elf)>,
|
||||
parsed_elf: &Elf,
|
||||
elf_file: &DentryMnt,
|
||||
elf_file: &Dentry,
|
||||
) -> Result<(Vaddr, AuxVec)> {
|
||||
let root_vmar = process_vm.root_vmar();
|
||||
|
||||
@ -203,7 +199,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: &DentryMnt) -> Result<Vaddr> {
|
||||
pub fn map_segment_vmos(elf: &Elf, root_vmar: &Vmar<Full>, elf_file: &Dentry) -> 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() {
|
||||
@ -292,10 +288,7 @@ 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: &DentryMnt,
|
||||
) -> Result<(Vmo, usize)> {
|
||||
fn init_segment_vmo(program_header: &ProgramHeader64, elf_file: &Dentry) -> 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::DentryMnt,
|
||||
path::Dentry,
|
||||
},
|
||||
prelude::*,
|
||||
};
|
||||
@ -25,7 +25,7 @@ use crate::{
|
||||
/// because the interpreter is usually an elf binary(e.g., /bin/bash)
|
||||
pub fn load_program_to_vm(
|
||||
process_vm: &ProcessVm,
|
||||
elf_file: Arc<DentryMnt>,
|
||||
elf_file: Arc<Dentry>,
|
||||
argv: Vec<CString>,
|
||||
envp: Vec<CString>,
|
||||
fs_resolver: &FsResolver,
|
||||
@ -68,16 +68,16 @@ pub fn load_program_to_vm(
|
||||
Ok((abs_path, elf_load_info))
|
||||
}
|
||||
|
||||
pub fn check_executable_file(dentrymnt: &Arc<DentryMnt>) -> Result<()> {
|
||||
if dentrymnt.type_().is_directory() {
|
||||
pub fn check_executable_file(dentry: &Arc<Dentry>) -> Result<()> {
|
||||
if dentry.type_().is_directory() {
|
||||
return_errno_with_message!(Errno::EISDIR, "the file is a directory");
|
||||
}
|
||||
|
||||
if !dentrymnt.type_().is_reguler_file() {
|
||||
if !dentry.type_().is_reguler_file() {
|
||||
return_errno_with_message!(Errno::EACCES, "the dentry is not a regular file");
|
||||
}
|
||||
|
||||
if !dentrymnt.mode()?.is_executable() {
|
||||
if !dentry.mode()?.is_executable() {
|
||||
return_errno_with_message!(Errno::EACCES, "the dentry is not executable");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user