@@ -108,33 +108,6 @@ fn mutex_set_id<'mir, 'tcx: 'mir>(
108
108
)
109
109
}
110
110
111
- fn mutex_get_or_create_id < ' mir , ' tcx : ' mir > (
112
- ecx : & mut MiriInterpCx < ' mir , ' tcx > ,
113
- mutex_op : & OpTy < ' tcx , Provenance > ,
114
- ) -> InterpResult < ' tcx , MutexId > {
115
- let value_place = ecx. deref_operand_and_offset ( mutex_op, 4 , ecx. machine . layouts . u32 ) ?;
116
-
117
- ecx. mutex_get_or_create ( |ecx, next_id| {
118
- let ( old, success) = ecx
119
- . atomic_compare_exchange_scalar (
120
- & value_place,
121
- & ImmTy :: from_uint ( 0u32 , ecx. machine . layouts . u32 ) ,
122
- next_id. to_u32_scalar ( ) ,
123
- AtomicRwOrd :: Relaxed ,
124
- AtomicReadOrd :: Relaxed ,
125
- false ,
126
- ) ?
127
- . to_scalar_pair ( ) ;
128
-
129
- Ok ( if success. to_bool ( ) . expect ( "compare_exchange's second return value is a bool" ) {
130
- // Caller of the closure needs to allocate next_id
131
- None
132
- } else {
133
- Some ( MutexId :: from_u32 ( old. to_u32 ( ) . expect ( "layout is u32" ) ) )
134
- } )
135
- } )
136
- }
137
-
138
111
// pthread_rwlock_t is between 32 and 56 bytes, depending on the platform.
139
112
140
113
// Our chosen memory layout for the emulated rwlock (does not have to match the platform layout!):
@@ -149,33 +122,6 @@ fn rwlock_get_id<'mir, 'tcx: 'mir>(
149
122
ecx. read_scalar_at_offset_atomic ( rwlock_op, 4 , ecx. machine . layouts . u32 , AtomicReadOrd :: Relaxed )
150
123
}
151
124
152
- fn rwlock_get_or_create_id < ' mir , ' tcx : ' mir > (
153
- ecx : & mut MiriInterpCx < ' mir , ' tcx > ,
154
- rwlock_op : & OpTy < ' tcx , Provenance > ,
155
- ) -> InterpResult < ' tcx , RwLockId > {
156
- let value_place = ecx. deref_operand_and_offset ( rwlock_op, 4 , ecx. machine . layouts . u32 ) ?;
157
-
158
- ecx. rwlock_get_or_create ( |ecx, next_id| {
159
- let ( old, success) = ecx
160
- . atomic_compare_exchange_scalar (
161
- & value_place,
162
- & ImmTy :: from_uint ( 0u32 , ecx. machine . layouts . u32 ) ,
163
- next_id. to_u32_scalar ( ) ,
164
- AtomicRwOrd :: Relaxed ,
165
- AtomicReadOrd :: Relaxed ,
166
- false ,
167
- ) ?
168
- . to_scalar_pair ( ) ;
169
-
170
- Ok ( if success. to_bool ( ) . expect ( "compare_exchange's second return value is a bool" ) {
171
- // Caller of the closure needs to allocate next_id
172
- None
173
- } else {
174
- Some ( RwLockId :: from_u32 ( old. to_u32 ( ) . expect ( "layout is u32" ) ) )
175
- } )
176
- } )
177
- }
178
-
179
125
// pthread_condattr_t
180
126
181
127
// Our chosen memory layout for emulation (does not have to match the platform layout!):
@@ -232,33 +178,6 @@ fn cond_set_id<'mir, 'tcx: 'mir>(
232
178
)
233
179
}
234
180
235
- fn cond_get_or_create_id < ' mir , ' tcx : ' mir > (
236
- ecx : & mut MiriInterpCx < ' mir , ' tcx > ,
237
- cond_op : & OpTy < ' tcx , Provenance > ,
238
- ) -> InterpResult < ' tcx , CondvarId > {
239
- let value_place = ecx. deref_operand_and_offset ( cond_op, 4 , ecx. machine . layouts . u32 ) ?;
240
-
241
- ecx. condvar_get_or_create ( |ecx, next_id| {
242
- let ( old, success) = ecx
243
- . atomic_compare_exchange_scalar (
244
- & value_place,
245
- & ImmTy :: from_uint ( 0u32 , ecx. machine . layouts . u32 ) ,
246
- next_id. to_u32_scalar ( ) ,
247
- AtomicRwOrd :: Relaxed ,
248
- AtomicReadOrd :: Relaxed ,
249
- false ,
250
- ) ?
251
- . to_scalar_pair ( ) ;
252
-
253
- Ok ( if success. to_bool ( ) . expect ( "compare_exchange's second return value is a bool" ) {
254
- // Caller of the closure needs to allocate next_id
255
- None
256
- } else {
257
- Some ( CondvarId :: from_u32 ( old. to_u32 ( ) . expect ( "layout is u32" ) ) )
258
- } )
259
- } )
260
- }
261
-
262
181
fn cond_get_clock_id < ' mir , ' tcx : ' mir > (
263
182
ecx : & MiriInterpCx < ' mir , ' tcx > ,
264
183
cond_op : & OpTy < ' tcx , Provenance > ,
@@ -435,7 +354,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
435
354
let this = self . eval_context_mut ( ) ;
436
355
437
356
let kind = mutex_get_kind ( this, mutex_op) ?;
438
- let id = mutex_get_or_create_id ( this , mutex_op ) ?;
357
+ let id = this . mutex_get_or_create_id ( mutex_op , 4 ) ?;
439
358
let active_thread = this. get_active_thread ( ) ;
440
359
441
360
if this. mutex_is_locked ( id) {
@@ -475,7 +394,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
475
394
let this = self . eval_context_mut ( ) ;
476
395
477
396
let kind = mutex_get_kind ( this, mutex_op) ?;
478
- let id = mutex_get_or_create_id ( this , mutex_op ) ?;
397
+ let id = this . mutex_get_or_create_id ( mutex_op , 4 ) ?;
479
398
let active_thread = this. get_active_thread ( ) ;
480
399
481
400
if this. mutex_is_locked ( id) {
@@ -511,7 +430,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
511
430
let this = self . eval_context_mut ( ) ;
512
431
513
432
let kind = mutex_get_kind ( this, mutex_op) ?;
514
- let id = mutex_get_or_create_id ( this , mutex_op ) ?;
433
+ let id = this . mutex_get_or_create_id ( mutex_op , 4 ) ?;
515
434
let active_thread = this. get_active_thread ( ) ;
516
435
517
436
if let Some ( _old_locked_count) = this. mutex_unlock ( id, active_thread) {
@@ -545,7 +464,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
545
464
) -> InterpResult < ' tcx , i32 > {
546
465
let this = self . eval_context_mut ( ) ;
547
466
548
- let id = mutex_get_or_create_id ( this , mutex_op ) ?;
467
+ let id = this . mutex_get_or_create_id ( mutex_op , 4 ) ?;
549
468
550
469
if this. mutex_is_locked ( id) {
551
470
throw_ub_format ! ( "destroyed a locked mutex" ) ;
@@ -568,7 +487,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
568
487
) -> InterpResult < ' tcx , i32 > {
569
488
let this = self . eval_context_mut ( ) ;
570
489
571
- let id = rwlock_get_or_create_id ( this , rwlock_op ) ?;
490
+ let id = this . rwlock_get_or_create_id ( rwlock_op , 4 ) ?;
572
491
let active_thread = this. get_active_thread ( ) ;
573
492
574
493
if this. rwlock_is_write_locked ( id) {
@@ -586,7 +505,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
586
505
) -> InterpResult < ' tcx , i32 > {
587
506
let this = self . eval_context_mut ( ) ;
588
507
589
- let id = rwlock_get_or_create_id ( this , rwlock_op ) ?;
508
+ let id = this . rwlock_get_or_create_id ( rwlock_op , 4 ) ?;
590
509
let active_thread = this. get_active_thread ( ) ;
591
510
592
511
if this. rwlock_is_write_locked ( id) {
@@ -603,7 +522,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
603
522
) -> InterpResult < ' tcx , i32 > {
604
523
let this = self . eval_context_mut ( ) ;
605
524
606
- let id = rwlock_get_or_create_id ( this , rwlock_op ) ?;
525
+ let id = this . rwlock_get_or_create_id ( rwlock_op , 4 ) ?;
607
526
let active_thread = this. get_active_thread ( ) ;
608
527
609
528
if this. rwlock_is_locked ( id) {
@@ -633,7 +552,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
633
552
) -> InterpResult < ' tcx , i32 > {
634
553
let this = self . eval_context_mut ( ) ;
635
554
636
- let id = rwlock_get_or_create_id ( this , rwlock_op ) ?;
555
+ let id = this . rwlock_get_or_create_id ( rwlock_op , 4 ) ?;
637
556
let active_thread = this. get_active_thread ( ) ;
638
557
639
558
if this. rwlock_is_locked ( id) {
@@ -650,7 +569,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
650
569
) -> InterpResult < ' tcx , i32 > {
651
570
let this = self . eval_context_mut ( ) ;
652
571
653
- let id = rwlock_get_or_create_id ( this , rwlock_op ) ?;
572
+ let id = this . rwlock_get_or_create_id ( rwlock_op , 4 ) ?;
654
573
let active_thread = this. get_active_thread ( ) ;
655
574
656
575
#[ allow( clippy:: if_same_then_else) ]
@@ -669,7 +588,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
669
588
) -> InterpResult < ' tcx , i32 > {
670
589
let this = self . eval_context_mut ( ) ;
671
590
672
- let id = rwlock_get_or_create_id ( this , rwlock_op ) ?;
591
+ let id = this . rwlock_get_or_create_id ( rwlock_op , 4 ) ?;
673
592
674
593
if this. rwlock_is_locked ( id) {
675
594
throw_ub_format ! ( "destroyed a locked rwlock" ) ;
@@ -772,7 +691,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
772
691
773
692
fn pthread_cond_signal ( & mut self , cond_op : & OpTy < ' tcx , Provenance > ) -> InterpResult < ' tcx , i32 > {
774
693
let this = self . eval_context_mut ( ) ;
775
- let id = cond_get_or_create_id ( this, cond_op ) ?;
694
+ let id = this. condvar_get_or_create_id ( cond_op , 4 ) ?;
776
695
if let Some ( ( thread, mutex) ) = this. condvar_signal ( id) {
777
696
post_cond_signal ( this, thread, mutex) ?;
778
697
}
@@ -785,7 +704,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
785
704
cond_op : & OpTy < ' tcx , Provenance > ,
786
705
) -> InterpResult < ' tcx , i32 > {
787
706
let this = self . eval_context_mut ( ) ;
788
- let id = cond_get_or_create_id ( this, cond_op ) ?;
707
+ let id = this. condvar_get_or_create_id ( cond_op , 4 ) ?;
789
708
790
709
while let Some ( ( thread, mutex) ) = this. condvar_signal ( id) {
791
710
post_cond_signal ( this, thread, mutex) ?;
@@ -801,8 +720,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
801
720
) -> InterpResult < ' tcx , i32 > {
802
721
let this = self . eval_context_mut ( ) ;
803
722
804
- let id = cond_get_or_create_id ( this, cond_op ) ?;
805
- let mutex_id = mutex_get_or_create_id ( this , mutex_op ) ?;
723
+ let id = this. condvar_get_or_create_id ( cond_op , 4 ) ?;
724
+ let mutex_id = this . mutex_get_or_create_id ( mutex_op , 4 ) ?;
806
725
let active_thread = this. get_active_thread ( ) ;
807
726
808
727
release_cond_mutex_and_block ( this, active_thread, mutex_id) ?;
@@ -822,8 +741,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
822
741
823
742
this. check_no_isolation ( "`pthread_cond_timedwait`" ) ?;
824
743
825
- let id = cond_get_or_create_id ( this, cond_op ) ?;
826
- let mutex_id = mutex_get_or_create_id ( this , mutex_op ) ?;
744
+ let id = this. condvar_get_or_create_id ( cond_op , 4 ) ?;
745
+ let mutex_id = this . mutex_get_or_create_id ( mutex_op , 4 ) ?;
827
746
let active_thread = this. get_active_thread ( ) ;
828
747
829
748
// Extract the timeout.
@@ -899,7 +818,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
899
818
) -> InterpResult < ' tcx , i32 > {
900
819
let this = self . eval_context_mut ( ) ;
901
820
902
- let id = cond_get_or_create_id ( this, cond_op ) ?;
821
+ let id = this. condvar_get_or_create_id ( cond_op , 4 ) ?;
903
822
if this. condvar_is_awaited ( id) {
904
823
throw_ub_format ! ( "destroying an awaited conditional variable" ) ;
905
824
}
0 commit comments