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