From 094fe05bdd68332fa617df8a98858e324afa15ec Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 25 Mar 2020 13:40:48 -0500 Subject: [PATCH] allow retrieving info about a supervisor allocation --- supervisor/memory.h | 1 + supervisor/shared/memory.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/supervisor/memory.h b/supervisor/memory.h index f557744ae5..f4359ca46e 100755 --- a/supervisor/memory.h +++ b/supervisor/memory.h @@ -43,6 +43,7 @@ typedef struct { void memory_init(void); void free_memory(supervisor_allocation* allocation); +supervisor_allocation* allocation_from_ptr(void *ptr); supervisor_allocation* allocate_remaining_memory(void); // Allocate a piece of a given length in bytes. If high_address is true then it should be allocated diff --git a/supervisor/shared/memory.c b/supervisor/shared/memory.c index 14c3b4979b..51037bd6d8 100755 --- a/supervisor/shared/memory.c +++ b/supervisor/shared/memory.c @@ -82,6 +82,15 @@ void free_memory(supervisor_allocation* allocation) { allocation->ptr = NULL; } +supervisor_allocation* allocation_from_ptr(void *ptr) { + for (size_t index = 0; index < CIRCUITPY_SUPERVISOR_ALLOC_COUNT; index++) { + if (allocations[index].ptr == ptr) { + return &allocations[index]; + } + } + return NULL; +} + supervisor_allocation* allocate_remaining_memory(void) { if (low_address == high_address) { return NULL;