chore: revert sandbox alloc API

main
Sean McBride 4 years ago
parent a9423b104c
commit 2ceede804a

@ -92,13 +92,10 @@ extern void worker_thread_wakeup_sandbox(struct sandbox *sandbox);
* Public API * * Public API *
**************************/ **************************/
int sandbox_allocate(struct sandbox **sandbox, struct sandbox_request *sandbox_request); struct sandbox *sandbox_allocate(struct sandbox_request *sandbox_request);
#define SANDBOX_ALLOCATE_OK 0 void sandbox_free(struct sandbox *sandbox);
#define SANDBOX_ALLOCATE_ERR -1 void sandbox_main(struct sandbox *sandbox);
int sandbox_parse_http_request(struct sandbox *sandbox, size_t length);
void sandbox_free(struct sandbox *sandbox);
void sandbox_main(struct sandbox *sandbox);
int sandbox_parse_http_request(struct sandbox *sandbox, size_t length);
/** /**
* Given a sandbox, returns the module that sandbox is executing * Given a sandbox, returns the module that sandbox is executing

@ -49,8 +49,9 @@ local_runqueue_list_get_next()
if (local_runqueue_is_empty()) { if (local_runqueue_is_empty()) {
if (global_request_scheduler_remove(&sandbox_request) != GLOBAL_REQUEST_SCHEDULER_REMOVE_OK) goto err; if (global_request_scheduler_remove(&sandbox_request) != GLOBAL_REQUEST_SCHEDULER_REMOVE_OK) goto err;
struct sandbox *sandbox; struct sandbox *sandbox = sandbox_allocate(sandbox_request);
if (sandbox_allocate(&sandbox, sandbox_request) == SANDBOX_ALLOCATE_ERR) goto sandbox_allocate_err; if (!sandbox) goto sandbox_allocate_err;
sandbox->state = SANDBOX_RUNNABLE; sandbox->state = SANDBOX_RUNNABLE;
local_runqueue_add(sandbox); local_runqueue_add(sandbox);

@ -90,7 +90,8 @@ local_runqueue_minheap_get_next()
if (global_request_scheduler_remove(&sandbox_request) != GLOBAL_REQUEST_SCHEDULER_REMOVE_OK) goto err; if (global_request_scheduler_remove(&sandbox_request) != GLOBAL_REQUEST_SCHEDULER_REMOVE_OK) goto err;
/* Try to allocate a sandbox, returning the request on failure */ /* Try to allocate a sandbox, returning the request on failure */
if (sandbox_allocate(&sandbox, sandbox_request) == SANDBOX_ALLOCATE_ERR) goto sandbox_allocate_err; sandbox = sandbox_allocate(sandbox_request);
if (!sandbox) goto sandbox_allocate_err;
sandbox->state = SANDBOX_RUNNABLE; sandbox->state = SANDBOX_RUNNABLE;
local_runqueue_minheap_add(sandbox); local_runqueue_minheap_add(sandbox);
@ -149,10 +150,10 @@ local_runqueue_minheap_preempt(ucontext_t *user_context)
debuglog("Thread %lu Preempted %lu for %lu\n", pthread_self(), local_deadline, debuglog("Thread %lu Preempted %lu for %lu\n", pthread_self(), local_deadline,
sandbox_request->absolute_deadline); sandbox_request->absolute_deadline);
/* Allocate the request */ /* Allocate the request */
struct sandbox *next_sandbox; struct sandbox *next_sandbox = sandbox_allocate(sandbox_request);
/* If sandbox allocation fails, add the request back and exit*/ if (!next_sandbox) goto err_sandbox_allocate;
if (sandbox_allocate(&next_sandbox, sandbox_request) == -1) goto err_sandbox_allocate;
/* Set as runnable and add it to the runqueue */ /* Set as runnable and add it to the runqueue */
next_sandbox->state = SANDBOX_RUNNABLE; next_sandbox->state = SANDBOX_RUNNABLE;

