kallisti5 / ElectricFence

A debugger which detects memory access violations
GNU General Public License v2.0
31 stars 17 forks source link

Add support for all functions provided by glibc #2

Open tuliom opened 2 weeks ago

tuliom commented 2 weeks ago

C11 added a new memory management function called aligned_alloc.

The lack of this function may cause errors such as https://github.com/zlib-ng/zlib-ng/issues/1809

Keep in mind that glibc provides more function too. A full list is available at: https://www.gnu.org/software/libc/manual/html_node/Replacing-malloc.html#Replacing-malloc

lanurmi commented 2 weeks ago

The fix is actually very simple, and here it is as a patch:

diff -rup ElectricFence-2.2.2/efence.c ElectricFence-2.2.2-build/efence.c
--- ElectricFence-2.2.2/efence.c        2024-11-15 10:41:40.989554003 +0200
+++ ElectricFence-2.2.2-build/efence.c  2024-11-15 10:42:43.287556617 +0200
@@ -968,6 +968,12 @@ calloc(size_t nelem, size_t elsize)
        return allocation;
 }

+extern C_LINKAGE void *
+aligned_alloc(size_t alignment, size_t userSize)
+{
+       return memalign(alignment, userSize);
+}
+
 /*
  * This will catch more bugs if you remove the page alignment, but it
  * will break some software.