/* * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ /* * Strong (non-weak) definitions of the heap trace hooks for KASAN. * * IMPORTANT: This file must NOT include esp_heap_caps.h or any header that * transitively includes it (e.g. freertos/idf_additions.h). The reason is * that esp_heap_caps.h declares esp_heap_trace_alloc_hook and * esp_heap_trace_free_hook with __attribute__((weak)), and GCC propagates the * weak attribute to the definition in the same TU. By keeping this file free * of that header we get strong (globally overriding) definitions that the * linker will prefer over the empty weak stubs. * * The actual KASAN logic lives in heap_kasan.c; this file just calls into it. */ #include "sdkconfig.h" #if CONFIG_COMPILER_KASAN && CONFIG_HEAP_USE_HOOKS #include #include #include "esp_kasan.h" /* Forward-declare the real implementation from heap_kasan.c */ void kasan_heap_alloc_impl(void *ptr, size_t size, uint32_t caps); void kasan_heap_free_impl(void *ptr); /* * These definitions are strong because this TU never sees the weak declaration * from esp_heap_caps.h. The linker will therefore use these in preference to * the empty weak stubs generated by the heap component's own code. */ void esp_heap_trace_alloc_hook(void *ptr, size_t size, uint32_t caps) { kasan_heap_alloc_impl(ptr, size, caps); } void esp_heap_trace_free_hook(void *ptr) { kasan_heap_free_impl(ptr); } #endif /* CONFIG_COMPILER_KASAN && CONFIG_HEAP_USE_HOOKS */