Skip to content

Commit 094fe05

Browse files
committed
allow retrieving info about a supervisor allocation
1 parent 8cba145 commit 094fe05

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

supervisor/memory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef struct {
4343

4444
void memory_init(void);
4545
void free_memory(supervisor_allocation* allocation);
46+
supervisor_allocation* allocation_from_ptr(void *ptr);
4647
supervisor_allocation* allocate_remaining_memory(void);
4748

4849
// Allocate a piece of a given length in bytes. If high_address is true then it should be allocated

supervisor/shared/memory.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ void free_memory(supervisor_allocation* allocation) {
8282
allocation->ptr = NULL;
8383
}
8484

85+
supervisor_allocation* allocation_from_ptr(void *ptr) {
86+
for (size_t index = 0; index < CIRCUITPY_SUPERVISOR_ALLOC_COUNT; index++) {
87+
if (allocations[index].ptr == ptr) {
88+
return &allocations[index];
89+
}
90+
}
91+
return NULL;
92+
}
93+
8594
supervisor_allocation* allocate_remaining_memory(void) {
8695
if (low_address == high_address) {
8796
return NULL;

0 commit comments

Comments
 (0)