@@ -20,6 +20,23 @@ use shims::unix::freebsd::foreign_items as freebsd;
2020use shims:: unix:: linux:: foreign_items as linux;
2121use shims:: unix:: macos:: foreign_items as macos;
2222
23+ fn is_dyn_sym ( name : & str , target_os : & str ) -> bool {
24+ match name {
25+ // `signal` is set up as a weak symbol in `init_extern_statics` so we might as well allow it
26+ // in `dlsym` as well.
27+ "signal" => true ,
28+ // Give specific OSes a chance to allow their symbols.
29+ _ =>
30+ match target_os {
31+ "android" => android:: is_dyn_sym ( name) ,
32+ "freebsd" => freebsd:: is_dyn_sym ( name) ,
33+ "linux" => linux:: is_dyn_sym ( name) ,
34+ "macos" => macos:: is_dyn_sym ( name) ,
35+ target_os => panic ! ( "unsupported Unix OS {target_os}" ) ,
36+ } ,
37+ }
38+ }
39+
2340impl < ' mir , ' tcx : ' mir > EvalContextExt < ' mir , ' tcx > for crate :: MiriInterpCx < ' mir , ' tcx > { }
2441pub trait EvalContextExt < ' mir , ' tcx : ' mir > : crate :: MiriInterpCxExt < ' mir , ' tcx > {
2542 fn emulate_foreign_item_inner (
@@ -237,14 +254,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
237254 this. read_target_usize ( handle) ?;
238255 let symbol = this. read_pointer ( symbol) ?;
239256 let name = this. read_c_str ( symbol) ?;
240- let is_dyn_sym = |name| match & * this. tcx . sess . target . os {
241- "android" => android:: is_dyn_sym ( name) ,
242- "freebsd" => freebsd:: is_dyn_sym ( name) ,
243- "linux" => linux:: is_dyn_sym ( name) ,
244- "macos" => macos:: is_dyn_sym ( name) ,
245- target_os => panic ! ( "unsupported Unix OS {target_os}" ) ,
246- } ;
247- if let Ok ( name) = str:: from_utf8 ( name) && is_dyn_sym ( name) {
257+ if let Ok ( name) = str:: from_utf8 ( name) && is_dyn_sym ( name, & this. tcx . sess . target . os ) {
248258 let ptr = this. fn_ptr ( FnVal :: Other ( DynSym :: from_str ( name) ) ) ;
249259 this. write_pointer ( ptr, dest) ?;
250260 } else {
0 commit comments