From eca987ccb405c2ee720b9d7a699d8fe1a659e56a Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Thu, 9 Jul 2020 18:38:45 -0400 Subject: [PATCH] fix: correct valgrind errors --- runtime/include/runtime.h | 1 + runtime/src/main.c | 8 +++++--- runtime/src/module.c | 5 ++--- runtime/src/software_interrupt.c | 8 +++++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index 668da81..b8d20a5 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -4,6 +4,7 @@ #include "types.h" extern int runtime_epoll_file_descriptor; +extern u32 runtime_total_worker_processors; void alloc_linear_memory(void); void expand_memory(void); diff --git a/runtime/src/main.c b/runtime/src/main.c index f68d727..d4547d1 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -84,14 +84,16 @@ runtime_allocate_available_cores() runtime_total_worker_processors = max_possible_workers; if (max_possible_workers >= WORKER_THREAD_CORE_COUNT) runtime_total_worker_processors = WORKER_THREAD_CORE_COUNT; + + assert(runtime_total_worker_processors == WORKER_THREAD_CORE_COUNT); } else { /* If single core, we'll do everything on CPUID 0 */ runtime_first_worker_processor = 0; runtime_total_worker_processors = 1; } - debuglog("Number of cores %u, sandboxing cores %u (start: %u) and module reqs %u\n", - runtime_total_online_processors, runtime_total_worker_processors, runtime_first_worker_processor, - LISTENER_THREAD_CORE_ID); + printf("Number of cores %u, sandboxing cores %u (start: %u) and module reqs %u\n", + runtime_total_online_processors, runtime_total_worker_processors, runtime_first_worker_processor, + LISTENER_THREAD_CORE_ID); } /** diff --git a/runtime/src/module.c b/runtime/src/module.c index cdb9383..eeef835 100644 --- a/runtime/src/module.c +++ b/runtime/src/module.c @@ -257,8 +257,7 @@ module_new_from_json(char *file_name) fprintf(stderr, "Attempt to read %s into buffer failed: %s\n", file_name, strerror(errno)); goto fread_err; } - - assert(strlen(file_buffer) > 1); + assert(total_chars_read > 0); /* Close the file */ errno = 0; @@ -274,7 +273,7 @@ module_new_from_json(char *file_name) jsmntok_t tokens[JSON_MAX_ELEMENT_SIZE * JSON_MAX_ELEMENT_COUNT]; /* Use Jasmine to parse the JSON */ - int total_tokens = jsmn_parse(&module_parser, file_buffer, strlen(file_buffer), tokens, + int total_tokens = jsmn_parse(&module_parser, file_buffer, total_chars_read, tokens, sizeof(tokens) / sizeof(tokens[0])); if (total_tokens < 0) { if (total_tokens == JSMN_ERROR_INVAL) { diff --git a/runtime/src/software_interrupt.c b/runtime/src/software_interrupt.c index 5dfcb25..f8811f2 100644 --- a/runtime/src/software_interrupt.c +++ b/runtime/src/software_interrupt.c @@ -11,6 +11,7 @@ #include "current_sandbox.h" #include "local_runqueue.h" #include "module.h" +#include "runtime.h" #include "sandbox.h" #include "software_interrupt.h" #include "types.h" @@ -66,9 +67,10 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void /* A POSIX signal is delivered to one of the threads in our process.If sent by the kernel, "broadcast" * by forwarding to all all threads */ if (signal_info->si_code == SI_KERNEL) { - for (int i = 0; i < WORKER_THREAD_CORE_COUNT; i++) { - if (pthread_self() == runtime_worker_threads[i]) continue; - pthread_kill(runtime_worker_threads[i], SIGALRM); + for (int i = 0; i < runtime_total_worker_processors; i++) { + if (pthread_self() != runtime_worker_threads[i]) { + pthread_kill(runtime_worker_threads[i], SIGALRM); + } } } else { /* If not sent by the kernel, this should be a signal forwarded from another thread */