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
This commit is contained in:
@@ -562,7 +562,7 @@ guarded_heap_realloc(void* address, size_t newSize)
|
|||||||
if (oldSize == newSize)
|
if (oldSize == newSize)
|
||||||
return address;
|
return address;
|
||||||
|
|
||||||
void* newBlock = memalign(0, newSize);
|
void* newBlock = malloc(newSize);
|
||||||
if (newBlock == NULL)
|
if (newBlock == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -974,7 +974,7 @@ realloc(void* address, size_t newSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (address == NULL)
|
if (address == NULL)
|
||||||
return memalign(0, newSize);
|
return malloc(newSize);
|
||||||
|
|
||||||
return guarded_heap_realloc(address, newSize);
|
return guarded_heap_realloc(address, newSize);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1864,7 +1864,7 @@ heap_realloc(heap_allocator *heap, void *address, void **newAddress,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// if not, allocate a new chunk of memory
|
// if not, allocate a new chunk of memory
|
||||||
*newAddress = memalign(0, newSize);
|
*newAddress = malloc(newSize);
|
||||||
T(Reallocate((addr_t)address, (addr_t)*newAddress, newSize));
|
T(Reallocate((addr_t)address, (addr_t)*newAddress, newSize));
|
||||||
if (*newAddress == NULL) {
|
if (*newAddress == NULL) {
|
||||||
// we tried but it didn't work out, but still the operation is done
|
// 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 *
|
void *
|
||||||
malloc(size_t size)
|
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)
|
if (address == NULL)
|
||||||
return memalign(0, newSize);
|
return malloc(newSize);
|
||||||
|
|
||||||
if (newSize == 0) {
|
if (newSize == 0) {
|
||||||
free(address);
|
free(address);
|
||||||
@@ -2455,7 +2455,7 @@ realloc(void *address, size_t newSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// have to allocate/copy/free - TODO maybe resize the area instead?
|
// have to allocate/copy/free - TODO maybe resize the area instead?
|
||||||
newAddress = memalign(0, newSize);
|
newAddress = malloc(newSize);
|
||||||
if (newAddress == NULL) {
|
if (newAddress == NULL) {
|
||||||
dprintf("realloc(): failed to allocate new block of %ld bytes\n",
|
dprintf("realloc(): failed to allocate new block of %ld bytes\n",
|
||||||
newSize);
|
newSize);
|
||||||
@@ -2482,7 +2482,7 @@ realloc(void *address, size_t newSize)
|
|||||||
void *
|
void *
|
||||||
calloc(size_t numElements, size_t size)
|
calloc(size_t numElements, size_t size)
|
||||||
{
|
{
|
||||||
void *address = memalign(0, numElements * size);
|
void *address = malloc(numElements * size);
|
||||||
if (address != NULL)
|
if (address != NULL)
|
||||||
memset(address, 0, numElements * size);
|
memset(address, 0, numElements * size);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user