refactor: sandbox stack

master
Sean McBride 3 years ago
parent e39b223c95
commit d95f25c46d

@ -34,9 +34,9 @@ sandbox_set_as_initialized(struct sandbox *sandbox, struct sandbox_request *sand
sandbox->state = SANDBOX_SET_AS_INITIALIZED;
/* Initialize the sandbox's context, stack, and instruction pointer */
/* stack_start points to the bottom of the usable stack, so add stack_size to get to top */
/* stack.start points to the bottom of the usable stack, so add stack_size to get to top */
arch_context_init(&sandbox->ctxt, (reg_t)current_sandbox_start,
(reg_t)sandbox->stack_start + sandbox->stack_size);
(reg_t)sandbox->stack.start + sandbox->stack.size);
/* Initialize Parsec control structures */
ps_list_init_d(sandbox);

@ -30,18 +30,20 @@ struct sandbox_io_handle {
int file_descriptor;
};
struct sandbox_stack {
void * start; /* points to the bottom of the usable stack */
uint32_t size;
};
struct sandbox {
uint64_t id;
sandbox_state_t state;
uint32_t sandbox_size; /* The struct plus enough buffer to hold the request or response (sized off largest) */
struct wasm_memory memory;
void * stack_start;
uint32_t stack_size;
struct arch_context ctxt; /* register context for context switch. */
/* Primitives that provide WebAssembly execution */
struct arch_context ctxt;
struct sandbox_stack stack;
struct wasm_memory memory;
uint64_t request_arrival_timestamp; /* Timestamp when request is received */
uint64_t allocation_timestamp; /* Timestamp when sandbox is allocated */

@ -2,6 +2,7 @@
#include <stdint.h>
/* bytes, not wasm pages */
struct wasm_memory {
void * start; /* after sandbox struct */
uint32_t size; /* from after sandbox struct */

@ -94,8 +94,8 @@ sandbox_allocate_stack(struct sandbox *sandbox)
/* TODO: Fix leak here. Issue #132 */
if (addr_rw == MAP_FAILED) goto err_stack_allocation_failed;
sandbox->stack_start = addr_rw;
sandbox->stack_size = sandbox->module->stack_size;
sandbox->stack.start = addr_rw;
sandbox->stack.size = sandbox->module->stack_size;
done:
return 0;
@ -179,7 +179,7 @@ sandbox_free(struct sandbox *sandbox)
errno = 0;
/* The stack start is the bottom of the usable stack, but we allocated a guard page below this */
rc = munmap((char *)sandbox->stack_start - PAGE_SIZE, sandbox->stack_size + PAGE_SIZE);
rc = munmap((char *)sandbox->stack.start - PAGE_SIZE, sandbox->stack.size + PAGE_SIZE);
if (rc == -1) {
debuglog("Failed to unmap stack of Sandbox %lu\n", sandbox->id);
goto err_free_stack_failed;

Loading…
Cancel
Save