1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:14:58 +00:00

LibC: Implement posix_memalign(3) and aligned_alloc(3)

Some ports linked against posix_memalign, but didn't use it, and others
used it if it was Available. So I decided to implement posix_memalign.

My implementation adds almost no overhead to regular mallocs. However,
if an alignment is specified, it will use the smallest ChunkedBlock, for
which aligned chunks exist, and simply use one of the chunks that is
aligned. If it cannot use a ChunkedBlock, for size or alignment reasons,
it will use a BigAllocationBlock, and return a pointer to the first
aligned address past the start of the block. This implementation
supports alignments up to 32768, due to the limitations of the
BigAllocationBlock technique.
This commit is contained in:
Peter Elliott 2022-05-04 23:08:57 -06:00 committed by Andreas Kling
parent 830f5c610d
commit 4e0adb638d
4 changed files with 172 additions and 60 deletions

View file

@ -1335,14 +1335,3 @@ void _Exit(int status)
{
_exit(status);
}
#ifdef SERENITY_LIBC_SHOW_POSIX_MEMALIGN
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_memalign.html
int posix_memalign(void** memptr, size_t alignment, size_t size)
{
(void)memptr;
(void)alignment;
(void)size;
TODO();
}
#endif