diff --git a/runtime/include/admissions_control.h b/runtime/include/admissions_control.h index b71f13a..03302cd 100644 --- a/runtime/include/admissions_control.h +++ b/runtime/include/admissions_control.h @@ -5,7 +5,7 @@ #define ADMISSIONS_CONTROL_GRANULARITY 1000000 -void admissions_control_initialize(); +void admissions_control_initialize(void); void admissions_control_add(uint64_t admissions_estimate); void admissions_control_subtract(uint64_t admissions_estimate); uint64_t admissions_control_calculate_estimate(uint64_t estimated_execution, uint64_t relative_deadline); diff --git a/runtime/include/client_socket.h b/runtime/include/client_socket.h index b862601..67b146a 100644 --- a/runtime/include/client_socket.h +++ b/runtime/include/client_socket.h @@ -23,7 +23,7 @@ client_socket_close(int client_socket, struct sockaddr *client_address) assert(client_socket != STDERR_FILENO); if (unlikely(close(client_socket) < 0)) { - char client_address_text[INET6_ADDRSTRLEN] = {}; + char client_address_text[INET6_ADDRSTRLEN] = { '\0' }; if (unlikely(inet_ntop(AF_INET, &client_address, client_address_text, INET6_ADDRSTRLEN) == NULL)) { debuglog("Failed to log client_address: %s", strerror(errno)); } @@ -55,19 +55,19 @@ client_socket_send(int client_socket, int status_code) panic("%d is not a valid status code\n", status_code); } - int sent = 0; - int to_send = strlen(response); + size_t total_sent = 0; + size_t to_send = strlen(response); - while (sent < to_send) { - rc = write(client_socket, &response[sent], to_send - sent); - if (rc < 0) { + while (total_sent < to_send) { + ssize_t sent = write(client_socket, &response[total_sent], to_send - total_sent); + if (sent < 0) { if (errno == EAGAIN) { debuglog("Unexpectedly blocking on write of %s\n", response); } debuglog("Error with %s\n", strerror(errno)); goto send_err; } - sent += rc; + total_sent += sent; }; rc = 0; diff --git a/runtime/include/generic_thread.h b/runtime/include/generic_thread.h index 68d26a0..9840660 100644 --- a/runtime/include/generic_thread.h +++ b/runtime/include/generic_thread.h @@ -6,5 +6,5 @@ extern __thread uint64_t generic_thread_lock_duration; extern __thread uint64_t generic_thread_lock_longest; extern __thread uint64_t generic_thread_start_timestamp; -void generic_thread_dump_lock_overhead(); -void generic_thread_initialize(); +void generic_thread_dump_lock_overhead(void); +void generic_thread_initialize(void); diff --git a/runtime/include/global_request_scheduler.h b/runtime/include/global_request_scheduler.h index b3ec0c7..5ec14d8 100644 --- a/runtime/include/global_request_scheduler.h +++ b/runtime/include/global_request_scheduler.h @@ -22,4 +22,4 @@ void global_request_scheduler_initialize(struct global_reques struct sandbox_request *global_request_scheduler_add(struct sandbox_request *); int global_request_scheduler_remove(struct sandbox_request **); int global_request_scheduler_remove_if_earlier(struct sandbox_request **, uint64_t targed_deadline); -uint64_t global_request_scheduler_peek(); +uint64_t global_request_scheduler_peek(void); diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index 5e80a0a..d72647e 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -53,7 +53,7 @@ extern uint64_t runtime_worker_threads_deadline[RUNTIME_WORK extern void runtime_initialize(void); extern void runtime_set_pthread_prio(pthread_t thread, unsigned int nice); -extern void runtime_set_resource_limits_to_max(); +extern void runtime_set_resource_limits_to_max(void); /* External Symbols */ extern void alloc_linear_memory(void); @@ -71,7 +71,7 @@ runtime_print_scheduler(enum RUNTIME_SCHEDULER variant) case RUNTIME_SCHEDULER_EDF: return "EDF"; } -}; +} static inline char * runtime_print_sigalrm_handler(enum RUNTIME_SIGALRM_HANDLER variant) @@ -82,4 +82,4 @@ runtime_print_sigalrm_handler(enum RUNTIME_SIGALRM_HANDLER variant) case RUNTIME_SIGALRM_HANDLER_TRIAGED: return "TRIAGED"; } -}; +} diff --git a/runtime/include/sandbox_request.h b/runtime/include/sandbox_request.h index e22f7f4..d74a8f4 100644 --- a/runtime/include/sandbox_request.h +++ b/runtime/include/sandbox_request.h @@ -28,7 +28,7 @@ struct sandbox_request { uint64_t admissions_estimate; }; -DEQUE_PROTOTYPE(sandbox, struct sandbox_request *); +DEQUE_PROTOTYPE(sandbox, struct sandbox_request *) /* Count of the total number of requests we've ever allocated. Never decrements as it is used to generate IDs */ extern _Atomic uint32_t sandbox_request_count; diff --git a/runtime/include/worker_thread.h b/runtime/include/worker_thread.h index a95818e..7c85679 100644 --- a/runtime/include/worker_thread.h +++ b/runtime/include/worker_thread.h @@ -41,7 +41,7 @@ worker_thread_get_memory_character(uint32_t offset) static inline char * worker_thread_get_memory_string(uint32_t offset, uint32_t max_length) { - for (int i = 0; i < max_length; i++) { + for (uint32_t i = 0; i < max_length; i++) { if (worker_thread_get_memory_character(offset + i) == '\0') { return (char *)worker_thread_get_memory_ptr_void(offset, 1); } @@ -49,4 +49,4 @@ worker_thread_get_memory_string(uint32_t offset, uint32_t max_length) return NULL; } -void worker_thread_switch_to_base_context(); +void worker_thread_switch_to_base_context(void); diff --git a/runtime/src/global_request_scheduler.c b/runtime/src/global_request_scheduler.c index e5eeac4..e852832 100644 --- a/runtime/src/global_request_scheduler.c +++ b/runtime/src/global_request_scheduler.c @@ -6,19 +6,19 @@ __attribute__((noreturn)) static struct sandbox_request * uninitialized_add(void *arg) { panic("Global Request Scheduler Add was called before initialization\n"); -}; +} __attribute__((noreturn)) static int uninitialized_remove(struct sandbox_request **arg) { panic("Global Request Scheduler Remove was called before initialization\n"); -}; +} __attribute__((noreturn)) static uint64_t uninitialized_peek() { panic("Global Request Scheduler Peek was called before initialization\n"); -}; +} /* The global of our polymorphic interface */ @@ -83,4 +83,4 @@ uint64_t global_request_scheduler_peek() { return global_request_scheduler.peek_fn(); -}; +} diff --git a/runtime/src/global_request_scheduler_deque.c b/runtime/src/global_request_scheduler_deque.c index c2edaaf..69f415a 100644 --- a/runtime/src/global_request_scheduler_deque.c +++ b/runtime/src/global_request_scheduler_deque.c @@ -2,7 +2,9 @@ #include "runtime.h" static struct deque_sandbox *global_request_scheduler_deque; -static pthread_mutex_t global_request_scheduler_deque_mutex = PTHREAD_MUTEX_INITIALIZER; + +/* TODO: Should this be used??? */ +static pthread_mutex_t global_request_scheduler_deque_mutex = PTHREAD_MUTEX_INITIALIZER; /** * Pushes a sandbox request to the global deque diff --git a/runtime/src/libc/syscall.c b/runtime/src/libc/syscall.c index 39c9054..546bfc1 100644 --- a/runtime/src/libc/syscall.c +++ b/runtime/src/libc/syscall.c @@ -18,12 +18,12 @@ #define GID 0xFE // Elf auxilary vector values (see google for what those are) -#define AT_NULL 0 -#define AT_IGNORE 1 -#define AT_EXECFD 2 -#define AT_PHDR 3 -#define AT_PHENT 4 -#define AT_PHNUM 5 +// #define AT_NULL 0 +// #define AT_IGNORE 1 +// #define AT_EXECFD 2 +// #define AT_PHDR 3 +#define AT_PHENT 4 +// #define AT_PHNUM 5 #define AT_PAGESZ 6 #define AT_BASE 7 #define AT_FLAGS 8 @@ -173,17 +173,17 @@ err: goto done; } -#define WO_RDONLY 00 -#define WO_WRONLY 01 -#define WO_RDWR 02 -#define WO_CREAT 0100 -#define WO_EXCL 0200 -#define WO_NOCTTY 0400 -#define WO_TRUNC 01000 -#define WO_APPEND 02000 -#define WO_NONBLOCK 04000 -#define WO_DSYNC 010000 -#define WO_SYNC 04010000 +#define WO_RDONLY 00 +#define WO_WRONLY 01 +#define WO_RDWR 02 +#define WO_CREAT 0100 +#define WO_EXCL 0200 +// #define WO_NOCTTY 0400 +// #define WO_TRUNC 01000 +#define WO_APPEND 02000 +// #define WO_NONBLOCK 04000 +// #define WO_DSYNC 010000 +// #define WO_SYNC 04010000 #define WO_RSYNC 04010000 #define WO_DIRECTORY 0200000 #define WO_NOFOLLOW 0400000 @@ -200,7 +200,7 @@ wasm_open(int32_t path_off, int32_t flags, int32_t mode) if (iofd < 0) return -1; int32_t modified_flags = 0; - if (flags & WO_RDONLY) { + if (flags == WO_RDONLY) { modified_flags |= O_RDONLY; // flags ^= WO_RDONLY; } @@ -255,142 +255,142 @@ wasm_close(int32_t io_handle_index) } // What the wasm stat structure looks like -struct wasm_stat { - int64_t st_dev; - uint64_t st_ino; - uint32_t st_nlink; - - uint32_t st_mode; - uint32_t st_uid; - uint32_t st_gid; - uint32_t __pad0; - uint64_t st_rdev; - uint64_t st_size; - int32_t st_blksize; - int64_t st_blocks; - - struct { - int32_t tv_sec; - int32_t tv_nsec; - } st_atim; - struct { - int32_t tv_sec; - int32_t tv_nsec; - } st_mtim; - struct { - int32_t tv_sec; - int32_t tv_nsec; - } st_ctim; - int32_t __pad1[3]; -}; - -#define SYS_STAT 4 - -int32_t -wasm_stat(uint32_t path_str_offset, int32_t stat_offset) -{ - char * path = worker_thread_get_memory_string(path_str_offset, MODULE_MAX_PATH_LENGTH); - struct wasm_stat *stat_ptr = worker_thread_get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat)); - - struct stat stat; - int32_t res = lstat(path, &stat); - if (res == -1) return -errno; - - *stat_ptr = (struct wasm_stat){ - .st_dev = stat.st_dev, - .st_ino = stat.st_ino, - .st_nlink = stat.st_nlink, - .st_mode = stat.st_mode, - .st_uid = stat.st_uid, - .st_gid = stat.st_gid, - .st_rdev = stat.st_rdev, - .st_size = stat.st_size, - .st_blksize = stat.st_blksize, - .st_blocks = stat.st_blocks, - }; - - stat_ptr->st_atim.tv_sec = stat.st_atim.tv_sec; - stat_ptr->st_atim.tv_nsec = stat.st_atim.tv_nsec; - - stat_ptr->st_mtim.tv_sec = stat.st_mtim.tv_sec; - stat_ptr->st_mtim.tv_nsec = stat.st_mtim.tv_nsec; - - stat_ptr->st_ctim.tv_sec = stat.st_ctim.tv_sec; - stat_ptr->st_ctim.tv_nsec = stat.st_ctim.tv_nsec; - - return res; -} - -#define SYS_FSTAT 5 -int32_t -wasm_fstat(int32_t filedes, int32_t stat_offset) -{ - struct wasm_stat *stat_ptr = worker_thread_get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat)); - - struct stat stat; - int32_t res = fstat(filedes, &stat); - if (res == -1) return -errno; - - *stat_ptr = (struct wasm_stat){ - .st_dev = stat.st_dev, - .st_ino = stat.st_ino, - .st_nlink = stat.st_nlink, - .st_mode = stat.st_mode, - .st_uid = stat.st_uid, - .st_gid = stat.st_gid, - .st_rdev = stat.st_rdev, - .st_size = stat.st_size, - .st_blksize = stat.st_blksize, - .st_blocks = stat.st_blocks, - }; - - stat_ptr->st_atim.tv_sec = stat.st_atim.tv_sec; - stat_ptr->st_atim.tv_nsec = stat.st_atim.tv_nsec; - - stat_ptr->st_mtim.tv_sec = stat.st_mtim.tv_sec; - stat_ptr->st_mtim.tv_nsec = stat.st_mtim.tv_nsec; - - stat_ptr->st_ctim.tv_sec = stat.st_ctim.tv_sec; - stat_ptr->st_ctim.tv_nsec = stat.st_ctim.tv_nsec; - - return res; -} - -#define SYS_LSTAT 6 -int32_t -wasm_lstat(int32_t path_str_offset, int32_t stat_offset) -{ - char * path = worker_thread_get_memory_string(path_str_offset, MODULE_MAX_PATH_LENGTH); - struct wasm_stat *stat_ptr = worker_thread_get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat)); - - struct stat stat; - int32_t res = lstat(path, &stat); - if (res == -1) return -errno; - - *stat_ptr = (struct wasm_stat){ - .st_dev = stat.st_dev, - .st_ino = stat.st_ino, - .st_nlink = stat.st_nlink, - .st_mode = stat.st_mode, - .st_uid = stat.st_uid, - .st_gid = stat.st_gid, - .st_rdev = stat.st_rdev, - .st_size = stat.st_size, - .st_blksize = stat.st_blksize, - .st_blocks = stat.st_blocks, - }; - - stat_ptr->st_atim.tv_sec = stat.st_atim.tv_sec; - stat_ptr->st_atim.tv_nsec = stat.st_atim.tv_nsec; - - stat_ptr->st_mtim.tv_sec = stat.st_mtim.tv_sec; - stat_ptr->st_mtim.tv_nsec = stat.st_mtim.tv_nsec; - - stat_ptr->st_ctim.tv_sec = stat.st_ctim.tv_sec; - stat_ptr->st_ctim.tv_nsec = stat.st_ctim.tv_nsec; - - return res; -} +// struct wasm_stat { +// int64_t st_dev; +// uint64_t st_ino; +// uint32_t st_nlink; + +// uint32_t st_mode; +// uint32_t st_uid; +// uint32_t st_gid; +// uint32_t __pad0; +// uint64_t st_rdev; +// uint64_t st_size; +// int32_t st_blksize; +// int64_t st_blocks; + +// struct { +// int32_t tv_sec; +// int32_t tv_nsec; +// } st_atim; +// struct { +// int32_t tv_sec; +// int32_t tv_nsec; +// } st_mtim; +// struct { +// int32_t tv_sec; +// int32_t tv_nsec; +// } st_ctim; +// int32_t __pad1[3]; +// }; + +// #define SYS_STAT 4 + +// int32_t +// wasm_stat(uint32_t path_str_offset, int32_t stat_offset) +// { +// char * path = worker_thread_get_memory_string(path_str_offset, MODULE_MAX_PATH_LENGTH); +// struct wasm_stat *stat_ptr = worker_thread_get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat)); + +// struct stat stat; +// int32_t res = lstat(path, &stat); +// if (res == -1) return -errno; + +// *stat_ptr = (struct wasm_stat){ +// .st_dev = stat.st_dev, +// .st_ino = stat.st_ino, +// .st_nlink = stat.st_nlink, +// .st_mode = stat.st_mode, +// .st_uid = stat.st_uid, +// .st_gid = stat.st_gid, +// .st_rdev = stat.st_rdev, +// .st_size = stat.st_size, +// .st_blksize = stat.st_blksize, +// .st_blocks = stat.st_blocks, +// }; + +// stat_ptr->st_atim.tv_sec = stat.st_atim.tv_sec; +// stat_ptr->st_atim.tv_nsec = stat.st_atim.tv_nsec; + +// stat_ptr->st_mtim.tv_sec = stat.st_mtim.tv_sec; +// stat_ptr->st_mtim.tv_nsec = stat.st_mtim.tv_nsec; + +// stat_ptr->st_ctim.tv_sec = stat.st_ctim.tv_sec; +// stat_ptr->st_ctim.tv_nsec = stat.st_ctim.tv_nsec; + +// return res; +// } + +// #define SYS_FSTAT 5 +// int32_t +// wasm_fstat(int32_t filedes, int32_t stat_offset) +// { +// struct wasm_stat *stat_ptr = worker_thread_get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat)); + +// struct stat stat; +// int32_t res = fstat(filedes, &stat); +// if (res == -1) return -errno; + +// *stat_ptr = (struct wasm_stat){ +// .st_dev = stat.st_dev, +// .st_ino = stat.st_ino, +// .st_nlink = stat.st_nlink, +// .st_mode = stat.st_mode, +// .st_uid = stat.st_uid, +// .st_gid = stat.st_gid, +// .st_rdev = stat.st_rdev, +// .st_size = stat.st_size, +// .st_blksize = stat.st_blksize, +// .st_blocks = stat.st_blocks, +// }; + +// stat_ptr->st_atim.tv_sec = stat.st_atim.tv_sec; +// stat_ptr->st_atim.tv_nsec = stat.st_atim.tv_nsec; + +// stat_ptr->st_mtim.tv_sec = stat.st_mtim.tv_sec; +// stat_ptr->st_mtim.tv_nsec = stat.st_mtim.tv_nsec; + +// stat_ptr->st_ctim.tv_sec = stat.st_ctim.tv_sec; +// stat_ptr->st_ctim.tv_nsec = stat.st_ctim.tv_nsec; + +// return res; +// } + +// #define SYS_LSTAT 6 +// int32_t +// wasm_lstat(int32_t path_str_offset, int32_t stat_offset) +// { +// char * path = worker_thread_get_memory_string(path_str_offset, MODULE_MAX_PATH_LENGTH); +// struct wasm_stat *stat_ptr = worker_thread_get_memory_ptr_void(stat_offset, sizeof(struct wasm_stat)); + +// struct stat stat; +// int32_t res = lstat(path, &stat); +// if (res == -1) return -errno; + +// *stat_ptr = (struct wasm_stat){ +// .st_dev = stat.st_dev, +// .st_ino = stat.st_ino, +// .st_nlink = stat.st_nlink, +// .st_mode = stat.st_mode, +// .st_uid = stat.st_uid, +// .st_gid = stat.st_gid, +// .st_rdev = stat.st_rdev, +// .st_size = stat.st_size, +// .st_blksize = stat.st_blksize, +// .st_blocks = stat.st_blocks, +// }; + +// stat_ptr->st_atim.tv_sec = stat.st_atim.tv_sec; +// stat_ptr->st_atim.tv_nsec = stat.st_atim.tv_nsec; + +// stat_ptr->st_mtim.tv_sec = stat.st_mtim.tv_sec; +// stat_ptr->st_mtim.tv_nsec = stat.st_mtim.tv_nsec; + +// stat_ptr->st_ctim.tv_sec = stat.st_ctim.tv_sec; +// stat_ptr->st_ctim.tv_nsec = stat.st_ctim.tv_nsec; + +// return res; +// } #define SYS_LSEEK 8 @@ -513,9 +513,9 @@ wasm_writev(int32_t fd, int32_t iov_offset, int32_t iovcnt) return res; } -#define SYS_MREMAP 25 -#define MREMAP_MAYMOVE 1 -#define MREMAP_FIXED 2 +#define SYS_MREMAP 25 +// #define MREMAP_MAYMOVE 1 +// #define MREMAP_FIXED 2 int32_t wasm_mremap(int32_t offset, int32_t old_size, int32_t new_size, int32_t flags) { @@ -568,74 +568,74 @@ wasm_getpid() } -#define WF_DUPFD 0 -#define WF_GETFD 1 +// #define WF_DUPFD 0 +// #define WF_GETFD 1 #define WF_SETFD 2 -#define WF_GETFL 3 -#define WF_SETFL 4 +// #define WF_GETFL 3 +// #define WF_SETFL 4 -#define WF_SETOWN 8 -#define WF_GETOWN 9 -#define WF_SETSIG 10 +// #define WF_SETOWN 8 +// #define WF_GETOWN 9 +// #define WF_SETSIG 10 #define WF_GETSIG 11 -#define WF_GETLK 5 +// #define WF_GETLK 5 #define WF_SETLK 6 #define WF_SETLKW 7 -#define SYS_FCNTL 72 -uint32_t -wasm_fcntl(uint32_t fd, uint32_t cmd, uint32_t arg_or_lock_ptr) -{ - switch (cmd) { - case WF_SETFD: - // return fcntl(fd, F_SETFD, arg_or_lock_ptr); - return 0; - case WF_SETLK: - return 0; - default: - panic("Unexpected Command"); - } -} - -#define SYS_FSYNC 74 -uint32_t -wasm_fsync(uint32_t filedes) -{ - uint32_t res = fsync(filedes); - if (res == -1) return -errno; - - return 0; -} - -#define SYS_GETCWD 79 -uint32_t -wasm_getcwd(uint32_t buf_offset, uint32_t buf_size) -{ - char *buf = worker_thread_get_memory_ptr_void(buf_offset, buf_size); - char *res = getcwd(buf, buf_size); - - if (!res) return 0; - return buf_offset; -} - -#define SYS_UNLINK 87 -uint32_t -wasm_unlink(uint32_t path_str_offset) -{ - char * str = worker_thread_get_memory_string(path_str_offset, MODULE_MAX_PATH_LENGTH); - uint32_t res = unlink(str); - if (res == -1) return -errno; - - return 0; -} - -#define SYS_GETEUID 107 -uint32_t -wasm_geteuid() -{ - return (uint32_t)geteuid(); -} +// #define SYS_FCNTL 72 +// uint32_t +// wasm_fcntl(uint32_t fd, uint32_t cmd, uint32_t arg_or_lock_ptr) +// { +// switch (cmd) { +// case WF_SETFD: +// // return fcntl(fd, F_SETFD, arg_or_lock_ptr); +// return 0; +// case WF_SETLK: +// return 0; +// default: +// panic("Unexpected Command"); +// } +// } + +// #define SYS_FSYNC 74 +// uint32_t +// wasm_fsync(uint32_t filedes) +// { +// uint32_t res = fsync(filedes); +// if (res == -1) return -errno; + +// return 0; +// } + +// #define SYS_GETCWD 79 +// uint32_t +// wasm_getcwd(uint32_t buf_offset, uint32_t buf_size) +// { +// char *buf = worker_thread_get_memory_ptr_void(buf_offset, buf_size); +// char *res = getcwd(buf, buf_size); + +// if (!res) return 0; +// return buf_offset; +// } + +// #define SYS_UNLINK 87 +// uint32_t +// wasm_unlink(uint32_t path_str_offset) +// { +// char * str = worker_thread_get_memory_string(path_str_offset, MODULE_MAX_PATH_LENGTH); +// uint32_t res = unlink(str); +// if (res == -1) return -errno; + +// return 0; +// } + +// #define SYS_GETEUID 107 +// uint32_t +// wasm_geteuid() +// { +// return (uint32_t)geteuid(); +// } #define SYS_SET_THREAD_AREA 205 @@ -683,82 +683,83 @@ wasm_get_time(int32_t clock_id, int32_t timespec_off) int32_t wasm_exit_group(int32_t status) { - exit(status); + debuglog("Called wasm_exit_group"); + // I believe that if a sandbox called this, it would cause the runtime to exit + // exit(status); return 0; } -#define SYS_FCHOWN 93 -int32_t -wasm_fchown(int32_t fd, uint32_t owner, uint32_t group) -{ - return fchown(fd, owner, group); -} +// #define SYS_FCHOWN 93 +// int32_t +// wasm_fchown(int32_t fd, uint32_t owner, uint32_t group) +// { +// return fchown(fd, owner, group); +// } // networking syscalls -#define SYS_SOCKET 41 -#define SYS_CONNECT 42 -#define SYS_ACCEPT 43 -#define SYS_BIND 49 -#define SYS_LISTEN 50 -int32_t -wasm_socket(int32_t domain, int32_t type, int32_t protocol) -{ - return socket(domain, type, protocol); -} - -int32_t -wasm_connect(int32_t sockfd, int32_t sockaddr_offset, int32_t addrlen) -{ - return connect(sockfd, worker_thread_get_memory_ptr_void(sockaddr_offset, addrlen), addrlen); -} - -int32_t -wasm_accept(int32_t sockfd, int32_t sockaddr_offset, int32_t addrlen_offset) -{ - socklen_t *addrlen = worker_thread_get_memory_ptr_void(addrlen_offset, sizeof(socklen_t)); - - return accept(sockfd, worker_thread_get_memory_ptr_void(sockaddr_offset, *addrlen), addrlen); -} - -int32_t -wasm_bind(int32_t sockfd, int32_t sockaddr_offset, int32_t addrlen) -{ - return bind(sockfd, worker_thread_get_memory_ptr_void(sockaddr_offset, addrlen), addrlen); -} - -int32_t -wasm_listen(int32_t sockfd, int32_t backlog) -{ - return listen(sockfd, backlog); -} - -#define SYS_SENDTO 44 -#define SYS_RECVFROM 45 - -int32_t -wasm_sendto(int32_t fd, int32_t buff_offset, int32_t len, int32_t flags, int32_t sockaddr_offset, int32_t sockaddr_len) -{ - char * buf = worker_thread_get_memory_ptr_void(buff_offset, len); - struct sockaddr *addr = sockaddr_len ? worker_thread_get_memory_ptr_void(sockaddr_offset, sockaddr_len) : NULL; - - return sendto(fd, buf, len, flags, addr, sockaddr_len); -} - -int32_t -wasm_recvfrom(int32_t fd, int32_t buff_offset, int32_t size, int32_t flags, int32_t sockaddr_offset, - int32_t socklen_offset) -{ - char * buf = worker_thread_get_memory_ptr_void(buff_offset, size); - socklen_t * len = worker_thread_get_memory_ptr_void(socklen_offset, sizeof(socklen_t)); - struct sockaddr *addr = *len ? worker_thread_get_memory_ptr_void(sockaddr_offset, *len) : NULL; - - return recvfrom(fd, buf, size, flags, addr, addr ? len : NULL); -} +// #define SYS_SOCKET 41 +// int32_t +// wasm_socket(int32_t domain, int32_t type, int32_t protocol) +// { +// return socket(domain, type, protocol); +// } + +// #define SYS_CONNECT 42 +// int32_t +// wasm_connect(int32_t sockfd, int32_t sockaddr_offset, int32_t addrlen) +// { +// return connect(sockfd, worker_thread_get_memory_ptr_void(sockaddr_offset, addrlen), addrlen); +// } + +// #define SYS_ACCEPT 43 +// int32_t +// wasm_accept(int32_t sockfd, int32_t sockaddr_offset, int32_t addrlen_offset) +// { +// socklen_t *addrlen = worker_thread_get_memory_ptr_void(addrlen_offset, sizeof(socklen_t)); + +// return accept(sockfd, worker_thread_get_memory_ptr_void(sockaddr_offset, *addrlen), addrlen); +// } + +// #define SYS_BIND 49 +// int32_t +// wasm_bind(int32_t sockfd, int32_t sockaddr_offset, int32_t addrlen) +// { +// return bind(sockfd, worker_thread_get_memory_ptr_void(sockaddr_offset, addrlen), addrlen); +// } + +// #define SYS_LISTEN 50 +// int32_t +// wasm_listen(int32_t sockfd, int32_t backlog) +// { +// return listen(sockfd, backlog); +// } + +// #define SYS_SENDTO 44 +// int32_t +// wasm_sendto(int32_t fd, int32_t buff_offset, int32_t len, int32_t flags, int32_t sockaddr_offset, int32_t +// sockaddr_len) +// { +// char * buf = worker_thread_get_memory_ptr_void(buff_offset, len); +// struct sockaddr *addr = sockaddr_len ? worker_thread_get_memory_ptr_void(sockaddr_offset, sockaddr_len) : NULL; + +// return sendto(fd, buf, len, flags, addr, sockaddr_len); +// } + +// #define SYS_RECVFROM 45 +// int32_t +// wasm_recvfrom(int32_t fd, int32_t buff_offset, int32_t size, int32_t flags, int32_t sockaddr_offset, +// int32_t socklen_offset) +// { +// char * buf = worker_thread_get_memory_ptr_void(buff_offset, size); +// socklen_t * len = worker_thread_get_memory_ptr_void(socklen_offset, sizeof(socklen_t)); +// struct sockaddr *addr = *len ? worker_thread_get_memory_ptr_void(sockaddr_offset, *len) : NULL; + +// return recvfrom(fd, buf, size, flags, addr, addr ? len : NULL); +// } int32_t inner_syscall_handler(int32_t n, int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, int32_t f) { - int32_t res; switch (n) { case SYS_READ: return wasm_read(a, b, c); @@ -794,6 +795,7 @@ inner_syscall_handler(int32_t n, int32_t a, int32_t b, int32_t c, int32_t d, int default: /* This is a general catch all for the other functions below */ debuglog("Call to unknown or implemented syscall %d\n", n); + debuglog("syscall %d (%d, %d, %d, %d, %d, %d)\n", n, a, b, c, d, e, f); errno = ENOSYS; return -1; @@ -806,8 +808,6 @@ inner_syscall_handler(int32_t n, int32_t a, int32_t b, int32_t c, int32_t d, int // return wasm_fstat(a, b); // case SYS_LSTAT: // return wasm_lstat(a, b); - // case SYS_LSEEK: - // return wasm_lseek(a, b, c); // case SYS_GETPID: // return wasm_getpid(); // case SYS_FCNTL: @@ -837,8 +837,4 @@ inner_syscall_handler(int32_t n, int32_t a, int32_t b, int32_t c, int32_t d, int // case SYS_RECVFROM: // return wasm_recvfrom(a, b, c, d, e, f); } - printf("syscall %d (%d, %d, %d, %d, %d, %d)\n", n, a, b, c, d, e, f); - assert(0); - - return 0; } diff --git a/runtime/src/listener_thread.c b/runtime/src/listener_thread.c index 3c79898..d0d7888 100644 --- a/runtime/src/listener_thread.c +++ b/runtime/src/listener_thread.c @@ -14,9 +14,6 @@ */ int listener_thread_epoll_file_descriptor; -/* Timestamp when listener thread began executing */ -static __thread uint64_t listener_thread_start_timestamp; - pthread_t listener_thread_id; /** diff --git a/runtime/src/memory/64bit_nix.c b/runtime/src/memory/64bit_nix.c index 980aeed..1bb63b8 100644 --- a/runtime/src/memory/64bit_nix.c +++ b/runtime/src/memory/64bit_nix.c @@ -8,20 +8,6 @@ #include -#define MAX_LINEAR_MEM ((1LL << 32) + WASM_PAGE_SIZE) - -void -alloc_linear_memory(void) -{ - // mmaped memory in sandbox_allocate. -} - -void -free_linear_memory(void *base, uint32_t bound, uint32_t max) -{ - // frees on sandbox_free -} - void expand_memory(void) { diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index b083765..822702d 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -286,9 +286,8 @@ sandbox_build_and_send_client_response(struct sandbox *sandbox) response_cursor += body_size; /* Capture Timekeeping data for end-to-end latency */ - uint64_t end_time = __getcycles(); - sandbox->total_time = end_time - sandbox->request_arrival_timestamp; - uint64_t total_time_us = sandbox->total_time / runtime_processor_speed_MHz; + uint64_t end_time = __getcycles(); + sandbox->total_time = end_time - sandbox->request_arrival_timestamp; int rc; int sent = 0; @@ -1043,7 +1042,6 @@ err_stack_allocation_failed: #endif ps_list_init_d(sandbox); err_memory_allocation_failed: -err: sandbox_set_as_error(sandbox, SANDBOX_SET_AS_INITIALIZED); perror(error_message); sandbox = NULL; @@ -1073,8 +1071,7 @@ sandbox_free(struct sandbox *sandbox) assert(sandbox != current_sandbox_get()); assert(sandbox->state == SANDBOX_ERROR || sandbox->state == SANDBOX_COMPLETE); - char *error_message = NULL; - int rc; + int rc; module_release(sandbox->module); @@ -1109,7 +1106,6 @@ done: return; err_free_sandbox_failed: err_free_stack_failed: -err: /* Errors freeing memory is a fatal error */ panic("Failed to free Sandbox %lu\n", sandbox->id); }