Skip to content

Commit

Permalink
Ensure that the jump buffer is appropriately aligned.
Browse files Browse the repository at this point in the history
  • Loading branch information
gareth-rees committed Dec 27, 2022
1 parent b71e18c commit 03f8716
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions code/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@
#define ATTRIBUTE_UNUSED
#endif

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


/* Compiler extensions */

Expand Down
10 changes: 9 additions & 1 deletion code/ss.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <design/stack-scan#.sol.setjmp.scan>.
*
* 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 <setjmp.h>

typedef struct StackContextStruct {
jmp_buf jumpBuffer;
ATTRIBUTE_ALIGNED(MPS_PF_ALIGN) jmp_buf jumpBuffer;
} StackContextStruct;


Expand Down

0 comments on commit 03f8716

Please sign in to comment.