File tree Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -1078,11 +1078,17 @@ void rv_step(void *arg)
10781078        assert (block -> satp  ==  rv -> csr_satp );
10791079#endif 
10801080
1081-         /* After emulating the previous block, it is determined whether the 
1082-          * branch is taken or not. The IR array of the current block is then 
1083-          * assigned to either the branch_taken or branch_untaken pointer of 
1084-          * the previous block. 
1085-          */ 
1081+ #if  !RV32_HAS (SYSTEM )
1082+         /* on exit */ 
1083+         if  (unlikely (block -> ir_head -> pc  ==  PRIV (rv )-> exit_addr ))
1084+             PRIV (rv )-> on_exit  =  true;
1085+ #endif 
1086+ 
1087+             /* After emulating the previous block, it is determined whether the 
1088+              * branch is taken or not. The IR array of the current block is then 
1089+              * assigned to either the branch_taken or branch_untaken pointer of 
1090+              * the previous block. 
1091+              */ 
10861092
10871093#if  RV32_HAS (BLOCK_CHAINING )
10881094        if  (prev 
Original file line number Diff line number Diff line change @@ -434,6 +434,15 @@ riscv_t *rv_create(riscv_user_t rv_attr)
434434    if  ((end  =  elf_get_symbol (elf , "_end" )))
435435        attr -> break_addr  =  end -> st_value ;
436436
437+ #if  !RV32_HAS (SYSTEM )
438+     /* set not exiting */ 
439+     attr -> on_exit  =  false;
440+ 
441+     const  struct  Elf32_Sym  * exit ;
442+     if  ((exit  =  elf_get_symbol (elf , "exit" )))
443+         attr -> exit_addr  =  exit -> st_value ;
444+ #endif 
445+ 
437446    assert (elf_load (elf , attr -> mem ));
438447
439448    /* set the entry pc */ 
Original file line number Diff line number Diff line change @@ -548,6 +548,14 @@ typedef struct {
548548    /* the data segment break address */ 
549549    riscv_word_t  break_addr ;
550550
551+ #if  !RV32_HAS (SYSTEM )
552+     /* the exit entry address */ 
553+     riscv_word_t  exit_addr ;
554+ 
555+     /* flag to determine if the emulator exits the target program */ 
556+     bool  on_exit ;
557+ #endif 
558+ 
551559    /* SBI timer */ 
552560    uint64_t  timer ;
553561} vm_attr_t ;
Original file line number Diff line number Diff line change @@ -230,6 +230,22 @@ static void syscall_close(riscv_t *rv)
230230    /* _close(fd); */ 
231231    uint32_t  fd  =  rv_get_reg (rv , rv_reg_a0 );
232232
233+ #if  !RV32_HAS (SYSTEM )
234+     /* 
235+      * The crt0 closes standard file descriptor(0, 1, 2) when 
236+      * the process exits. Thus, the operations by the crt0 
237+      * should not considered as error. 
238+      */ 
239+     if  (fd  <  3  &&  !PRIV (rv )-> on_exit ) {
240+         rv_set_reg (rv , rv_reg_a0 , -1 );
241+         rv_log_error (
242+             "Attempted to close a file descriptor < 3 (fd=%u). Operation " 
243+             "not supported." ,
244+             fd );
245+         return ;
246+     }
247+ #endif 
248+ 
233249    if  (fd  >= 3 ) { /* lookup the file descriptor */ 
234250        map_iter_t  it ;
235251        map_find (attr -> fd_map , & it , & fd );
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments