Skip to content

Commit

Permalink
staticdata: make completeinfo memory-/gc-safe (#48832)
Browse files Browse the repository at this point in the history
There is actually almost no cases where `jl_alloc_svec_uninit` is safe,
since if was safe, you would likely would prefer to use the `jl_svec`
constructor instead.
  • Loading branch information
vtjnash authored Mar 1, 2023
1 parent bdcd5e2 commit 0608824
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -3229,7 +3229,7 @@ static jl_value_t *jl_validate_cache_file(ios_t *f, jl_array_t *depmods, uint64_
}

// TODO?: refactor to make it easier to create the "package inspector"
static jl_value_t *jl_restore_package_image_from_stream(ios_t *f, jl_image_t *image, jl_array_t *depmods, int complete)
static jl_value_t *jl_restore_package_image_from_stream(ios_t *f, jl_image_t *image, jl_array_t *depmods, int completeinfo)
{
uint64_t checksum = 0;
int64_t dataendpos = 0;
Expand Down Expand Up @@ -3275,19 +3275,22 @@ static jl_value_t *jl_restore_package_image_from_stream(ios_t *f, jl_image_t *im
// reinit ccallables
jl_reinit_ccallable(&ccallable_list, base, NULL);
arraylist_free(&ccallable_list);
if (complete) {
cachesizes_sv = jl_alloc_svec_uninit(7);
jl_svec_data(cachesizes_sv)[0] = jl_box_long(cachesizes.sysdata);
jl_svec_data(cachesizes_sv)[1] = jl_box_long(cachesizes.isbitsdata);
jl_svec_data(cachesizes_sv)[2] = jl_box_long(cachesizes.symboldata);
jl_svec_data(cachesizes_sv)[3] = jl_box_long(cachesizes.tagslist);
jl_svec_data(cachesizes_sv)[4] = jl_box_long(cachesizes.reloclist);
jl_svec_data(cachesizes_sv)[5] = jl_box_long(cachesizes.gvarlist);
jl_svec_data(cachesizes_sv)[6] = jl_box_long(cachesizes.fptrlist);

if (completeinfo) {
cachesizes_sv = jl_alloc_svec(7);
jl_svecset(cachesizes_sv, 0, jl_box_long(cachesizes.sysdata));
jl_svecset(cachesizes_sv, 1, jl_box_long(cachesizes.isbitsdata));
jl_svecset(cachesizes_sv, 2, jl_box_long(cachesizes.symboldata));
jl_svecset(cachesizes_sv, 3, jl_box_long(cachesizes.tagslist));
jl_svecset(cachesizes_sv, 4, jl_box_long(cachesizes.reloclist));
jl_svecset(cachesizes_sv, 5, jl_box_long(cachesizes.gvarlist));
jl_svecset(cachesizes_sv, 6, jl_box_long(cachesizes.fptrlist));
restored = (jl_value_t*)jl_svec(8, restored, init_order, extext_methods, new_specializations, method_roots_list,
ext_targets, edges, cachesizes_sv);
} else
}
else {
restored = (jl_value_t*)jl_svec(2, restored, init_order);
}
}
}

Expand All @@ -3301,24 +3304,24 @@ static void jl_restore_system_image_from_stream(ios_t *f, jl_image_t *image)
jl_restore_system_image_from_stream_(f, image, NULL, checksum, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
}

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 complete)
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)
{
ios_t f;
ios_static_buffer(&f, (char*)buf, sz);
jl_value_t *ret = jl_restore_package_image_from_stream(&f, image, depmods, complete);
jl_value_t *ret = jl_restore_package_image_from_stream(&f, image, depmods, completeinfo);
ios_close(&f);
return ret;
}

JL_DLLEXPORT jl_value_t *jl_restore_incremental(const char *fname, jl_array_t *depmods, int complete)
JL_DLLEXPORT jl_value_t *jl_restore_incremental(const char *fname, jl_array_t *depmods, int completeinfo)
{
ios_t f;
if (ios_file(&f, fname, 1, 0, 0, 0) == NULL) {
return jl_get_exceptionf(jl_errorexception_type,
"Cache file \"%s\" not found.\n", fname);
}
jl_image_t pkgimage = {};
jl_value_t *ret = jl_restore_package_image_from_stream(&f, &pkgimage, depmods, complete);
jl_value_t *ret = jl_restore_package_image_from_stream(&f, &pkgimage, depmods, completeinfo);
ios_close(&f);
return ret;
}
Expand Down Expand Up @@ -3366,7 +3369,7 @@ JL_DLLEXPORT void jl_restore_system_image_data(const char *buf, size_t len)
JL_SIGATOMIC_END();
}

JL_DLLEXPORT jl_value_t *jl_restore_package_image_from_file(const char *fname, jl_array_t *depmods, int complete)
JL_DLLEXPORT jl_value_t *jl_restore_package_image_from_file(const char *fname, jl_array_t *depmods, int completeinfo)
{
void *pkgimg_handle = jl_dlopen(fname, JL_RTLD_LAZY);
if (!pkgimg_handle) {
Expand Down Expand Up @@ -3418,7 +3421,7 @@ JL_DLLEXPORT jl_value_t *jl_restore_package_image_from_file(const char *fname, j
}
#endif

jl_value_t* mod = jl_restore_incremental_from_buf(pkgimg_data, &pkgimage, *plen, depmods, complete);
jl_value_t* mod = jl_restore_incremental_from_buf(pkgimg_data, &pkgimage, *plen, depmods, completeinfo);

return mod;
}
Expand Down

0 comments on commit 0608824

Please sign in to comment.