Skip to content

Commit

Permalink
julia_gc: compensate for Julia guard pages (#5737)
Browse files Browse the repository at this point in the history
This avoids triggering Julia's `safe_restore` mechanism
completely in my local tests, i.e., avoids causing a segfault
by scanning right into the guard pages set up by Julia.

Note that this is unrelated to the recently removed
`SKIP_GUARD_PAGES` feature which was about adjusting for
pthread guard pages, which in practice turns out to be
irrelevant for our purposes.
  • Loading branch information
fingolfin authored Jun 10, 2024
1 parent dcf704f commit b099afe
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/julia_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,28 @@ static inline void * align_ptr(void * p)

static void FindLiveRangeReverse(PtrArray * arr, void * start, void * end)
{
// HACK: the following deals with stacks of 'negative size' exposed by
// Julia -- however, despite us having this code in here for a few years,
// I know think it may actually be due to a bug on the Julia side. See
// <https://github.com/JuliaLang/julia/pull/54639> for details.
if (lt_ptr(end, start)) {
SWAP(void *, start, end);
}
#if JULIA_VERSION_MAJOR == 1 && JULIA_VERSION_MINOR <= 11
// adjust for Julia guard pages if necessary
// In Julia >= 1.12 this is no longer necessary thanks
// to <https://github.com/JuliaLang/julia/pull/54591>
// TODO: hopefully this actually also gets backported to 1.11.0
//
// unfortunately jl_guard_size is not exported; fortunately it
// is the same in all Julia versions were we need it
else {
void * new_start = (char *)start + (4096 * 8);
if ((uintptr_t)new_start <= (uintptr_t)end) {
start = new_start;
}
}
#endif
char * p = (char *)(align_ptr(start));
char * q = (char *)end - sizeof(void *);
while (!lt_ptr(q, p)) {
Expand Down

0 comments on commit b099afe

Please sign in to comment.