Merge pull request #324 from gwsystems/update-wasm-apps-5

Update wasm apps 5
master
Sean McBride 3 years ago committed by GitHub
commit ee760577ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -110,6 +110,7 @@
"current_wasm_module_instance.h": "c",
"wasm_memory.h": "c",
"sledge_abi.h": "c",
"vec.h": "c"
},
"files.exclude": {
"**/.git": true,

@ -85,3 +85,6 @@ trap_divzero.install: ../runtime/bin/trap_divzero.wasm.so
.PHONY: stack_overflow.install
stack_overflow.install: ../runtime/bin/stack_overflow.wasm.so
.PHONY: html.install
html.install: ../runtime/bin/html.wasm.so

@ -1 +1 @@
Subproject commit f6d07455676a1a5cb64b03276c9b4985ef721451
Subproject commit 88e4c441dd3c51bc4035a94a0942495ece7f42a8

@ -1 +1 @@
Subproject commit 3aca5263d346065173d35437c319d6d3d61204b9
Subproject commit acc4cadf97a6bdbccc283cff2e75a307b57d4297

@ -26,7 +26,7 @@ dist:
dist/%.o: src/%.c dist
clang ${CFLAGS} -c ${INCLUDES} -o $@ $<
dist/libsledge.a: dist/memory_instructions.o dist/numeric_instructions.o dist/table_instructions.o dist/variable_instructions.o dist/instantiation.o dist/wasi_snapshot_preview1.o
dist/libsledge.a: dist/control_instructions.o dist/memory_instructions.o dist/numeric_instructions.o dist/table_instructions.o dist/variable_instructions.o dist/instantiation.o dist/wasi_snapshot_preview1.o
ar rcs dist/libsledge.a $^
clean:

@ -45,12 +45,12 @@ struct sledge_abi__wasm_module_instance {
/* Based on example traps listed at https://webassembly.org/docs/security/ */
enum sledge_abi__wasm_trap
{
WASM_TRAP_EXIT = 1,
WASM_TRAP_INVALID_INDEX = 2,
WASM_TRAP_MISMATCHED_TYPE = 3,
WASM_TRAP_PROTECTED_CALL_STACK_OVERFLOW = 4,
WASM_TRAP_OUT_OF_BOUNDS_LINEAR_MEMORY = 5,
WASM_TRAP_ILLEGAL_ARITHMETIC_OPERATION = 6,
WASM_TRAP_INVALID_INDEX = 1,
WASM_TRAP_MISMATCHED_TYPE = 2,
WASM_TRAP_PROTECTED_CALL_STACK_OVERFLOW = 3,
WASM_TRAP_OUT_OF_BOUNDS_LINEAR_MEMORY = 4,
WASM_TRAP_ILLEGAL_ARITHMETIC_OPERATION = 5,
WASM_TRAP_UNREACHABLE = 6,
WASM_TRAP_COUNT
};

@ -0,0 +1,7 @@
#include "sledge_abi.h"
void
awsm_abi__trap_unreachable(void)
{
sledge_abi__wasm_trap_raise(WASM_TRAP_UNREACHABLE);
}

@ -6,7 +6,7 @@
uint32_t
wasi_snapshot_preview1_args_get(__wasi_size_t argv_retoffset, __wasi_size_t argv_buf_retoffset)
{
return sledge_abi__wasi_snapshot_preview1_args_get(argv_buf_retoffset, argv_buf_retoffset);
return sledge_abi__wasi_snapshot_preview1_args_get(argv_retoffset, argv_buf_retoffset);
}
uint32_t
@ -268,7 +268,7 @@ wasi_snapshot_preview1_poll_oneoff(__wasi_size_t in_baseoffset, __wasi_size_t ou
void
wasi_snapshot_preview1_proc_exit(__wasi_exitcode_t exitcode)
{
sledge_abi__wasi_snapshot_preview1_proc_raise(exitcode);
sledge_abi__wasi_snapshot_preview1_proc_exit(exitcode);
}
uint32_t

@ -109,3 +109,5 @@ current_sandbox_trap(enum sledge_abi__wasm_trap trapno)
siglongjmp(sandbox->ctxt.start_buf, trapno);
}
extern noreturn void current_sandbox_fini();

@ -7,7 +7,10 @@
#define HTTP_MAX_HEADER_COUNT 16
#define HTTP_MAX_HEADER_LENGTH 32
#define HTTP_MAX_HEADER_VALUE_LENGTH 64
#define HTTP_MAX_HEADER_VALUE_LENGTH 256
#define HTTP_MAX_QUERY_PARAM_COUNT 16
#define HTTP_MAX_QUERY_PARAM_LENGTH 32
#define HTTP_RESPONSE_200_TEMPLATE \
"HTTP/1.1 200 OK\r\n" \

@ -12,12 +12,19 @@ struct http_header {
int value_length;
};
struct http_query_param {
char value[HTTP_MAX_QUERY_PARAM_LENGTH];
int value_length;
};
struct http_request {
struct http_header headers[HTTP_MAX_HEADER_COUNT];
int header_count;
char *body;
int body_length;
int body_read_length; /* How far we've read */
struct http_header headers[HTTP_MAX_HEADER_COUNT];
int header_count;
struct http_query_param query_params[HTTP_MAX_QUERY_PARAM_COUNT];
int query_params_count;
char *body;
int body_length;
int body_read_length; /* How far we've read */
/* additional members for http-parser */
bool last_was_value; /* http-parser flag used to help the http-parser callbacks differentiate between header

@ -78,7 +78,7 @@ sandbox_receive_request(struct sandbox *sandbox)
#ifdef LOG_HTTP_PARSER
debuglog("Sandbox: %lu http_parser_execute(%p, %p, %p, %zu\n)", sandbox->id, parser, settings,
&sandbox->request.base[sandbox->request.length], bytes_received);
&sandbox->request.buffer[sandbox->request.length], bytes_received);
#endif
size_t bytes_parsed = http_parser_execute(parser, settings,
(const char *)&request->buffer[request_length],
@ -96,6 +96,14 @@ sandbox_receive_request(struct sandbox *sandbox)
request->length += bytes_parsed;
}
#ifdef LOG_HTTP_PARSER
for (int i = 0; i < sandbox->http_request.query_params_count; i++) {
debuglog("Argument %d, Len: %d, %.*s\n", i, sandbox->http_request.query_params[i].value_length,
sandbox->http_request.query_params[i].value_length,
sandbox->http_request.query_params[i].value);
}
#endif
rc = 0;
done:
return rc;

@ -18,10 +18,6 @@
thread_local struct sandbox *worker_thread_current_sandbox = NULL;
// TODO: Propagate arguments from *.json spec file
const int dummy_argc = 1;
const char *dummy_argv[] = { "Test" };
/**
* @brief Switches from an executing sandbox to the worker thread base context
*
@ -87,8 +83,6 @@ current_sandbox_wasm_trap_handler(int trapno)
sandbox_syscall(sandbox);
switch (trapno) {
case WASM_TRAP_EXIT:
break;
case WASM_TRAP_INVALID_INDEX:
error_message = "WebAssembly Trap: Invalid Index\n";
client_socket_send(sandbox->client_socket_descriptor, http_header_build(500), http_header_len(500),
@ -114,6 +108,16 @@ current_sandbox_wasm_trap_handler(int trapno)
client_socket_send(sandbox->client_socket_descriptor, http_header_build(500), http_header_len(500),
current_sandbox_sleep);
break;
case WASM_TRAP_UNREACHABLE:
error_message = "WebAssembly Trap: Unreachable Instruction\n";
client_socket_send(sandbox->client_socket_descriptor, http_header_build(500), http_header_len(500),
current_sandbox_sleep);
break;
default:
error_message = "WebAssembly Trap: Unknown Trapno\n";
client_socket_send(sandbox->client_socket_descriptor, http_header_build(500), http_header_len(500),
current_sandbox_sleep);
break;
}
debuglog("%s", error_message);
@ -156,8 +160,15 @@ current_sandbox_init()
/* Initialize WASI */
wasi_options_t options;
wasi_options_init(&options);
options.argc = dummy_argc;
options.argv = dummy_argv;
/* Initialize Arguments. First arg is the module name. Subsequent args are query parameters */
char *args[HTTP_MAX_QUERY_PARAM_COUNT + 1];
args[0] = sandbox->module->name;
for (int i = 0; i < sandbox->http_request.query_params_count; i++)
args[i + 1] = (char *)sandbox->http_request.query_params[i].value;
options.argc = sandbox->http_request.query_params_count + 1;
options.argv = (const char **)&args;
sandbox->wasi_context = wasi_context_init(&options);
sledge_abi__current_wasm_module_instance.wasi_context = sandbox->wasi_context;
assert(sandbox->wasi_context != NULL);
@ -177,7 +188,7 @@ err:
return NULL;
}
static inline void
extern noreturn void
current_sandbox_fini()
{
struct sandbox *sandbox = current_sandbox_get();

@ -28,9 +28,42 @@ http_parser_settings_on_url(http_parser *parser, const char *at, size_t length)
#ifdef LOG_HTTP_PARSER
debuglog("sandbox: %lu, length: %zu, Content \"%.*s\"\n", sandbox->id, length, (int)length, at);
assert(strncmp(sandbox->module->name, (at + 1), length - 1) == 0);
#endif
char *query_params = memchr(at, '?', length);
if (query_params != NULL) {
char *prev = query_params + 1;
char *cur = NULL;
while ((cur = strchr(prev, '&')) != NULL
&& sandbox->http_request.query_params_count < HTTP_MAX_QUERY_PARAM_COUNT) {
cur++;
size_t len = cur - prev - 1;
sandbox->http_request.query_params[sandbox->http_request.query_params_count].value_length =
len < HTTP_MAX_QUERY_PARAM_LENGTH - 1 ? len : HTTP_MAX_QUERY_PARAM_LENGTH - 1;
strncpy(sandbox->http_request.query_params[sandbox->http_request.query_params_count].value,
prev,
sandbox->http_request.query_params[sandbox->http_request.query_params_count]
.value_length);
sandbox->http_request.query_params_count++;
prev = cur;
}
if (prev != NULL && sandbox->http_request.query_params_count < HTTP_MAX_QUERY_PARAM_COUNT) {
size_t len = &at[length] - prev;
sandbox->http_request.query_params[sandbox->http_request.query_params_count].value_length =
len < HTTP_MAX_QUERY_PARAM_LENGTH - 1 ? len : HTTP_MAX_QUERY_PARAM_LENGTH - 1;
strncpy(sandbox->http_request.query_params[sandbox->http_request.query_params_count].value,
prev,
sandbox->http_request.query_params[sandbox->http_request.query_params_count]
.value_length);
sandbox->http_request.query_params_count++;
}
}
return 0;
}

@ -36,27 +36,12 @@ wasi_context_init(wasi_options_t *options)
if (options->argc > 0) {
assert(options->argv != NULL);
/* Strip path from first arg, calculating offset and length */
size_t first_arg_offset = 0;
size_t first_arg_len = 0;
for (first_arg_offset = strlen(options->argv[0]); first_arg_offset > 0; first_arg_offset--) {
if (options->argv[0][first_arg_offset] == '/') {
first_arg_offset++;
break;
}
}
first_arg_len = strlen(options->argv[0]) - first_arg_offset;
/* Calculate argument buffer size */
__wasi_size_t argv_buf_size = 0;
__wasi_size_t argv_buffer_offsets[options->argc + 1];
for (int i = 0; i < options->argc; i++) {
argv_buffer_offsets[i] = argv_buf_size;
if (i == 0) {
argv_buf_size += first_arg_len + 1;
} else {
argv_buf_size += strlen(options->argv[i]) + 1;
}
argv_buf_size += strlen(options->argv[i]) + 1;
}
argv_buffer_offsets[options->argc] = argv_buf_size;
@ -76,10 +61,7 @@ wasi_context_init(wasi_options_t *options)
}
/* Copy the binary name minux the path as the first arg */
strncpy(wasi_context->argv_buf, &options->argv[0][first_arg_offset], first_arg_len);
/* Copy the binary name minux the path as the first arg */
for (int i = 1; i < options->argc; i++) {
for (int i = 0; i < options->argc; i++) {
strncpy(&wasi_context->argv_buf[argv_buffer_offsets[i]], options->argv[i],
argv_buffer_offsets[i + 1] - argv_buffer_offsets[i]);
}
@ -326,8 +308,8 @@ wasi_fromerrno(int errno_)
* Callers of this syscall only provide the base address of the two buffers because the WASI specification
* assumes that the caller first called args_sizes_get and sized the buffers appropriately.
*
* @param argv_retptr
* @param argv_buf_retptr
* @param argv - temp argv to store host pointers into sandbox linear memory
* @param argv_buf_retptr - host pointer to the start of the argv buffer in linear memory
* @return __WASI_ERRNO_SUCCESS or WASI_EINVAL
*/
__wasi_errno_t
@ -338,8 +320,8 @@ wasi_snapshot_preview1_backing_args_get(wasi_context_t *context, char **argv, ch
if (context->argc > 0) memcpy(argv_buf, context->argv_buf, context->argv_buf_size);
for (__wasi_size_t i = 0; i < context->argc; i++) {
__wasi_size_t offset = context->argv[i] - context->argv_buf;
argv[i] = &argv_buf[context->argv[i] - context->argv_buf];
size_t offset = context->argv[i] - context->argv_buf;
argv[i] = &argv_buf[offset];
}
@ -360,10 +342,6 @@ wasi_snapshot_preview1_backing_args_sizes_get(wasi_context_t *context, __wasi_si
{
if (context == NULL || argc_retptr == NULL || argv_buf_len_retptr == NULL) return __WASI_ERRNO_INVAL;
// TODO: Delete after refactoring args logic
// fprintf(stderr, "argc: %d\n", wasi_context->argc);
// fprintf(stderr, "argv_buf_size: %d\n", wasi_context->argv_buf_size);
*argc_retptr = context->argc;
*argv_buf_len_retptr = context->argv_buf_size;
return __WASI_ERRNO_SUCCESS;
@ -1064,9 +1042,8 @@ wasi_snapshot_preview1_backing_poll_oneoff(wasi_context_t *context, const __wasi
noreturn void
wasi_snapshot_preview1_backing_proc_exit(wasi_context_t *context, __wasi_exitcode_t exitcode)
{
struct sandbox *s = current_sandbox_get();
s->return_value = exitcode;
siglongjmp(s->ctxt.start_buf, WASM_TRAP_EXIT);
current_sandbox_fini();
assert(0);
}
/**

@ -921,7 +921,8 @@ sledge_abi__wasi_snapshot_preview1_poll_oneoff(__wasi_size_t in_baseoffset, __wa
EXPORT void
sledge_abi__wasi_snapshot_preview1_proc_exit(__wasi_exitcode_t exitcode)
{
wasi_unsupported_syscall(__func__);
struct sandbox *sandbox = current_sandbox_get();
wasi_snapshot_preview1_backing_proc_exit(sandbox->wasi_context, exitcode);
}
/**

@ -0,0 +1,3 @@
res
perf.data
perf.data.old

@ -0,0 +1,52 @@
RUNTIME_DIR=../../runtime/
SLEDGE_BINARY_DIR=${RUNTIME_DIR}/bin
SLEDGE_TESTS_DIR=${RUNTIME_DIR}/tests
HOSTNAME=localhost
all: run
clean:
make -C ${RUNTIME_DIR} clean
make -C ${SLEDGE_TESTS_DIR} clean
rm -f ${SLEDGE_BINARY_DIR}/html.wasm.so
${SLEDGE_BINARY_DIR}/sledgert:
make -C ${RUNTIME_DIR} runtime
.PHONY: sledgert
sledgert: ${SLEDGE_BINARY_DIR}/sledgert
${SLEDGE_BINARY_DIR}/html.wasm.so:
make -C ../../applications html.install
.PHONY: html
html: ${SLEDGE_BINARY_DIR}/html.wasm.so
run: sledgert html
LD_LIBRARY_PATH=${SLEDGE_BINARY_DIR} ${SLEDGE_BINARY_DIR}/sledgert spec.json
debug: sledgert html
SLEDGE_DISABLE_PREEMPTION=true SLEDGE_NWORKERS=1 \
LD_LIBRARY_PATH=${SLEDGE_BINARY_DIR} gdb ${SLEDGE_BINARY_DIR}/sledgert \
--eval-command="handle SIGUSR1 noprint nostop" \
--eval-command="handle SIGPIPE noprint nostop" \
--eval-command="set pagination off" \
--eval-command="run spec.json"
client:
http :1337
browser-args:
xdg-open "http://localhost:1337"
client-stdin:
echo "Example STDIN" | http :1337
client-args:
http ":1337?firstArg&secondArg&thirdArg"
browser-args:
xdg-open "http://localhost:1337?firstArg&secondArg&thirdArg"
client-stdin-args:
echo "Example STDIN" | http ":1337?firstArg&secondArg&thirdArg"

@ -0,0 +1,2 @@
SLEDGE_SCHEDULER=EDF
SLEDGE_DISABLE_PREEMPTION=true

@ -0,0 +1,3 @@
SLEDGE_SCHEDULER=EDF
SLEDGE_DISABLE_PREEMPTION=false
SLEDGE_SIGALRM_HANDLER=TRIAGED

@ -0,0 +1,2 @@
SLEDGE_SCHEDULER=FIFO
SLEDGE_DISABLE_PREEMPTION=true

@ -0,0 +1,2 @@
SLEDGE_SCHEDULER=FIFO
SLEDGE_DISABLE_PREEMPTION=false

@ -0,0 +1,13 @@
#!/bin/bash
if ! command -v hey > /dev/null; then
HEY_URL=https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64
wget $HEY_URL -O hey
chmod +x hey
if [[ $(whoami) == "root" ]]; then
mv hey /usr/bin/hey
else
sudo mv hey /usr/bin/hey
fi
fi

@ -0,0 +1,13 @@
[
{
"name": "html",
"path": "html.wasm.so",
"port": 1337,
"expected-execution-us": 10000000,
"admissions-percentile": 70,
"relative-deadline-us": 20000000,
"http-req-size": 1024,
"http-resp-size": 102400,
"http-resp-content-type": "text/html"
}
]
Loading…
Cancel
Save