G'day (or night, as I'm writing this),

On Tuesday, 16 December 2025 at 00:41, Alejandro Colomar <[email protected]> 
wrote:
> Hi!
> 

> In v2, I've removed the explicit sentence saying that one should use
> aligned_alloc(3) instead of memalign(3).
> 

> I've also documented that C11 had a bogus specification for
> aligned_alloc(3), and that OpenBSD still implements that (although at
> least, they don't exploit the UB). I've CCed them, in case they're not
> aware that C17 fixed those issues.
> 

> I've documented that while the C11 specification had a lot of UB, no
> implementation has ever implemented that, and so it's just theoretical
> (and thankfully extinct) UB.

I had a look at FreeBSD's documentation for aligned_alloc(3) - which is
just jemalloc's manual - and it does explicitly specify the C11
undefined behaviour.[1]

"The aligned_alloc() function allocates size bytes of memory such that
the allocation's base address is a multiple of alignment. The requested
alignment must be a power of 2. Behavior is undefined if size is not an
integral multiple of alignment."

However, I have spent a while going over FreeBSD's (jemalloc's)
implementation of aligned_alloc(3), and as far as I can tell, it
appears to work as expected even when size is not a multiple of
alignment. So it seems the man page is just repeating the C11 standard
to conform to it (though the page doesn't specify this conformance,
strangely enough).

Even so, it may be useful to also document FreeBSD's nominal undefined
behaviour in addition to OpenBSD. Perhaps emphasising how jemalloc
doesn't actually exploit this undefined behaviour, and never will given
the project's recent retirement. Thereby meaning the point about C11's
extinct undefined behaviour should still stand.

This would also prevent people (like myself, I imagine) from thinking
that the Linux man page is potentially outdated due to seemingly not
knowing about FreeBSD's (ostensible, but documented) undefined
behaviour.

----
Seth McDonald.
sethmcmail at pm dot me (mailing lists)
2336 E8D2 FEB1 5300 692C  62A9 5839 6AD8 9243 D369

----
[1] 
https://man.freebsd.org/cgi/man.cgi?query=aligned_alloc&sektion=3&manpath=FreeBSD+15.0-RELEASE+and+Ports

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to