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