mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
Merge branch 'fix/missing-block-owner-in-heap-init-alloc_v5.2' into 'release/v5.2'
fix(heap): Add block owner to allocs in heap_caps_init() (backport v5.2) See merge request espressif/esp-idf!30215
This commit is contained in:
@ -61,7 +61,7 @@ void heap_caps_init(void)
|
|||||||
num_regions = soc_get_available_memory_regions(regions);
|
num_regions = soc_get_available_memory_regions(regions);
|
||||||
|
|
||||||
// the following for loop will calculate the number of possible heaps
|
// the following for loop will calculate the number of possible heaps
|
||||||
// based on how many regions were coalesed.
|
// based on how many regions were coalesced.
|
||||||
size_t num_heaps = num_regions;
|
size_t num_heaps = num_regions;
|
||||||
|
|
||||||
//The heap allocator will treat every region given to it as separate. In order to get bigger ranges of contiguous memory,
|
//The heap allocator will treat every region given to it as separate. In order to get bigger ranges of contiguous memory,
|
||||||
@ -75,7 +75,7 @@ void heap_caps_init(void)
|
|||||||
b->size += a->size;
|
b->size += a->size;
|
||||||
|
|
||||||
// remove one heap from the number of heaps as
|
// remove one heap from the number of heaps as
|
||||||
// 2 regions just got coalesed.
|
// 2 regions just got coalesced.
|
||||||
num_heaps--;
|
num_heaps--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,14 +124,19 @@ void heap_caps_init(void)
|
|||||||
heap_t *heaps_array = NULL;
|
heap_t *heaps_array = NULL;
|
||||||
for (size_t i = 0; i < num_heaps; i++) {
|
for (size_t i = 0; i < num_heaps; i++) {
|
||||||
if (heap_caps_match(&temp_heaps[i], MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL)) {
|
if (heap_caps_match(&temp_heaps[i], MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL)) {
|
||||||
/* use the first DRAM heap which can fit the data */
|
/* use the first DRAM heap which can fit the data.
|
||||||
heaps_array = multi_heap_malloc(temp_heaps[i].heap, sizeof(heap_t) * num_heaps);
|
* the allocated block won't include the block owner bytes since this operation
|
||||||
|
* is done by the top level API heap_caps_malloc(). So we need to add it manually
|
||||||
|
* after successful allocation. Allocate extra 4 bytes for that purpose. */
|
||||||
|
heaps_array = multi_heap_malloc(temp_heaps[i].heap, MULTI_HEAP_ADD_BLOCK_OWNER_SIZE(sizeof(heap_t) * num_heaps));
|
||||||
if (heaps_array != NULL) {
|
if (heaps_array != NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(heaps_array != NULL); /* if NULL, there's not enough free startup heap space */
|
assert(heaps_array != NULL); /* if NULL, there's not enough free startup heap space */
|
||||||
|
MULTI_HEAP_SET_BLOCK_OWNER(heaps_array);
|
||||||
|
heaps_array = (heap_t *)MULTI_HEAP_ADD_BLOCK_OWNER_OFFSET(heaps_array);
|
||||||
|
|
||||||
memcpy(heaps_array, temp_heaps, sizeof(heap_t)*num_heaps);
|
memcpy(heaps_array, temp_heaps, sizeof(heap_t)*num_heaps);
|
||||||
|
|
||||||
@ -178,7 +183,7 @@ bool heap_caps_check_add_region_allowed(intptr_t heap_start, intptr_t heap_end,
|
|||||||
* cannot be added twice. In fact, registering the same memory region as a heap twice
|
* cannot be added twice. In fact, registering the same memory region as a heap twice
|
||||||
* would cause a corruption and then an exception at runtime.
|
* would cause a corruption and then an exception at runtime.
|
||||||
*
|
*
|
||||||
* the existing heap region s(tart) e(nd)
|
* the existing heap region start end
|
||||||
* |----------------------|
|
* |----------------------|
|
||||||
*
|
*
|
||||||
* 1.add region (e1<s) |-----| correct: bool condition_1 = end < heap_start;
|
* 1.add region (e1<s) |-----| correct: bool condition_1 = end < heap_start;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -49,6 +49,16 @@ static void check_heap_task_info(TaskHandle_t taskHdl)
|
|||||||
// heap_caps_get_per_task_info includes the size of the block owner (4 bytes)
|
// heap_caps_get_per_task_info includes the size of the block owner (4 bytes)
|
||||||
TEST_ASSERT(heap_info.totals[i].size[0] == ALLOC_BYTES + 4);
|
TEST_ASSERT(heap_info.totals[i].size[0] == ALLOC_BYTES + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test that if not 0, the task handle corresponds to an actual task.
|
||||||
|
// this test is to make sure no rubbish is stored as a task handle.
|
||||||
|
if (heap_info.totals[i].task != 0) {
|
||||||
|
// feeding the task name returned by pcTaskGetName() to xTaskGetHandle().
|
||||||
|
// xTaskGetHandle would return the task handler used as parameter in
|
||||||
|
// pcTaskGetName if the task handle is valid. Otherwise, it will return
|
||||||
|
// NULL or just crash if the pointer to the task name is complete nonsense.
|
||||||
|
TEST_ASSERT_EQUAL(heap_info.totals[i].task, xTaskGetHandle(pcTaskGetName(heap_info.totals[i].task)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TEST_ASSERT_TRUE(task_found);
|
TEST_ASSERT_TRUE(task_found);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user