Closed thomcc closed 1 year ago
Yeaaaah. Postgres is fairly pedantic about alignment and I suspect we've been effectively coasting on the Postgres inclination to be pedantic about alignment... but notably it does not really care about alignments greater than 8, whereas Rust supports alignments up to at least a page size, and indeed many types are aligned to 16 and greater, so we were due for getting busted on this the moment we tried to use SIMD stuff.
We no longer use this allocator so I'm closing this.
I noticed that
pallocator
does not respect the requested alignment -- it totally ignores it --palloc
only guarantees word-alignment (e.g.size_of::<usize>()
), so this is unsound, asrustc
tells LLVM about the alignment, so which can actually cause problems (crashes on aarch64 for sure, but even x86_64 if SIMD gets used... and given our-Ctarget-cpu=native
use, it might).Fixing it basically looks like:
if layout.align() <= WORD_ALIGN
usepalloc
/pfree
/etc, since they're fine.size + align
bytes for overaligned requests, and store the real pointer that you need to free immediately before the aligned pointer.-size_of::<*mut u8>()
,read()
the result, and pass it topfree
.There's some trickiness to how you offset the pointer to get the aligned version (even if it didn't have the "do not rely on this for correctness" caveat,
align_offset
is not quite right -- we need to ensure we have space for the real pointer).A totally rough/untested sketch that punts on realloc: https://gist.github.com/thomcc/d3ce63c4f592cc5be6f894234c4e220b.