From 40fa1b0c6d9134815d88670dc61e8c8a7d564fbc Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Thu, 1 Dec 2022 10:34:58 +0100 Subject: [PATCH] gint/kmalloc: show _ostk arena --- src/gint/kmalloc.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/gint/kmalloc.c b/src/gint/kmalloc.c index c675bd3..fa4b3d8 100644 --- a/src/gint/kmalloc.c +++ b/src/gint/kmalloc.c @@ -442,10 +442,30 @@ static void draw_integrity(kmalloc_arena_t *arena) #endif /* GINT_KMALLOC_DEBUG */ } +static char const *arena_names[] = { NULL, "_uram", "_ostk", "_os" }; + +static kmalloc_arena_t *next_arena(int *current) +{ + int n = sizeof arena_names / sizeof arena_names[0]; + int j = *current; + kmalloc_arena_t *arena = NULL; + + do { + j = (j + 1 >= n) ? 0 : j + 1; + char const *name = arena_names[j]; + arena = name ? kmalloc_get_arena(name) : NULL; + } + while(j != *current && !arena); + + *current = j; + return arena; +} + /* gintctl_gint_kmalloc(): Dynamic memory allocator */ void gintctl_gint_kmalloc(void) { - kmalloc_arena_t *arena = kmalloc_get_arena("_uram"); + int current_arena = 0; + kmalloc_arena_t *arena = next_arena(¤t_arena); int tab=0, key=0; /* Data for the manual allocation test */ @@ -510,10 +530,7 @@ void gintctl_gint_kmalloc(void) /* Reset mass test info */ mass_test.done = 0; - if(!strcmp(arena->name, "_os")) - arena = kmalloc_get_arena("_uram"); - else - arena = kmalloc_get_arena("_os"); + arena = next_arena(¤t_arena); } /* Actions on the manual tab */