@@ -67,27 +67,30 @@ impl AppManager {
6767 }
6868 }
6969
70- unsafe fn load_app ( & self , app_id : usize ) {
70+ fn load_app ( & self , app_id : usize ) {
7171 if app_id >= self . num_app {
7272 println ! ( "All applications completed!" ) ;
7373 shutdown ( false ) ;
7474 }
7575 println ! ( "[kernel] Loading app_{}" , app_id) ;
76- // clear app area
77- core:: slice:: from_raw_parts_mut ( APP_BASE_ADDRESS as * mut u8 , APP_SIZE_LIMIT ) . fill ( 0 ) ;
78- let app_src = core:: slice:: from_raw_parts (
79- self . app_start [ app_id] as * const u8 ,
80- self . app_start [ app_id + 1 ] - self . app_start [ app_id] ,
81- ) ;
82- let app_dst = core:: slice:: from_raw_parts_mut ( APP_BASE_ADDRESS as * mut u8 , app_src. len ( ) ) ;
83- app_dst. copy_from_slice ( app_src) ;
84- // Memory fence about fetching the instruction memory
85- // It is guaranteed that a subsequent instruction fetch must
86- // observes all previous writes to the instruction memory.
87- // Therefore, fence.i must be executed after we have loaded
88- // the code of the next app into the instruction memory.
89- // See also: riscv non-priv spec chapter 3, 'Zifencei' extension.
90- asm ! ( "fence.i" ) ;
76+ unsafe {
77+ // clear app area
78+ core:: slice:: from_raw_parts_mut ( APP_BASE_ADDRESS as * mut u8 , APP_SIZE_LIMIT ) . fill ( 0 ) ;
79+ let app_src = core:: slice:: from_raw_parts (
80+ self . app_start [ app_id] as * const u8 ,
81+ self . app_start [ app_id + 1 ] - self . app_start [ app_id] ,
82+ ) ;
83+ let app_dst =
84+ core:: slice:: from_raw_parts_mut ( APP_BASE_ADDRESS as * mut u8 , app_src. len ( ) ) ;
85+ app_dst. copy_from_slice ( app_src) ;
86+ // Memory fence about fetching the instruction memory
87+ // It is guaranteed that a subsequent instruction fetch must
88+ // observes all previous writes to the instruction memory.
89+ // Therefore, fence.i must be executed after we have loaded
90+ // the code of the next app into the instruction memory.
91+ // See also: riscv non-priv spec chapter 3, 'Zifencei' extension.
92+ asm ! ( "fence.i" ) ;
93+ }
9194 }
9295
9396 pub fn get_current_app ( & self ) -> usize {
@@ -102,8 +105,8 @@ impl AppManager {
102105lazy_static ! {
103106 static ref APP_MANAGER : UPSafeCell <AppManager > = unsafe {
104107 UPSafeCell :: new( {
105- extern "C" {
106- fn _num_app( ) ;
108+ unsafe extern "C" {
109+ safe fn _num_app( ) ;
107110 }
108111 let num_app_ptr = _num_app as usize as * const usize ;
109112 let num_app = num_app_ptr. read_volatile( ) ;
@@ -134,15 +137,13 @@ pub fn print_app_info() {
134137pub fn run_next_app ( ) -> ! {
135138 let mut app_manager = APP_MANAGER . exclusive_access ( ) ;
136139 let current_app = app_manager. get_current_app ( ) ;
137- unsafe {
138- app_manager. load_app ( current_app) ;
139- }
140+ app_manager. load_app ( current_app) ;
140141 app_manager. move_to_next_app ( ) ;
141142 drop ( app_manager) ;
142143 // before this we have to drop local variables related to resources manually
143144 // and release the resources
144- extern "C" {
145- fn __restore ( cx_addr : usize ) ;
145+ unsafe extern "C" {
146+ unsafe fn __restore ( cx_addr : usize ) ;
146147 }
147148 unsafe {
148149 __restore ( KERNEL_STACK . push_context ( TrapContext :: app_init_context (
0 commit comments