Skip to content

Commit f5f8510

Browse files
authored
Pin pointer literals in code, and julia values in julia_to_scm (#63)
Julia may embed heap pointers in the code. Those objects cannot be moved, otherwise the pointer value in the code becomes invalid. This PR pins those pointers in `literal_pointer_val` and `literal_static_pointer_val`. Julia also reference heap pointers from scm/flisp values. We pin those heap pointers in `julia_to_scm_`.
1 parent 7bc3b32 commit f5f8510

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/ast.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ static value_t julia_to_list2_noalloc(fl_context_t *fl_ctx, jl_value_t *a, jl_va
722722

723723
static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v, int check_valid)
724724
{
725+
PTR_PIN(v);
725726
value_t retval;
726727
if (julia_to_scm_noalloc1(fl_ctx, v, &retval))
727728
return retval;

src/cgutils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ static Value *literal_pointer_val(jl_codectx_t &ctx, jl_value_t *p)
472472
if (p == NULL)
473473
return Constant::getNullValue(ctx.types().T_pjlvalue);
474474
if (!ctx.emission_context.imaging)
475+
// literal_static_pointer_val will pin p.
475476
return literal_static_pointer_val(p, ctx.types().T_pjlvalue);
477+
PTR_PIN(p);
476478
Value *pgv = literal_pointer_val_slot(ctx, p);
477479
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
478480
return ai.decorateInst(maybe_mark_load_dereferenceable(
@@ -487,7 +489,9 @@ static Value *literal_pointer_val(jl_codectx_t &ctx, jl_binding_t *p)
487489
if (p == NULL)
488490
return Constant::getNullValue(ctx.types().T_pjlvalue);
489491
if (!ctx.emission_context.imaging)
492+
// literal_static_pointer_val will pin p.
490493
return literal_static_pointer_val(p, ctx.types().T_pjlvalue);
494+
PTR_PIN(p);
491495
// bindings are prefixed with jl_bnd#
492496
Value *pgv = julia_pgv(ctx, "jl_bnd#", p->name, p->owner, p);
493497
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);

src/jitlayers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ void add_named_global(StringRef name, void *addr);
242242

243243
static inline Constant *literal_static_pointer_val(const void *p, Type *T)
244244
{
245+
PTR_PIN((void*)p);
245246
// this function will emit a static pointer into the generated code
246247
// the generated code will only be valid during the current session,
247248
// and thus, this should typically be avoided in new API's

0 commit comments

Comments
 (0)