From c9474064dc39a53fac9edc2529d9e2d9b397a3a5 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Tue, 27 Dec 2022 16:12:34 +0000 Subject: [PATCH] Ensure that the jump buffer is appropriately aligned. --- code/config.h | 10 ++++++++++ code/ss.h | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/code/config.h b/code/config.h index 83f985a885..d9d71e31cf 100644 --- a/code/config.h +++ b/code/config.h @@ -314,6 +314,16 @@ #define ATTRIBUTE_UNUSED #endif +/* Attribute for data structures that need to be allocated at + * addresses with a particular alignment. + * GCC: + */ +#if defined(MPS_BUILD_GC) || defined(MPS_BUILD_LL) +#define ATTRIBUTE_ALIGNED(ALIGNMENT) __attribute__((__aligned__(ALIGNMENT))) +#else +#define ATTRIBUTE_ALIGNED(ALIGNMENT) +#endif + /* Compiler extensions */ diff --git a/code/ss.h b/code/ss.h index f05ff67b62..cd46990ebc 100644 --- a/code/ss.h +++ b/code/ss.h @@ -19,12 +19,20 @@ * The jumpBuffer is used to capture most of the mutator's state on * entry to the MPS, but can't capture it all. See * . + * + * The stack capturing mechanism in STACK_CONTEXT_BEGIN puts the + * StackContextStruct on the stack, where it will later be scanned + * using TraceScanArea. The jumpBuffer must be allocated on the stack + * at an address with suitable alignment so that TraceScanArea will + * correctly fix any addresses therein. This is vital on platform XCA6 + * where jmp_buf is declared as an array of int, which has 4-byte + * alignment, but we need it to have 8-byte alignment. */ #include typedef struct StackContextStruct { - jmp_buf jumpBuffer; + ATTRIBUTE_ALIGNED(MPS_PF_ALIGN) jmp_buf jumpBuffer; } StackContextStruct;