fix(heap): memalign respect malloc_alwaysinternal_limit

This changes `memalign` (and `posix_memalign`) so that it uses an
allocation method with the same selection criteria (checking
`malloc_alwaysinternal_limit` and picking one of:

- always MALLOC_CAP_INTERNAL
- MALLOC_CAP_INTERNAL first with fallback
- MALLOC_CAP_SPIRAM first with fallback

`malloc_alwaysinternal_limit` is in turn set by the options
`CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL` and
`CONFIG_SPRIAM_USE_CAPS_ALLOC`.

This notably affects folks using esp-rs to build rust code for the
esp-idf, as all allocations from rust use `memalign`.

Merges https://github.com/espressif/esp-idf/pull/12375
This commit is contained in:
Cody P Schafer
2023-10-06 16:51:26 -04:00
committed by KonstantinKondrashov
parent 283a3d64b9
commit 9e1e245477
4 changed files with 101 additions and 30 deletions

View File

@@ -62,6 +62,7 @@ inline static uint32_t get_all_caps(const heap_t *heap)
*/
void *heap_caps_realloc_default(void *p, size_t size);
void *heap_caps_malloc_default(size_t size);
void *heap_caps_aligned_alloc_default(size_t alignment, size_t size);
#ifdef __cplusplus