Skip to content

Commit

Permalink
runtime: Flush queue before exiting process in permissive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrtonm committed Oct 9, 2024
1 parent 239330a commit 504ba14
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions runtime/libia2/include/permissive_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,22 @@ void print_address(FILE *log, char *identifier, void *addr) {
}
}

void flush_queue(FILE *log) {
// Ensure the sighandler isn't pushing onto the queue
struct queue *q = get_queue();
mpk_err err;
// Pop everything currently in the queue
while (pop_queue(q, &err)) {
print_address(log, "addr", (void *)err.addr);
print_address(log, "val", (void *)err.val);
print_address(log, "pc", (void *)err.pc);
print_address(log, "sp", (void *)err.sp);
print_address(log, "fp", (void *)err.fp);
fprintf(log, "pkru: %x\n", err.pkru);
}
release_queue(q);
}

// The main function in the logging thread
void *log_mpk_violations(void *arg) {
/* Explicitly enter compartment 1, because this function isn't wrapped. */
Expand All @@ -368,21 +384,10 @@ void *log_mpk_violations(void *arg) {
// We don't want this thread to just spin if nothing is happening
sleep(1);

// Ensure the sighandler isn't pushing onto the queue
struct queue *q = get_queue();
mpk_err err;
// Pop everything currently in the queue
while (pop_queue(q, &err)) {
print_address(log, "addr", (void *)err.addr);
print_address(log, "val", (void *)err.val);
print_address(log, "pc", (void *)err.pc);
print_address(log, "sp", (void *)err.sp);
print_address(log, "fp", (void *)err.fp);
fprintf(log, "pkru: %x\n", err.pkru);
}
release_queue(q);
flush_queue(log);

if (exiting) {
flush_queue(log);
fclose(log);
return NULL;
}
Expand Down

0 comments on commit 504ba14

Please sign in to comment.