chore: assorted refactors

main
Sean McBride 5 years ago
parent 63a6e702d9
commit 3d6266750e

@ -17,12 +17,12 @@ struct module {
struct indirect_table_entry indirect_table[INDIRECT_TABLE_SIZE];
i32 nargs;
i32 argument_count;
u32 stack_size; // a specification?
u64 max_memory; // perhaps a specification of the module. (max 4GB)
u32 timeout; // again part of the module specification.
u32 refcnt; // ref count how many instances exist here.
u32 reference_count; // ref count how many instances exist here.
struct sockaddr_in srvaddr;
int srvsock, srvport;
@ -32,94 +32,108 @@ struct module {
// rest of the connection is handled in sandboxing threads, with per-core(per-thread) tls data-structures.
// so, using direct epoll for accepting connections.
// uv_handle_t srvuv;
unsigned long max_req_sz, max_resp_sz, max_rr_sz; // req/resp from http, (resp size including headers!)..
int nreqhdrs, nresphdrs;
char reqhdrs[HTTP_HEADERS_MAX][HTTP_HEADER_MAXSZ];
char rqctype[HTTP_HEADERVAL_MAXSZ];
char rspctype[HTTP_HEADERVAL_MAXSZ];
char resphdrs[HTTP_HEADERS_MAX][HTTP_HEADER_MAXSZ];
// req/resp from http, (resp size including headers!)..
unsigned long max_request_size;
unsigned long max_response_size;
// Equals the largest of either max_request_size or max_response_size
unsigned long max_request_or_response_size;
int request_header_count;
int response_header_count;
char request_headers[HTTP_HEADERS_MAX][HTTP_HEADER_MAXSZ];
char request_content_type[HTTP_HEADERVAL_MAXSZ];
char response_content_type[HTTP_HEADERVAL_MAXSZ];
char response_headers[HTTP_HEADERS_MAX][HTTP_HEADER_MAXSZ];
};
struct module *module_alloc(char *mod_name, char *mod_path, i32 nargs, u32 stack_sz, u32 max_heap, u32 timeout,
struct module *module_alloc(char *mod_name, char *mod_path, i32 argument_count, u32 stack_sz, u32 max_heap, u32 timeout,
int port, int req_sz, int resp_sz);
// frees only if refcnt == 0
void module_free(struct module *mod);
// frees only if reference_count == 0
void module_free(struct module *module);
struct module *module_find_by_name(char *name);
struct module *module_find_by_sock(int sock);
static inline void
module_http_info(struct module *m, int nrq, char *rqs, char rqtype[], int nrs, char *rs, char rsptype[])
module_http_info(
struct module *module,
int request_count,
char *request_headers,
char request_content_type[],
int response_count,
char *response_headers,
char response_content_type[])
{
assert(m);
m->nreqhdrs = nrq;
m->nresphdrs = nrs;
memcpy(m->reqhdrs, rqs, HTTP_HEADER_MAXSZ * HTTP_HEADERS_MAX);
memcpy(m->resphdrs, rs, HTTP_HEADER_MAXSZ * HTTP_HEADERS_MAX);
strcpy(m->rqctype, rqtype);
strcpy(m->rspctype, rsptype);
assert(module);
module->request_header_count = request_count;
memcpy(module->request_headers, request_headers, HTTP_HEADER_MAXSZ * HTTP_HEADERS_MAX);
strcpy(module->request_content_type, request_content_type);
module->response_header_count = response_count;
memcpy(module->response_headers, response_headers, HTTP_HEADER_MAXSZ * HTTP_HEADERS_MAX);
strcpy(module->response_content_type, response_content_type);
}
static inline int
module_is_valid(struct module *mod)
module_is_valid(struct module *module)
{
if (mod && mod->dl_handle && mod->entry_fn) return 1;
if (module && module->dl_handle && module->entry_fn) return 1;
return 0;
}
static inline void
module_globals_init(struct module *mod)
module_globals_init(struct module *module)
{
// called in a sandbox.
mod->glb_init_fn();
module->glb_init_fn();
}
static inline void
module_table_init(struct module *mod)
module_table_init(struct module *module)
{
// called at module creation time (once only per module).
mod->tbl_init_fn();
module->tbl_init_fn();
}
static inline void
module_libc_init(struct module *mod, i32 env, i32 args)
module_libc_init(struct module *module, i32 env, i32 args)
{
// called in a sandbox.
mod->libc_init_fn(env, args);
module->libc_init_fn(env, args);
}
static inline void
module_memory_init(struct module *mod)
module_memory_init(struct module *module)
{
// called in a sandbox.
mod->mem_init_fn();
module->mem_init_fn();
}
static inline i32
module_entry(struct module *mod, i32 argc, i32 argv)
module_entry(struct module *module, i32 argc, i32 argv)
{
return mod->entry_fn(argc, argv);
return module->entry_fn(argc, argv);
}
// instantiate this module.
static inline void
module_acquire(struct module *mod)
module_acquire(struct module *module)
{
// FIXME: atomic.
mod->refcnt++;
module->reference_count++;
}
static inline void
module_release(struct module *mod)
module_release(struct module *module)
{
// FIXME: atomic.
mod->refcnt--;
module->reference_count--;
}
static inline i32
module_nargs(struct module *mod)
module_argument_count(struct module *module)
{
return mod->nargs;
return module->argument_count;
}
#endif /* SFRT_MODULE_H */

@ -51,10 +51,10 @@ struct sandbox {
u64 remaining_time;
u64 start_time;
struct module *mod; // which module is this an instance of?
struct module *module; // which module is this an instance of?
i32 args_offset; // actual placement of args in the sandbox.
void *args; // args from request, must be of module->nargs size.
void *args; // args from request, must be of module->argument_count size.
i32 retval;
struct io_handle handles[SBOX_MAX_OPEN];
@ -71,12 +71,12 @@ struct sandbox {
struct ps_list list;
ssize_t rr_data_len; // <= max(mod->max_rr_sz)
ssize_t rr_data_len; // <= max(module->max_request_or_response_size)
char req_resp_data[1]; // of rr_data_sz, following sandbox mem..
} PAGE_ALIGNED;
struct sandbox_request {
struct module * mod;
struct module * module;
char * args;
int sock;
struct sockaddr *addr;
@ -87,7 +87,7 @@ typedef struct sandbox_request sbox_request_t;
DEQUE_PROTOTYPE(sandbox, sbox_request_t *);
// a runtime resource, malloc on this!
struct sandbox *sandbox_alloc(struct module *mod, char *args, int sock, const struct sockaddr *addr, u64 start_time);
struct sandbox *sandbox_alloc(struct module *module, char *args, int sock, const struct sockaddr *addr, u64 start_time);
// should free stack and heap resources.. also any I/O handles.
void sandbox_free(struct sandbox *sbox);
@ -100,7 +100,7 @@ void sandbox_run(sbox_request_t *s);
static inline sbox_request_t *
sbox_request_alloc(
struct module *mod,
struct module *module,
char *args,
int sock,
const struct sockaddr *addr,
@ -109,7 +109,7 @@ sbox_request_alloc(
// sandbox_alloc seems to be
sbox_request_t *s = malloc(sizeof(sbox_request_t));
assert(s);
s->mod = mod;
s->module = module;
s->args = args;
s->sock = sock;
s->addr = (struct sockaddr *)addr;
@ -134,7 +134,7 @@ sandbox_current_set(struct sandbox *sbox)
sandbox_lmbase = sbox->linear_start;
sandbox_lmbound = sbox->linear_size;
// TODO: module table or sandbox table?
module_indirect_table = sbox->mod->indirect_table;
module_indirect_table = sbox->module->indirect_table;
}
/**
@ -145,7 +145,7 @@ sandbox_current_check(void)
{
struct sandbox *c = sandbox_current();
assert(c && c->linear_start == sandbox_lmbase && c->linear_size == sandbox_lmbound);
assert(c->mod->indirect_table == module_indirect_table);
assert(c->module->indirect_table == module_indirect_table);
}
/**
@ -155,7 +155,7 @@ static inline struct module *
sandbox_module(struct sandbox *s)
{
if (!s) return NULL;
return s->mod;
return s->module;
}
extern void sandbox_local_end(struct sandbox *s);

@ -42,7 +42,7 @@ http_on_url(http_parser *parser, const char *at, size_t length)
struct sandbox * s = parser->data;
struct http_request *r = &s->rqi;
assert(strncmp(s->mod->name, (at + 1), length - 1) == 0);
assert(strncmp(s->module->name, (at + 1), length - 1) == 0);
return 0;
}
@ -83,7 +83,7 @@ http_on_body(http_parser *parser, const char *at, size_t length)
struct sandbox * s = parser->data;
struct http_request *r = &s->rqi;
assert(r->bodylen + length <= s->mod->max_req_sz);
assert(r->bodylen + length <= s->module->max_request_size);
if (!r->body)
r->body = (char *)at;
else
@ -122,7 +122,7 @@ http_response_body_set_sb(struct sandbox *c, char *body, int len)
{
struct http_response *r = &c->rsi;
assert(len <= c->mod->max_resp_sz);
assert(len <= c->module->max_response_size);
r->body = body;
r->bodylen = len;

@ -33,7 +33,7 @@ void
stub_init(i32 offset)
{
// What program name will we put in the auxiliary vectors
char *program_name = sandbox_current()->mod->name;
char *program_name = sandbox_current()->module->name;
// Copy the program name into WASM accessible memory
i32 program_name_offset = offset;
strcpy(get_memory_ptr_for_runtime(offset, sizeof(program_name)), program_name);
@ -64,7 +64,7 @@ stub_init(i32 offset)
i32 env_vec_offset = offset;
memcpy(get_memory_ptr_for_runtime(env_vec_offset, sizeof(env_vec)), env_vec, sizeof(env_vec));
module_libc_init(sandbox_current()->mod, env_vec_offset, program_name_offset);
module_libc_init(sandbox_current()->module, env_vec_offset, program_name_offset);
}
// Emulated syscall implementations
@ -138,7 +138,7 @@ wasm_write(i32 fd, i32 buf_offset, i32 buf_size)
if (fd == 1 || fd == 2) {
char * buf = get_memory_ptr_void(buf_offset, buf_size);
struct sandbox *s = sandbox_current();
int l = s->mod->max_resp_sz - s->rr_data_len;
int l = s->module->max_response_size - s->rr_data_len;
l = l > buf_size ? buf_size : l;
if (l == 0) return 0;
memcpy(s->req_resp_data + s->rr_data_len, buf, l);

@ -32,115 +32,117 @@ module_find_by_sock(int sock)
}
static inline int
module_add(struct module *m)
module_add(struct module *module)
{
assert(m->srvsock == -1);
assert(module->srvsock == -1);
int f = __sync_fetch_and_add(&__mod_free_off, 1);
assert(f < MOD_MAX);
__mod_db[f] = m;
__mod_db[f] = module;
return 0;
}
static inline void
module_server_init(struct module *m)
module_server_init(struct module *module)
{
int fd = socket(AF_INET, SOCK_STREAM, 0);
assert(fd > 0);
m->srvaddr.sin_family = AF_INET;
m->srvaddr.sin_addr.s_addr = htonl(INADDR_ANY);
m->srvaddr.sin_port = htons((unsigned short)m->srvport);
module->srvaddr.sin_family = AF_INET;
module->srvaddr.sin_addr.s_addr = htonl(INADDR_ANY);
module->srvaddr.sin_port = htons((unsigned short)module->srvport);
int optval = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval));
optval = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
if (bind(fd, (struct sockaddr *)&m->srvaddr, sizeof(m->srvaddr)) < 0) {
if (bind(fd, (struct sockaddr *)&module->srvaddr, sizeof(module->srvaddr)) < 0) {
perror("bind");
assert(0);
}
if (listen(fd, MOD_BACKLOG) < 0) assert(0);
m->srvsock = fd;
module->srvsock = fd;
struct epoll_event accept_evt;
accept_evt.data.ptr = (void *)m;
accept_evt.data.ptr = (void *)module;
accept_evt.events = EPOLLIN;
if (epoll_ctl(epoll_file_descriptor, EPOLL_CTL_ADD, m->srvsock, &accept_evt) < 0) assert(0);
if (epoll_ctl(epoll_file_descriptor, EPOLL_CTL_ADD, module->srvsock, &accept_evt) < 0) assert(0);
}
struct module *
module_alloc(char *modname, char *modpath, i32 nargs, u32 stacksz, u32 maxheap, u32 timeout, int port, int req_sz,
int resp_sz)
module_alloc(char *module_name, char *module_path, i32 argument_count, u32 stack_size, u32 max_memory, u32 timeout, int port, int request_size,
int response_size)
{
struct module *mod = (struct module *)malloc(sizeof(struct module));
if (!mod) return NULL;
struct module *module = (struct module *)malloc(sizeof(struct module));
if (!module) return NULL;
memset(mod, 0, sizeof(struct module));
mod->dl_handle = dlopen(modpath, RTLD_LAZY | RTLD_DEEPBIND);
if (mod->dl_handle == NULL) goto dl_open_error;
memset(module, 0, sizeof(struct module));
module->dl_handle = dlopen(module_path, RTLD_LAZY | RTLD_DEEPBIND);
if (module->dl_handle == NULL) goto dl_open_error;
mod->entry_fn = (mod_main_fn_t)dlsym(mod->dl_handle, MOD_MAIN_FN);
if (mod->entry_fn == NULL) goto dl_error;
module->entry_fn = (mod_main_fn_t)dlsym(module->dl_handle, MOD_MAIN_FN);
if (module->entry_fn == NULL) goto dl_error;
mod->glb_init_fn = (mod_glb_fn_t)dlsym(mod->dl_handle, MOD_GLB_FN);
if (mod->glb_init_fn == NULL) goto dl_error;
module->glb_init_fn = (mod_glb_fn_t)dlsym(module->dl_handle, MOD_GLB_FN);
if (module->glb_init_fn == NULL) goto dl_error;
mod->mem_init_fn = (mod_mem_fn_t)dlsym(mod->dl_handle, MOD_MEM_FN);
if (mod->mem_init_fn == NULL) goto dl_error;
module->mem_init_fn = (mod_mem_fn_t)dlsym(module->dl_handle, MOD_MEM_FN);
if (module->mem_init_fn == NULL) goto dl_error;
mod->tbl_init_fn = (mod_tbl_fn_t)dlsym(mod->dl_handle, MOD_TBL_FN);
if (mod->tbl_init_fn == NULL) goto dl_error;
module->tbl_init_fn = (mod_tbl_fn_t)dlsym(module->dl_handle, MOD_TBL_FN);
if (module->tbl_init_fn == NULL) goto dl_error;
mod->libc_init_fn = (mod_libc_fn_t)dlsym(mod->dl_handle, MOD_LIBC_FN);
if (mod->libc_init_fn == NULL) goto dl_error;
module->libc_init_fn = (mod_libc_fn_t)dlsym(module->dl_handle, MOD_LIBC_FN);
if (module->libc_init_fn == NULL) goto dl_error;
strncpy(mod->name, modname, MOD_NAME_MAX);
strncpy(mod->path, modpath, MOD_PATH_MAX);
strncpy(module->name, module_name, MOD_NAME_MAX);
strncpy(module->path, module_path, MOD_PATH_MAX);
mod->nargs = nargs;
mod->stack_size = round_up_to_page(stacksz == 0 ? WASM_STACK_SIZE : stacksz);
mod->max_memory = maxheap == 0 ? ((u64)WASM_PAGE_SIZE * WASM_MAX_PAGES) : maxheap;
mod->timeout = timeout;
mod->srvsock = -1;
mod->srvport = port;
if (req_sz == 0) req_sz = MOD_REQ_RESP_DEFAULT;
if (resp_sz == 0) resp_sz = MOD_REQ_RESP_DEFAULT;
mod->max_req_sz = req_sz;
mod->max_resp_sz = resp_sz;
mod->max_rr_sz = round_up_to_page(req_sz > resp_sz ? req_sz : resp_sz);
module->argument_count = argument_count;
module->stack_size = round_up_to_page(stack_size == 0 ? WASM_STACK_SIZE : stack_size);
module->max_memory = max_memory == 0 ? ((u64)WASM_PAGE_SIZE * WASM_MAX_PAGES) : max_memory;
module->timeout = timeout;
module->srvsock = -1;
module->srvport = port;
if (request_size == 0) request_size = MOD_REQ_RESP_DEFAULT;
if (response_size == 0) response_size = MOD_REQ_RESP_DEFAULT;
module->max_request_size = request_size;
module->max_response_size = response_size;
module->max_request_or_response_size = round_up_to_page(request_size > response_size ? request_size : response_size);
struct indirect_table_entry *cache_tbl = module_indirect_table;
// assumption: modules are created before enabling preemption and before running runtime-sandboxing threads..
// if this isn't a good assumption, just let the first invocation do table init..!!
assert(cache_tbl == NULL);
module_indirect_table = mod->indirect_table;
module_table_init(mod);
module_indirect_table = module->indirect_table;
module_table_init(module);
module_indirect_table = cache_tbl;
module_add(mod);
module_server_init(mod);
module_add(module);
module_server_init(module);
return mod;
return module;
dl_error:
dlclose(mod->dl_handle);
dlclose(module->dl_handle);
dl_open_error:
free(mod);
free(module);
debuglog("%s\n", dlerror());
return NULL;
}
void
module_free(struct module *mod)
module_free(struct module *module)
{
if (mod == NULL) return;
if (mod->dl_handle == NULL) return;
if (mod->refcnt) return;
if (module == NULL) return;
if (module->dl_handle == NULL) return;
close(mod->srvsock);
dlclose(mod->dl_handle);
free(mod);
// Do not free if we still have oustanding references
if (module->reference_count) return;
close(module->srvsock);
dlclose(module->dl_handle);
free(module);
}

@ -38,7 +38,7 @@ static inline void
sandbox_local_run(struct sandbox *s)
{
assert(ps_list_singleton_d(s));
// fprintf(stderr, "(%d,%lu) %s: run %p, %s\n", sched_getcpu(), pthread_self(), __func__, s, s->mod->name);
// fprintf(stderr, "(%d,%lu) %s: run %p, %s\n", sched_getcpu(), pthread_self(), __func__, s, s->module->name);
ps_list_head_append_d(&local_run_queue, s);
}
@ -55,7 +55,7 @@ sandbox_pull(void)
while (total_sandboxes_pulled < SBOX_PULL_MAX) {
sbox_request_t *sandbox_request;
if ((sandbox_request = sandbox_deque_steal()) == NULL) break;
struct sandbox *sandbox = sandbox_alloc(sandbox_request->mod, sandbox_request->args, sandbox_request->sock, sandbox_request->addr, sandbox_request->start_time);
struct sandbox *sandbox = sandbox_alloc(sandbox_request->module, sandbox_request->args, sandbox_request->sock, sandbox_request->addr, sandbox_request->start_time);
assert(sandbox);
free(sandbox_request);
sandbox->state = SANDBOX_RUNNABLE;
@ -107,7 +107,7 @@ sandbox_schedule(int interrupt)
// round-robin
ps_list_rem_d(sandbox);
ps_list_head_append_d(&local_run_queue, sandbox);
debuglog("[%p: %s]\n", sandbox, sandbox->mod->name);
debuglog("[%p: %s]\n", sandbox, sandbox->module->name);
return sandbox;
}
@ -158,7 +158,7 @@ void
sandbox_wakeup(sandbox_t *s)
{
softint_disable();
debuglog("[%p: %s]\n", s, s->mod->name);
debuglog("[%p: %s]\n", s, s->module->name);
if (s->state != SANDBOX_BLOCKED) goto done;
assert(s->state == SANDBOX_BLOCKED);
assert(ps_list_singleton_d(s));
@ -181,7 +181,7 @@ sandbox_block(void)
ps_list_rem_d(c);
c->state = SANDBOX_BLOCKED;
struct sandbox *s = sandbox_schedule(0);
debuglog("[%p: %s, %p: %s]\n", c, c->mod->name, s, s ? s->mod->name : "");
debuglog("[%p: %s, %p: %s]\n", c, c->module->name, s, s ? s->module->name : "");
softint_enable();
sandbox_switch(s);
}
@ -281,7 +281,7 @@ sandbox_run_func(void *data)
void
sandbox_run(sbox_request_t *sandbox_request)
{
debuglog("[%p: %s]\n", sandbox_request, sandbox_request->mod->name);
debuglog("[%p: %s]\n", sandbox_request, sandbox_request->module->name);
sandbox_deque_push(sandbox_request);
}
@ -360,12 +360,14 @@ runtime_init(void)
{
epoll_file_descriptor = epoll_create1(0);
assert(epoll_file_descriptor >= 0);
// Allocate and Initialize the global deque
global_deque = (struct deque_sandbox *)malloc(sizeof(struct deque_sandbox));
assert(global_deque);
// Note: Below is a Macro
deque_init_sandbox(global_deque, SBOX_MAX_REQS);
// Mask Signals
softint_mask(SIGUSR1);
softint_mask(SIGALRM);

@ -8,10 +8,10 @@
#include <http_api.h>
static inline struct sandbox *
sandbox_memory_map(struct module *m)
sandbox_memory_map(struct module *module)
{
unsigned long mem_sz = SBOX_MAX_MEM; // 4GB
unsigned long sb_sz = sizeof(struct sandbox) + m->max_rr_sz;
unsigned long sb_sz = sizeof(struct sandbox) + module->max_request_or_response_size;
unsigned long lm_sz = WASM_PAGE_SIZE * WASM_START_PAGES;
if (lm_sz + sb_sz > mem_sz) return NULL;
@ -32,9 +32,9 @@ sandbox_memory_map(struct module *m)
// can it include sandbox as well?
s->linear_start = (char *)addr + sb_sz;
s->linear_size = lm_sz;
s->mod = m;
s->module = module;
s->sb_size = sb_sz;
module_acquire(m);
module_acquire(module);
return s;
}
@ -112,7 +112,7 @@ static inline void
sb_alloc_callback(uv_handle_t *h, size_t suggested, uv_buf_t *buf)
{
struct sandbox *c = h->data;
size_t l = (c->mod->max_rr_sz - c->rr_data_len);
size_t l = (c->module->max_request_or_response_size - c->rr_data_len);
buf->base = (c->req_resp_data + c->rr_data_len);
buf->len = l > suggested ? suggested : l;
}
@ -124,7 +124,7 @@ sandbox_client_request_get(void)
curr->rr_data_len = 0;
#ifndef USE_HTTP_UVIO
int r = 0;
r = recv(curr->csock, (curr->req_resp_data), curr->mod->max_req_sz, 0);
r = recv(curr->csock, (curr->req_resp_data), curr->module->max_request_size, 0);
if (r <= 0) {
if (r < 0) perror("recv1");
return r;
@ -136,7 +136,7 @@ sandbox_client_request_get(void)
if (rh->message_end) break;
r = recv(curr->csock, (curr->req_resp_data + curr->rr_data_len),
curr->mod->max_req_sz - curr->rr_data_len, 0);
curr->module->max_request_size - curr->rr_data_len, 0);
if (r < 0) {
perror("recv2");
return r;
@ -169,12 +169,12 @@ sandbox_client_response_set(void)
if (bodylen == 0) goto done;
strncpy(curr->req_resp_data + sndsz, HTTP_RESP_CONTTYPE, strlen(HTTP_RESP_CONTTYPE));
if (strlen(curr->mod->rspctype) <= 0) {
if (strlen(curr->module->response_content_type) <= 0) {
strncpy(curr->req_resp_data + sndsz + strlen("Content-type: "), HTTP_RESP_CONTTYPE_PLAIN,
strlen(HTTP_RESP_CONTTYPE_PLAIN));
} else {
strncpy(curr->req_resp_data + sndsz + strlen("Content-type: "), curr->mod->rspctype,
strlen(curr->mod->rspctype));
strncpy(curr->req_resp_data + sndsz + strlen("Content-type: "), curr->module->response_content_type,
strlen(curr->module->response_content_type));
}
sndsz += strlen(HTTP_RESP_CONTTYPE);
char len[10] = { 0 };
@ -228,7 +228,7 @@ sandbox_entry(void)
softint_enable();
}
struct module *curr_mod = sandbox_module(curr);
int argc = module_nargs(curr_mod);
int argc = module_argument_count(curr_mod);
// for stdio
int f = io_handle_open(0);
assert(f == 0);
@ -273,13 +273,13 @@ sandbox_entry(void)
}
struct sandbox *
sandbox_alloc(struct module *mod, char *args, int sock, const struct sockaddr *addr, u64 start_time)
sandbox_alloc(struct module *module, char *args, int sock, const struct sockaddr *addr, u64 start_time)
{
if (!module_is_valid(mod)) return NULL;
if (!module_is_valid(module)) return NULL;
// FIXME: don't use malloc. huge security problem!
// perhaps, main should be in its own sandbox, when it is not running any sandbox.
struct sandbox *sb = (struct sandbox *)sandbox_memory_map(mod);
struct sandbox *sb = (struct sandbox *)sandbox_memory_map(module);
if (!sb) return NULL;
// Assign the start time from the request
@ -287,7 +287,7 @@ sandbox_alloc(struct module *mod, char *args, int sock, const struct sockaddr *a
// actual module instantiation!
sb->args = (void *)args;
sb->stack_size = mod->stack_size;
sb->stack_size = module->stack_size;
sb->stack_start = mmap(NULL, sb->stack_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_GROWSDOWN, -1, 0);
if (sb->stack_start == MAP_FAILED) {
@ -317,8 +317,8 @@ sandbox_free(struct sandbox *sb)
int sz = sizeof(struct sandbox);
sz += sb->mod->max_rr_sz;
module_release(sb->mod);
sz += sb->module->max_request_or_response_size;
module_release(sb->module);
// TODO free(sb->args);
void * stkaddr = sb->stack_start;

Loading…
Cancel
Save