@@ -18,10 +18,10 @@ fn mutexattr_kind_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u
18
18
19
19
fn mutexattr_get_kind < ' tcx > (
20
20
ecx : & MiriInterpCx < ' tcx > ,
21
- attr_op : & OpTy < ' tcx > ,
21
+ attr_ptr : & OpTy < ' tcx > ,
22
22
) -> InterpResult < ' tcx , i32 > {
23
23
ecx. deref_pointer_and_read (
24
- attr_op ,
24
+ attr_ptr ,
25
25
mutexattr_kind_offset ( ecx) ?,
26
26
ecx. libc_ty_layout ( "pthread_mutexattr_t" ) ,
27
27
ecx. machine . layouts . i32 ,
@@ -31,11 +31,11 @@ fn mutexattr_get_kind<'tcx>(
31
31
32
32
fn mutexattr_set_kind < ' tcx > (
33
33
ecx : & mut MiriInterpCx < ' tcx > ,
34
- attr_op : & OpTy < ' tcx > ,
34
+ attr_ptr : & OpTy < ' tcx > ,
35
35
kind : i32 ,
36
36
) -> InterpResult < ' tcx , ( ) > {
37
37
ecx. deref_pointer_and_write (
38
- attr_op ,
38
+ attr_ptr ,
39
39
mutexattr_kind_offset ( ecx) ?,
40
40
Scalar :: from_i32 ( kind) ,
41
41
ecx. libc_ty_layout ( "pthread_mutexattr_t" ) ,
@@ -94,15 +94,14 @@ fn mutex_id_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u64> {
94
94
/// Eagerly create and initialize a new mutex.
95
95
fn mutex_create < ' tcx > (
96
96
ecx : & mut MiriInterpCx < ' tcx > ,
97
- mutex_op : & OpTy < ' tcx > ,
97
+ mutex_ptr : & OpTy < ' tcx > ,
98
98
kind : i32 ,
99
99
) -> InterpResult < ' tcx > {
100
- // FIXME: might be worth changing mutex_create to take the mplace
101
- // rather than the `OpTy`.
102
- let address = ecx. read_pointer ( mutex_op) ?. addr ( ) . bytes ( ) ;
100
+ let mutex = ecx. deref_pointer ( mutex_ptr) ?;
101
+ let address = mutex. ptr ( ) . addr ( ) . bytes ( ) ;
103
102
let kind = translate_kind ( ecx, kind) ?;
104
103
let data = Some ( AdditionalMutexData { address, kind } ) ;
105
- ecx. mutex_create ( mutex_op , ecx . libc_ty_layout ( "pthread_mutex_t" ) , mutex_id_offset ( ecx) ?, data) ?;
104
+ ecx. mutex_create ( & mutex , mutex_id_offset ( ecx) ?, data) ?;
106
105
Ok ( ( ) )
107
106
}
108
107
@@ -112,24 +111,18 @@ fn mutex_create<'tcx>(
112
111
/// return an error if it has.
113
112
fn mutex_get_id < ' tcx > (
114
113
ecx : & mut MiriInterpCx < ' tcx > ,
115
- mutex_op : & OpTy < ' tcx > ,
114
+ mutex_ptr : & OpTy < ' tcx > ,
116
115
) -> InterpResult < ' tcx , MutexId > {
117
- let address = ecx. read_pointer ( mutex_op) ?. addr ( ) . bytes ( ) ;
118
-
119
- // FIXME: might be worth changing mutex_get_or_create_id to take the mplace
120
- // rather than the `OpTy`.
121
- let id = ecx. mutex_get_or_create_id (
122
- mutex_op,
123
- ecx. libc_ty_layout ( "pthread_mutex_t" ) ,
124
- mutex_id_offset ( ecx) ?,
125
- |ecx| {
126
- // This is called if a static initializer was used and the lock has not been assigned
127
- // an ID yet. We have to determine the mutex kind from the static initializer.
128
- let kind = kind_from_static_initializer ( ecx, mutex_op) ?;
129
-
130
- Ok ( Some ( AdditionalMutexData { kind, address } ) )
131
- } ,
132
- ) ?;
116
+ let mutex = ecx. deref_pointer ( mutex_ptr) ?;
117
+ let address = mutex. ptr ( ) . addr ( ) . bytes ( ) ;
118
+
119
+ let id = ecx. mutex_get_or_create_id ( & mutex, mutex_id_offset ( ecx) ?, |ecx| {
120
+ // This is called if a static initializer was used and the lock has not been assigned
121
+ // an ID yet. We have to determine the mutex kind from the static initializer.
122
+ let kind = kind_from_static_initializer ( ecx, & mutex) ?;
123
+
124
+ Ok ( Some ( AdditionalMutexData { kind, address } ) )
125
+ } ) ?;
133
126
134
127
// Check that the mutex has not been moved since last use.
135
128
let data = ecx. mutex_get_data ( id) . expect ( "data should be always exist for pthreads" ) ;
@@ -143,20 +136,15 @@ fn mutex_get_id<'tcx>(
143
136
/// Returns the kind of a static initializer.
144
137
fn kind_from_static_initializer < ' tcx > (
145
138
ecx : & MiriInterpCx < ' tcx > ,
146
- mutex_op : & OpTy < ' tcx > ,
139
+ mutex : & MPlaceTy < ' tcx > ,
147
140
) -> InterpResult < ' tcx , MutexKind > {
148
141
// Only linux has static initializers other than PTHREAD_MUTEX_DEFAULT.
149
142
let kind = match & * ecx. tcx . sess . target . os {
150
143
"linux" => {
151
144
let offset = if ecx. pointer_size ( ) . bytes ( ) == 8 { 16 } else { 12 } ;
152
-
153
- ecx. deref_pointer_and_read (
154
- mutex_op,
155
- offset,
156
- ecx. libc_ty_layout ( "pthread_mutex_t" ) ,
157
- ecx. machine . layouts . i32 ,
158
- ) ?
159
- . to_i32 ( ) ?
145
+ let kind_place =
146
+ mutex. offset ( Size :: from_bytes ( offset) , ecx. machine . layouts . i32 , ecx) ?;
147
+ ecx. read_scalar ( & kind_place) ?. to_i32 ( ) ?
160
148
}
161
149
| "illumos" | "solaris" | "macos" => ecx. eval_libc_i32 ( "PTHREAD_MUTEX_DEFAULT" ) ,
162
150
os => throw_unsup_format ! ( "`pthread_mutex` is not supported on {os}" ) ,
@@ -211,16 +199,14 @@ fn rwlock_id_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u64> {
211
199
212
200
fn rwlock_get_id < ' tcx > (
213
201
ecx : & mut MiriInterpCx < ' tcx > ,
214
- rwlock_op : & OpTy < ' tcx > ,
202
+ rwlock_ptr : & OpTy < ' tcx > ,
215
203
) -> InterpResult < ' tcx , RwLockId > {
216
- let address = ecx. read_pointer ( rwlock_op) ?. addr ( ) . bytes ( ) ;
204
+ let rwlock = ecx. deref_pointer ( rwlock_ptr) ?;
205
+ let address = rwlock. ptr ( ) . addr ( ) . bytes ( ) ;
217
206
218
- let id = ecx. rwlock_get_or_create_id (
219
- rwlock_op,
220
- ecx. libc_ty_layout ( "pthread_rwlock_t" ) ,
221
- rwlock_id_offset ( ecx) ?,
222
- |_| Ok ( Some ( AdditionalRwLockData { address } ) ) ,
223
- ) ?;
207
+ let id = ecx. rwlock_get_or_create_id ( & rwlock, rwlock_id_offset ( ecx) ?, |_| {
208
+ Ok ( Some ( AdditionalRwLockData { address } ) )
209
+ } ) ?;
224
210
225
211
// Check that the rwlock has not been moved since last use.
226
212
let data = ecx. rwlock_get_data ( id) . expect ( "data should be always exist for pthreads" ) ;
@@ -246,10 +232,10 @@ fn condattr_clock_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u
246
232
247
233
fn condattr_get_clock_id < ' tcx > (
248
234
ecx : & MiriInterpCx < ' tcx > ,
249
- attr_op : & OpTy < ' tcx > ,
235
+ attr_ptr : & OpTy < ' tcx > ,
250
236
) -> InterpResult < ' tcx , i32 > {
251
237
ecx. deref_pointer_and_read (
252
- attr_op ,
238
+ attr_ptr ,
253
239
condattr_clock_offset ( ecx) ?,
254
240
ecx. libc_ty_layout ( "pthread_condattr_t" ) ,
255
241
ecx. machine . layouts . i32 ,
@@ -259,11 +245,11 @@ fn condattr_get_clock_id<'tcx>(
259
245
260
246
fn condattr_set_clock_id < ' tcx > (
261
247
ecx : & mut MiriInterpCx < ' tcx > ,
262
- attr_op : & OpTy < ' tcx > ,
248
+ attr_ptr : & OpTy < ' tcx > ,
263
249
clock_id : i32 ,
264
250
) -> InterpResult < ' tcx , ( ) > {
265
251
ecx. deref_pointer_and_write (
266
- attr_op ,
252
+ attr_ptr ,
267
253
condattr_clock_offset ( ecx) ?,
268
254
Scalar :: from_i32 ( clock_id) ,
269
255
ecx. libc_ty_layout ( "pthread_condattr_t" ) ,
@@ -337,21 +323,18 @@ fn cond_clock_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> u64 {
337
323
338
324
fn cond_get_id < ' tcx > (
339
325
ecx : & mut MiriInterpCx < ' tcx > ,
340
- cond_op : & OpTy < ' tcx > ,
326
+ cond_ptr : & OpTy < ' tcx > ,
341
327
) -> InterpResult < ' tcx , CondvarId > {
342
- ecx. condvar_get_or_create_id (
343
- cond_op,
344
- ecx. libc_ty_layout ( "pthread_cond_t" ) ,
345
- cond_id_offset ( ecx) ?,
346
- )
328
+ let cond = ecx. deref_pointer ( cond_ptr) ?;
329
+ ecx. condvar_get_or_create_id ( & cond, cond_id_offset ( ecx) ?)
347
330
}
348
331
349
332
fn cond_reset_id < ' tcx > (
350
333
ecx : & mut MiriInterpCx < ' tcx > ,
351
- cond_op : & OpTy < ' tcx > ,
334
+ cond_ptr : & OpTy < ' tcx > ,
352
335
) -> InterpResult < ' tcx , ( ) > {
353
336
ecx. deref_pointer_and_write (
354
- cond_op ,
337
+ cond_ptr ,
355
338
cond_id_offset ( ecx) ?,
356
339
Scalar :: from_i32 ( 0 ) ,
357
340
ecx. libc_ty_layout ( "pthread_cond_t" ) ,
@@ -361,10 +344,10 @@ fn cond_reset_id<'tcx>(
361
344
362
345
fn cond_get_clock_id < ' tcx > (
363
346
ecx : & MiriInterpCx < ' tcx > ,
364
- cond_op : & OpTy < ' tcx > ,
347
+ cond_ptr : & OpTy < ' tcx > ,
365
348
) -> InterpResult < ' tcx , i32 > {
366
349
ecx. deref_pointer_and_read (
367
- cond_op ,
350
+ cond_ptr ,
368
351
cond_clock_offset ( ecx) ,
369
352
ecx. libc_ty_layout ( "pthread_cond_t" ) ,
370
353
ecx. machine . layouts . i32 ,
@@ -374,11 +357,11 @@ fn cond_get_clock_id<'tcx>(
374
357
375
358
fn cond_set_clock_id < ' tcx > (
376
359
ecx : & mut MiriInterpCx < ' tcx > ,
377
- cond_op : & OpTy < ' tcx > ,
360
+ cond_ptr : & OpTy < ' tcx > ,
378
361
clock_id : i32 ,
379
362
) -> InterpResult < ' tcx , ( ) > {
380
363
ecx. deref_pointer_and_write (
381
- cond_op ,
364
+ cond_ptr ,
382
365
cond_clock_offset ( ecx) ,
383
366
Scalar :: from_i32 ( clock_id) ,
384
367
ecx. libc_ty_layout ( "pthread_cond_t" ) ,
0 commit comments