From 9c82a2af0fd843449ecd4b440023cf13a86c1eb9 Mon Sep 17 00:00:00 2001 From: ph10 Date: Tue, 27 Feb 2018 17:19:51 +0000 Subject: [PATCH] Add alignment patch for m68k. --- ChangeLog | 6 ++++++ src/pcre2_intmodedep.h | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ChangeLog b/ChangeLog index a092e02..2f9c6a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -32,6 +32,12 @@ read from files via the -f option. 7. Added --enable-jit=auto support to configure.ac. +8. Added some dummy variables to the heapframe structure in 16-bit and 32-bit +modes for the benefit of m68k, where pointers can be 16-bit aligned. The +dummies force 32-bit alignment and this ensures that the structure is a +multiple of PCRE2_SIZE, a requirement that is tested at compile time. In other +architectures, alignment requirements take care of this automatically. + Version 10.31 12-February-2018 ------------------------------ diff --git a/src/pcre2_intmodedep.h b/src/pcre2_intmodedep.h index c4c4c3a..d744e39 100644 --- a/src/pcre2_intmodedep.h +++ b/src/pcre2_intmodedep.h @@ -793,12 +793,23 @@ typedef struct heapframe { uint8_t return_id; /* Where to go on in internal "return" */ uint8_t op; /* Processing opcode */ + /* At this point, the structure is 16-bit aligned. On most architectures + the alignment requirement for a pointer will ensure that the eptr field below + is 32-bit or 64-bit aligned. However, on m68k it is fine to have a pointer + that is 16-bit aligned. We must therefore ensure that the occu vector is an + odd multiple of 16 bits so as to get back into 32-bit alignment. This happens + naturally when PCRE2_UCHAR is 8 bits wide, but needs fudges in the other + cases. Without these, this structure is no longer a multiple of PCRE2_SIZE + and the check below fails. */ + #if PCRE2_CODE_UNIT_WIDTH == 8 PCRE2_UCHAR occu[6]; /* Used for other case code units */ #elif PCRE2_CODE_UNIT_WIDTH == 16 PCRE2_UCHAR occu[2]; /* Used for other case code units */ + uint8_t unused[2]; /* Ensure 32-bit alignment (see above) */ #else PCRE2_UCHAR occu[1]; /* Used for other case code units */ + uint8_t unused[2]; /* Ensure 32-bit alignment (see above) */ #endif /* The rest have to be copied from the previous frame whenever a new frame @@ -818,6 +829,9 @@ typedef struct heapframe { PCRE2_SIZE ovector[131072]; /* Must be last in the structure */ } heapframe; +/* This typedef is a check that the size of the heapframe structure is a +multiple of PCRE2_SIZE. See various comments above. */ + typedef char check_heapframe_size[ ((sizeof(heapframe) % sizeof(PCRE2_SIZE)) == 0)? (+1):(-1)];