1
- use libffi:: { high:: call:: * , low:: CodePtr } ;
1
+ use libffi:: { high:: call as ffi , low:: CodePtr } ;
2
2
use std:: ops:: Deref ;
3
3
4
4
use rustc_middle:: ty:: { IntTy , Ty , TyKind , UintTy } ;
@@ -34,6 +34,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
34
34
return Ok ( CArg :: Int64 ( k. to_i64 ( ) ?) ) ;
35
35
}
36
36
TyKind :: Int ( IntTy :: Isize ) => {
37
+ // This will fail if host != target, but then the entire FFI thing probably won't work well
38
+ // in that situation.
37
39
return Ok ( CArg :: ISize ( k. to_machine_isize ( cx) ?. try_into ( ) . unwrap ( ) ) ) ;
38
40
}
39
41
// the uints
@@ -50,6 +52,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
50
52
return Ok ( CArg :: UInt64 ( k. to_u64 ( ) ?) ) ;
51
53
}
52
54
TyKind :: Uint ( UintTy :: Usize ) => {
55
+ // This will fail if host != target, but then the entire FFI thing probably won't work well
56
+ // in that situation.
53
57
return Ok ( CArg :: USize ( k. to_machine_usize ( cx) ?. try_into ( ) . unwrap ( ) ) ) ;
54
58
}
55
59
_ => { }
@@ -82,55 +86,55 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
82
86
match dest. layout . ty . kind ( ) {
83
87
// ints
84
88
TyKind :: Int ( IntTy :: I8 ) => {
85
- let x = call :: < i8 > ( ptr, libffi_args. as_slice ( ) ) ;
89
+ let x = ffi :: call :: < i8 > ( ptr, libffi_args. as_slice ( ) ) ;
86
90
this. write_int ( x, dest) ?;
87
91
return Ok ( ( ) ) ;
88
92
}
89
93
TyKind :: Int ( IntTy :: I16 ) => {
90
- let x = call :: < i16 > ( ptr, libffi_args. as_slice ( ) ) ;
94
+ let x = ffi :: call :: < i16 > ( ptr, libffi_args. as_slice ( ) ) ;
91
95
this. write_int ( x, dest) ?;
92
96
return Ok ( ( ) ) ;
93
97
}
94
98
TyKind :: Int ( IntTy :: I32 ) => {
95
- let x = call :: < i32 > ( ptr, libffi_args. as_slice ( ) ) ;
99
+ let x = ffi :: call :: < i32 > ( ptr, libffi_args. as_slice ( ) ) ;
96
100
this. write_int ( x, dest) ?;
97
101
return Ok ( ( ) ) ;
98
102
}
99
103
TyKind :: Int ( IntTy :: I64 ) => {
100
- let x = call :: < i64 > ( ptr, libffi_args. as_slice ( ) ) ;
104
+ let x = ffi :: call :: < i64 > ( ptr, libffi_args. as_slice ( ) ) ;
101
105
this. write_int ( x, dest) ?;
102
106
return Ok ( ( ) ) ;
103
107
}
104
108
TyKind :: Int ( IntTy :: Isize ) => {
105
- let x = call :: < isize > ( ptr, libffi_args. as_slice ( ) ) ;
109
+ let x = ffi :: call :: < isize > ( ptr, libffi_args. as_slice ( ) ) ;
106
110
// `isize` doesn't `impl Into<i128>`, so convert manually.
107
111
// Convert to `i64` since this covers both 32- and 64-bit machines.
108
112
this. write_int ( i64:: try_from ( x) . unwrap ( ) , dest) ?;
109
113
return Ok ( ( ) ) ;
110
114
}
111
115
// uints
112
116
TyKind :: Uint ( UintTy :: U8 ) => {
113
- let x = call :: < u8 > ( ptr, libffi_args. as_slice ( ) ) ;
117
+ let x = ffi :: call :: < u8 > ( ptr, libffi_args. as_slice ( ) ) ;
114
118
this. write_int ( x, dest) ?;
115
119
return Ok ( ( ) ) ;
116
120
}
117
121
TyKind :: Uint ( UintTy :: U16 ) => {
118
- let x = call :: < u16 > ( ptr, libffi_args. as_slice ( ) ) ;
122
+ let x = ffi :: call :: < u16 > ( ptr, libffi_args. as_slice ( ) ) ;
119
123
this. write_int ( x, dest) ?;
120
124
return Ok ( ( ) ) ;
121
125
}
122
126
TyKind :: Uint ( UintTy :: U32 ) => {
123
- let x = call :: < u32 > ( ptr, libffi_args. as_slice ( ) ) ;
127
+ let x = ffi :: call :: < u32 > ( ptr, libffi_args. as_slice ( ) ) ;
124
128
this. write_int ( x, dest) ?;
125
129
return Ok ( ( ) ) ;
126
130
}
127
131
TyKind :: Uint ( UintTy :: U64 ) => {
128
- let x = call :: < u64 > ( ptr, libffi_args. as_slice ( ) ) ;
132
+ let x = ffi :: call :: < u64 > ( ptr, libffi_args. as_slice ( ) ) ;
129
133
this. write_int ( x, dest) ?;
130
134
return Ok ( ( ) ) ;
131
135
}
132
136
TyKind :: Uint ( UintTy :: Usize ) => {
133
- let x = call :: < usize > ( ptr, libffi_args. as_slice ( ) ) ;
137
+ let x = ffi :: call :: < usize > ( ptr, libffi_args. as_slice ( ) ) ;
134
138
// `usize` doesn't `impl Into<i128>`, so convert manually.
135
139
// Convert to `u64` since this covers both 32- and 64-bit machines.
136
140
this. write_int ( u64:: try_from ( x) . unwrap ( ) , dest) ?;
@@ -140,7 +144,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
140
144
// have the output_type `Tuple([])`.
141
145
TyKind :: Tuple ( t_list) =>
142
146
if t_list. len ( ) == 0 {
143
- call :: < ( ) > ( ptr, libffi_args. as_slice ( ) ) ;
147
+ ffi :: call :: < ( ) > ( ptr, libffi_args. as_slice ( ) ) ;
144
148
return Ok ( ( ) ) ;
145
149
} ,
146
150
_ => { }
@@ -200,7 +204,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
200
204
/// a form compatible with C (through `libffi` call).
201
205
/// Then, convert return from the C call into a corresponding form that
202
206
/// can be stored in Miri internal memory.
203
- fn call_and_add_external_c_fct_to_context (
207
+ fn call_external_c_fct (
204
208
& mut self ,
205
209
link_name : Symbol ,
206
210
dest : & PlaceTy < ' tcx , Provenance > ,
@@ -270,16 +274,16 @@ impl<'a> CArg {
270
274
/// Convert a `CArg` to a `libffi` argument type.
271
275
pub fn arg_downcast ( & ' a self ) -> libffi:: high:: Arg < ' a > {
272
276
match self {
273
- CArg :: Int8 ( i) => arg ( i) ,
274
- CArg :: Int16 ( i) => arg ( i) ,
275
- CArg :: Int32 ( i) => arg ( i) ,
276
- CArg :: Int64 ( i) => arg ( i) ,
277
- CArg :: ISize ( i) => arg ( i) ,
278
- CArg :: UInt8 ( i) => arg ( i) ,
279
- CArg :: UInt16 ( i) => arg ( i) ,
280
- CArg :: UInt32 ( i) => arg ( i) ,
281
- CArg :: UInt64 ( i) => arg ( i) ,
282
- CArg :: USize ( i) => arg ( i) ,
277
+ CArg :: Int8 ( i) => ffi :: arg ( i) ,
278
+ CArg :: Int16 ( i) => ffi :: arg ( i) ,
279
+ CArg :: Int32 ( i) => ffi :: arg ( i) ,
280
+ CArg :: Int64 ( i) => ffi :: arg ( i) ,
281
+ CArg :: ISize ( i) => ffi :: arg ( i) ,
282
+ CArg :: UInt8 ( i) => ffi :: arg ( i) ,
283
+ CArg :: UInt16 ( i) => ffi :: arg ( i) ,
284
+ CArg :: UInt32 ( i) => ffi :: arg ( i) ,
285
+ CArg :: UInt64 ( i) => ffi :: arg ( i) ,
286
+ CArg :: USize ( i) => ffi :: arg ( i) ,
283
287
}
284
288
}
285
289
}
0 commit comments