heap: heap_caps_malloc(..., MALLOC_CAP_32_BIT) should always align a 32-bit aligned size
Fixes crash in heap poisoning code if a non-32bit-aligned size is specified.
This commit is contained in:
parent
9d2f7c60d9
commit
ae59d7522a
1 changed files with 8 additions and 1 deletions
|
@ -75,9 +75,16 @@ IRAM_ATTR void *heap_caps_malloc( size_t size, uint32_t caps )
|
||||||
if ((caps & MALLOC_CAP_8BIT) || (caps & MALLOC_CAP_DMA)) {
|
if ((caps & MALLOC_CAP_8BIT) || (caps & MALLOC_CAP_DMA)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
//If any, EXEC memory should be 32-bit aligned, so round up to the next multiple of 4.
|
caps |= MALLOC_CAP_32BIT; // IRAM is 32-bit accessible RAM
|
||||||
|
}
|
||||||
|
|
||||||
|
if (caps & MALLOC_CAP_32BIT) {
|
||||||
|
/* 32-bit accessible RAM should allocated in 4 byte aligned sizes
|
||||||
|
* (Future versions of ESP-IDF should possibly fail if an invalid size is requested)
|
||||||
|
*/
|
||||||
size = (size + 3) & (~3);
|
size = (size + 3) & (~3);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int prio = 0; prio < SOC_MEMORY_TYPE_NO_PRIOS; prio++) {
|
for (int prio = 0; prio < SOC_MEMORY_TYPE_NO_PRIOS; prio++) {
|
||||||
//Iterate over heaps and check capabilities at this priority
|
//Iterate over heaps and check capabilities at this priority
|
||||||
heap_t *heap;
|
heap_t *heap;
|
||||||
|
|
Loading…
Reference in a new issue