1
1
use rustc_middle:: mir;
2
2
3
3
use crate :: * ;
4
- use helpers:: check_arg_count;
4
+ use shims:: posix:: dlsym as posix;
5
+ use shims:: windows:: dlsym as windows;
5
6
6
7
#[ derive( Debug , Copy , Clone ) ]
8
+ #[ allow( non_camel_case_types) ]
7
9
pub enum Dlsym {
8
- GetEntropy ,
10
+ Posix ( posix:: Dlsym ) ,
11
+ Windows ( windows:: Dlsym ) ,
9
12
}
10
13
11
14
impl Dlsym {
12
15
// Returns an error for unsupported symbols, and None if this symbol
13
16
// should become a NULL pointer (pretend it does not exist).
14
17
pub fn from_str ( name : & [ u8 ] , target_os : & str ) -> InterpResult < ' static , Option < Dlsym > > {
15
- use self :: Dlsym :: * ;
16
- let name = String :: from_utf8_lossy ( name) ;
18
+ let name = & * String :: from_utf8_lossy ( name) ;
17
19
Ok ( match target_os {
18
- "linux" => match & * name {
19
- "__pthread_get_minstack" => None ,
20
- _ => throw_unsup_format ! ( "unsupported Linux dlsym: {}" , name) ,
21
- }
22
- "macos" => match & * name {
23
- "getentropy" => Some ( GetEntropy ) ,
24
- _ => throw_unsup_format ! ( "unsupported macOS dlsym: {}" , name) ,
25
- }
26
- "windows" => match & * name {
27
- "SetThreadStackGuarantee" => None ,
28
- "AcquireSRWLockExclusive" => None ,
29
- "GetSystemTimePreciseAsFileTime" => None ,
30
- _ => throw_unsup_format ! ( "unsupported Windows dlsym: {}" , name) ,
31
- }
20
+ "linux" | "macos" => posix:: Dlsym :: from_str ( name, target_os) ?. map ( Dlsym :: Posix ) ,
21
+ "windows" => windows:: Dlsym :: from_str ( name) ?. map ( Dlsym :: Windows ) ,
32
22
os => bug ! ( "dlsym not implemented for target_os {}" , os) ,
33
23
} )
34
24
}
@@ -42,23 +32,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
42
32
args : & [ OpTy < ' tcx , Tag > ] ,
43
33
ret : Option < ( PlaceTy < ' tcx , Tag > , mir:: BasicBlock ) > ,
44
34
) -> InterpResult < ' tcx > {
45
- use self :: Dlsym :: * ;
46
-
47
35
let this = self . eval_context_mut ( ) ;
48
- let ( dest, ret) = ret. expect ( "we don't support any diverging dlsym" ) ;
49
-
50
36
match dlsym {
51
- GetEntropy => {
52
- let & [ ptr, len] = check_arg_count ( args) ?;
53
- let ptr = this. read_scalar ( ptr) ?. not_undef ( ) ?;
54
- let len = this. read_scalar ( len) ?. to_machine_usize ( this) ?;
55
- this. gen_random ( ptr, len) ?;
56
- this. write_null ( dest) ?;
57
- }
37
+ Dlsym :: Posix ( dlsym) => posix:: EvalContextExt :: call_dlsym ( this, dlsym, args, ret) ,
38
+ Dlsym :: Windows ( dlsym) => windows:: EvalContextExt :: call_dlsym ( this, dlsym, args, ret) ,
58
39
}
59
-
60
- this. dump_place ( * dest) ;
61
- this. go_to_block ( ret) ;
62
- Ok ( ( ) )
63
40
}
64
41
}
0 commit comments