From f614a44ee612a8496755e3230d26e4cb1a7c78e4 Mon Sep 17 00:00:00 2001 From: Mike Miller Date: Sat, 11 Nov 2023 18:13:29 -0800 Subject: [PATCH] o code cleanup in jit.c o additional error checking for rusage_get_current() in resource.c --- jit/jit.c | 7 ------- kernel/resource.c | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/jit/jit.c b/jit/jit.c index 75df921f60..39892d053c 100644 --- a/jit/jit.c +++ b/jit/jit.c @@ -30,8 +30,6 @@ struct jit *jit_new(struct mmu *mmu) { return jit; } - - void jit_free(struct jit *jit) { bool signal_pending = !!(current->pending & ~current->blocked); while((critical_region_count(current) > 2) || (locks_held_count(current)) || (current->process_info_being_read) || (signal_pending)) { // Wait for now, task is in one or more critical sections, and/or has locks, or signals in flight @@ -166,21 +164,16 @@ static void jit_block_disconnect(struct jit *jit, struct jit_block *block) { } list_remove(&block->chain); for (int i = 0; i <= 1; i++) { - ////modify_critical_region_counter(current, 1, __FILE__, __LINE__); list_remove(&block->page[i]); list_remove_safe(&block->jumps_from_links[i]); - ////modify_critical_region_counter(current, -1, __FILE__, __LINE__); struct jit_block *prev_block, *tmp; - ////modify_critical_region_counter(current, 1, __FILE__, __LINE__); list_for_each_entry_safe(&block->jumps_from[i], prev_block, tmp, jumps_from_links[i]) { if (prev_block->jump_ip[i] != NULL) *prev_block->jump_ip[i] = prev_block->old_jump_ip[i]; // Crashed here June 12 2022, 19 Nov 2022 list_remove(&prev_block->jumps_from_links[i]); } - - ////modify_critical_region_counter(current, -1, __FILE__, __LINE__); } } diff --git a/kernel/resource.c b/kernel/resource.c index 529c5c334e..64d71f70b9 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -137,14 +137,17 @@ dword_t sys_prlimit64(pid_t_ pid, dword_t resource, addr_t new_limit_addr, addr_ return 0; } -struct rusage_ rusage_get_current() { - // only the time fields are currently implemented +struct rusage_ rusage_get_current(void) { struct rusage_ rusage; - ////modify_critical_region_counter(current, 1, __FILE__, __LINE__); + memset(&rusage, 0, sizeof(rusage)); + #if __linux__ struct rusage usage; - int err = getrusage(RUSAGE_THREAD, &usage); - assert(err == 0); + if (getrusage(RUSAGE_THREAD, &usage) != 0) { + // Handle error appropriately, e.g., log an error or set default values + perror("getrusage failed"); + return rusage; + } rusage.utime.sec = usage.ru_utime.tv_sec; rusage.utime.usec = usage.ru_utime.tv_usec; rusage.stime.sec = usage.ru_stime.tv_sec; @@ -152,16 +155,20 @@ struct rusage_ rusage_get_current() { #elif __APPLE__ thread_basic_info_data_t info; mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; - thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t) &info, &count); + if (thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t) &info, &count) != KERN_SUCCESS) { + // Handle error appropriately + printk("ERROR: thread_info failed (rusage_get_current()\n"); + return rusage; + } rusage.utime.sec = info.user_time.seconds; rusage.utime.usec = info.user_time.microseconds; rusage.stime.sec = info.system_time.seconds; rusage.stime.usec = info.system_time.microseconds; #endif - ////modify_critical_region_counter(current, -1, __FILE__, __LINE__); return rusage; } + static void timeval_add(struct timeval_ *dst, struct timeval_ *src) { dst->sec += src->sec; dst->usec += src->usec;