Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

match: Properly align heapframes for CHERI/Arm's Morello prototype #72

Merged
merged 1 commit into from
Jan 4, 2022
Merged

match: Properly align heapframes for CHERI/Arm's Morello prototype #72

merged 1 commit into from
Jan 4, 2022

Conversation

jrtc27
Copy link
Contributor

@jrtc27 jrtc27 commented Jan 4, 2022

On CHERI, and thus Arm's Morello prototype, pointers are represented as
hardware capabilities, which consist of both an integer address and
additional metadata, meaning they are twice the size of the platform's
size_t type, i.e. 16 bytes on a 64-bit system. The ovector member of
heapframe happens to only be 8 byte aligned, and so computing frame_size
ends up with a multiple of 8 but not 16. Whilst the first frame is
always suitably aligned, this then misaligns the frame that follows it,
resulting in an alignment fault when storing a pointer to Fecode at the
start of match.

Thus, round up frame_size to a multiple of heapframe's alignment to
ensure alignment is preserved. This can be completely optimised away on
traditional architectures and, since CHERI's capabilities are in fact
2 * sizeof(PCRE2_SIZE) bytes in size, the variable part of the
expression is also proven to be a multiple of the alignment and so the
aligning gets folded into the offsetof part by adding an additional 8,
so no dynamic alignment code is needed even on CHERI architectures.

On CHERI, and thus Arm's Morello prototype, pointers are represented as
hardware capabilities, which consist of both an integer address and
additional metadata, meaning they are twice the size of the platform's
size_t type, i.e. 16 bytes on a 64-bit system. The ovector member of
heapframe happens to only be 8 byte aligned, and so computing frame_size
ends up with a multiple of 8 but not 16. Whilst the first frame is
always suitably aligned, this then misaligns the frame that follows it,
resulting in an alignment fault when storing a pointer to Fecode at the
start of match.

Thus, round up frame_size to a multiple of heapframe's alignment to
ensure alignment is preserved. This can be completely optimised away on
traditional architectures and, since CHERI's capabilities are in fact
2 * sizeof(PCRE2_SIZE) bytes in size, the variable part of the
expression is also proven to be a multiple of the alignment and so the
aligning gets folded into the offsetof part by adding an additional 8,
so no dynamic alignment code is needed even on CHERI architectures.
@PhilipHazel PhilipHazel merged commit 04ecb26 into PCRE2Project:master Jan 4, 2022
@PhilipHazel
Copy link
Collaborator

Nice patch, thank you.

@jrtc27 jrtc27 deleted the align-heapframes branch January 4, 2022 17:13
jrtc27 referenced this pull request in CTSRD-CHERI/cheribsd-ports Apr 3, 2022
We could use the tiny flavor for devel/git to disable the unsupported
options. However, devel/git@tiny seems not to compile without perl.

We probably should change the default options only for CHERI-enabled
architectures leaving them as in upstream for the rest of architectures.
We could disable the default options in an options directory mounted by
Poudriere instead of changing it in the cheribsd-ports ports tree.
We'll introduce these improvements separately.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants