allow retrieving info about a supervisor allocation

This commit is contained in:
Jeff Epler 2020-03-25 13:40:48 -05:00 committed by Jeff Epler
parent 8cba145c90
commit 094fe05bdd
2 changed files with 10 additions and 0 deletions

View File

@ -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

View File

@ -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;