@@ -71,6 +71,7 @@ External links:
71
71
*/
72
72
#include <stdlib.h>
73
73
#include <string.h>
74
+ #include <stdbool.h>
74
75
#include <stdio.h> // printf
75
76
#include <inttypes.h> // PRIxPTR
76
77
@@ -3364,7 +3365,7 @@ static jl_value_t *jl_validate_cache_file(ios_t *f, jl_array_t *depmods, uint64_
3364
3365
}
3365
3366
3366
3367
// TODO?: refactor to make it easier to create the "package inspector"
3367
- static jl_value_t * jl_restore_package_image_from_stream (ios_t * f , jl_image_t * image , jl_array_t * depmods , int completeinfo , const char * pkgname )
3368
+ static jl_value_t * jl_restore_package_image_from_stream (ios_t * f , jl_image_t * image , jl_array_t * depmods , int completeinfo , const char * pkgname , bool needs_permalloc )
3368
3369
{
3369
3370
JL_TIMING (LOAD_IMAGE , LOAD_Pkgimg );
3370
3371
jl_timing_printf (JL_TIMING_DEFAULT_BLOCK , pkgname );
@@ -3377,7 +3378,7 @@ static jl_value_t *jl_restore_package_image_from_stream(ios_t *f, jl_image_t *im
3377
3378
return verify_fail ;
3378
3379
3379
3380
assert (datastartpos > 0 && datastartpos < dataendpos );
3380
-
3381
+ needs_permalloc = jl_options . permalloc_pkgimg || needs_permalloc ;
3381
3382
jl_value_t * restored = NULL ;
3382
3383
jl_array_t * init_order = NULL , * extext_methods = NULL , * new_specializations = NULL , * method_roots_list = NULL , * ext_targets = NULL , * edges = NULL ;
3383
3384
jl_svec_t * cachesizes_sv = NULL ;
@@ -3389,14 +3390,22 @@ static jl_value_t *jl_restore_package_image_from_stream(ios_t *f, jl_image_t *im
3389
3390
ios_bufmode (f , bm_none );
3390
3391
JL_SIGATOMIC_BEGIN ();
3391
3392
size_t len = dataendpos - datastartpos ;
3392
- char * sysimg = (char * )jl_gc_perm_alloc (len , 0 , 64 , 0 );
3393
+ char * sysimg ;
3394
+ bool success = !needs_permalloc ;
3393
3395
ios_seek (f , datastartpos );
3394
- if (ios_readall (f , sysimg , len ) != len || jl_crc32c (0 , sysimg , len ) != (uint32_t )checksum ) {
3395
- restored = jl_get_exceptionf (jl_errorexception_type , "Error reading system image file." );
3396
+ if (needs_permalloc )
3397
+ sysimg = (char * )jl_gc_perm_alloc (len , 0 , 64 , 0 );
3398
+ else
3399
+ sysimg = & f -> buf [f -> bpos ];
3400
+ if (needs_permalloc )
3401
+ success = ios_readall (f , sysimg , len ) == len ;
3402
+ if (!success || jl_crc32c (0 , sysimg , len ) != (uint32_t )checksum ) {
3403
+ restored = jl_get_exceptionf (jl_errorexception_type , "Error reading package image file." );
3396
3404
JL_SIGATOMIC_END ();
3397
3405
}
3398
3406
else {
3399
- ios_close (f );
3407
+ if (needs_permalloc )
3408
+ ios_close (f );
3400
3409
ios_static_buffer (f , sysimg , len );
3401
3410
pkgcachesizes cachesizes ;
3402
3411
jl_restore_system_image_from_stream_ (f , image , depmods , checksum , (jl_array_t * * )& restored , & init_order , & extext_methods , & new_specializations , & method_roots_list , & ext_targets , & edges , & base , & ccallable_list , & cachesizes );
@@ -3442,11 +3451,11 @@ static void jl_restore_system_image_from_stream(ios_t *f, jl_image_t *image, uin
3442
3451
jl_restore_system_image_from_stream_ (f , image , NULL , checksum | ((uint64_t )0xfdfcfbfa << 32 ), NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL );
3443
3452
}
3444
3453
3445
- JL_DLLEXPORT jl_value_t * jl_restore_incremental_from_buf (const char * buf , jl_image_t * image , size_t sz , jl_array_t * depmods , int completeinfo , const char * pkgname )
3454
+ JL_DLLEXPORT jl_value_t * jl_restore_incremental_from_buf (const char * buf , jl_image_t * image , size_t sz , jl_array_t * depmods , int completeinfo , const char * pkgname , bool needs_permalloc )
3446
3455
{
3447
3456
ios_t f ;
3448
3457
ios_static_buffer (& f , (char * )buf , sz );
3449
- jl_value_t * ret = jl_restore_package_image_from_stream (& f , image , depmods , completeinfo , pkgname );
3458
+ jl_value_t * ret = jl_restore_package_image_from_stream (& f , image , depmods , completeinfo , pkgname , needs_permalloc );
3450
3459
ios_close (& f );
3451
3460
return ret ;
3452
3461
}
@@ -3459,7 +3468,7 @@ JL_DLLEXPORT jl_value_t *jl_restore_incremental(const char *fname, jl_array_t *d
3459
3468
"Cache file \"%s\" not found.\n" , fname );
3460
3469
}
3461
3470
jl_image_t pkgimage = {};
3462
- jl_value_t * ret = jl_restore_package_image_from_stream (& f , & pkgimage , depmods , completeinfo , pkgname );
3471
+ jl_value_t * ret = jl_restore_package_image_from_stream (& f , & pkgimage , depmods , completeinfo , pkgname , true );
3463
3472
ios_close (& f );
3464
3473
return ret ;
3465
3474
}
@@ -3530,7 +3539,7 @@ JL_DLLEXPORT jl_value_t *jl_restore_package_image_from_file(const char *fname, j
3530
3539
3531
3540
jl_image_t pkgimage = jl_init_processor_pkgimg (pkgimg_handle );
3532
3541
3533
- jl_value_t * mod = jl_restore_incremental_from_buf (pkgimg_data , & pkgimage , * plen , depmods , completeinfo , pkgname );
3542
+ jl_value_t * mod = jl_restore_incremental_from_buf (pkgimg_data , & pkgimage , * plen , depmods , completeinfo , pkgname , false );
3534
3543
3535
3544
return mod ;
3536
3545
}
0 commit comments