From 4e16be4fa06a0e1fdf860d5d3e363d3165cb1219 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 25 Apr 2022 18:14:44 -0400 Subject: [PATCH] kernel: Do not invoke memalign with 0 as the alignment argument. The memalign() function has special semantics for its arguments even when -fno-builtin is enabled, it seems (that may be a problem on Clang's part, however.) The alloc_align attribute, which we apply to the memalign_etc function, does not seem to have the same problems; at least its documentation at GCC gives no indication that 0 is not a legal value to pass. Change-Id: Ie5ba090b924ac3577775165d20f11f9696be97f3 --- src/system/kernel/guarded_heap.cpp | 4 ++-- src/system/kernel/heap.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/system/kernel/guarded_heap.cpp b/src/system/kernel/guarded_heap.cpp index 492f646a39..20b1f7dc40 100644 --- a/src/system/kernel/guarded_heap.cpp +++ b/src/system/kernel/guarded_heap.cpp @@ -562,7 +562,7 @@ guarded_heap_realloc(void* address, size_t newSize) if (oldSize == newSize) return address; - void* newBlock = memalign(0, newSize); + void* newBlock = malloc(newSize); if (newBlock == NULL) return NULL; @@ -974,7 +974,7 @@ realloc(void* address, size_t newSize) } if (address == NULL) - return memalign(0, newSize); + return malloc(newSize); return guarded_heap_realloc(address, newSize); } diff --git a/src/system/kernel/heap.cpp b/src/system/kernel/heap.cpp index bf3dec6d73..9fb146c3b5 100644 --- a/src/system/kernel/heap.cpp +++ b/src/system/kernel/heap.cpp @@ -1864,7 +1864,7 @@ heap_realloc(heap_allocator *heap, void *address, void **newAddress, #endif // if not, allocate a new chunk of memory - *newAddress = memalign(0, newSize); + *newAddress = malloc(newSize); T(Reallocate((addr_t)address, (addr_t)*newAddress, newSize)); if (*newAddress == NULL) { // we tried but it didn't work out, but still the operation is done @@ -2349,7 +2349,7 @@ free_etc(void *address, uint32 flags) void * malloc(size_t size) { - return memalign(0, size); + return memalign_etc(0, size, 0); } @@ -2410,7 +2410,7 @@ realloc(void *address, size_t newSize) } if (address == NULL) - return memalign(0, newSize); + return malloc(newSize); if (newSize == 0) { free(address); @@ -2455,7 +2455,7 @@ realloc(void *address, size_t newSize) } // have to allocate/copy/free - TODO maybe resize the area instead? - newAddress = memalign(0, newSize); + newAddress = malloc(newSize); if (newAddress == NULL) { dprintf("realloc(): failed to allocate new block of %ld bytes\n", newSize); @@ -2482,7 +2482,7 @@ realloc(void *address, size_t newSize) void * calloc(size_t numElements, size_t size) { - void *address = memalign(0, numElements * size); + void *address = malloc(numElements * size); if (address != NULL) memset(address, 0, numElements * size);