]> git.lizzy.rs Git - rust.git/blob - src/shims/dlsym.rs
adjust for goto_block refactoring
[rust.git] / src / shims / dlsym.rs
1 use rustc::mir;
2
3 use crate::*;
4
5 #[derive(Debug, Copy, Clone)]
6 pub enum Dlsym {
7     GetEntropy,
8 }
9
10 impl Dlsym {
11     // Returns an error for unsupported symbols, and None if this symbol
12     // should become a NULL pointer (pretend it does not exist).
13     pub fn from_str(name: &str) -> InterpResult<'static, Option<Dlsym>> {
14         use self::Dlsym::*;
15         Ok(match name {
16             "getentropy" => Some(GetEntropy),
17             "__pthread_get_minstack" => None,
18             _ =>
19                 throw_unsup_format!("Unsupported dlsym: {}", name),
20         })
21     }
22 }
23
24 impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
25 pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
26     fn call_dlsym(
27         &mut self,
28         dlsym: Dlsym,
29         args: &[OpTy<'tcx, Tag>],
30         ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
31     ) -> InterpResult<'tcx> {
32         use self::Dlsym::*;
33
34         let this = self.eval_context_mut();
35         let (dest, ret) = ret.expect("we don't support any diverging dlsym");
36
37         match dlsym {
38             GetEntropy => {
39                 let ptr = this.read_scalar(args[0])?.not_undef()?;
40                 let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
41                 this.gen_random(ptr, len as usize)?;
42                 this.write_null(dest)?;
43             }
44         }
45
46         this.dump_place(*dest);
47         this.go_to_block(ret);
48         Ok(())
49     }
50 }