From 4d660e666b666b080ab88ce7bbb8bdacb5f38c79 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Thu, 19 Mar 2020 11:40:46 -0400 Subject: [PATCH] chore: de-dunder listener thrd, module, libuv cbs --- runtime/include/libuv_callbacks.h | 12 ++++++------ runtime/include/module.h | 30 +++++++++++++++--------------- runtime/include/runtime.h | 2 +- runtime/src/libc/uvio.c | 2 +- runtime/src/main.c | 4 ++-- runtime/src/module.c | 24 ++++++++++++------------ runtime/src/runtime.c | 6 +++--- runtime/src/sandbox.c | 24 ++++++++++++------------ 8 files changed, 52 insertions(+), 52 deletions(-) diff --git a/runtime/include/libuv_callbacks.h b/runtime/include/libuv_callbacks.h index ad68546..3fe2a61 100644 --- a/runtime/include/libuv_callbacks.h +++ b/runtime/include/libuv_callbacks.h @@ -21,7 +21,7 @@ * @param buffer unused **/ static inline void -libuv_callbacks__on_read_parse_http_request(uv_stream_t *stream, ssize_t number_read, const uv_buf_t *buffer) +libuv_callbacks_on_read_parse_http_request(uv_stream_t *stream, ssize_t number_read, const uv_buf_t *buffer) { struct sandbox *sandbox = stream->data; @@ -43,7 +43,7 @@ libuv_callbacks__on_read_parse_http_request(uv_stream_t *stream, ssize_t number_ * @param stream **/ static inline void -libuv_callbacks__on_close_wakeup_sakebox(uv_handle_t *stream) +libuv_callbacks_on_close_wakeup_sakebox(uv_handle_t *stream) { struct sandbox *sandbox = stream->data; worker_thread__wakeup_sandbox(sandbox); @@ -55,7 +55,7 @@ libuv_callbacks__on_close_wakeup_sakebox(uv_handle_t *stream) * @param status unused in callback **/ static inline void -libuv_callbacks__on_shutdown_wakeup_sakebox(uv_shutdown_t *req, int status) +libuv_callbacks_on_shutdown_wakeup_sakebox(uv_shutdown_t *req, int status) { struct sandbox *sandbox = req->data; worker_thread__wakeup_sandbox(sandbox); @@ -68,20 +68,20 @@ libuv_callbacks__on_shutdown_wakeup_sakebox(uv_shutdown_t *req, int status) * @param status status code **/ static inline void -libuv_callbacks__on_write_wakeup_sandbox(uv_write_t *write, int status) +libuv_callbacks_on_write_wakeup_sandbox(uv_write_t *write, int status) { struct sandbox *sandbox = write->data; if (status < 0) { sandbox->client_libuv_shutdown_request.data = sandbox; uv_shutdown(&sandbox->client_libuv_shutdown_request, (uv_stream_t *)&sandbox->client_libuv_stream, - libuv_callbacks__on_shutdown_wakeup_sakebox); + libuv_callbacks_on_shutdown_wakeup_sakebox); return; } worker_thread__wakeup_sandbox(sandbox); } static inline void -libuv_callbacks__on_allocate_setup_request_response_data(uv_handle_t *h, size_t suggested, uv_buf_t *buf) +libuv_callbacks_on_allocate_setup_request_response_data(uv_handle_t *h, size_t suggested, uv_buf_t *buf) { struct sandbox *sandbox = h->data; size_t l = (sandbox->module->max_request_or_response_size - sandbox->request_response_data_length); diff --git a/runtime/include/module.h b/runtime/include/module.h index 4f43821..57dcd35 100644 --- a/runtime/include/module.h +++ b/runtime/include/module.h @@ -59,7 +59,7 @@ struct module { * @param module **/ static inline void -module__acquire(struct module *module) +module_acquire(struct module *module) { module->reference_count++; } @@ -70,7 +70,7 @@ module__acquire(struct module *module) * @returns the number of arguments **/ static inline i32 -module__get_argument_count(struct module *module) +module_get_argument_count(struct module *module) { return module->argument_count; } @@ -80,7 +80,7 @@ module__get_argument_count(struct module *module) * @param module **/ static inline void -module__initialize_globals(struct module *module) +module_initialize_globals(struct module *module) { // called in a sandbox. module->initialize_globals(); @@ -91,7 +91,7 @@ module__initialize_globals(struct module *module) * @param module **/ static inline void -module__initialize_table(struct module *module) +module_initialize_table(struct module *module) { // called at module creation time (once only per module). module->initialize_tables(); @@ -104,7 +104,7 @@ module__initialize_table(struct module *module) * @param arguments **/ static inline void -module__initialize_libc(struct module *module, i32 env, i32 arguments) +module_initialize_libc(struct module *module, i32 env, i32 arguments) { // called in a sandbox. module->initialize_libc(env, arguments); @@ -115,7 +115,7 @@ module__initialize_libc(struct module *module, i32 env, i32 arguments) * @param module **/ static inline void -module__initialize_memory(struct module *module) +module_initialize_memory(struct module *module) { // called in a sandbox. module->initialize_memory(); @@ -127,7 +127,7 @@ module__initialize_memory(struct module *module) * @return 1 if valid. 0 if invalid **/ static inline int -module__is_valid(struct module *module) +module_is_valid(struct module *module) { if (module && module->dynamic_library_handle && module->main) return 1; return 0; @@ -140,7 +140,7 @@ module__is_valid(struct module *module) * @param argv standard UNIX vector of arguments **/ static inline i32 -module__main(struct module *module, i32 argc, i32 argv) +module_main(struct module *module, i32 argc, i32 argv) { return module->main(argc, argv); } @@ -150,7 +150,7 @@ module__main(struct module *module, i32 argc, i32 argv) * @param module **/ static inline void -module__release(struct module *module) +module_release(struct module *module) { module->reference_count--; } @@ -166,8 +166,8 @@ module__release(struct module *module) * @param response_content_type **/ static inline void -module__set_http_info(struct module *module, int request_count, char *request_headers, char request_content_type[], - int response_count, char *response_headers, char response_content_type[]) +module_set_http_info(struct module *module, int request_count, char *request_headers, char request_content_type[], + int response_count, char *response_headers, char response_content_type[]) { assert(module); module->request_header_count = request_count; @@ -182,9 +182,9 @@ module__set_http_info(struct module *module, int request_count, char *request_he * Public Methods from module.c ***************************************/ -void module__free(struct module *module); -struct module *module__new(char *mod_name, char *mod_path, i32 argument_count, u32 stack_sz, u32 max_heap, u32 timeout, - int port, int req_sz, int resp_sz); -int module__new_from_json(char *filename); +void module_free(struct module *module); +struct module *module_new(char *mod_name, char *mod_path, i32 argument_count, u32 stack_sz, u32 max_heap, u32 timeout, + int port, int req_sz, int resp_sz); +int module_new_from_json(char *filename); #endif /* SFRT_MODULE_H */ diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index 4a07256..b45a6b5 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -19,7 +19,7 @@ void free_linear_memory(void *base, u32 bound, u32 max); INLINE char *get_function_from_table(u32 idx, u32 type_id); INLINE char *get_memory_ptr_for_runtime(u32 offset, u32 bounds_check); void runtime__initialize(void); -void listener_thread__initialize(void); +void listener_thread_initialize(void); void stub_init(i32 offset); void * worker_thread__main(void *return_code); diff --git a/runtime/src/libc/uvio.c b/runtime/src/libc/uvio.c index 9c8505a..eaeaade 100644 --- a/runtime/src/libc/uvio.c +++ b/runtime/src/libc/uvio.c @@ -65,7 +65,7 @@ stub_init(i32 offset) i32 env_vec_offset = offset; memcpy(get_memory_ptr_for_runtime(env_vec_offset, sizeof(env_vec)), env_vec, sizeof(env_vec)); - module__initialize_libc(current_sandbox_get()->module, env_vec_offset, program_name_offset); + module_initialize_libc(current_sandbox_get()->module, env_vec_offset, program_name_offset); } // Emulated syscall implementations diff --git a/runtime/src/main.c b/runtime/src/main.c index 5a048c3..8be4eee 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -172,11 +172,11 @@ main(int argc, char **argv) runtime__initialize(); debuglog("Parsing modules file [%s]\n", argv[1]); - if (module__new_from_json(argv[1])) { + if (module_new_from_json(argv[1])) { printf("failed to parse modules file[%s]\n", argv[1]); exit(-1); } - listener_thread__initialize(); + listener_thread_initialize(); runtime__start_runtime__worker_threads(); } diff --git a/runtime/src/module.c b/runtime/src/module.c index 04b278a..2a97f93 100644 --- a/runtime/src/module.c +++ b/runtime/src/module.c @@ -18,7 +18,7 @@ * @param module **/ static inline void -module__initialize_as_server(struct module *module) +module_initialize_as_server(struct module *module) { // Allocate a new socket int socket_descriptor = socket(AF_INET, SOCK_STREAM, 0); @@ -67,7 +67,7 @@ module__initialize_as_server(struct module *module) * @param module - the module to teardown **/ void -module__free(struct module *module) +module_free(struct module *module) { if (module == NULL) return; if (module->dynamic_library_handle == NULL) return; @@ -99,8 +99,8 @@ module__free(struct module *module) * @returns A new module or NULL in case of failure **/ struct module * -module__new(char *name, char *path, i32 argument_count, u32 stack_size, u32 max_memory, u32 timeout, int port, - int request_size, int response_size) +module_new(char *name, char *path, i32 argument_count, u32 stack_size, u32 max_memory, u32 timeout, int port, + int request_size, int response_size) { struct module *module = (struct module *)malloc(sizeof(struct module)); if (!module) return NULL; @@ -149,21 +149,21 @@ module__new(char *name, char *path, i32 argument_count, u32 stack_size, u32 max_ // assumption: All modules are created at program start before we enable preemption or enable the execution of // any worker threads We are checking that thread-local module_indirect_table is NULL to prove that we aren't - // yet preempting If we want to be able to do this later, we can possibly defer module__initialize_table until + // yet preempting If we want to be able to do this later, we can possibly defer module_initialize_table until // the first invocation assert(cache_tbl == NULL); // TODO: determine why we have to set the module_indirect_table state before calling table init and then restore // the existing value What is the relationship between these things? module_indirect_table = module->indirect_table; - module__initialize_table(module); + module_initialize_table(module); module_indirect_table = cache_tbl; // Add the module to the in-memory module DB module_database__add(module); // Start listening for requests - module__initialize_as_server(module); + module_initialize_as_server(module); return module; @@ -182,7 +182,7 @@ dl_open_error: * @return RC 0 on Success. -1 on Error */ int -module__new_from_json(char *file_name) +module_new_from_json(char *file_name) { // Use stat to get file attributes and make sure file is there and OK struct stat stat_buffer; @@ -310,11 +310,11 @@ module__new_from_json(char *file_name) if (is_active == 0) continue; // Allocate a module based on the values from the JSON - struct module *module = module__new(module_name, module_path, argument_count, 0, 0, 0, port, - request_size, response_size); + struct module *module = module_new(module_name, module_path, argument_count, 0, 0, 0, port, + request_size, response_size); assert(module); - module__set_http_info(module, request_count, request_headers, request_content_type, response_count, - reponse_headers, response_content_type); + module_set_http_info(module, request_count, request_headers, request_content_type, response_count, + reponse_headers, response_content_type); module_count++; free(request_headers); free(reponse_headers); diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index df13507..d5aeded 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -75,7 +75,7 @@ runtime__initialize(void) * */ void * -listener_thread__main(void *dummy) +listener_thread_main(void *dummy) { struct epoll_event *epoll_events = (struct epoll_event *)malloc(LISTENER_THREAD__MAX_EPOLL_EVENTS * sizeof(struct epoll_event)); @@ -122,7 +122,7 @@ listener_thread__main(void *dummy) * Initializes the listener thread, pinned to core 0, and starts to listen for requests */ void -listener_thread__initialize(void) +listener_thread_initialize(void) { cpu_set_t cs; @@ -130,7 +130,7 @@ listener_thread__initialize(void) CPU_SET(LISTENER_THREAD__CORE_ID, &cs); pthread_t listener_thread; - int ret = pthread_create(&listener_thread, NULL, listener_thread__main, NULL); + int ret = pthread_create(&listener_thread, NULL, listener_thread_main, NULL); assert(ret == 0); ret = pthread_setaffinity_np(listener_thread, sizeof(cpu_set_t), &cs); assert(ret == 0); diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index b7d32f0..bf2a8df 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -92,8 +92,8 @@ current_sandbox_receive_and_parse_client_request(void) } #else int r = uv_read_start((uv_stream_t *)&curr->client_libuv_stream, - libuv_callbacks__on_allocate_setup_request_response_data, - libuv_callbacks__on_read_parse_http_request); + libuv_callbacks_on_allocate_setup_request_response_data, + libuv_callbacks_on_read_parse_http_request); worker_thread__process_io(); if (curr->request_response_data_length == 0) return 0; #endif @@ -163,7 +163,7 @@ done: }; uv_buf_t bufv = uv_buf_init(curr->request_response_data, sndsz); int r = uv_write(&req, (uv_stream_t *)&curr->client_libuv_stream, &bufv, 1, - libuv_callbacks__on_write_wakeup_sandbox); + libuv_callbacks_on_write_wakeup_sandbox); worker_thread__process_io(); #endif return 0; @@ -187,7 +187,7 @@ current_sandbox_main(void) software_interrupt__enable(); } struct module *current_module = sandbox__get_module(current_sandbox); - int argument_count = module__get_argument_count(current_module); + int argument_count = module_get_argument_count(current_module); // for stdio // Try to initialize file descriptors 0, 1, and 2 as io handles 0, 1, 2 @@ -232,15 +232,15 @@ current_sandbox_main(void) // Allocate the WebAssembly Sandbox alloc_linear_memory(); - module__initialize_globals(current_module); - module__initialize_memory(current_module); + module_initialize_globals(current_module); + module_initialize_memory(current_module); // Copy the arguments into the WebAssembly sandbox current_sandbox_setup_arguments(argument_count); // Executing the function within the WebAssembly sandbox - current_sandbox->return_value = module__main(current_module, argument_count, - current_sandbox->arguments_offset); + current_sandbox->return_value = module_main(current_module, argument_count, + current_sandbox->arguments_offset); // Retrieve the result from the WebAssembly sandbox, construct the HTTP response, and send to client current_sandbox_build_and_send_client_response(); @@ -249,7 +249,7 @@ current_sandbox_main(void) // Cleanup connection and exit sandbox #ifdef USE_HTTP_UVIO - uv_close((uv_handle_t *)¤t_sandbox->client_libuv_stream, libuv_callbacks__on_close_wakeup_sakebox); + uv_close((uv_handle_t *)¤t_sandbox->client_libuv_stream, libuv_callbacks_on_close_wakeup_sakebox); worker_thread__process_io(); #else close(current_sandbox->client_socket_descriptor); @@ -292,7 +292,7 @@ sandbox__allocate_memory(struct module *module) sandbox->linear_memory_size = linear_memory_size; sandbox->module = module; sandbox->sandbox_size = sandbox_size; - module__acquire(module); + module_acquire(module); return sandbox; } @@ -301,7 +301,7 @@ struct sandbox * sandbox__allocate(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, u64 start_time) { - if (!module__is_valid(module)) return NULL; + if (!module_is_valid(module)) return NULL; // FIXME: don't use malloc. huge security problem! // perhaps, main should be in its own sandbox, when it is not running any sandbox. @@ -347,7 +347,7 @@ sandbox__free(struct sandbox *sandbox) int sz = sizeof(struct sandbox); sz += sandbox->module->max_request_or_response_size; - module__release(sandbox->module); + module_release(sandbox->module); void * stkaddr = sandbox->stack_start; size_t stksz = sandbox->stack_size;