fix(heap): Tracing of all heap_caps API

This commit fixes the missing tracing on all
heap_caps_xx_prefer and heap_caps_xx_aligned
functions.
This commit is contained in:
Guillaume Souchere
2024-03-08 13:58:13 +01:00
parent 96c81c87bf
commit dd1dde5fb9
5 changed files with 350 additions and 386 deletions

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -11,6 +11,7 @@
#include "multi_heap.h"
#include "multi_heap_platform.h"
#include "sys/queue.h"
#include "esp_attr.h"
#ifdef __cplusplus
extern "C" {
@@ -43,7 +44,7 @@ extern SLIST_HEAD(registered_heap_ll, heap_t_) registered_heaps;
bool heap_caps_match(const heap_t *heap, uint32_t caps);
/* return all possible capabilities (across all priorities) for a given heap */
inline static uint32_t get_all_caps(const heap_t *heap)
FORCE_INLINE_ATTR uint32_t get_all_caps(const heap_t *heap)
{
if (heap->heap == NULL) {
return 0;
@@ -55,6 +56,24 @@ inline static uint32_t get_all_caps(const heap_t *heap)
return all_caps;
}
/* Find the heap which belongs to ptr, or return NULL if it's
not in any heap.
(This confirms if ptr is inside the heap's region, doesn't confirm if 'ptr'
is an allocated block or is some other random address inside the heap.)
*/
FORCE_INLINE_ATTR heap_t *find_containing_heap(void *ptr )
{
intptr_t p = (intptr_t)ptr;
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if (heap->heap != NULL && p >= heap->start && p < heap->end) {
return heap;
}
}
return NULL;
}
/*
Because we don't want to add _another_ known allocation method to the stack of functions to trace wrt memory tracing,
these are declared private. The newlib malloc()/realloc() implementation also calls these, so they are declared
@@ -63,7 +82,10 @@ 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);
void *heap_caps_realloc_base(void *ptr, size_t size, uint32_t caps);
void *heap_caps_calloc_base(size_t n, size_t size, uint32_t caps);
void *heap_caps_malloc_base(size_t size, uint32_t caps);
void *heap_caps_aligned_alloc_base(size_t alignment, size_t size, uint32_t caps);
#ifdef __cplusplus
}