@@ -68,6 +68,30 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
6868        throw_unsup_format ! ( "unimplemented sysconf name: {}" ,  name) 
6969    } 
7070
71+     fn  strerror_r ( 
72+         & mut  self , 
73+         errnum :  & OpTy < ' tcx > , 
74+         buf :  & OpTy < ' tcx > , 
75+         buflen :  & OpTy < ' tcx > , 
76+     )  -> InterpResult < ' tcx ,  Scalar >  { 
77+         let  this = self . eval_context_mut ( ) ; 
78+ 
79+         let  errnum = this. read_scalar ( errnum) ?; 
80+         let  buf = this. read_pointer ( buf) ?; 
81+         let  buflen = this. read_target_usize ( buflen) ?; 
82+         let  error = this. try_errnum_to_io_error ( errnum) ?; 
83+         let  formatted = match  error { 
84+             Some ( err)  => format ! ( "{err}" ) , 
85+             None  => format ! ( "<unknown errnum in strerror_r: {errnum}>" ) , 
86+         } ; 
87+         let  ( complete,  _)  = this. write_os_str_to_c_str ( OsStr :: new ( & formatted) ,  buf,  buflen) ?; 
88+         if  complete { 
89+             interp_ok ( Scalar :: from_i32 ( 0 ) ) 
90+         }  else  { 
91+             interp_ok ( Scalar :: from_i32 ( this. eval_libc_i32 ( "ERANGE" ) ) ) 
92+         } 
93+     } 
94+ 
7195    fn  emulate_foreign_item_inner ( 
7296        & mut  self , 
7397        link_name :  Symbol , 
@@ -113,6 +137,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
113137                this. write_scalar ( result,  dest) ?; 
114138            } 
115139
140+             "sysconf"  => { 
141+                 let  [ val]  =
142+                     this. check_shim ( abi,  ExternAbi :: C  {  unwind :  false  } ,  link_name,  args) ?; 
143+                 let  result = this. sysconf ( val) ?; 
144+                 this. write_scalar ( result,  dest) ?; 
145+             } 
146+ 
116147            // File descriptors 
117148            "read"  => { 
118149                let  [ fd,  buf,  count]  = this. check_shim ( abi,  ExternAbi :: C  {  unwind :  false  } ,  link_name,  args) ?; 
@@ -724,21 +755,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
724755                // We do not support forking, so there is nothing to do here. 
725756                this. write_null ( dest) ?; 
726757            } 
727-             "strerror_r"  | "__xpg_strerror_r"  => { 
728-                 let  [ errnum,  buf,  buflen]  = this. check_shim ( abi,  ExternAbi :: C  {  unwind :  false  } ,  link_name,  args) ?; 
729-                 let  errnum = this. read_scalar ( errnum) ?; 
730-                 let  buf = this. read_pointer ( buf) ?; 
731-                 let  buflen = this. read_target_usize ( buflen) ?; 
732- 
733-                 let  error = this. try_errnum_to_io_error ( errnum) ?; 
734-                 let  formatted = match  error { 
735-                     Some ( err)  => format ! ( "{err}" ) , 
736-                     None  => format ! ( "<unknown errnum in strerror_r: {errnum}>" ) , 
737-                 } ; 
738-                 let  ( complete,  _)  = this. write_os_str_to_c_str ( OsStr :: new ( & formatted) ,  buf,  buflen) ?; 
739-                 let  ret = if  complete {  0  }  else  {  this. eval_libc_i32 ( "ERANGE" )  } ; 
740-                 this. write_int ( ret,  dest) ?; 
741-             } 
742758            "getentropy"  => { 
743759                // This function is non-standard but exists with the same signature and behavior on 
744760                // Linux, macOS, FreeBSD and Solaris/Illumos. 
@@ -766,6 +782,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
766782                    this. write_null ( dest) ?; 
767783                } 
768784            } 
785+ 
786+             "strerror_r"  => { 
787+                 let  [ errnum,  buf,  buflen]  =
788+                     this. check_shim ( abi,  ExternAbi :: C  {  unwind :  false  } ,  link_name,  args) ?; 
789+                 let  result = this. strerror_r ( errnum,  buf,  buflen) ?; 
790+                 this. write_scalar ( result,  dest) ?; 
791+             } 
792+ 
769793            "getrandom"  => { 
770794                // This function is non-standard but exists with the same signature and behavior on 
771795                // Linux, FreeBSD and Solaris/Illumos. 
0 commit comments