mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 04:27:45 +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:
parent
830f5c610d
commit
4e0adb638d
4 changed files with 172 additions and 60 deletions
|
@ -139,9 +139,6 @@ set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ELF_SOURCES} ${ASM_SOURCES})
|
|||
# Prevent GCC from removing null checks by marking the `FILE*` argument non-null
|
||||
set_source_files_properties(stdio.cpp PROPERTIES COMPILE_FLAGS "-fno-builtin-fputc -fno-builtin-fputs -fno-builtin-fwrite")
|
||||
|
||||
# Add in the `posix_memalign` symbol to avoid breaking existing binaries.
|
||||
set_source_files_properties(stdlib.cpp PROPERTIES COMPILE_FLAGS "-DSERENITY_LIBC_SHOW_POSIX_MEMALIGN")
|
||||
|
||||
# Prevent naively implemented string functions (like strlen) from being "optimized" into a call to themselves.
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set_source_files_properties(string.cpp wchar.cpp PROPERTIES COMPILE_FLAGS "-fno-tree-loop-distribution -fno-tree-loop-distribute-patterns")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue