@@ -724,11 +724,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
724
724
// Hook pthread calls that go to the thread-local storage memory subsystem
725
725
"pthread_key_create" => {
726
726
let key_ptr = args[ 0 ] . read_ptr ( & self . memory ) ?;
727
-
727
+
728
728
// Extract the function type out of the signature (that seems easier than constructing it ourselves...)
729
729
let dtor_ptr = args[ 1 ] . read_ptr ( & self . memory ) ?;
730
730
let dtor = if dtor_ptr. is_null_ptr ( ) { None } else { Some ( self . memory . get_fn ( dtor_ptr. alloc_id ) ?) } ;
731
-
731
+
732
732
// Figure out how large a pthread TLS key actually is. This is libc::pthread_key_t.
733
733
let key_size = match self . operand_ty ( & arg_operands[ 0 ] ) . sty {
734
734
TypeVariants :: TyRawPtr ( TypeAndMut { ty, .. } ) => {
@@ -737,14 +737,14 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
737
737
}
738
738
_ => return Err ( EvalError :: AbiViolation ( "Wrong signature used for pthread_key_create: First argument must be a raw pointer." . to_owned ( ) ) )
739
739
} ;
740
-
740
+
741
741
// Create key and write it into the memory where key_ptr wants it
742
- let key = self . memory . create_tls_key ( dtor) ;
743
- if key >= ( 1 << key_size. bits ( ) ) {
742
+ let key = self . memory . create_tls_key ( dtor) as u128 ;
743
+ if key_size . bits ( ) < 128 && key >= ( 1u128 << key_size. bits ( ) as u128 ) {
744
744
return Err ( EvalError :: OutOfTls ) ;
745
745
}
746
- self . memory . write_int ( key_ptr, key as i128 , key_size. bytes ( ) ) ?;
747
-
746
+ self . memory . write_uint ( key_ptr, key, key_size. bytes ( ) ) ?;
747
+
748
748
// Return success (0)
749
749
self . write_primval ( dest, PrimVal :: Bytes ( 0 ) , dest_ty) ?;
750
750
}
0 commit comments