Skip to content

fix(bindings): use max_align_t for allocator alignment#5745

Merged
jouho merged 1 commit intomainfrom
WesleyRosenblum/alignment
Feb 18, 2026
Merged

fix(bindings): use max_align_t for allocator alignment#5745
jouho merged 1 commit intomainfrom
WesleyRosenblum/alignment

Conversation

@WesleyRosenblum
Copy link
Copy Markdown
Contributor

@WesleyRosenblum WesleyRosenblum commented Feb 17, 2026

Goal

Fix the alignment used in the Rust bindings custom allocator to match the C malloc alignment contract.

We would like to thank Joshua Rogers (https://joshua.hu/) of AISLE Research Team (https://aisle.com/) for reporting this issue.

Why

The custom allocator was using size_of::<usize>() (8 bytes on 64-bit) for alignment, but C's malloc is required to return memory "suitably aligned for any built-in type." On platforms like x86_64 Linux, max_align_t has a 16-byte alignment requirement (due to long double), so the previous alignment could return under-aligned memory for C code.

How

Changed the alignment constant from size_of::<usize>() to align_of::<libc::max_align_t>(), which matches the C standard's alignment guarantee for malloc.

Callouts

This isn't expected to have an effect in practice as most allocators I tested (default Rust allocator, jemalloc, mimalloc), already align to 16-bytes regardless of the specified alignment.

Testing

Existing tests

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the s2n-core team label Feb 17, 2026
@WesleyRosenblum WesleyRosenblum marked this pull request as ready for review February 17, 2026 23:39
@WesleyRosenblum WesleyRosenblum added this pull request to the merge queue Feb 18, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 18, 2026
@jouho jouho added this pull request to the merge queue Feb 18, 2026
Merged via the queue into main with commit 38b96a7 Feb 18, 2026
58 checks passed
@jouho jouho deleted the WesleyRosenblum/alignment branch February 18, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants