@@ -232,13 +232,15 @@ pub struct PrimitiveLayouts<'tcx> {
232
232
pub u32 : TyAndLayout < ' tcx > ,
233
233
pub usize : TyAndLayout < ' tcx > ,
234
234
pub bool : TyAndLayout < ' tcx > ,
235
- pub mut_raw_ptr : TyAndLayout < ' tcx > ,
235
+ pub mut_raw_ptr : TyAndLayout < ' tcx > , // *mut ()
236
+ pub const_raw_ptr : TyAndLayout < ' tcx > , // *const ()
236
237
}
237
238
238
239
impl < ' mir , ' tcx : ' mir > PrimitiveLayouts < ' tcx > {
239
240
fn new ( layout_cx : LayoutCx < ' tcx , TyCtxt < ' tcx > > ) -> Result < Self , LayoutError < ' tcx > > {
240
241
let tcx = layout_cx. tcx ;
241
242
let mut_raw_ptr = tcx. mk_ptr ( TypeAndMut { ty : tcx. types . unit , mutbl : Mutability :: Mut } ) ;
243
+ let const_raw_ptr = tcx. mk_ptr ( TypeAndMut { ty : tcx. types . unit , mutbl : Mutability :: Not } ) ;
242
244
Ok ( Self {
243
245
unit : layout_cx. layout_of ( tcx. mk_unit ( ) ) ?,
244
246
i8 : layout_cx. layout_of ( tcx. types . i8 ) ?,
@@ -251,6 +253,7 @@ impl<'mir, 'tcx: 'mir> PrimitiveLayouts<'tcx> {
251
253
usize : layout_cx. layout_of ( tcx. types . usize ) ?,
252
254
bool : layout_cx. layout_of ( tcx. types . bool ) ?,
253
255
mut_raw_ptr : layout_cx. layout_of ( mut_raw_ptr) ?,
256
+ const_raw_ptr : layout_cx. layout_of ( const_raw_ptr) ?,
254
257
} )
255
258
}
256
259
}
@@ -431,6 +434,17 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
431
434
this. machine . extern_statics . try_insert ( Symbol :: intern ( name) , ptr) . unwrap ( ) ;
432
435
}
433
436
437
+ fn alloc_extern_static (
438
+ this : & mut MiriEvalContext < ' mir , ' tcx > ,
439
+ name : & str ,
440
+ val : ImmTy < ' tcx , Provenance > ,
441
+ ) -> InterpResult < ' tcx > {
442
+ let place = this. allocate ( val. layout , MiriMemoryKind :: ExternStatic . into ( ) ) ?;
443
+ this. write_immediate ( * val, & place. into ( ) ) ?;
444
+ Self :: add_extern_static ( this, name, place. ptr ) ;
445
+ Ok ( ( ) )
446
+ }
447
+
434
448
/// Sets up the "extern statics" for this machine.
435
449
fn init_extern_statics ( this : & mut MiriEvalContext < ' mir , ' tcx > ) -> InterpResult < ' tcx > {
436
450
match this. tcx . sess . target . os . as_ref ( ) {
@@ -447,10 +461,8 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
447
461
// syscall that we do support).
448
462
for name in & [ "__cxa_thread_atexit_impl" , "getrandom" , "statx" , "__clock_gettime64" ]
449
463
{
450
- let layout = this. machine . layouts . usize ;
451
- let place = this. allocate ( layout, MiriMemoryKind :: ExternStatic . into ( ) ) ?;
452
- this. write_scalar ( Scalar :: from_machine_usize ( 0 , this) , & place. into ( ) ) ?;
453
- Self :: add_extern_static ( this, name, place. ptr ) ;
464
+ let val = ImmTy :: from_int ( 0 , this. machine . layouts . usize ) ;
465
+ Self :: alloc_extern_static ( this, name, val) ?;
454
466
}
455
467
}
456
468
"freebsd" => {
@@ -461,13 +473,27 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
461
473
this. machine . env_vars . environ . unwrap ( ) . ptr ,
462
474
) ;
463
475
}
476
+ "android" => {
477
+ // "signal"
478
+ let layout = this. machine . layouts . const_raw_ptr ;
479
+ let dlsym = Dlsym :: from_str ( "signal" . as_bytes ( ) , & this. tcx . sess . target . os ) ?
480
+ . expect ( "`signal` must be an actual dlsym on android" ) ;
481
+ let ptr = this. create_fn_alloc_ptr ( FnVal :: Other ( dlsym) ) ;
482
+ let val = ImmTy :: from_scalar ( Scalar :: from_pointer ( ptr, this) , layout) ;
483
+ Self :: alloc_extern_static ( this, "signal" , val) ?;
484
+ // A couple zero-initialized pointer-sized extern statics.
485
+ // Most of them are for weak symbols, which we all set to null (indicating that the
486
+ // symbol is not supported, and triggering fallback code.)
487
+ for name in & [ "bsd_signal" ] {
488
+ let val = ImmTy :: from_int ( 0 , this. machine . layouts . usize ) ;
489
+ Self :: alloc_extern_static ( this, name, val) ?;
490
+ }
491
+ }
464
492
"windows" => {
465
493
// "_tls_used"
466
494
// This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
467
- let layout = this. machine . layouts . u8 ;
468
- let place = this. allocate ( layout, MiriMemoryKind :: ExternStatic . into ( ) ) ?;
469
- this. write_scalar ( Scalar :: from_u8 ( 0 ) , & place. into ( ) ) ?;
470
- Self :: add_extern_static ( this, "_tls_used" , place. ptr ) ;
495
+ let val = ImmTy :: from_int ( 0 , this. machine . layouts . u8 ) ;
496
+ Self :: alloc_extern_static ( this, "_tls_used" , val) ?;
471
497
}
472
498
_ => { } // No "extern statics" supported on this target
473
499
}
0 commit comments