diff --git a/runtime/include/current_sandbox.h b/runtime/include/current_sandbox.h index 7d09dfb..8c0bdb5 100644 --- a/runtime/include/current_sandbox.h +++ b/runtime/include/current_sandbox.h @@ -1,8 +1,10 @@ #ifndef SFRT_CURRENT_SANDBOX_H #define SFRT_CURRENT_SANDBOX_H -#include -#include +#include "sandbox.h" +#include "types.h" + +extern http_parser_settings runtime__http_parser_settings; /** * Getter for the current sandbox executing on this thread @@ -65,7 +67,6 @@ current_sandbox__initialize_io_handle_and_set_file_descriptor(int file_descripto return sandbox__initialize_io_handle_and_set_file_descriptor(sandbox, file_descriptor); } -extern http_parser_settings global__http_parser_settings; int sandbox__parse_http_request(struct sandbox *sandbox, size_t l); /** diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index 552eda7..04f87a6 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -8,10 +8,10 @@ #include "sandbox.h" #include "types.h" -extern int epoll_file_descriptor; -extern struct deque_sandbox *global_deque; -extern pthread_mutex_t global_deque_mutex; -extern __thread uv_loop_t uvio_handle; +extern int runtime__epoll_file_descriptor; +extern struct deque_sandbox *runtime__global_deque; +extern pthread_mutex_t runtime__global_deque_mutex; +extern __thread uv_loop_t runtime__uvio_handle; void alloc_linear_memory(void); void expand_memory(void); @@ -62,7 +62,7 @@ get_memory_string(u32 offset) static inline uv_loop_t * get_thread_libuv_handle(void) { - return &uvio_handle; + return &runtime__uvio_handle; } #endif /* SFRT_RUNTIME_H */ diff --git a/runtime/include/sandbox_request.h b/runtime/include/sandbox_request.h index 55ab577..03ab66c 100644 --- a/runtime/include/sandbox_request.h +++ b/runtime/include/sandbox_request.h @@ -1,11 +1,11 @@ #ifndef SFRT_SANDBOX_REQUEST_H #define SFRT_SANDBOX_REQUEST_H -#include "types.h" #include "deque.h" +#include "types.h" -extern struct deque_sandbox *global_deque; -extern pthread_mutex_t global_deque_mutex; +extern struct deque_sandbox *runtime__global_deque; +extern pthread_mutex_t runtime__global_deque_mutex; struct sandbox_request { struct module * module; @@ -28,11 +28,11 @@ sandbox_request__add_to_global_dequeue(sandbox_request_t *sandbox_request) int return_code; #if NCORES == 1 - pthread_mutex_lock(&global_deque_mutex); + pthread_mutex_lock(&runtime__global_deque_mutex); #endif - return_code = deque_push_sandbox(global_deque, &sandbox_request); + return_code = deque_push_sandbox(runtime__global_deque, &sandbox_request); #if NCORES == 1 - pthread_mutex_unlock(&global_deque_mutex); + pthread_mutex_unlock(&runtime__global_deque_mutex); #endif return return_code; @@ -73,11 +73,11 @@ sandbox_request__pop_from_global_dequeue(sandbox_request_t **sandbox_request) int return_code; #if NCORES == 1 - pthread_mutex_lock(&global_deque_mutex); + pthread_mutex_lock(&runtime__global_deque_mutex); #endif - return_code = deque_pop_sandbox(global_deque, sandbox_request); + return_code = deque_pop_sandbox(runtime__global_deque, sandbox_request); #if NCORES == 1 - pthread_mutex_unlock(&global_deque_mutex); + pthread_mutex_unlock(&runtime__global_deque_mutex); #endif return return_code; } @@ -94,7 +94,7 @@ sandbox_request__steal_from_global_dequeue(void) #if NCORES == 1 sandbox_request__pop_from_global_dequeue(&sandbox_request); #else - int r = deque_steal_sandbox(global_deque, &sandbox_request); + int r = deque_steal_sandbox(runtime__global_deque, &sandbox_request); if (r) sandbox_request = NULL; #endif diff --git a/runtime/src/module.c b/runtime/src/module.c index bb35c70..606e420 100644 --- a/runtime/src/module.c +++ b/runtime/src/module.c @@ -50,7 +50,7 @@ module__initialize_as_server(struct module *module) struct epoll_event accept_evt; accept_evt.data.ptr = (void *)module; accept_evt.events = EPOLLIN; - if (epoll_ctl(epoll_file_descriptor, EPOLL_CTL_ADD, module->socket_descriptor, &accept_evt) < 0) assert(0); + if (epoll_ctl(runtime__epoll_file_descriptor, EPOLL_CTL_ADD, module->socket_descriptor, &accept_evt) < 0) assert(0); } /*************************************** diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index cb9bf5f..a474c25 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -19,10 +19,10 @@ * Shared Process State * **************************/ -struct deque_sandbox *global_deque; -pthread_mutex_t global_deque_mutex = PTHREAD_MUTEX_INITIALIZER; -int epoll_file_descriptor; -http_parser_settings global__http_parser_settings; +struct deque_sandbox *runtime__global_deque; +pthread_mutex_t runtime__global_deque_mutex = PTHREAD_MUTEX_INITIALIZER; +int runtime__epoll_file_descriptor; +http_parser_settings runtime__http_parser_settings; /****************************************** * Shared Process / Listener Thread Logic * @@ -34,22 +34,22 @@ http_parser_settings global__http_parser_settings; void initialize_runtime(void) { - epoll_file_descriptor = epoll_create1(0); - assert(epoll_file_descriptor >= 0); + runtime__epoll_file_descriptor = epoll_create1(0); + assert(runtime__epoll_file_descriptor >= 0); // Allocate and Initialize the global deque - global_deque = (struct deque_sandbox *)malloc(sizeof(struct deque_sandbox)); - assert(global_deque); + runtime__global_deque = (struct deque_sandbox *)malloc(sizeof(struct deque_sandbox)); + assert(runtime__global_deque); // Note: Below is a Macro - deque_init_sandbox(global_deque, SBOX_MAX_REQS); + deque_init_sandbox(runtime__global_deque, SBOX_MAX_REQS); // Mask Signals softint__mask(SIGUSR1); softint__mask(SIGALRM); // Initialize http_parser_settings global - http_parser_settings__initialize(&global__http_parser_settings); - http_parser_settings__register_callbacks(&global__http_parser_settings); + http_parser_settings__initialize(&runtime__http_parser_settings); + http_parser_settings__register_callbacks(&runtime__http_parser_settings); } /******************************** @@ -63,7 +63,7 @@ initialize_runtime(void) * @return NULL * * Used Globals: - * epoll_file_descriptor - the epoll file descriptor + * runtime__epoll_file_descriptor - the epoll file descriptor * */ void * @@ -73,7 +73,7 @@ listener_thread_main(void *dummy) int total_requests = 0; while (true) { - int request_count = epoll_wait(epoll_file_descriptor, epoll_events, EPOLL_MAX, -1); + int request_count = epoll_wait(runtime__epoll_file_descriptor, epoll_events, EPOLL_MAX, -1); u64 start_time = util__rdtsc(); for (int i = 0; i < request_count; i++) { if (epoll_events[i].events & EPOLLERR) { @@ -151,7 +151,7 @@ __thread arch_context_t *next_context = NULL; __thread arch_context_t base_context; // libuv i/o loop handle per sandboxing thread! -__thread uv_loop_t uvio_handle; +__thread uv_loop_t runtime__uvio_handle; // Flag to signify if the thread is currently running callbacks in the libuv event loop static __thread unsigned int in_callback; @@ -419,7 +419,7 @@ worker_thread_main(void *return_code) softint__unmask(SIGALRM); softint__unmask(SIGUSR1); #endif - uv_loop_init(&uvio_handle); + uv_loop_init(&runtime__uvio_handle); in_callback = 0; while (true) { diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index a60e399..403f65c 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -47,14 +47,14 @@ current_sandbox__setup_arguments(i32 argument_count) * @param length The size of the request_response_data that we want to parse * @returns 0 * - * Globals: global__http_parser_settings + * Globals: runtime__http_parser_settings **/ int sandbox__parse_http_request(struct sandbox *sandbox, size_t length) { // Why is our start address sandbox->request_response_data + sandbox->request_response_data_length? // it's like a cursor to keep track of what we've read so far - http_parser_execute(&sandbox->http_parser, &global__http_parser_settings, sandbox->request_response_data + sandbox->request_response_data_length, length); + http_parser_execute(&sandbox->http_parser, &runtime__http_parser_settings, sandbox->request_response_data + sandbox->request_response_data_length, length); return 0; }