chore: run clang-format

main
Sean McBride 5 years ago
parent 2805934d49
commit c9b9a6553e

@ -6,7 +6,6 @@ Language: Cpp
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignTrailingComments: true

@ -13,7 +13,8 @@
/**
* http-parser data callback called when a URL is called
* Sanity check to make sure that the path matches the name of the module
* TODO: Why does this not fail this assertion? To execute fibonacci, I just request localhost:10000, not localhost:10000/fibonacci
* TODO: Why does this not fail this assertion? To execute fibonacci, I just request localhost:10000, not
*localhost:10000/fibonacci
* @param parser
* @param at the start of the URL
* @param length the length of the URL
@ -49,7 +50,8 @@ http_parser_settings__on_message_begin(http_parser *parser)
* Sets the key value of the latest header
* on a new header if last_was_value is true
* updating an existing header if last_was_value is false
* TODO: Is this logic correct? What is the relationship between fields and values? Is overwrite the correct logic if on_header executes twice in a row?
* TODO: Is this logic correct? What is the relationship between fields and values? Is overwrite the correct logic if
*on_header executes twice in a row?
* @param parser
* @param at start address of the header field
* @param length length of the header field
@ -66,7 +68,8 @@ http_parser_settings__on_header_field(http_parser *parser, const char *at, size_
assert(length < HTTP_HEADER_MAXSZ);
http_request->last_was_value = 0;
http_request->headers[http_request->header_count - 1].key = (char *)at; // it is from the sandbox's request_response_data, should persist.
http_request->headers[http_request->header_count - 1].key = (char *)
at; // it is from the sandbox's request_response_data, should persist.
return 0;
}
@ -89,7 +92,8 @@ http_parser_settings__on_header_value(http_parser *parser, const char *at, size_
assert(http_request->header_count <= HTTP_HEADERS_MAX);
assert(length < HTTP_HEADERVAL_MAXSZ);
http_request->headers[http_request->header_count - 1].value = (char *)at; // it is from the sandbox's request_response_data, should persist.
http_request->headers[http_request->header_count - 1].value = (char *)
at; // it is from the sandbox's request_response_data, should persist.
return 0;
}

@ -16,7 +16,8 @@ struct http_request {
int body_length;
int body_read_length; // How far we've read
// additional for http-parser
int last_was_value; // http-parser flag used to help the http-parser callbacks differentiate between header fields and values to know when to allocate a new header
int last_was_value; // http-parser flag used to help the http-parser callbacks differentiate between header
// fields and values to know when to allocate a new header
int header_end; // boolean flag set when header processing is complete
int message_begin; // boolean flag set when body processing begins
int message_end; // boolean flag set when body processing is complete

@ -73,7 +73,8 @@ libuv_callbacks__on_write_wakeup_sandbox(uv_write_t *write, int status)
struct sandbox *sandbox = write->data;
if (status < 0) {
sandbox->client_libuv_shutdown_request.data = sandbox;
uv_shutdown(&sandbox->client_libuv_shutdown_request, (uv_stream_t *)&sandbox->client_libuv_stream, libuv_callbacks__on_shutdown_wakeup_sakebox);
uv_shutdown(&sandbox->client_libuv_shutdown_request, (uv_stream_t *)&sandbox->client_libuv_stream,
libuv_callbacks__on_shutdown_wakeup_sakebox);
return;
}
worker_thread__wakeup_sandbox(sandbox);

@ -181,7 +181,8 @@ module__set_http_info(struct module *module, int request_count, char *request_he
***************************************/
void module__free(struct module *module);
struct module *module__new(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);
struct module *module__new(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);
int module__new_from_json(char *filename);
#endif /* SFRT_MODULE_H */

