]> git.lizzy.rs Git - rust.git/blob - src/shims/dlsym.rs
Auto merge of #2183 - RalfJung:better-provenance-control, r=RalfJung
[rust.git] / src / shims / dlsym.rs
1 use rustc_middle::mir;
2 use rustc_target::spec::abi::Abi;
3
4 use crate::*;
5 use shims::unix::dlsym as unix;
6 use shims::windows::dlsym as windows;
7
8 #[derive(Debug, Copy, Clone)]
9 #[allow(non_camel_case_types)]
10 pub enum Dlsym {
11     Posix(unix::Dlsym),
12     Windows(windows::Dlsym),
13 }
14
15 impl Dlsym {
16     // Returns an error for unsupported symbols, and None if this symbol
17     // should become a NULL pointer (pretend it does not exist).
18     pub fn from_str<'tcx>(name: &[u8], target_os: &str) -> InterpResult<'tcx, Option<Dlsym>> {
19         let name = &*String::from_utf8_lossy(name);
20         Ok(match target_os {
21             "linux" | "macos" => unix::Dlsym::from_str(name, target_os)?.map(Dlsym::Posix),
22             "windows" => windows::Dlsym::from_str(name)?.map(Dlsym::Windows),
23             os => bug!("dlsym not implemented for target_os {}", os),
24         })
25     }
26 }
27
28 impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
29 pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
30     fn call_dlsym(
31         &mut self,
32         dlsym: Dlsym,
33         abi: Abi,
34         args: &[OpTy<'tcx, Tag>],
35         dest: &PlaceTy<'tcx, Tag>,
36         ret: Option<mir::BasicBlock>,
37     ) -> InterpResult<'tcx> {
38         let this = self.eval_context_mut();
39         match dlsym {
40             Dlsym::Posix(dlsym) =>
41                 unix::EvalContextExt::call_dlsym(this, dlsym, abi, args, dest, ret),
42             Dlsym::Windows(dlsym) =>
43                 windows::EvalContextExt::call_dlsym(this, dlsym, abi, args, dest, ret),
44         }
45     }
46 }