@@ -3,11 +3,12 @@ use core::ffi::c_int;
33
44use axerrno:: { LinuxError , LinuxResult } ;
55use axio:: PollState ;
6+ use axns:: { ResArc , def_resource} ;
67use flatten_objects:: FlattenObjects ;
78use spin:: RwLock ;
89
9- use super :: stdio:: { stdin, stdout} ;
1010use crate :: ctypes;
11+ use crate :: imp:: stdio:: { stdin, stdout} ;
1112
1213pub const AX_FILE_LIMIT : usize = 1024 ;
1314
@@ -21,14 +22,8 @@ pub trait FileLike: Send + Sync {
2122 fn set_nonblocking ( & self , nonblocking : bool ) -> LinuxResult ;
2223}
2324
24- lazy_static:: lazy_static! {
25- static ref FD_TABLE : RwLock <FlattenObjects <Arc <dyn FileLike >, AX_FILE_LIMIT >> = {
26- let mut fd_table = FlattenObjects :: new( ) ;
27- fd_table. add_at( 0 , Arc :: new( stdin( ) ) as _) . unwrap_or_else( |_| panic!( ) ) ; // stdin
28- fd_table. add_at( 1 , Arc :: new( stdout( ) ) as _) . unwrap_or_else( |_| panic!( ) ) ; // stdout
29- fd_table. add_at( 2 , Arc :: new( stdout( ) ) as _) . unwrap_or_else( |_| panic!( ) ) ; // stderr
30- RwLock :: new( fd_table)
31- } ;
25+ def_resource ! {
26+ pub ( crate ) static FD_TABLE : ResArc <RwLock <FlattenObjects <Arc <dyn FileLike >, AX_FILE_LIMIT >>> = ResArc :: new( ) ;
3227}
3328
3429pub fn get_file_like ( fd : c_int ) -> LinuxResult < Arc < dyn FileLike > > {
@@ -127,3 +122,18 @@ pub fn sys_fcntl(fd: c_int, cmd: c_int, arg: usize) -> c_int {
127122 }
128123 } )
129124}
125+
126+ #[ ctor_bare:: register_ctor]
127+ fn init_stdio ( ) {
128+ let mut fd_table = flatten_objects:: FlattenObjects :: new ( ) ;
129+ fd_table
130+ . add_at ( 0 , Arc :: new ( stdin ( ) ) as _ )
131+ . unwrap_or_else ( |_| panic ! ( ) ) ; // stdin
132+ fd_table
133+ . add_at ( 1 , Arc :: new ( stdout ( ) ) as _ )
134+ . unwrap_or_else ( |_| panic ! ( ) ) ; // stdout
135+ fd_table
136+ . add_at ( 2 , Arc :: new ( stdout ( ) ) as _ )
137+ . unwrap_or_else ( |_| panic ! ( ) ) ; // stderr
138+ FD_TABLE . init_new ( spin:: RwLock :: new ( fd_table) ) ;
139+ }
0 commit comments