@@ -18,10 +18,10 @@ fn mutexattr_kind_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u
1818
1919fn mutexattr_get_kind < ' tcx > (
2020 ecx : & MiriInterpCx < ' tcx > ,
21- attr_op : & OpTy < ' tcx > ,
21+ attr_ptr : & OpTy < ' tcx > ,
2222) -> InterpResult < ' tcx , i32 > {
2323 ecx. deref_pointer_and_read (
24- attr_op ,
24+ attr_ptr ,
2525 mutexattr_kind_offset ( ecx) ?,
2626 ecx. libc_ty_layout ( "pthread_mutexattr_t" ) ,
2727 ecx. machine . layouts . i32 ,
@@ -31,11 +31,11 @@ fn mutexattr_get_kind<'tcx>(
3131
3232fn mutexattr_set_kind < ' tcx > (
3333 ecx : & mut MiriInterpCx < ' tcx > ,
34- attr_op : & OpTy < ' tcx > ,
34+ attr_ptr : & OpTy < ' tcx > ,
3535 kind : i32 ,
3636) -> InterpResult < ' tcx , ( ) > {
3737 ecx. deref_pointer_and_write (
38- attr_op ,
38+ attr_ptr ,
3939 mutexattr_kind_offset ( ecx) ?,
4040 Scalar :: from_i32 ( kind) ,
4141 ecx. libc_ty_layout ( "pthread_mutexattr_t" ) ,
@@ -94,15 +94,14 @@ fn mutex_id_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u64> {
9494/// Eagerly create and initialize a new mutex.
9595fn mutex_create < ' tcx > (
9696 ecx : & mut MiriInterpCx < ' tcx > ,
97- mutex_op : & OpTy < ' tcx > ,
97+ mutex_ptr : & OpTy < ' tcx > ,
9898 kind : i32 ,
9999) -> 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 ( ) ;
103102 let kind = translate_kind ( ecx, kind) ?;
104103 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) ?;
106105 Ok ( ( ) )
107106}
108107
@@ -112,24 +111,18 @@ fn mutex_create<'tcx>(
112111/// return an error if it has.
113112fn mutex_get_id < ' tcx > (
114113 ecx : & mut MiriInterpCx < ' tcx > ,
115- mutex_op : & OpTy < ' tcx > ,
114+ mutex_ptr : & OpTy < ' tcx > ,
116115) -> 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+ } ) ?;
133126
134127 // Check that the mutex has not been moved since last use.
135128 let data = ecx. mutex_get_data ( id) . expect ( "data should be always exist for pthreads" ) ;
@@ -143,20 +136,15 @@ fn mutex_get_id<'tcx>(
143136/// Returns the kind of a static initializer.
144137fn kind_from_static_initializer < ' tcx > (
145138 ecx : & MiriInterpCx < ' tcx > ,
146- mutex_op : & OpTy < ' tcx > ,
139+ mutex : & MPlaceTy < ' tcx > ,
147140) -> InterpResult < ' tcx , MutexKind > {
148141 // Only linux has static initializers other than PTHREAD_MUTEX_DEFAULT.
149142 let kind = match & * ecx. tcx . sess . target . os {
150143 "linux" => {
151144 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 ( ) ?
160148 }
161149 | "illumos" | "solaris" | "macos" => ecx. eval_libc_i32 ( "PTHREAD_MUTEX_DEFAULT" ) ,
162150 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> {
211199
212200fn rwlock_get_id < ' tcx > (
213201 ecx : & mut MiriInterpCx < ' tcx > ,
214- rwlock_op : & OpTy < ' tcx > ,
202+ rwlock_ptr : & OpTy < ' tcx > ,
215203) -> 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 ( ) ;
217206
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+ } ) ?;
224210
225211 // Check that the rwlock has not been moved since last use.
226212 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
246232
247233fn condattr_get_clock_id < ' tcx > (
248234 ecx : & MiriInterpCx < ' tcx > ,
249- attr_op : & OpTy < ' tcx > ,
235+ attr_ptr : & OpTy < ' tcx > ,
250236) -> InterpResult < ' tcx , i32 > {
251237 ecx. deref_pointer_and_read (
252- attr_op ,
238+ attr_ptr ,
253239 condattr_clock_offset ( ecx) ?,
254240 ecx. libc_ty_layout ( "pthread_condattr_t" ) ,
255241 ecx. machine . layouts . i32 ,
@@ -259,11 +245,11 @@ fn condattr_get_clock_id<'tcx>(
259245
260246fn condattr_set_clock_id < ' tcx > (
261247 ecx : & mut MiriInterpCx < ' tcx > ,
262- attr_op : & OpTy < ' tcx > ,
248+ attr_ptr : & OpTy < ' tcx > ,
263249 clock_id : i32 ,
264250) -> InterpResult < ' tcx , ( ) > {
265251 ecx. deref_pointer_and_write (
266- attr_op ,
252+ attr_ptr ,
267253 condattr_clock_offset ( ecx) ?,
268254 Scalar :: from_i32 ( clock_id) ,
269255 ecx. libc_ty_layout ( "pthread_condattr_t" ) ,
@@ -337,21 +323,18 @@ fn cond_clock_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> u64 {
337323
338324fn cond_get_id < ' tcx > (
339325 ecx : & mut MiriInterpCx < ' tcx > ,
340- cond_op : & OpTy < ' tcx > ,
326+ cond_ptr : & OpTy < ' tcx > ,
341327) -> 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) ?)
347330}
348331
349332fn cond_reset_id < ' tcx > (
350333 ecx : & mut MiriInterpCx < ' tcx > ,
351- cond_op : & OpTy < ' tcx > ,
334+ cond_ptr : & OpTy < ' tcx > ,
352335) -> InterpResult < ' tcx , ( ) > {
353336 ecx. deref_pointer_and_write (
354- cond_op ,
337+ cond_ptr ,
355338 cond_id_offset ( ecx) ?,
356339 Scalar :: from_i32 ( 0 ) ,
357340 ecx. libc_ty_layout ( "pthread_cond_t" ) ,
@@ -361,10 +344,10 @@ fn cond_reset_id<'tcx>(
361344
362345fn cond_get_clock_id < ' tcx > (
363346 ecx : & MiriInterpCx < ' tcx > ,
364- cond_op : & OpTy < ' tcx > ,
347+ cond_ptr : & OpTy < ' tcx > ,
365348) -> InterpResult < ' tcx , i32 > {
366349 ecx. deref_pointer_and_read (
367- cond_op ,
350+ cond_ptr ,
368351 cond_clock_offset ( ecx) ,
369352 ecx. libc_ty_layout ( "pthread_cond_t" ) ,
370353 ecx. machine . layouts . i32 ,
@@ -374,11 +357,11 @@ fn cond_get_clock_id<'tcx>(
374357
375358fn cond_set_clock_id < ' tcx > (
376359 ecx : & mut MiriInterpCx < ' tcx > ,
377- cond_op : & OpTy < ' tcx > ,
360+ cond_ptr : & OpTy < ' tcx > ,
378361 clock_id : i32 ,
379362) -> InterpResult < ' tcx , ( ) > {
380363 ecx. deref_pointer_and_write (
381- cond_op ,
364+ cond_ptr ,
382365 cond_clock_offset ( ecx) ,
383366 Scalar :: from_i32 ( clock_id) ,
384367 ecx. libc_ty_layout ( "pthread_cond_t" ) ,
0 commit comments