@ -381,72 +381,70 @@ err_stack_allocation_failed:
} }
/** /**
* Allocates a new sandbox from a sandbox request, freeing the sandbox request on success * Allocates a new sandbox from a sandbox request
* @param sandbox pointer to destination pointer to set to newly allocated sandbox * Frees the sandbox request on success
* @param sandbox_request request being allocated * @param sandbox_request request being allocated
* @returns 0 on success, -1 on error * @returns sandbox * on success, NULL on error
*/ */
int struct sandbox *
sandbox_allocate(struct sandbox **sandbox, struct sandbox_request *sandbox_request) sandbox_allocate(struct sandbox_request *sandbox_request)
{ {
/* Assumption: Caller has disabled software interrupts */ /* Assumption: Caller has disabled software interrupts */
assert(!software_interrupt_is_enabled()); assert(!software_interrupt_is_enabled());
/* Validate Arguments */ /* Validate Arguments */
assert(sandbox != NULL);
assert(sandbox_request != NULL); assert(sandbox_request != NULL);
module_validate(sandbox_request->module); module_validate(sandbox_request->module);
char *error_message = ""; struct sandbox *new_sandbox;
int rc; char * error_message = "";
/* Allocate Sandbox control structures, buffers, and linear memory in a 4GB address space */ /* Allocate Sandbox control structures, buffers, and linear memory in a 4GB address space */
*sandbox = (struct sandbox *)sandbox_allocate_memory(sandbox_request->module); new_sandbox = sandbox_allocate_memory(sandbox_request->module);
if (!sandbox) { if (!new_sandbox) {
error_message = "failed to allocate sandbox heap and linear memory"; error_message = "failed to allocate sandbox heap and linear memory";
goto err_memory_allocation_failed; goto err_memory_allocation_failed;
} }
/* Set state to initializing */ /* Set state to initializing */
(*sandbox)->state = SANDBOX_INITIALIZING; new_sandbox->state = SANDBOX_INITIALIZING;
/* Allocate the Stack */ /* Allocate the Stack */
if (sandbox_allocate_stack(*sandbox) == -1) { if (sandbox_allocate_stack(new_sandbox) == -1) {
error_message = "failed to allocate sandbox heap and linear memory"; error_message = "failed to allocate sandbox heap and linear memory";
goto err_stack_allocation_failed; goto err_stack_allocation_failed;
} }
/* Copy the socket descriptor, address, and arguments of the client invocation */ /* Copy the socket descriptor, address, and arguments of the client invocation */
(*sandbox)->absolute_deadline = sandbox_request->absolute_deadline; new_sandbox->absolute_deadline = sandbox_request->absolute_deadline;
(*sandbox)->arguments = (void *)sandbox_request->arguments; new_sandbox->arguments = (void *)sandbox_request->arguments;
(*sandbox)->client_socket_descriptor = sandbox_request->socket_descriptor; new_sandbox->client_socket_descriptor = sandbox_request->socket_descriptor;
(*sandbox)->request_arrival_timestamp = sandbox_request->request_arrival_timestamp; new_sandbox->request_arrival_timestamp = sandbox_request->request_arrival_timestamp;
/* Initialize the sandbox's context, stack, and instruction pointer */ /* Initialize the sandbox's context, stack, and instruction pointer */
arch_context_init(&(*sandbox)->ctxt, (reg_t)current_sandbox_main, arch_context_init(&new_sandbox->ctxt, (reg_t)current_sandbox_main,
(reg_t)((*sandbox)->stack_start + (*sandbox)->stack_size)); (reg_t)(new_sandbox->stack_start + new_sandbox->stack_size));
/* TODO: What does it mean if there isn't a socket_address? Shouldn't this be a hard requirement? /* TODO: What does it mean if there isn't a socket_address? Shouldn't this be a hard requirement?
It seems that only the socket descriptor is used to send response */ It seems that only the socket descriptor is used to send response */
const struct sockaddr *socket_address = sandbox_request->socket_address; const struct sockaddr *socket_address = sandbox_request->socket_address;
if (socket_address) memcpy(&(*sandbox)->client_address, socket_address, sizeof(struct sockaddr)); if (socket_address) memcpy(&new_sandbox->client_address, socket_address, sizeof(struct sockaddr));
/* Initialize file descriptors to -1 */ /* Initialize file descriptors to -1 */
for (int i = 0; i < SANDBOX_MAX_IO_HANDLE_COUNT; i++) (*sandbox)->io_handles[i].file_descriptor = -1; for (int i = 0; i < SANDBOX_MAX_IO_HANDLE_COUNT; i++) new_sandbox->io_handles[i].file_descriptor = -1;
/* Initialize Parsec control structures (used by Completion Queue) */ /* Initialize Parsec control structures (used by Completion Queue) */
ps_list_init_d(*sandbox); ps_list_init_d(new_sandbox);
free(sandbox_request); free(sandbox_request);
rc = 0;
done: done:
return rc; return new_sandbox;
err_stack_allocation_failed: err_stack_allocation_failed:
sandbox_free(*sandbox); sandbox_free(new_sandbox);
err_memory_allocation_failed: err_memory_allocation_failed:
err: err:
perror(error_message); perror(error_message);
rc = -1; new_sandbox = NULL;
goto done; goto done;
} }

Loading…
Cancel
Save