diff --git a/runtime/include/current_sandbox.h b/runtime/include/current_sandbox.h index 3f10268..dd5a3ce 100644 --- a/runtime/include/current_sandbox.h +++ b/runtime/include/current_sandbox.h @@ -41,7 +41,7 @@ static inline char * current_sandbox_get_arguments(void) { struct sandbox *sandbox = current_sandbox_get(); - return sandbox__get_arguments(sandbox); + return sandbox_get_arguments(sandbox); } /** @@ -52,7 +52,7 @@ static inline int current_sandbox_initialize_io_handle(void) { struct sandbox *sandbox = current_sandbox_get(); - return sandbox__initialize_io_handle(sandbox); + return sandbox_initialize_io_handle(sandbox); } /** @@ -64,10 +64,10 @@ static inline int current_sandbox_initialize_io_handle_and_set_file_descriptor(int file_descriptor) { struct sandbox *sandbox = current_sandbox_get(); - return sandbox__initialize_io_handle_and_set_file_descriptor(sandbox, file_descriptor); + return sandbox_initialize_io_handle_and_set_file_descriptor(sandbox, file_descriptor); } -int sandbox__parse_http_request(struct sandbox *sandbox, size_t l); +int sandbox_parse_http_request(struct sandbox *sandbox, size_t l); /** * Parse the current sandbox's request_response_data up to length @@ -77,7 +77,7 @@ int sandbox__parse_http_request(struct sandbox *sandbox, size_t l); static inline int current_sandbox_parse_http_request(size_t length) { - return sandbox__parse_http_request(current_sandbox_get(), length); + return sandbox_parse_http_request(current_sandbox_get(), length); } /** @@ -91,7 +91,7 @@ static inline int current_sandbox_set_file_descriptor(int io_handle_index, int file_descriptor) { struct sandbox *sandbox = current_sandbox_get(); - return sandbox__set_file_descriptor(sandbox, io_handle_index, file_descriptor); + return sandbox_set_file_descriptor(sandbox, io_handle_index, file_descriptor); } /** @@ -103,7 +103,7 @@ static inline int current_sandbox_get_file_descriptor(int io_handle_index) { struct sandbox *sandbox = current_sandbox_get(); - return sandbox__get_file_descriptor(sandbox, io_handle_index); + return sandbox_get_file_descriptor(sandbox, io_handle_index); } /** @@ -114,7 +114,7 @@ static inline void current_sandbox_close_file_descriptor(int io_handle_index) { struct sandbox *sandbox = current_sandbox_get(); - sandbox__close_file_descriptor(sandbox, io_handle_index); + sandbox_close_file_descriptor(sandbox, io_handle_index); } /** @@ -126,7 +126,7 @@ static inline union uv_any_handle * current_sandbox_get_libuv_handle(int io_handle_index) { struct sandbox *sandbox = current_sandbox_get(); - return sandbox__get_libuv_handle(sandbox, io_handle_index); + return sandbox_get_libuv_handle(sandbox, io_handle_index); } /** diff --git a/runtime/include/libuv_callbacks.h b/runtime/include/libuv_callbacks.h index 3fe2a61..68c8a64 100644 --- a/runtime/include/libuv_callbacks.h +++ b/runtime/include/libuv_callbacks.h @@ -27,7 +27,7 @@ libuv_callbacks_on_read_parse_http_request(uv_stream_t *stream, ssize_t number_r // Parse the chunks libuv has read on our behalf until we've parse to message end if (number_read > 0) { - if (sandbox__parse_http_request(sandbox, number_read) != 0) return; + if (sandbox_parse_http_request(sandbox, number_read) != 0) return; sandbox->request_response_data_length += number_read; struct http_request *rh = &sandbox->http_request; if (!rh->message_end) return; diff --git a/runtime/include/sandbox.h b/runtime/include/sandbox.h index 584c30d..f84bfd4 100644 --- a/runtime/include/sandbox.h +++ b/runtime/include/sandbox.h @@ -16,7 +16,7 @@ * Structs and Types * **************************/ -struct sandbox__io_handle { +struct sandbox_io_handle { int file_descriptor; union uv_any_handle libuv_handle; }; @@ -26,12 +26,12 @@ typedef enum RUNNABLE, BLOCKED, RETURNED -} sandbox__state_t; +} sandbox_state_t; // TODO: linear_memory_max_size is not really used struct sandbox { - sandbox__state_t state; + sandbox_state_t state; u32 sandbox_size; // The struct plus enough buffer to hold the request or response (sized off largest) @@ -53,11 +53,11 @@ struct sandbox { void *arguments; // arguments from request, must be of module->argument_count size. i32 return_value; - struct sandbox__io_handle io_handles[SANDBOX__MAX_IO_HANDLE_COUNT]; - struct sockaddr client_address; // client requesting connection! - int client_socket_descriptor; - uv_tcp_t client_libuv_stream; - uv_shutdown_t client_libuv_shutdown_request; + struct sandbox_io_handle io_handles[SANDBOX__MAX_IO_HANDLE_COUNT]; + struct sockaddr client_address; // client requesting connection! + int client_socket_descriptor; + uv_tcp_t client_libuv_stream; + uv_shutdown_t client_libuv_shutdown_request; http_parser http_parser; struct http_request http_request; @@ -96,10 +96,10 @@ extern void worker_thread__wakeup_sandbox(sandbox_t *sandbox); * Public API * **************************/ -struct sandbox *sandbox__allocate(struct module *module, char *arguments, int socket_descriptor, - const struct sockaddr *socket_address, u64 start_time); -void sandbox__free(struct sandbox *sandbox); -int sandbox__parse_http_request(struct sandbox *sandbox, size_t length); +struct sandbox *sandbox_allocate(struct module *module, char *arguments, int socket_descriptor, + const struct sockaddr *socket_address, u64 start_time); +void sandbox_free(struct sandbox *sandbox); +int sandbox_parse_http_request(struct sandbox *sandbox, size_t length); /** @@ -108,7 +108,7 @@ int sandbox__parse_http_request(struct sandbox *sandbox, size_t leng * @return the module of the provided sandbox */ static inline struct module * -sandbox__get_module(struct sandbox *sandbox) +sandbox_get_module(struct sandbox *sandbox) { if (!sandbox) return NULL; return sandbox->module; @@ -120,7 +120,7 @@ sandbox__get_module(struct sandbox *sandbox) * @return the arguments of the sandbox */ static inline char * -sandbox__get_arguments(struct sandbox *sandbox) +sandbox_get_arguments(struct sandbox *sandbox) { if (!sandbox) return NULL; return (char *)sandbox->arguments; @@ -132,7 +132,7 @@ sandbox__get_arguments(struct sandbox *sandbox) * @return index of handle we preopened or -1 on error (sandbox is null or all io_handles are exhausted) **/ static inline int -sandbox__initialize_io_handle(struct sandbox *sandbox) +sandbox_initialize_io_handle(struct sandbox *sandbox) { if (!sandbox) return -1; int io_handle_index; @@ -153,11 +153,11 @@ sandbox__initialize_io_handle(struct sandbox *sandbox) * @return index of handle we preopened or -1 if all io_handles are exhausted **/ static inline int -sandbox__initialize_io_handle_and_set_file_descriptor(struct sandbox *sandbox, int file_descriptor) +sandbox_initialize_io_handle_and_set_file_descriptor(struct sandbox *sandbox, int file_descriptor) { if (!sandbox) return -1; if (file_descriptor < 0) return file_descriptor; - int io_handle_index = sandbox__initialize_io_handle(sandbox); + int io_handle_index = sandbox_initialize_io_handle(sandbox); if (io_handle_index != -1) sandbox->io_handles[io_handle_index].file_descriptor = file_descriptor; // well, per sandbox.. so synchronization necessary! @@ -173,7 +173,7 @@ sandbox__initialize_io_handle_and_set_file_descriptor(struct sandbox *sandbox, i * @returns the index that was set or -1 in case of error **/ static inline int -sandbox__set_file_descriptor(struct sandbox *sandbox, int io_handle_index, int file_descriptor) +sandbox_set_file_descriptor(struct sandbox *sandbox, int io_handle_index, int file_descriptor) { if (!sandbox) return -1; if (io_handle_index >= SANDBOX__MAX_IO_HANDLE_COUNT || io_handle_index < 0) return -1; @@ -191,7 +191,7 @@ sandbox__set_file_descriptor(struct sandbox *sandbox, int io_handle_index, int f * @returns file descriptor or -1 in case of error **/ static inline int -sandbox__get_file_descriptor(struct sandbox *sandbox, int io_handle_index) +sandbox_get_file_descriptor(struct sandbox *sandbox, int io_handle_index) { if (!sandbox) return -1; if (io_handle_index >= SANDBOX__MAX_IO_HANDLE_COUNT || io_handle_index < 0) return -1; @@ -204,7 +204,7 @@ sandbox__get_file_descriptor(struct sandbox *sandbox, int io_handle_index) * @param io_handle_index index of the handle to close **/ static inline void -sandbox__close_file_descriptor(struct sandbox *sandbox, int io_handle_index) +sandbox_close_file_descriptor(struct sandbox *sandbox, int io_handle_index) { if (io_handle_index >= SANDBOX__MAX_IO_HANDLE_COUNT || io_handle_index < 0) return; // TODO: Do we actually need to call some sort of close function here? @@ -218,7 +218,7 @@ sandbox__close_file_descriptor(struct sandbox *sandbox, int io_handle_index) * @returns any libuv handle or a NULL pointer in case of error **/ static inline union uv_any_handle * -sandbox__get_libuv_handle(struct sandbox *sandbox, int io_handle_index) +sandbox_get_libuv_handle(struct sandbox *sandbox, int io_handle_index) { if (!sandbox) return NULL; if (io_handle_index >= SANDBOX__MAX_IO_HANDLE_COUNT || io_handle_index < 0) return NULL; diff --git a/runtime/src/memory/64bit_nix.c b/runtime/src/memory/64bit_nix.c index d49933f..2317794 100644 --- a/runtime/src/memory/64bit_nix.c +++ b/runtime/src/memory/64bit_nix.c @@ -12,13 +12,13 @@ void alloc_linear_memory(void) { - // mmaped memory in sandbox__allocate. + // mmaped memory in sandbox_allocate. } void free_linear_memory(void *base, u32 bound, u32 max) { - // frees on sandbox__free + // frees on sandbox_free } void diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index c33c266..c52a134 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -277,10 +277,10 @@ worker_thread__pull_and_process_sandbox_requests(void) sandbox_request_t *sandbox_request; if ((sandbox_request = sandbox_request__steal_from_dequeue()) == NULL) break; // Actually allocate the sandbox for the requests that we've pulled - struct sandbox *sandbox = sandbox__allocate(sandbox_request->module, sandbox_request->arguments, - sandbox_request->socket_descriptor, - sandbox_request->socket_address, - sandbox_request->start_time); + struct sandbox *sandbox = sandbox_allocate(sandbox_request->module, sandbox_request->arguments, + sandbox_request->socket_descriptor, + sandbox_request->socket_address, + sandbox_request->start_time); assert(sandbox); free(sandbox_request); // Set the sandbox as runnable and place on the local runqueue @@ -387,7 +387,7 @@ worker_thread__pop_and_free_n_sandboxes_from_completion_queue(unsigned int numbe struct sandbox *sandbox = ps_list_head_first_d(&worker_thread__completion_queue, struct sandbox); if (!sandbox) break; ps_list_rem_d(sandbox); - sandbox__free(sandbox); + sandbox_free(sandbox); } } diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index 5ff9f92..992af7c 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -50,7 +50,7 @@ current_sandbox_setup_arguments(i32 argument_count) * Globals: runtime_http_parser_settings **/ int -sandbox__parse_http_request(struct sandbox *sandbox, size_t length) +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 @@ -186,7 +186,7 @@ current_sandbox_main(void) worker_thread__next_context = NULL; software_interrupt__enable(); } - struct module *current_module = sandbox__get_module(current_sandbox); + struct module *current_module = sandbox_get_module(current_sandbox); int argument_count = module_get_argument_count(current_module); // for stdio @@ -263,7 +263,7 @@ current_sandbox_main(void) * @returns the resulting sandbox or NULL if mmap failed **/ static inline struct sandbox * -sandbox__allocate_memory(struct module *module) +sandbox_allocate_memory(struct module *module) { unsigned long memory_size = SBOX_MAX_MEM; // 4GB @@ -298,14 +298,14 @@ sandbox__allocate_memory(struct module *module) } struct sandbox * -sandbox__allocate(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, - u64 start_time) +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; // FIXME: don't use malloc. huge security problem! // perhaps, main should be in its own sandbox, when it is not running any sandbox. - struct sandbox *sandbox = (struct sandbox *)sandbox__allocate_memory(module); + struct sandbox *sandbox = (struct sandbox *)sandbox_allocate_memory(module); if (!sandbox) return NULL; // Assign the start time from the request @@ -336,7 +336,7 @@ sandbox__allocate(struct module *module, char *arguments, int socket_descriptor, * @param sandbox **/ void -sandbox__free(struct sandbox *sandbox) +sandbox_free(struct sandbox *sandbox) { // you have to context switch away to free a sandbox. if (!sandbox || sandbox == current_sandbox_get()) return;