@ -99,7 +99,8 @@ extern void worker_thread__wakeup_sandbox(sandbox_t *s
* Public API *
**************************/
struct sandbox *sandbox__allocate(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, u64 start_time);
struct sandbox *sandbox__allocate(struct module *module, char *arguments, int socket_descriptor,
const struct sockaddr *socket_address, u64 start_time);
void sandbox__free(struct sandbox *sandbox);
int sandbox__parse_http_request(struct sandbox *sandbox, size_t length);
@ -160,7 +161,9 @@ sandbox__initialize_io_handle_and_set_file_descriptor(struct sandbox *sandbox, i
if (!sandbox) return -1;
if (file_descriptor < 0) return file_descriptor;
int handle_index = sandbox__initialize_io_handle(sandbox);
if (handle_index != -1) sandbox->handles[handle_index].file_descriptor = file_descriptor; // well, per sandbox.. so synchronization necessary!
if (handle_index != -1)
sandbox->handles[handle_index].file_descriptor =
file_descriptor; // well, per sandbox.. so synchronization necessary!
return handle_index;
}

@ -48,7 +48,8 @@ sandbox_request__add_to_global_dequeue(sandbox_request_t *sandbox_request)
* @return the new sandbox request
**/
static inline sandbox_request_t *
sandbox_request__allocate(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, u64 start_time)
sandbox_request__allocate(struct module *module, char *arguments, int socket_descriptor,
const struct sockaddr *socket_address, u64 start_time)
{
sandbox_request_t *sandbox_request = (sandbox_request_t *)malloc(sizeof(sandbox_request_t));
assert(sandbox_request);

@ -123,7 +123,8 @@ typedef enum
#ifdef DEBUG
#ifdef NOSTDIO
#define debuglog(fmt, ...) dprintf(log_file_descriptor, "(%d,%lu) %s: " fmt, sched_getcpu(), pthread_self(), __func__, ##__VA_ARGS__)
#define debuglog(fmt, ...) \
dprintf(log_file_descriptor, "(%d,%lu) %s: " fmt, sched_getcpu(), pthread_self(), __func__, ##__VA_ARGS__)
#else
#define debuglog(fmt, ...) printf("(%d,%lu) %s: " fmt, sched_getcpu(), pthread_self(), __func__, ##__VA_ARGS__)
#endif

@ -16,4 +16,3 @@ http_request__get_body(struct http_request *http_request, char **body)
*body = http_request->body;
return http_request->body_length;
}

@ -23,14 +23,17 @@ http_response__encode_as_vector(struct http_response *http_response)
http_response->bufs[buffer_count] = uv_buf_init(http_response->status, http_response->status_length);
buffer_count++;
for (int i = 0; i < http_response->header_count; i++) {
http_response->bufs[buffer_count] = uv_buf_init(http_response->headers[i].header, http_response->headers[i].length);
http_response->bufs[buffer_count] = uv_buf_init(http_response->headers[i].header,
http_response->headers[i].length);
buffer_count++;
}
if (http_response->body) {
http_response->bufs[buffer_count] = uv_buf_init(http_response->body, http_response->body_length);
buffer_count++;
http_response->bufs[buffer_count] = uv_buf_init(http_response->status + http_response->status_length - 2, 2); // for crlf
http_response->bufs[buffer_count] = uv_buf_init(http_response->status + http_response->status_length
- 2,
2); // for crlf
buffer_count++;
}
#else

@ -943,7 +943,8 @@ wasm_write_callback(uv_write_t *req, int status)
}
void
wasm_udp_recv_callback(uv_udp_t *h, ssize_t nread, const uv_buf_t *buffer, const struct sockaddr *socket_address, unsigned flags)
wasm_udp_recv_callback(uv_udp_t *h, ssize_t nread, const uv_buf_t *buffer, const struct sockaddr *socket_address,
unsigned flags)
{
struct sandbox *c = h->data;

@ -50,7 +50,8 @@ module__initialize_as_server(struct module *module)
struct epoll_event accept_evt;
accept_evt.data.ptr = (void *)module;
accept_evt.events = EPOLLIN;
if (epoll_ctl(runtime__epoll_file_descriptor, EPOLL_CTL_ADD, module->socket_descriptor, &accept_evt) < 0) assert(0);
if (epoll_ctl(runtime__epoll_file_descriptor, EPOLL_CTL_ADD, module->socket_descriptor, &accept_evt) < 0)
assert(0);
}
/***************************************
@ -82,8 +83,8 @@ module__free(struct module *module)
/**
* Module Contructor
* Creates a new module, invokes initialize_tables to initialize the indirect table, adds it to the module DB, and starts
*listening for HTTP Requests
* Creates a new module, invokes initialize_tables to initialize the indirect table, adds it to the module DB, and
*starts listening for HTTP Requests
*
* @param name
* @param path
@ -146,8 +147,8 @@ module__new(char *name, char *path, i32 argument_count, u32 stack_size, u32 max_
// assumption: All modules are created at program start before we enable preemption or enable the execution of
// any worker threads We are checking that thread-local module_indirect_table is NULL to prove that we aren't
// yet preempting If we want to be able to do this later, we can possibly defer module__initialize_table until the
// first invocation
// yet preempting If we want to be able to do this later, we can possibly defer module__initialize_table until
// the first invocation
assert(cache_tbl == NULL);
// TODO: determine why we have to set the module_indirect_table state before calling table init and then restore

@ -93,12 +93,9 @@ listener_thread__main(void *dummy)
total_requests++;
printf("Received Request %d at %lu\n", total_requests, start_time);
sandbox_request_t *sandbox_request = sandbox_request__allocate(
module,
module->name,
socket_descriptor,
(const struct sockaddr *)&client_address,
start_time);
sandbox_request_t *sandbox_request =
sandbox_request__allocate(module, module->name, socket_descriptor,
(const struct sockaddr *)&client_address, start_time);
assert(sandbox_request);
// TODO: Refactor sandbox_request__allocate to not add to global request queue and do this here
@ -176,7 +173,8 @@ worker_thread__switch_to_sandbox(struct sandbox *next_sandbox)
arch_context_t *current_register_context = current_sandbox == NULL ? NULL : &current_sandbox->ctxt;
current_sandbox__set(next_sandbox);
// If the current sandbox we're switching from is in a RETURNED state, add to completion queue
if (current_sandbox && current_sandbox->state == RETURNED) worker_thread__completion_queue__add_sandbox(current_sandbox);
if (current_sandbox && current_sandbox->state == RETURNED)
worker_thread__completion_queue__add_sandbox(current_sandbox);
worker_thread__next_context = next_register_context;
arch_context_switch(current_register_context, next_register_context);
softint__enable();
@ -202,7 +200,8 @@ done:
/**
* Mark the currently executing sandbox as blocked, remove it from the local runqueue, and pull the sandbox at the head of the runqueue
* Mark the currently executing sandbox as blocked, remove it from the local runqueue, and pull the sandbox at the head
*of the runqueue
**/
void
worker_thread__block_current_sandbox(void)
@ -213,7 +212,8 @@ worker_thread__block_current_sandbox(void)
ps_list_rem_d(current_sandbox);
current_sandbox->state = BLOCKED;
struct sandbox *next_sandbox = worker_thread__get_next_sandbox(0);
debuglog("[%p: %next_sandbox, %p: %next_sandbox]\n", current_sandbox, current_sandbox->module->name, next_sandbox, next_sandbox ? next_sandbox->module->name : "");
debuglog("[%p: %next_sandbox, %p: %next_sandbox]\n", current_sandbox, current_sandbox->module->name,
next_sandbox, next_sandbox ? next_sandbox->module->name : "");
softint__enable();
worker_thread__switch_to_sandbox(next_sandbox);
}
@ -267,7 +267,8 @@ worker_thread__pull_and_process_sandbox_requests(void)
if ((sandbox_request = sandbox_request__steal_from_global_dequeue()) == NULL) break;
// Actually allocate the sandbox for the requests that we've pulled
struct sandbox *sandbox = sandbox__allocate(sandbox_request->module, sandbox_request->arguments,
sandbox_request->socket_descriptor, sandbox_request->socket_address,
sandbox_request->socket_descriptor,
sandbox_request->socket_address,
sandbox_request->start_time);
assert(sandbox);
free(sandbox_request);
@ -341,7 +342,8 @@ worker_thread__get_next_sandbox(int in_interrupt)
// Execute Round Robin Scheduling Logic
// Grab the sandbox at the head of the thread local runqueue, add it to the end, and return it
struct sandbox *sandbox = ps_list_head_first_d(&worker_thread__run_queue, struct sandbox);
// We are assuming that any sandboxed in the RETURNED state should have been pulled from the local runqueue by now!
// We are assuming that any sandboxed in the RETURNED state should have been pulled from the local runqueue by
// now!
assert(sandbox->state != RETURNED);
ps_list_rem_d(sandbox);
ps_list_head_append_d(&worker_thread__run_queue, sandbox);

@ -54,7 +54,8 @@ sandbox__parse_http_request(struct sandbox *sandbox, size_t length)
{
// Why is our start address sandbox->request_response_data + sandbox->request_response_data_length?
// it's like a cursor to keep track of what we've read so far
http_parser_execute(&sandbox->http_parser, &runtime__http_parser_settings, sandbox->request_response_data + sandbox->request_response_data_length, length);
http_parser_execute(&sandbox->http_parser, &runtime__http_parser_settings,
sandbox->request_response_data + sandbox->request_response_data_length, length);
return 0;
}
@ -81,7 +82,8 @@ current_sandbox__receive_and_parse_client_request(void)
struct http_request *rh = &curr->http_request;
if (rh->message_end) break;
r = recv(curr->client_socket_descriptor, (curr->request_response_data + curr->request_response_data_length),
r = recv(curr->client_socket_descriptor,
(curr->request_response_data + curr->request_response_data_length),
curr->module->max_request_size - curr->request_response_data_length, 0);
if (r < 0) {
perror("recv2");
@ -89,7 +91,9 @@ current_sandbox__receive_and_parse_client_request(void)
}
}
#else
int r = uv_read_start((uv_stream_t *)&curr->client_libuv_stream, libuv_callbacks__on_allocate_setup_request_response_data, libuv_callbacks__on_read_parse_http_request);
int r = uv_read_start((uv_stream_t *)&curr->client_libuv_stream,
libuv_callbacks__on_allocate_setup_request_response_data,
libuv_callbacks__on_read_parse_http_request);
worker_thread__process_io();
if (curr->request_response_data_length == 0) return 0;
#endif
@ -119,8 +123,8 @@ current_sandbox__build_and_send_client_response(void)
strncpy(curr->request_response_data + sndsz + strlen("Content-type: "), HTTP_RESP_CONTTYPE_PLAIN,
strlen(HTTP_RESP_CONTTYPE_PLAIN));
} else {
strncpy(curr->request_response_data + sndsz + strlen("Content-type: "), curr->module->response_content_type,
strlen(curr->module->response_content_type));
strncpy(curr->request_response_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 };
@ -155,7 +159,8 @@ done:
.data = curr,
};
uv_buf_t bufv = uv_buf_init(curr->request_response_data, sndsz);
int r = uv_write(&req, (uv_stream_t *)&curr->client_libuv_stream, &bufv, 1, libuv_callbacks__on_write_wakeup_sandbox);
int r = uv_write(&req, (uv_stream_t *)&curr->client_libuv_stream, &bufv, 1,
libuv_callbacks__on_write_wakeup_sandbox);
worker_thread__process_io();
#endif
return 0;
@ -163,7 +168,8 @@ done:
/**
* Sandbox execution logic
* Handles setup, request parsing, WebAssembly initialization, function execution, response building and sending, and cleanup
* Handles setup, request parsing, WebAssembly initialization, function execution, response building and sending, and
*cleanup
**/
void
current_sandbox__main(void)
@ -216,7 +222,6 @@ current_sandbox__main(void)
// If the HTTP Request returns 1, we've successfully received and parsed the HTTP request, so execute it!
if (current_sandbox__receive_and_parse_client_request() > 0) {
//
current_sandbox->request_response_data_length = response_header_length;
@ -229,7 +234,8 @@ current_sandbox__main(void)
current_sandbox__setup_arguments(argument_count);
// Executing the function within the WebAssembly sandbox
current_sandbox->return_value = module__main(current_module, argument_count, current_sandbox->arguments_offset);
current_sandbox->return_value = module__main(current_module, argument_count,
current_sandbox->arguments_offset);
// Retrieve the result from the WebAssembly sandbox, construct the HTTP response, and send to client
current_sandbox__build_and_send_client_response();
@ -287,7 +293,8 @@ sandbox__allocate_memory(struct module *module)
}
struct sandbox *
sandbox__allocate(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address, u64 start_time)
sandbox__allocate(struct module *module, char *arguments, int socket_descriptor, const struct sockaddr *socket_address,
u64 start_time)
{
if (!module__is_valid(module)) return NULL;
@ -314,7 +321,8 @@ sandbox__allocate(struct module *module, char *arguments, int socket_descriptor,
ps_list_init_d(sandbox);
// Setup the sandbox's context, stack, and instruction pointer
arch_context_init(&sandbox->ctxt, (reg_t)current_sandbox__main, (reg_t)(sandbox->stack_start + sandbox->stack_size));
arch_context_init(&sandbox->ctxt, (reg_t)current_sandbox__main,
(reg_t)(sandbox->stack_start + sandbox->stack_size));
return sandbox;
}
@ -340,7 +348,8 @@ sandbox__free(struct sandbox *sandbox)
size_t stksz = sandbox->stack_size;
// depending on the memory type
// free_linear_memory(sandbox->linear_memory_start, sandbox->linear_memory_size, sandbox->linear_memory_max_size);
// free_linear_memory(sandbox->linear_memory_start, sandbox->linear_memory_size,
// sandbox->linear_memory_max_size);
int ret;
// mmaped memory includes sandbox structure in there.

@ -192,7 +192,6 @@ softint__disarm_timer(void)
}
/**
* Initialize software Interrupts
* Register sonftint_handler to execute on SIGALRM and SIGUSR1

Loading…
Cancel
Save