From 04030c858a1e0502f212c487dab8d5628d38b949 Mon Sep 17 00:00:00 2001 From: Ayrton Munoz Date: Fri, 4 Oct 2024 18:34:59 -0400 Subject: [PATCH] wip --- runtime/libia2/include/permissive_mode.h | 25 ++++++++++++++++++++++-- runtime/libia2/init.c | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/runtime/libia2/include/permissive_mode.h b/runtime/libia2/include/permissive_mode.h index 350a209fc..faea59cca 100644 --- a/runtime/libia2/include/permissive_mode.h +++ b/runtime/libia2/include/permissive_mode.h @@ -212,7 +212,7 @@ void permissive_mode_handler(int sig, siginfo_t *info, void *ctxt) { static bool exiting IA2_SHARED_DATA = false; // Process-specific name for log file -static char log_name[256] IA2_SHARED_DATA = {0}; +char log_name[256] IA2_SHARED_DATA = {0}; int elfaddr(const void *addr, Dl_info *info) { static struct f { @@ -458,6 +458,7 @@ __attribute__((constructor)) void permissive_mode_init(void) { install_permissive_mode_handler(); } +extern char *ia2_stacks[16]; /* * Constructor to wait for the logging thread to finish and log the memory map. * If a process forks and execve's this function will not be called. @@ -471,7 +472,27 @@ __attribute((destructor)) void wait_logging_thread(void) { assert(maps); char tmp[256] = {0}; while (fgets(tmp, sizeof(tmp), maps)) { - fprintf(log, "%s", tmp); + bool identified = false; + uintptr_t start, end, offset; + int name_pos; + char prot[5] = {0}; + sscanf(tmp, "%lx-%lx %4c %lx %*lx:%*lx %*lu %n", &start, &end, prot, &offset, &name_pos); + fprintf(log, "%08lx-%08lx %s %08lx ", start, end, prot, offset); + if (name_pos != strlen(tmp)) { + fprintf(log, "%s", tmp + name_pos); + identified = true; + } else { + for (int i = 0; i < 16; i++) { + if (start == ia2_stacks[i]) { + fprintf(log, "[stack:tid ?:compartment %d]\n", i); + identified = true; + break; + } + } + } + if (!identified) { + fprintf(log, "TODO: identify this segment\n"); + } memset(tmp, 0, sizeof(tmp)); } fclose(log); diff --git a/runtime/libia2/init.c b/runtime/libia2/init.c index 707efa649..7973226e2 100644 --- a/runtime/libia2/init.c +++ b/runtime/libia2/init.c @@ -10,6 +10,7 @@ extern __thread void *ia2_stackptr_0[PAGE_SIZE / sizeof(void *)] __attribute__((aligned(4096))); +char *ia2_stacks[16] = {0}; /* Allocate a fixed-size stack and protect it with the ith pkey. */ /* Returns the top of the stack, not the base address of the allocation. */ char *allocate_stack(int i) { @@ -26,6 +27,7 @@ char *allocate_stack(int i) { exit(-1); } } + ia2_stacks[i] = stack; /* Each stack frame start + 8 is initially 16-byte aligned. */ return stack + STACK_SIZE - 8; }