Skip to content

Unaligned jmp_buf on macos/aarch64 #310

@pipcet

Description

@pipcet

MacOS/Aarch64 incorrectly defines jmp_buf to be an array of int. That means that it sometimes (this depends on the precise compiler used and compiler options) ends up not being 8-byte aligned on the stack (ints have 4-byte alignment), and that breaks STACK_CONTEXT_BEGIN: the _setjmp works fine, but then the words on the stack are misaligned, so our scanning function won't find them.

It's easy enough to fix for this case, as we simply need to align a single jmp_buf in a single place (StackContextStruct).

However, applications may create other jmp_bufs on the stack, and we must trace them so a longjmp doesn't revive dead objects. This is particularly true with compilers which clobber callee-saved registers in noreturn functions (GCC with -mreturn-no-callee-saved-registers, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38534).

We might end up having to double-scan the stack (and ambiguous roots on the heap if they contain jmp_bufs) to catch those misaligned words, similar to the m68k situation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions