mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-14 15:56:47 +00:00
Export /proc/self-thread
This commit is contained in:
parent
532dac8fe3
commit
327a6b5e30
@ -3,15 +3,16 @@
|
||||
use core::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
use filesystems::{FileSystemType, FILESYSTEM_TYPES};
|
||||
use loadavg::LoadAvgFileOps;
|
||||
use sys::SysDirOps;
|
||||
|
||||
use self::{
|
||||
cpuinfo::CpuInfoFileOps,
|
||||
loadavg::LoadAvgFileOps,
|
||||
meminfo::MemInfoFileOps,
|
||||
pid::PidDirOps,
|
||||
self_::SelfSymOps,
|
||||
sys::SysDirOps,
|
||||
template::{DirOps, ProcDir, ProcDirBuilder, ProcSymBuilder, SymOps},
|
||||
thread_self::ThreadSelfSymOps,
|
||||
};
|
||||
use crate::{
|
||||
events::Observer,
|
||||
@ -20,7 +21,10 @@ use crate::{
|
||||
utils::{DirEntryVecExt, FileSystem, FsFlags, Inode, SuperBlock, NAME_MAX},
|
||||
},
|
||||
prelude::*,
|
||||
process::{process_table, process_table::PidEvent, Pid},
|
||||
process::{
|
||||
process_table::{self, PidEvent},
|
||||
Pid,
|
||||
},
|
||||
};
|
||||
|
||||
mod cpuinfo;
|
||||
@ -31,6 +35,7 @@ mod pid;
|
||||
mod self_;
|
||||
mod sys;
|
||||
mod template;
|
||||
mod thread_self;
|
||||
|
||||
pub(super) fn init() {
|
||||
FILESYSTEM_TYPES.call_once(|| {
|
||||
@ -119,6 +124,8 @@ impl DirOps for RootDirOps {
|
||||
SelfSymOps::new_inode(this_ptr.clone())
|
||||
} else if name == "sys" {
|
||||
SysDirOps::new_inode(this_ptr.clone())
|
||||
} else if name == "thread-self" {
|
||||
ThreadSelfSymOps::new_inode(this_ptr.clone())
|
||||
} else if name == "filesystems" {
|
||||
FileSystemsFileOps::new_inode(this_ptr.clone())
|
||||
} else if name == "meminfo" {
|
||||
@ -144,6 +151,9 @@ impl DirOps for RootDirOps {
|
||||
};
|
||||
let mut cached_children = this.cached_children().write();
|
||||
cached_children.put_entry_if_not_found("self", || SelfSymOps::new_inode(this_ptr.clone()));
|
||||
cached_children.put_entry_if_not_found("thread-self", || {
|
||||
ThreadSelfSymOps::new_inode(this_ptr.clone())
|
||||
});
|
||||
cached_children.put_entry_if_not_found("sys", || SysDirOps::new_inode(this_ptr.clone()));
|
||||
cached_children.put_entry_if_not_found("filesystems", || {
|
||||
FileSystemsFileOps::new_inode(this_ptr.clone())
|
||||
|
@ -40,6 +40,7 @@ impl DirOps for ThreadDirOps {
|
||||
fn lookup_child(&self, this_ptr: Weak<dyn Inode>, name: &str) -> Result<Arc<dyn Inode>> {
|
||||
let inode = match name {
|
||||
"fd" => FdDirOps::new_inode(self.0.clone(), this_ptr.clone()),
|
||||
"exe" => ExeSymOps::new_inode(self.0.clone(), this_ptr.clone()),
|
||||
_ => return_errno!(Errno::ENOENT),
|
||||
};
|
||||
Ok(inode)
|
||||
@ -54,6 +55,9 @@ impl DirOps for ThreadDirOps {
|
||||
cached_children.put_entry_if_not_found("fd", || {
|
||||
FdDirOps::new_inode(self.0.clone(), this_ptr.clone())
|
||||
});
|
||||
cached_children.put_entry_if_not_found("exe", || {
|
||||
ExeSymOps::new_inode(self.0.clone(), this_ptr.clone())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
29
kernel/src/fs/procfs/thread_self.rs
Normal file
29
kernel/src/fs/procfs/thread_self.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use alloc::format;
|
||||
|
||||
use crate::{
|
||||
fs::{
|
||||
procfs::{ProcSymBuilder, SymOps},
|
||||
utils::Inode,
|
||||
},
|
||||
prelude::*,
|
||||
process::posix_thread::AsPosixThread,
|
||||
};
|
||||
|
||||
/// Represents the inode at `/proc/self-thread`.
|
||||
pub struct ThreadSelfSymOps;
|
||||
|
||||
impl ThreadSelfSymOps {
|
||||
pub fn new_inode(parent: Weak<dyn Inode>) -> Arc<dyn Inode> {
|
||||
ProcSymBuilder::new(Self).parent(parent).build().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl SymOps for ThreadSelfSymOps {
|
||||
fn read_link(&self) -> Result<String> {
|
||||
let pid = current!().pid();
|
||||
let tid = current_thread!().as_posix_thread().unwrap().tid();
|
||||
Ok(format!("{}/task/{}", pid, tid))
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user