diff --git a/runtime/include/sandbox.h b/runtime/include/sandbox.h index ede6e4d..b4b58a4 100644 --- a/runtime/include/sandbox.h +++ b/runtime/include/sandbox.h @@ -1,15 +1,20 @@ #ifndef SFRT_SANDBOX_H #define SFRT_SANDBOX_H -#include "ps_list.h" -#include "module.h" -#include "arch/context.h" -#include "softint.h" #include #include + +#include "arch/context.h" #include "deque.h" #include #include +#include "module.h" +#include "ps_list.h" +#include "softint.h" + +/************************** + * Structs and Types * + **************************/ struct sandbox__io_handle { int file_descriptor; @@ -23,12 +28,6 @@ typedef enum RETURNED } sandbox__state_t; -/* - * This is the slowpath switch to a preempted sandbox! - * SIGUSR1 on the current thread and restore mcontext there! - */ -extern void __attribute__((noreturn)) worker_thread__sandbox_switch_preempt(void); - // TODO: linear_memory_max_size is not really used struct sandbox { @@ -78,21 +77,31 @@ struct sandbox { char request_response_data[1]; // of rr_data_sz, following sandbox mem.. } PAGE_ALIGNED; +typedef struct sandbox sandbox_t; + +/*************************** + * Externs * + **************************/ + + extern __thread struct sandbox *worker_thread__current_sandbox; -// next_sandbox only used in SIGUSR1 extern __thread arch_context_t *worker_thread__next_context; -typedef struct sandbox sandbox_t; -extern void worker_thread__completion_queue__add_sandbox(struct sandbox *sandbox); +extern void worker_thread__block_current_sandbox(void); +extern void worker_thread__completion_queue__add_sandbox(struct sandbox *sandbox); +extern void worker_thread__current_sandbox__exit(void); +extern struct sandbox * worker_thread__get_next_sandbox(int interrupt); +extern void worker_thread__process_io(void); +extern void __attribute__((noreturn)) worker_thread__sandbox_switch_preempt(void); +extern void worker_thread__wakeup_sandbox(sandbox_t *sb); /*************************** - * Sandbox * + * Public API * **************************/ -// a runtime resource, malloc on this! struct sandbox *sandbox__allocate(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, u64 start_time); -// should free stack and heap resources.. also any I/O handles. -void sandbox__free(struct sandbox *sandbox); +void sandbox__free(struct sandbox *sandbox); +int sandbox__parse_http_request(struct sandbox *sandbox, size_t length); /** @@ -214,21 +223,4 @@ sandbox__get_libuv_handle(struct sandbox *sandbox, int handle_index) return &sandbox->handles[handle_index].libuv_handle; } - - -void * sandbox_worker_main(void *data); -struct sandbox *worker_thread__get_next_sandbox(int interrupt); -void worker_thread__block_current_sandbox(void); -void worker_thread__wakeup_sandbox(sandbox_t *sb); -// called in sandbox_main() before and after fn() execution -// for http request/response processing using uvio -void worker_thread__process_io(void); -void sandbox_response(void); - -// should be the entry-point for each sandbox so it can do per-sandbox mem/etc init. -// should have been called with stack allocated and current_sandbox__get() set! -void sandbox_main(void); -void current_sandbox__exit(void); -int sandbox__parse_http_request(struct sandbox *sandbox, size_t length); - #endif /* SFRT_SANDBOX_H */ diff --git a/runtime/src/runtime.c b/runtime/src/runtime.c index 8a1ed41..508449f 100644 --- a/runtime/src/runtime.c +++ b/runtime/src/runtime.c @@ -442,7 +442,7 @@ worker_thread__main(void *return_code) * TODO: Does this belong in sandbox.c? **/ void -current_sandbox__exit(void) +worker_thread__current_sandbox__exit(void) { struct sandbox *current_sandbox = current_sandbox__get(); assert(current_sandbox); diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index 43592d9..da25923 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -166,7 +166,7 @@ done: * Handles setup, request parsing, WebAssembly initialization, function execution, response building and sending, and cleanup **/ void -sandbox_main(void) +current_sandbox__main(void) { struct sandbox *current_sandbox = current_sandbox__get(); // FIXME: is this right? this is the first time this sandbox is running.. so it wont @@ -243,7 +243,7 @@ sandbox_main(void) #else close(current_sandbox->client_socket_descriptor); #endif - current_sandbox__exit(); + worker_thread__current_sandbox__exit(); } /** @@ -314,10 +314,14 @@ sandbox__allocate(struct module *module, char *arguments, int socket_descriptor, ps_list_init_d(sandbox); // Setup the sandbox's context, stack, and instruction pointer - arch_context_init(&sandbox->ctxt, (reg_t)sandbox_main, (reg_t)(sandbox->stack_start + sandbox->stack_size)); + arch_context_init(&sandbox->ctxt, (reg_t)current_sandbox__main, (reg_t)(sandbox->stack_start + sandbox->stack_size)); return sandbox; } +/** + * Free stack and heap resources.. also any I/O handles. + * @param sandbox + **/ void sandbox__free(struct sandbox *sandbox) {