kernel: Add CONFIG_MEM_SLAB_POINTER_VALIDATE

Makes the validation of both allocated memory slab pointer and the
memory slab pointer to free configurable.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
This commit is contained in:
Peter Mitsis 2024-12-11 14:00:29 -08:00 committed by Benjamin Cabé
commit 869acdbbab
2 changed files with 11 additions and 0 deletions

View file

@ -677,6 +677,13 @@ config POLL
concurrently, which can be either directly triggered or triggered by
the availability of some kernel objects (semaphores and FIFOs).
config MEM_SLAB_POINTER_VALIDATE
bool "Validate the memory slab pointer when allocating or freeing"
default ASSERT
help
This enables additional runtime checks to validate the memory slab
pointer during when allocating or freeing a memory slab.
config MEM_SLAB_TRACE_MAX_UTILIZATION
bool "Getting maximum slab utilization"
help

View file

@ -206,6 +206,10 @@ out:
static bool slab_ptr_is_good(struct k_mem_slab *slab, const void *ptr)
{
if (!IS_ENABLED(CONFIG_MEM_SLAB_POINTER_VALIDATE)) {
return true;
}
const char *p = ptr;
ptrdiff_t offset = p - slab->buffer;