File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -44,13 +44,14 @@ impl Process {
44
44
pub fn new (
45
45
name : String ,
46
46
parent : Option < Weak < Process > > ,
47
- page_table : PageTableContext ,
47
+ proc_vm : Option < ProcessVm > ,
48
48
proc_data : Option < ProcessData > ,
49
49
) -> Arc < Self > {
50
50
let name = name. to_ascii_lowercase ( ) ;
51
51
52
52
// create context
53
53
let pid = ProcessId :: new ( ) ;
54
+ let proc_vm = proc_vm. unwrap_or_else ( || ProcessVm :: new ( PageTableContext :: new ( ) ) ) ;
54
55
55
56
let inner = ProcessInner {
56
57
name,
@@ -60,7 +61,7 @@ impl Process {
60
61
ticks_passed : 0 ,
61
62
exit_code : None ,
62
63
children : Vec :: new ( ) ,
63
- page_table : Some ( page_table ) ,
64
+ proc_vm : Some ( proc_vm ) ,
64
65
proc_data : Some ( proc_data. unwrap_or_default ( ) ) ,
65
66
} ;
66
67
@@ -117,7 +118,7 @@ impl ProcessInner {
117
118
}
118
119
119
120
pub fn clone_page_table ( & self ) -> PageTableContext {
120
- self . page_table . as_ref ( ) . unwrap ( ) . clone_level_4 ( )
121
+ self . proc_vm . as_ref ( ) . unwrap ( )
121
122
}
122
123
123
124
pub fn is_ready ( & self ) -> bool {
Original file line number Diff line number Diff line change @@ -61,3 +61,31 @@ fn wait(pid: ProcessId) {
61
61
}
62
62
}
63
63
}
64
+
65
+ const SHORT_UNITS : [ & str ; 4 ] = [ "B" , "K" , "M" , "G" ] ;
66
+ const UNITS : [ & str ; 4 ] = [ "B" , "KiB" , "MiB" , "GiB" ] ;
67
+
68
+ pub fn humanized_size ( size : u64 ) -> ( f32 , & ' static str ) {
69
+ humanized_size_impl ( size, false )
70
+ }
71
+
72
+ pub fn humanized_size_short ( size : u64 ) -> ( f32 , & ' static str ) {
73
+ humanized_size_impl ( size, true )
74
+ }
75
+
76
+ #[ inline]
77
+ pub fn humanized_size_impl ( size : u64 , short : bool ) -> ( f32 , & ' static str ) {
78
+ let bytes = size as f32 ;
79
+
80
+ let units = if short { & SHORT_UNITS } else { & UNITS } ;
81
+
82
+ let mut unit = 0 ;
83
+ let mut bytes = bytes;
84
+
85
+ while bytes >= 1024f32 && unit < units. len ( ) {
86
+ bytes /= 1024f32 ;
87
+ unit += 1 ;
88
+ }
89
+
90
+ ( bytes, units[ unit] )
91
+ }
You can’t perform that action at this time.
0 commit comments