|
|
@ -7,23 +7,13 @@
|
|
|
|
struct module {
|
|
|
|
struct module {
|
|
|
|
char name[MOD_NAME_MAX];
|
|
|
|
char name[MOD_NAME_MAX];
|
|
|
|
char path[MOD_PATH_MAX];
|
|
|
|
char path[MOD_PATH_MAX];
|
|
|
|
|
|
|
|
|
|
|
|
void *dynamic_library_handle; // Handle to the *.so of the serverless function
|
|
|
|
void *dynamic_library_handle; // Handle to the *.so of the serverless function
|
|
|
|
mod_main_fn_t entry_fn;
|
|
|
|
|
|
|
|
mod_glb_fn_t glb_init_fn;
|
|
|
|
|
|
|
|
mod_mem_fn_t mem_init_fn;
|
|
|
|
|
|
|
|
mod_tbl_fn_t tbl_init_fn;
|
|
|
|
|
|
|
|
mod_libc_fn_t libc_init_fn;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct indirect_table_entry indirect_table[INDIRECT_TABLE_SIZE];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i32 argument_count;
|
|
|
|
i32 argument_count;
|
|
|
|
u32 stack_size; // a specification?
|
|
|
|
u32 stack_size; // a specification?
|
|
|
|
u64 max_memory; // perhaps a specification of the module. (max 4GB)
|
|
|
|
u64 max_memory; // perhaps a specification of the module. (max 4GB)
|
|
|
|
u32 timeout; // again part of the module specification.
|
|
|
|
u32 timeout; // again part of the module specification.
|
|
|
|
|
|
|
|
|
|
|
|
u32 reference_count; // ref count how many instances exist here.
|
|
|
|
u32 reference_count; // ref count how many instances exist here.
|
|
|
|
|
|
|
|
struct indirect_table_entry indirect_table[INDIRECT_TABLE_SIZE];
|
|
|
|
struct sockaddr_in socket_address;
|
|
|
|
struct sockaddr_in socket_address;
|
|
|
|
int socket_descriptor;
|
|
|
|
int socket_descriptor;
|
|
|
|
int port;
|
|
|
|
int port;
|
|
|
@ -35,27 +25,46 @@ struct module {
|
|
|
|
// so, using direct epoll for accepting connections.
|
|
|
|
// so, using direct epoll for accepting connections.
|
|
|
|
// uv_handle_t srvuv;
|
|
|
|
// uv_handle_t srvuv;
|
|
|
|
|
|
|
|
|
|
|
|
// req/resp from http, (resp size including headers!)..
|
|
|
|
|
|
|
|
unsigned long max_request_size;
|
|
|
|
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_headers[HTTP_HEADERS_MAX][HTTP_HEADER_MAXSZ];
|
|
|
|
|
|
|
|
int request_header_count;
|
|
|
|
char request_content_type[HTTP_HEADERVAL_MAXSZ];
|
|
|
|
char request_content_type[HTTP_HEADERVAL_MAXSZ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// resp size including headers!
|
|
|
|
|
|
|
|
unsigned long max_response_size;
|
|
|
|
|
|
|
|
int response_header_count;
|
|
|
|
char response_content_type[HTTP_HEADERVAL_MAXSZ];
|
|
|
|
char response_content_type[HTTP_HEADERVAL_MAXSZ];
|
|
|
|
char response_headers[HTTP_HEADERS_MAX][HTTP_HEADER_MAXSZ];
|
|
|
|
char response_headers[HTTP_HEADERS_MAX][HTTP_HEADER_MAXSZ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Equals the largest of either max_request_size or max_response_size
|
|
|
|
|
|
|
|
unsigned long max_request_or_response_size;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Functions to initialize aspects of sandbox
|
|
|
|
|
|
|
|
mod_glb_fn_t initialize_globals;
|
|
|
|
|
|
|
|
mod_mem_fn_t initialize_memory;
|
|
|
|
|
|
|
|
mod_tbl_fn_t initialize_tables;
|
|
|
|
|
|
|
|
mod_libc_fn_t initialize_libc;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Entry Function to invoke serverless function
|
|
|
|
|
|
|
|
mod_main_fn_t main;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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 reference_count == 0
|
|
|
|
|
|
|
|
void module_free(struct module *module);
|
|
|
|
|
|
|
|
struct module *module_find_by_name(char *name);
|
|
|
|
struct module *module_find_by_name(char *name);
|
|
|
|
struct module *module_find_by_socket_descriptor(int sock);
|
|
|
|
struct module *module_find_by_socket_descriptor(int sock);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
void module_free(struct module *module);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Sets the HTTP Request and Response Headers and Content type on a module
|
|
|
|
|
|
|
|
* @param module
|
|
|
|
|
|
|
|
* @param request_count
|
|
|
|
|
|
|
|
* @param request_headers
|
|
|
|
|
|
|
|
* @param request_content_type
|
|
|
|
|
|
|
|
* @param response_count
|
|
|
|
|
|
|
|
* @param response_headers
|
|
|
|
|
|
|
|
* @param response_content_type
|
|
|
|
|
|
|
|
**/
|
|
|
|
static inline void
|
|
|
|
static inline void
|
|
|
|
module_http_info(struct module *module, int request_count, char *request_headers, char request_content_type[],
|
|
|
|
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[])
|
|
|
|
int response_count, char *response_headers, char response_content_type[])
|
|
|
@ -77,53 +86,55 @@ module_http_info(struct module *module, int request_count, char *request_headers
|
|
|
|
static inline int
|
|
|
|
static inline int
|
|
|
|
module_is_valid(struct module *module)
|
|
|
|
module_is_valid(struct module *module)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (module && module->dynamic_library_handle && module->entry_fn) return 1;
|
|
|
|
if (module && module->dynamic_library_handle && module->main) return 1;
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: What is the point of these wrapper functions. They seem exceptionally silly
|
|
|
|
|
|
|
|
// We have the module, so why not just invoke the function pointer directly?
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Invoke a module's glb_init_fn
|
|
|
|
* Invoke a module's initialize_globals
|
|
|
|
* @param module
|
|
|
|
* @param module
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
static inline void
|
|
|
|
static inline void
|
|
|
|
module_globals_init(struct module *module)
|
|
|
|
module_globals_init(struct module *module)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// called in a sandbox.
|
|
|
|
// called in a sandbox.
|
|
|
|
module->glb_init_fn();
|
|
|
|
module->initialize_globals();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Invoke a module's tbl_init_fn
|
|
|
|
* Invoke a module's initialize_tables
|
|
|
|
* @param module
|
|
|
|
* @param module
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
static inline void
|
|
|
|
static inline void
|
|
|
|
module_table_init(struct module *module)
|
|
|
|
module_table_init(struct module *module)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// called at module creation time (once only per module).
|
|
|
|
// called at module creation time (once only per module).
|
|
|
|
module->tbl_init_fn();
|
|
|
|
module->initialize_tables();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Invoke a module's libc_init_fn
|
|
|
|
* Invoke a module's initialize_libc
|
|
|
|
* @param module
|
|
|
|
* @param module
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
static inline void
|
|
|
|
static inline void
|
|
|
|
module_libc_init(struct module *module, i32 env, i32 args)
|
|
|
|
module_libc_init(struct module *module, i32 env, i32 args)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// called in a sandbox.
|
|
|
|
// called in a sandbox.
|
|
|
|
module->libc_init_fn(env, args);
|
|
|
|
module->initialize_libc(env, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Invoke a module's mem_init_fn
|
|
|
|
* Invoke a module's initialize_memory
|
|
|
|
* @param module
|
|
|
|
* @param module
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
static inline void
|
|
|
|
static inline void
|
|
|
|
module_memory_init(struct module *module)
|
|
|
|
module_memory_init(struct module *module)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// called in a sandbox.
|
|
|
|
// called in a sandbox.
|
|
|
|
module->mem_init_fn();
|
|
|
|
module->initialize_memory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -135,7 +146,7 @@ module_memory_init(struct module *module)
|
|
|
|
static inline i32
|
|
|
|
static inline i32
|
|
|
|
module_entry(struct module *module, i32 argc, i32 argv)
|
|
|
|
module_entry(struct module *module, i32 argc, i32 argv)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return module->entry_fn(argc, argv);
|
|
|
|
return module->main(argc, argv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|