summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2022-05-03 13:01:14 +0200
committerAndreas Kling <kling@serenityos.org>2022-05-03 21:53:19 +0200
commitdcd76db319a59a02eb2f4092e428c8624351ecec (patch)
treef6ab5cf2417fc41d6760a85365305c43caca0831
parent45995aaeb638a7cd08f71dd48e91e3049261d036 (diff)
downloadserenity-dcd76db319a59a02eb2f4092e428c8624351ecec.zip
LibC: Hide `posix_memalign` by default
This should keep ports from preferring `posix_memalign` over other implementations of aligned memory.
-rw-r--r--Userland/Libraries/LibC/CMakeLists.txt3
-rw-r--r--Userland/Libraries/LibC/stdlib.cpp2
-rw-r--r--Userland/Libraries/LibC/stdlib.h5
3 files changed, 10 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/CMakeLists.txt b/Userland/Libraries/LibC/CMakeLists.txt
index ad7dc31b3c..2842d32fe0 100644
--- a/Userland/Libraries/LibC/CMakeLists.txt
+++ b/Userland/Libraries/LibC/CMakeLists.txt
@@ -139,6 +139,9 @@ 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")
+
add_library(LibCStaticWithoutDeps STATIC ${SOURCES})
target_link_libraries(LibCStaticWithoutDeps PUBLIC ssp LibTimeZone PRIVATE NoCoverage)
add_dependencies(LibCStaticWithoutDeps LibM LibSystem LibUBSanitizer)
diff --git a/Userland/Libraries/LibC/stdlib.cpp b/Userland/Libraries/LibC/stdlib.cpp
index 18af5fe9e6..bd21c87fa7 100644
--- a/Userland/Libraries/LibC/stdlib.cpp
+++ b/Userland/Libraries/LibC/stdlib.cpp
@@ -1336,6 +1336,7 @@ 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)
{
@@ -1344,3 +1345,4 @@ int posix_memalign(void** memptr, size_t alignment, size_t size)
(void)size;
TODO();
}
+#endif
diff --git a/Userland/Libraries/LibC/stdlib.h b/Userland/Libraries/LibC/stdlib.h
index 3ea05e6c0c..2b38dc6590 100644
--- a/Userland/Libraries/LibC/stdlib.h
+++ b/Userland/Libraries/LibC/stdlib.h
@@ -101,6 +101,11 @@ int posix_openpt(int flags);
int grantpt(int fd);
int unlockpt(int fd);
+// FIXME: Remove the ifdef once we have a working memalign implementation.
+// This is hidden by default until then because many applications prefer
+// `posix_memalign` over other implementations of aligned memory.
+#ifdef SERENITY_LIBC_SHOW_POSIX_MEMALIGN
int posix_memalign(void**, size_t alignment, size_t size);
+#endif
__END_DECLS