@@ -39,6 +39,35 @@ pub fn is_dyn_sym(name: &str, target_os: &str) -> bool {
3939
4040impl < ' tcx > EvalContextExt < ' tcx > for crate :: MiriInterpCx < ' tcx > { }
4141pub trait EvalContextExt < ' tcx > : crate :: MiriInterpCxExt < ' tcx > {
42+ // Querying system information
43+ fn sysconf ( & mut self , val : & OpTy < ' tcx > ) -> InterpResult < ' tcx , Scalar > {
44+ let this = self . eval_context_mut ( ) ;
45+
46+ let name = this. read_scalar ( val) ?. to_i32 ( ) ?;
47+ // FIXME: Which of these are POSIX, and which are GNU/Linux?
48+ // At least the names seem to all also exist on macOS.
49+ let sysconfs: & [ ( & str , fn ( & MiriInterpCx < ' _ > ) -> Scalar ) ] = & [
50+ ( "_SC_PAGESIZE" , |this| Scalar :: from_int ( this. machine . page_size , this. pointer_size ( ) ) ) ,
51+ ( "_SC_PAGE_SIZE" , |this| Scalar :: from_int ( this. machine . page_size , this. pointer_size ( ) ) ) ,
52+ ( "_SC_NPROCESSORS_CONF" , |this| {
53+ Scalar :: from_int ( this. machine . num_cpus , this. pointer_size ( ) )
54+ } ) ,
55+ ( "_SC_NPROCESSORS_ONLN" , |this| {
56+ Scalar :: from_int ( this. machine . num_cpus , this. pointer_size ( ) )
57+ } ) ,
58+ // 512 seems to be a reasonable default. The value is not critical, in
59+ // the sense that getpwuid_r takes and checks the buffer length.
60+ ( "_SC_GETPW_R_SIZE_MAX" , |this| Scalar :: from_int ( 512 , this. pointer_size ( ) ) ) ,
61+ ] ;
62+ for & ( sysconf_name, value) in sysconfs {
63+ let sysconf_name = this. eval_libc_i32 ( sysconf_name) ;
64+ if sysconf_name == name {
65+ return interp_ok ( value ( this) ) ;
66+ }
67+ }
68+ throw_unsup_format ! ( "unimplemented sysconf name: {}" , name)
69+ }
70+
4271 fn emulate_foreign_item_inner (
4372 & mut self ,
4473 link_name : Symbol ,
@@ -393,35 +422,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
393422 }
394423 }
395424
396- // Querying system information
397- "sysconf" => {
398- let [ name] = this. check_shim ( abi, ExternAbi :: C { unwind : false } , link_name, args) ?;
399- let name = this. read_scalar ( name) ?. to_i32 ( ) ?;
400- // FIXME: Which of these are POSIX, and which are GNU/Linux?
401- // At least the names seem to all also exist on macOS.
402- let sysconfs: & [ ( & str , fn ( & MiriInterpCx < ' _ > ) -> Scalar ) ] = & [
403- ( "_SC_PAGESIZE" , |this| Scalar :: from_int ( this. machine . page_size , this. pointer_size ( ) ) ) ,
404- ( "_SC_NPROCESSORS_CONF" , |this| Scalar :: from_int ( this. machine . num_cpus , this. pointer_size ( ) ) ) ,
405- ( "_SC_NPROCESSORS_ONLN" , |this| Scalar :: from_int ( this. machine . num_cpus , this. pointer_size ( ) ) ) ,
406- // 512 seems to be a reasonable default. The value is not critical, in
407- // the sense that getpwuid_r takes and checks the buffer length.
408- ( "_SC_GETPW_R_SIZE_MAX" , |this| Scalar :: from_int ( 512 , this. pointer_size ( ) ) )
409- ] ;
410- let mut result = None ;
411- for & ( sysconf_name, value) in sysconfs {
412- let sysconf_name = this. eval_libc_i32 ( sysconf_name) ;
413- if sysconf_name == name {
414- result = Some ( value ( this) ) ;
415- break ;
416- }
417- }
418- if let Some ( result) = result {
419- this. write_scalar ( result, dest) ?;
420- } else {
421- throw_unsup_format ! ( "unimplemented sysconf name: {}" , name)
422- }
423- }
424-
425425 // Thread-local storage
426426 "pthread_key_create" => {
427427 let [ key, dtor] = this. check_shim ( abi, ExternAbi :: C { unwind : false } , link_name, args) ?;
0 commit comments