mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 19:03:27 +00:00
Move FS things to PosixThread
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
fe7e4884c9
commit
36fc1d3757
@ -18,7 +18,7 @@ use super::{
|
||||
use crate::{
|
||||
cpu::LinuxAbi,
|
||||
current_userspace,
|
||||
fs::{file_table::FileTable, fs_resolver::FsResolver, utils::FileCreationMask},
|
||||
fs::{file_table::FileTable, thread_info::ThreadFsInfo},
|
||||
prelude::*,
|
||||
process::posix_thread::allocate_posix_tid,
|
||||
thread::{AsThread, Tid},
|
||||
@ -213,15 +213,6 @@ fn clone_child_task(
|
||||
);
|
||||
}
|
||||
|
||||
// This is valid combination in Linux. But we do not support it yet.
|
||||
if !clone_flags.contains(CloneFlags::CLONE_FILES) || !clone_flags.contains(CloneFlags::CLONE_FS)
|
||||
{
|
||||
return_errno_with_message!(
|
||||
Errno::EINVAL,
|
||||
"`CLONE_THREAD` without `CLONE_FILES` or `CLONE_FS` is not supported"
|
||||
);
|
||||
}
|
||||
|
||||
let Context {
|
||||
process,
|
||||
posix_thread,
|
||||
@ -232,6 +223,12 @@ fn clone_child_task(
|
||||
// clone system V semaphore
|
||||
clone_sysvsem(clone_flags)?;
|
||||
|
||||
// clone file table
|
||||
let child_file_table = clone_files(posix_thread.file_table(), clone_flags);
|
||||
|
||||
// clone fs
|
||||
let child_fs = clone_fs(posix_thread.fs(), clone_flags);
|
||||
|
||||
let child_root_vmar = process.root_vmar();
|
||||
let child_user_space = {
|
||||
let child_vm_space = child_root_vmar.vm_space().clone();
|
||||
@ -257,7 +254,9 @@ fn clone_child_task(
|
||||
|
||||
let thread_builder = PosixThreadBuilder::new(child_tid, child_user_space, credentials)
|
||||
.process(posix_thread.weak_process())
|
||||
.sig_mask(sig_mask);
|
||||
.sig_mask(sig_mask)
|
||||
.file_table(child_file_table)
|
||||
.fs(child_fs);
|
||||
thread_builder.build()
|
||||
};
|
||||
|
||||
@ -307,16 +306,10 @@ fn clone_child_process(
|
||||
};
|
||||
|
||||
// clone file table
|
||||
let child_file_table = clone_files(process.file_table(), clone_flags);
|
||||
let child_file_table = clone_files(posix_thread.file_table(), clone_flags);
|
||||
|
||||
// clone fs
|
||||
let child_fs = clone_fs(process.fs(), clone_flags);
|
||||
|
||||
// clone umask
|
||||
let child_umask = {
|
||||
let parent_umask = process.umask().read().get();
|
||||
Arc::new(RwLock::new(FileCreationMask::new(parent_umask)))
|
||||
};
|
||||
let child_fs = clone_fs(posix_thread.fs(), clone_flags);
|
||||
|
||||
// clone sig dispositions
|
||||
let child_sig_dispositions = clone_sighand(process.sig_dispositions(), clone_flags);
|
||||
@ -345,6 +338,8 @@ fn clone_child_process(
|
||||
PosixThreadBuilder::new(child_tid, child_user_space, credentials)
|
||||
.thread_name(Some(child_thread_name))
|
||||
.sig_mask(child_sig_mask)
|
||||
.file_table(child_file_table)
|
||||
.fs(child_fs)
|
||||
};
|
||||
|
||||
let mut process_builder =
|
||||
@ -353,9 +348,6 @@ fn clone_child_process(
|
||||
process_builder
|
||||
.main_thread_builder(child_thread_builder)
|
||||
.process_vm(child_process_vm)
|
||||
.file_table(child_file_table)
|
||||
.fs(child_fs)
|
||||
.umask(child_umask)
|
||||
.sig_dispositions(child_sig_dispositions)
|
||||
.nice(child_nice);
|
||||
|
||||
@ -460,14 +452,11 @@ fn clone_cpu_context(
|
||||
child_context
|
||||
}
|
||||
|
||||
fn clone_fs(
|
||||
parent_fs: &Arc<RwMutex<FsResolver>>,
|
||||
clone_flags: CloneFlags,
|
||||
) -> Arc<RwMutex<FsResolver>> {
|
||||
fn clone_fs(parent_fs: &Arc<ThreadFsInfo>, clone_flags: CloneFlags) -> Arc<ThreadFsInfo> {
|
||||
if clone_flags.contains(CloneFlags::CLONE_FS) {
|
||||
parent_fs.clone()
|
||||
} else {
|
||||
Arc::new(RwMutex::new(parent_fs.read().clone()))
|
||||
Arc::new(parent_fs.as_ref().clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user