mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-18 00:10:08 +01:00
heap: pushed down all the aligned_alloc / free implementation
This commit is contained in:
@@ -472,20 +472,20 @@ void *multi_heap_malloc_impl(multi_heap_handle_t heap, size_t size)
|
||||
|
||||
void *multi_heap_aligned_alloc_impl(multi_heap_handle_t heap, size_t size, size_t alignment)
|
||||
{
|
||||
if(heap == NULL) {
|
||||
if (heap == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!size) {
|
||||
if (!size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(!alignment) {
|
||||
if (!alignment) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//Alignment must be a power of two...
|
||||
if((alignment & (alignment - 1)) != 0) {
|
||||
if ((alignment & (alignment - 1)) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -493,7 +493,7 @@ void *multi_heap_aligned_alloc_impl(multi_heap_handle_t heap, size_t size, size_
|
||||
|
||||
multi_heap_internal_lock(heap);
|
||||
void *head = multi_heap_malloc_impl(heap, size + overhead);
|
||||
if(head == NULL) {
|
||||
if (head == NULL) {
|
||||
multi_heap_internal_unlock(heap);
|
||||
return NULL;
|
||||
}
|
||||
@@ -510,13 +510,18 @@ void *multi_heap_aligned_alloc_impl(multi_heap_handle_t heap, size_t size, size_
|
||||
|
||||
void multi_heap_aligned_free_impl(multi_heap_handle_t heap, void *p)
|
||||
{
|
||||
if(p == NULL) {
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
multi_heap_internal_lock(heap);
|
||||
uint32_t offset = *((uint32_t *)p - 1);
|
||||
void *block_head = (void *)((uint8_t *)p - offset);
|
||||
|
||||
#ifdef MULTI_HEAP_POISONING_SLOW
|
||||
multi_heap_internal_poison_fill_region(block_head, multi_heap_get_allocated_size_impl(heap, block_head), true /* free */);
|
||||
#endif
|
||||
|
||||
multi_heap_free_impl(heap, block_head);
|
||||
multi_heap_internal_unlock(heap);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user