@@ -53,6 +53,8 @@ mod proc_cpuinfo;
5353mod proc_maps;
5454mod proc_mounts;
5555mod proc_pid_cmdline;
56+ mod proc_pid_stat;
57+ mod proc_pid_task;
5658mod proc_thread_self_ns;
5759mod proc_version;
5860mod procfs_setup;
@@ -92,6 +94,14 @@ pub enum ProcFileType {
9294 ProcCmdline ,
9395 /// /proc/<pid>/cmdline(也覆盖 /proc/self/cmdline)
9496 ProcPidCmdline ,
97+ /// /proc/<pid>/stat
98+ ProcPidStat ,
99+ /// /proc/<pid>/task 目录
100+ ProcPidTaskDir ,
101+ /// /proc/<pid>/task/<tid> 目录
102+ ProcPidTaskTidDir ,
103+ /// /proc/<pid>/task/<tid>/stat 文件
104+ ProcPidTaskTidStat ,
95105 /// /proc/thread-self/ns itself
96106 ProcThreadSelfNsRoot ,
97107 /// /proc/thread-self/ns/* namespace files
@@ -190,6 +200,8 @@ impl<'a> ProcFileCreationParamsBuilder<'a> {
190200pub struct InodeInfo {
191201 ///进程的pid
192202 pid : Option < RawPid > ,
203+ /// 线程的 tid(用于 /proc/<pid>/task/<tid>)
204+ tid : Option < RawPid > ,
193205 ///文件类型
194206 ftype : ProcFileType ,
195207 /// 文件描述符
@@ -203,6 +215,7 @@ impl core::fmt::Debug for InodeInfo {
203215 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
204216 f. debug_struct ( "InodeInfo" )
205217 . field ( "pid" , & self . pid )
218+ . field ( "tid" , & self . tid )
206219 . field ( "ftype" , & self . ftype )
207220 . field ( "fd" , & self . fd )
208221 . field ( "target_inode" , & self . target_inode . is_some ( ) )
@@ -660,6 +673,7 @@ impl ProcFS {
660673 fs : Weak :: default ( ) ,
661674 fdata : InodeInfo {
662675 pid : None ,
676+ tid : None ,
663677 ftype : ProcFileType :: Default ,
664678 fd : -1 ,
665679 target_inode : None ,
@@ -729,6 +743,15 @@ impl ProcFS {
729743 statm_file. 0 . lock ( ) . fdata . pid = Some ( pid) ;
730744 statm_file. 0 . lock ( ) . fdata . ftype = ProcFileType :: ProcStatm ;
731745
746+ // stat 文件: /proc/<pid>/stat
747+ let stat_binding = pid_dir. create ( "stat" , FileType :: File , InodeMode :: S_IRUGO ) ?;
748+ let stat_file = stat_binding
749+ . as_any_ref ( )
750+ . downcast_ref :: < LockedProcFSInode > ( )
751+ . unwrap ( ) ;
752+ stat_file. 0 . lock ( ) . fdata . pid = Some ( pid) ;
753+ stat_file. 0 . lock ( ) . fdata . ftype = ProcFileType :: ProcPidStat ;
754+
732755 // maps 文件
733756 let maps_binding = pid_dir. create ( "maps" , FileType :: File , InodeMode :: S_IRUGO ) ?;
734757 let maps_file = maps_binding
@@ -747,6 +770,16 @@ impl ProcFS {
747770 cmdline_file. 0 . lock ( ) . fdata . pid = Some ( pid) ;
748771 cmdline_file. 0 . lock ( ) . fdata . ftype = ProcFileType :: ProcPidCmdline ;
749772
773+ // task dir: /proc/<pid>/task
774+ let task_dir =
775+ pid_dir. create ( "task" , FileType :: Dir , InodeMode :: from_bits_truncate ( 0o555 ) ) ?;
776+ let task_dir = task_dir
777+ . as_any_ref ( )
778+ . downcast_ref :: < LockedProcFSInode > ( )
779+ . unwrap ( ) ;
780+ task_dir. 0 . lock ( ) . fdata . pid = Some ( pid) ;
781+ task_dir. 0 . lock ( ) . fdata . ftype = ProcFileType :: ProcPidTaskDir ;
782+
750783 // fd dir
751784 let fd = pid_dir. create ( "fd" , FileType :: Dir , InodeMode :: from_bits_truncate ( 0o555 ) ) ?;
752785 let fd = fd. as_any_ref ( ) . downcast_ref :: < LockedProcFSInode > ( ) . unwrap ( ) ;
@@ -797,6 +830,8 @@ impl ProcFS {
797830 // 删除进程文件夹下文件
798831 pid_dir. unlink ( "status" ) ?;
799832 pid_dir. unlink ( "exe" ) ?;
833+ let _ = pid_dir. unlink ( "stat" ) ;
834+ let _ = pid_dir. rmdir ( "task" ) ;
800835 pid_dir. rmdir ( "fd" ) ?;
801836 pid_dir. rmdir ( "fdinfo" ) ?;
802837 let _ = pid_dir. unlink ( "mounts" ) ;
@@ -985,6 +1020,8 @@ impl IndexNode for LockedProcFSInode {
9851020 ProcFileType :: ProcMaps => inode. open_maps ( & mut proc_private) ?,
9861021 ProcFileType :: ProcCmdline => inode. open_cmdline ( & mut proc_private) ?,
9871022 ProcFileType :: ProcPidCmdline => inode. open_pid_cmdline ( & mut proc_private) ?,
1023+ ProcFileType :: ProcPidStat => inode. open_pid_stat ( & mut proc_private) ?,
1024+ ProcFileType :: ProcPidTaskTidStat => inode. open_pid_task_tid_stat ( & mut proc_private) ?,
9881025 ProcFileType :: ProcExe => inode. open_exe ( & mut proc_private) ?,
9891026 ProcFileType :: ProcMounts => inode. open_mounts ( & mut proc_private) ?,
9901027 ProcFileType :: ProcMountInfo => {
@@ -1002,6 +1039,8 @@ impl IndexNode for LockedProcFSInode {
10021039 }
10031040 ProcFileType :: Default => inode. data . len ( ) as i64 ,
10041041 ProcFileType :: ProcKmsg
1042+ | ProcFileType :: ProcPidTaskDir
1043+ | ProcFileType :: ProcPidTaskTidDir
10051044 | ProcFileType :: ProcFdDir
10061045 | ProcFileType :: ProcFdFile
10071046 | ProcFileType :: ProcFdInfoDir
@@ -1076,6 +1115,8 @@ impl IndexNode for LockedProcFSInode {
10761115 | ProcFileType :: ProcMaps
10771116 | ProcFileType :: ProcCmdline
10781117 | ProcFileType :: ProcPidCmdline
1118+ | ProcFileType :: ProcPidStat
1119+ | ProcFileType :: ProcPidTaskTidStat
10791120 | ProcFileType :: ProcMounts
10801121 | ProcFileType :: ProcMountInfo
10811122 | ProcFileType :: ProcVersion
@@ -1243,6 +1284,7 @@ impl IndexNode for LockedProcFSInode {
12431284 fs : inode. fs . clone ( ) ,
12441285 fdata : InodeInfo {
12451286 pid : None ,
1287+ tid : None ,
12461288 ftype : ProcFileType :: Default ,
12471289 fd : -1 ,
12481290 target_inode : None ,
@@ -1369,6 +1411,12 @@ impl IndexNode for LockedProcFSInode {
13691411 ProcFileType :: ProcThreadSelfNsRoot => {
13701412 return self . dynamical_find_thread_self_ns ( name) ;
13711413 }
1414+ ProcFileType :: ProcPidTaskDir => {
1415+ return self . dynamical_find_task_tid ( name) ;
1416+ }
1417+ ProcFileType :: ProcPidTaskTidDir => {
1418+ return self . dynamical_find_task_tid_child ( name) ;
1419+ }
13721420 _ => { }
13731421 }
13741422
@@ -1457,6 +1505,11 @@ impl IndexNode for LockedProcFSInode {
14571505
14581506 return Ok ( keys) ;
14591507 }
1508+ ProcFileType :: ProcPidTaskDir => {
1509+ let mut tids = self . dynamical_list_task_tids ( ) ?;
1510+ keys. append ( & mut tids) ;
1511+ return Ok ( keys) ;
1512+ }
14601513 _ => { }
14611514 }
14621515
0 commit comments