]> git.ipfire.org Git - thirdparty/git.git/commit
mem-pool: don't assume uintmax_t is aligned enough for all types
authorJessica Clarke <jrtc27@jrtc27.com>
Sun, 23 Jan 2022 20:33:47 +0000 (20:33 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Jan 2022 18:26:40 +0000 (10:26 -0800)
commite38bcc66d8af1a46203abe9b6ffc8aa124865803
tree01c0873f8af3cccd5b16e52e64bf893f6ca7f29b
parente9d7761bb94f20acc98824275e317fa82436c25d
mem-pool: don't assume uintmax_t is aligned enough for all types

mem_pool_alloc uses sizeof(uintmax_t) as a proxy for what should be
_Alignof(max_align_t) in C11. On most architectures this is sufficient
(though on m68k it is in fact overly strict, since the de-facto ABI,
which differs from the specified System V ABI, has the maximum alignment
of all types as 2 bytes), but on CHERI, and thus Arm's Morello
prototype, it is insufficient for any type that stores a pointer, which
must be aligned to 128 bits (on 64-bit architectures extended with
CHERI), whilst uintmax_t is a 64-bit integer.

Fix this by introducing our own approximation for max_align_t and a
means to compute _Alignof it without relying on C11. Currently this
union only contains uintmax_t and void *, but more types can be added as
needed.

Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
mem-pool.c