chore: de-dunder sandbox

sledge_graph
Sean McBride 5 years ago
parent ba032a5905
commit fefd80d6a9

@ -41,7 +41,7 @@ static inline char *
current_sandbox_get_arguments(void) current_sandbox_get_arguments(void)
{ {
struct sandbox *sandbox = current_sandbox_get(); 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) current_sandbox_initialize_io_handle(void)
{ {
struct sandbox *sandbox = current_sandbox_get(); 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) current_sandbox_initialize_io_handle_and_set_file_descriptor(int file_descriptor)
{ {
struct sandbox *sandbox = current_sandbox_get(); 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 * 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 static inline int
current_sandbox_parse_http_request(size_t length) 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) current_sandbox_set_file_descriptor(int io_handle_index, int file_descriptor)
{ {
struct sandbox *sandbox = current_sandbox_get(); 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) current_sandbox_get_file_descriptor(int io_handle_index)
{ {
struct sandbox *sandbox = current_sandbox_get(); 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) current_sandbox_close_file_descriptor(int io_handle_index)
{ {
struct sandbox *sandbox = current_sandbox_get(); 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) current_sandbox_get_libuv_handle(int io_handle_index)
{ {
struct sandbox *sandbox = current_sandbox_get(); struct sandbox *sandbox = current_sandbox_get();
return sandbox__get_libuv_handle(sandbox, io_handle_index); return sandbox_get_libuv_handle(sandbox, io_handle_index);
} }
/** /**

@ -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 // Parse the chunks libuv has read on our behalf until we've parse to message end
if (number_read > 0) { 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; sandbox->request_response_data_length += number_read;
struct http_request *rh = &sandbox->http_request; struct http_request *rh = &sandbox->http_request;
if (!rh->message_end) return; if (!rh->message_end) return;

@ -16,7 +16,7 @@
* Structs and Types * * Structs and Types *
**************************/ **************************/
struct sandbox__io_handle { struct sandbox_io_handle {
int file_descriptor; int file_descriptor;
union uv_any_handle libuv_handle; union uv_any_handle libuv_handle;
}; };
@ -26,12 +26,12 @@ typedef enum
RUNNABLE, RUNNABLE,
BLOCKED, BLOCKED,
RETURNED RETURNED
} sandbox__state_t; } sandbox_state_t;
// TODO: linear_memory_max_size is not really used // TODO: linear_memory_max_size is not really used
struct sandbox { 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) 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. void *arguments; // arguments from request, must be of module->argument_count size.
i32 return_value; i32 return_value;
struct sandbox__io_handle io_handles[SANDBOX__MAX_IO_HANDLE_COUNT]; struct sandbox_io_handle io_handles[SANDBOX__MAX_IO_HANDLE_COUNT];
struct sockaddr client_address; // client requesting connection! struct sockaddr client_address; // client requesting connection!
int client_socket_descriptor; int client_socket_descriptor;
uv_tcp_t client_libuv_stream; uv_tcp_t client_libuv_stream;
uv_shutdown_t client_libuv_shutdown_request; uv_shutdown_t client_libuv_shutdown_request;
http_parser http_parser; http_parser http_parser;
struct http_request http_request; struct http_request http_request;
@ -96,10 +96,10 @@ extern void worker_thread__wakeup_sandbox(sandbox_t *sandbox);
* Public API * * Public API *
**************************/ **************************/
struct sandbox *sandbox__allocate(struct module *module, char *arguments, int socket_descriptor, struct sandbox *sandbox_allocate(struct module *module, char *arguments, int socket_descriptor,
const struct sockaddr *socket_address, u64 start_time); const struct sockaddr *socket_address, u64 start_time);
void sandbox__free(struct sandbox *sandbox); void sandbox_free(struct sandbox *sandbox);
int sandbox__parse_http_request(struct sandbox *sandbox, size_t length); 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 * @return the module of the provided sandbox
*/ */
static inline struct module * static inline struct module *
sandbox__get_module(struct sandbox *sandbox) sandbox_get_module(struct sandbox *sandbox)
{ {
if (!sandbox) return NULL; if (!sandbox) return NULL;
return sandbox->module; return sandbox->module;
@ -120,7 +120,7 @@ sandbox__get_module(struct sandbox *sandbox)
* @return the arguments of the sandbox * @return the arguments of the sandbox
*/ */
static inline char * static inline char *
sandbox__get_arguments(struct sandbox *sandbox) sandbox_get_arguments(struct sandbox *sandbox)
{ {
if (!sandbox) return NULL; if (!sandbox) return NULL;
return (char *)sandbox->arguments; 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) * @return index of handle we preopened or -1 on error (sandbox is null or all io_handles are exhausted)
**/ **/
static inline int static inline int
sandbox__initialize_io_handle(struct sandbox *sandbox) sandbox_initialize_io_handle(struct sandbox *sandbox)
{ {
if (!sandbox) return -1; if (!sandbox) return -1;
int io_handle_index; 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 * @return index of handle we preopened or -1 if all io_handles are exhausted
**/ **/
static inline int 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 (!sandbox) return -1;
if (file_descriptor < 0) return file_descriptor; 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) if (io_handle_index != -1)
sandbox->io_handles[io_handle_index].file_descriptor = sandbox->io_handles[io_handle_index].file_descriptor =
file_descriptor; // well, per sandbox.. so synchronization necessary! 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 * @returns the index that was set or -1 in case of error
**/ **/
static inline int 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 (!sandbox) return -1;
if (io_handle_index >= SANDBOX__MAX_IO_HANDLE_COUNT || io_handle_index < 0) 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 * @returns file descriptor or -1 in case of error
**/ **/
static inline int 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 (!sandbox) return -1;
if (io_handle_index >= SANDBOX__MAX_IO_HANDLE_COUNT || io_handle_index < 0) 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 * @param io_handle_index index of the handle to close
**/ **/
static inline void 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; 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? // 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 * @returns any libuv handle or a NULL pointer in case of error
**/ **/
static inline union uv_any_handle * 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 (!sandbox) return NULL;
if (io_handle_index >= SANDBOX__MAX_IO_HANDLE_COUNT || io_handle_index < 0) return NULL; if (io_handle_index >= SANDBOX__MAX_IO_HANDLE_COUNT || io_handle_index < 0) return NULL;

@ -12,13 +12,13 @@
void void
alloc_linear_memory(void) alloc_linear_memory(void)
{ {
// mmaped memory in sandbox__allocate. // mmaped memory in sandbox_allocate.
} }
void void
free_linear_memory(void *base, u32 bound, u32 max) free_linear_memory(void *base, u32 bound, u32 max)
{ {
// frees on sandbox__free // frees on sandbox_free
} }
void void

@ -277,10 +277,10 @@ worker_thread__pull_and_process_sandbox_requests(void)
sandbox_request_t *sandbox_request; sandbox_request_t *sandbox_request;
if ((sandbox_request = sandbox_request__steal_from_dequeue()) == NULL) break; if ((sandbox_request = sandbox_request__steal_from_dequeue()) == NULL) break;
// Actually allocate the sandbox for the requests that we've pulled // Actually allocate the sandbox for the requests that we've pulled
struct sandbox *sandbox = sandbox__allocate(sandbox_request->module, sandbox_request->arguments, struct sandbox *sandbox = sandbox_allocate(sandbox_request->module, sandbox_request->arguments,
sandbox_request->socket_descriptor, sandbox_request->socket_descriptor,
sandbox_request->socket_address, sandbox_request->socket_address,
sandbox_request->start_time); sandbox_request->start_time);
assert(sandbox); assert(sandbox);
free(sandbox_request); free(sandbox_request);
// Set the sandbox as runnable and place on the local runqueue // 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); struct sandbox *sandbox = ps_list_head_first_d(&worker_thread__completion_queue, struct sandbox);
if (!sandbox) break; if (!sandbox) break;
ps_list_rem_d(sandbox); ps_list_rem_d(sandbox);
sandbox__free(sandbox); sandbox_free(sandbox);
} }
} }

@ -50,7 +50,7 @@ current_sandbox_setup_arguments(i32 argument_count)
* Globals: runtime_http_parser_settings * Globals: runtime_http_parser_settings
**/ **/
int 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? // 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 // 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; worker_thread__next_context = NULL;
software_interrupt__enable(); 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); int argument_count = module_get_argument_count(current_module);
// for stdio // for stdio
@ -263,7 +263,7 @@ current_sandbox_main(void)
* @returns the resulting sandbox or NULL if mmap failed * @returns the resulting sandbox or NULL if mmap failed
**/ **/
static inline struct sandbox * static inline struct sandbox *
sandbox__allocate_memory(struct module *module) sandbox_allocate_memory(struct module *module)
{ {
unsigned long memory_size = SBOX_MAX_MEM; // 4GB unsigned long memory_size = SBOX_MAX_MEM; // 4GB
@ -298,14 +298,14 @@ sandbox__allocate_memory(struct module *module)
} }
struct sandbox * struct sandbox *
sandbox__allocate(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, sandbox_allocate(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address,
u64 start_time) 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! // FIXME: don't use malloc. huge security problem!
// perhaps, main should be in its own sandbox, when it is not running any sandbox. // 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; if (!sandbox) return NULL;
// Assign the start time from the request // Assign the start time from the request
@ -336,7 +336,7 @@ sandbox__allocate(struct module *module, char *arguments, int socket_descriptor,
* @param sandbox * @param sandbox
**/ **/
void void
sandbox__free(struct sandbox *sandbox) sandbox_free(struct sandbox *sandbox)
{ {
// you have to context switch away to free a sandbox. // you have to context switch away to free a sandbox.
if (!sandbox || sandbox == current_sandbox_get()) return; if (!sandbox || sandbox == current_sandbox_get()) return;

Loading…
Cancel
Save