@@ -96,15 +96,28 @@ fn mutex_id_offset<'tcx>(ecx: &MiriInterpCx<'tcx>) -> InterpResult<'tcx, u64> {
96
96
// recursive or error checking mutexes. We should also add thme in this sanity check.
97
97
static SANITY : AtomicBool = AtomicBool :: new ( false ) ;
98
98
if !SANITY . swap ( true , Ordering :: Relaxed ) {
99
- let static_initializer = ecx. eval_path ( & [ "libc" , "PTHREAD_MUTEX_INITIALIZER" ] ) ;
100
- let id_field = static_initializer
101
- . offset ( Size :: from_bytes ( offset) , ecx. machine . layouts . u32 , ecx)
102
- . unwrap ( ) ;
103
- let id = ecx. read_scalar ( & id_field) . unwrap ( ) . to_u32 ( ) . unwrap ( ) ;
104
- assert_eq ! (
105
- id, 0 ,
106
- "PTHREAD_MUTEX_INITIALIZER is incompatible with our pthread_mutex layout: id is not 0"
107
- ) ;
99
+ let check_static_initializer = |name| {
100
+ let static_initializer = ecx. eval_path ( & [ "libc" , name] ) ;
101
+ let id_field = static_initializer
102
+ . offset ( Size :: from_bytes ( offset) , ecx. machine . layouts . u32 , ecx)
103
+ . unwrap ( ) ;
104
+ let id = ecx. read_scalar ( & id_field) . unwrap ( ) . to_u32 ( ) . unwrap ( ) ;
105
+ assert_eq ! ( id, 0 , "{name} is incompatible with our pthread_mutex layout: id is not 0" ) ;
106
+ } ;
107
+
108
+ check_static_initializer ( "PTHREAD_MUTEX_INITIALIZER" ) ;
109
+ // Check non-standard initializers.
110
+ match & * ecx. tcx . sess . target . os {
111
+ "linux" => {
112
+ check_static_initializer ( "PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP" ) ;
113
+ check_static_initializer ( "PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP" ) ;
114
+ check_static_initializer ( "PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP" ) ;
115
+ }
116
+ "illumos" | "solaris" | "macos" => {
117
+ // No non-standard initializers.
118
+ }
119
+ os => throw_unsup_format ! ( "`pthread_mutex` is not supported on {os}" ) ,
120
+ }
108
121
}
109
122
110
123
Ok ( offset)
@@ -167,7 +180,7 @@ fn kind_from_static_initializer<'tcx>(
167
180
mutex. offset ( Size :: from_bytes ( offset) , ecx. machine . layouts . i32 , ecx) ?;
168
181
ecx. read_scalar ( & kind_place) ?. to_i32 ( ) ?
169
182
}
170
- | "illumos" | "solaris" | "macos" => ecx. eval_libc_i32 ( "PTHREAD_MUTEX_DEFAULT" ) ,
183
+ "illumos" | "solaris" | "macos" => ecx. eval_libc_i32 ( "PTHREAD_MUTEX_DEFAULT" ) ,
171
184
os => throw_unsup_format ! ( "`pthread_mutex` is not supported on {os}" ) ,
172
185
} ;
173
186
0 commit comments