]> git.lizzy.rs Git - rust.git/blob - src/shims/windows/dlsym.rs
introduce platform-specific module hierarchy for dlsym (similar to foreign_items)
[rust.git] / src / shims / windows / dlsym.rs
1 use rustc_middle::mir;
2
3 use crate::*;
4 use helpers::check_arg_count;
5
6 #[derive(Debug, Copy, Clone)]
7 pub enum Dlsym {
8     AcquireSRWLockExclusive,
9     AcquireSRWLockShared,
10 }
11
12 impl Dlsym {
13     // Returns an error for unsupported symbols, and None if this symbol
14     // should become a NULL pointer (pretend it does not exist).
15     pub fn from_str(name: &str) -> InterpResult<'static, Option<Dlsym>> {
16         Ok(match name {
17             "AcquireSRWLockExclusive" => Some(Dlsym::AcquireSRWLockExclusive),
18             "AcquireSRWLockShared" => Some(Dlsym::AcquireSRWLockShared),
19             "SetThreadStackGuarantee" => None,
20             "GetSystemTimePreciseAsFileTime" => None,
21             _ => throw_unsup_format!("unsupported Windows dlsym: {}", name),
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         args: &[OpTy<'tcx, Tag>],
32         ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
33     ) -> InterpResult<'tcx> {
34         let this = self.eval_context_mut();
35         let (dest, ret) = ret.expect("we don't support any diverging dlsym");
36         assert!(this.tcx.sess.target.target.target_os == "windows");
37
38         match dlsym {
39             Dlsym::AcquireSRWLockExclusive => {
40                 let &[ptr] = check_arg_count(args)?;
41                 let lock = this.deref_operand(ptr)?; // points to ptr-sized data
42                 throw_unsup_format!("AcquireSRWLockExclusive is not actually implemented");
43             }
44             Dlsym::AcquireSRWLockShared => {
45                 let &[ptr] = check_arg_count(args)?;
46                 let lock = this.deref_operand(ptr)?; // points to ptr-sized data
47                 throw_unsup_format!("AcquireSRWLockExclusive is not actually implemented");
48             }
49         }
50
51         this.dump_place(*dest);
52         this.go_to_block(ret);
53         Ok(())
54     }
55 }