chore: simplify sandbox_allocate

main
Sean McBride 5 years ago
parent c2c6332bc1
commit d42370c357

@ -10,7 +10,6 @@
extern int runtime_epoll_file_descriptor; extern int runtime_epoll_file_descriptor;
extern __thread uv_loop_t worker_thread_uvio_handle; extern __thread uv_loop_t worker_thread_uvio_handle;
extern float runtime_processor_speed_MHz;
void alloc_linear_memory(void); void alloc_linear_memory(void);
void expand_memory(void); void expand_memory(void);

@ -3,6 +3,8 @@
#include <ucontext.h> #include <ucontext.h>
#include <uv.h> #include <uv.h>
#include <stdbool.h>
#include "sandbox_request.h"
#include "arch/context.h" #include "arch/context.h"
#include "deque.h" #include "deque.h"
@ -95,8 +97,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, // TODO: Why do I have to redeclare this type here?
const struct sockaddr *socket_address, u64 start_time, u64 absolute_deadline); typedef struct sandbox_request sandbox_request_t;
struct sandbox *sandbox_allocate(sandbox_request_t *sandbox_request);
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);

@ -5,6 +5,8 @@
#include "types.h" #include "types.h"
#include "runtime.h" #include "runtime.h"
extern float runtime_processor_speed_MHz;
struct sandbox_request { struct sandbox_request {
struct module * module; struct module * module;
char * arguments; char * arguments;
@ -13,6 +15,7 @@ struct sandbox_request {
u64 start_time; // cycles u64 start_time; // cycles
u64 absolute_deadline; // cycles u64 absolute_deadline; // cycles
}; };
typedef struct sandbox_request sandbox_request_t; typedef struct sandbox_request sandbox_request_t;
DEQUE_PROTOTYPE(sandbox, sandbox_request_t *); DEQUE_PROTOTYPE(sandbox, sandbox_request_t *);

@ -265,10 +265,7 @@ worker_thread_pull_and_process_sandbox_requests(void)
sandbox_request_t *sandbox_request; sandbox_request_t *sandbox_request;
if ((sandbox_request = sandbox_request_scheduler_remove()) == NULL) break; if ((sandbox_request = sandbox_request_scheduler_remove()) == 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);
sandbox_request->socket_descriptor,
sandbox_request->socket_address, sandbox_request->start_time,
sandbox_request->absolute_deadline);
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

@ -307,9 +307,15 @@ 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(sandbox_request_t *sandbox_request)
u64 start_time, u64 absolute_deadline)
{ {
struct module * module = sandbox_request->module;
char * arguments = sandbox_request->arguments;
int socket_descriptor = sandbox_request->socket_descriptor;
const struct sockaddr *socket_address = sandbox_request->socket_address;
u64 start_time = sandbox_request->start_time;
u64 absolute_deadline = sandbox_request->absolute_deadline;
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!

Loading…
Cancel
Save