Skip to content

Commit 03f8716

Browse files
committed
Ensure that the jump buffer is appropriately aligned.
1 parent b71e18c commit 03f8716

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

code/config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,16 @@
314314
#define ATTRIBUTE_UNUSED
315315
#endif
316316

317+
/* Attribute for data structures that need to be allocated at
318+
* addresses with a particular alignment.
319+
* GCC: <https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-aligned-function-attribute>
320+
*/
321+
#if defined(MPS_BUILD_GC) || defined(MPS_BUILD_LL)
322+
#define ATTRIBUTE_ALIGNED(ALIGNMENT) __attribute__((__aligned__(ALIGNMENT)))
323+
#else
324+
#define ATTRIBUTE_ALIGNED(ALIGNMENT)
325+
#endif
326+
317327

318328
/* Compiler extensions */
319329

code/ss.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@
1919
* The jumpBuffer is used to capture most of the mutator's state on
2020
* entry to the MPS, but can't capture it all. See
2121
* <design/stack-scan#.sol.setjmp.scan>.
22+
*
23+
* The stack capturing mechanism in STACK_CONTEXT_BEGIN puts the
24+
* StackContextStruct on the stack, where it will later be scanned
25+
* using TraceScanArea. The jumpBuffer must be allocated on the stack
26+
* at an address with suitable alignment so that TraceScanArea will
27+
* correctly fix any addresses therein. This is vital on platform XCA6
28+
* where jmp_buf is declared as an array of int, which has 4-byte
29+
* alignment, but we need it to have 8-byte alignment.
2230
*/
2331

2432
#include <setjmp.h>
2533

2634
typedef struct StackContextStruct {
27-
jmp_buf jumpBuffer;
35+
ATTRIBUTE_ALIGNED(MPS_PF_ALIGN) jmp_buf jumpBuffer;
2836
} StackContextStruct;
2937

3038

0 commit comments

Comments
 (0)