]> git.lizzy.rs Git - rust.git/blobdiff - src/shims/dlsym.rs
Auto merge of #2162 - RalfJung:rustup, r=RalfJung
[rust.git] / src / shims / dlsym.rs
index ca53f5d23015a6f94bb526fbe2348fed9b45a3cb..05296d3a4eb70e47db8236c871fc701ee6e49eaa 100644 (file)
@@ -1,53 +1,46 @@
-use rustc::mir;
+use rustc_middle::mir;
+use rustc_target::spec::abi::Abi;
 
 use crate::*;
+use shims::posix::dlsym as posix;
+use shims::windows::dlsym as windows;
 
 #[derive(Debug, Copy, Clone)]
+#[allow(non_camel_case_types)]
 pub enum Dlsym {
-    GetEntropy,
+    Posix(posix::Dlsym),
+    Windows(windows::Dlsym),
 }
 
 impl Dlsym {
     // Returns an error for unsupported symbols, and None if this symbol
     // should become a NULL pointer (pretend it does not exist).
-    pub fn from_str(name: &str) -> InterpResult<'static, Option<Dlsym>> {
-        use self::Dlsym::*;
-        Ok(match name {
-            "getentropy" => Some(GetEntropy),
-            "__pthread_get_minstack" => None,
-            _ =>
-                throw_unsup_format!("Unsupported dlsym: {}", name),
+    pub fn from_str<'tcx>(name: &[u8], target_os: &str) -> InterpResult<'tcx, Option<Dlsym>> {
+        let name = &*String::from_utf8_lossy(name);
+        Ok(match target_os {
+            "linux" | "macos" => posix::Dlsym::from_str(name, target_os)?.map(Dlsym::Posix),
+            "windows" => windows::Dlsym::from_str(name)?.map(Dlsym::Windows),
+            os => bug!("dlsym not implemented for target_os {}", os),
         })
     }
 }
 
-impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
+impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
 pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
     fn call_dlsym(
         &mut self,
         dlsym: Dlsym,
+        abi: Abi,
         args: &[OpTy<'tcx, Tag>],
-        dest: Option<PlaceTy<'tcx, Tag>>,
+        dest: &PlaceTy<'tcx, Tag>,
         ret: Option<mir::BasicBlock>,
     ) -> InterpResult<'tcx> {
-        use self::Dlsym::*;
-
         let this = self.eval_context_mut();
-
-        let dest = dest.expect("we don't support any diverging dlsym");
-        let ret = ret.expect("dest is `Some` but ret is `None`");
-
         match dlsym {
-            GetEntropy => {
-                let ptr = this.read_scalar(args[0])?.not_undef()?;
-                let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
-                this.gen_random(ptr, len as usize)?;
-                this.write_null(dest)?;
-            }
+            Dlsym::Posix(dlsym) =>
+                posix::EvalContextExt::call_dlsym(this, dlsym, abi, args, dest, ret),
+            Dlsym::Windows(dlsym) =>
+                windows::EvalContextExt::call_dlsym(this, dlsym, abi, args, dest, ret),
         }
-
-        this.goto_block(Some(ret))?;
-        this.dump_place(*dest);
-        Ok(())
     }
 }