diff --git a/runtime/compiletime/instr.c b/runtime/compiletime/instr.c index 881522c..4c87f21 100644 --- a/runtime/compiletime/instr.c +++ b/runtime/compiletime/instr.c @@ -7,8 +7,8 @@ // The below functions are for implementing WASM instructions // ROTL and ROTR helper functions -INLINE u32 -rotl_u32(u32 n, u32 c_u32) +INLINE uint32_t +rotl_u32(uint32_t n, uint32_t c_u32) { // WASM requires a modulus here (usually a single bitwise op, but it means we need no assert) unsigned int c = c_u32 % (CHAR_BIT * sizeof(n)); @@ -18,8 +18,8 @@ rotl_u32(u32 n, u32 c_u32) return (n << c) | (n >> ((-c) & mask)); } -INLINE u32 -rotr_u32(u32 n, u32 c_u32) +INLINE uint32_t +rotr_u32(uint32_t n, uint32_t c_u32) { // WASM requires a modulus here (usually a single bitwise op, but it means we need no assert) unsigned int c = c_u32 % (CHAR_BIT * sizeof(n)); @@ -52,15 +52,15 @@ rotr_u64(uint64_t n, uint64_t c_u64) } // Now safe division and remainder -INLINE u32 -u32_div(u32 a, u32 b) +INLINE uint32_t +u32_div(uint32_t a, uint32_t b) { assert(b); return a / b; } -INLINE u32 -u32_rem(u32 a, u32 b) +INLINE uint32_t +u32_rem(uint32_t a, uint32_t b) { assert(b); return a % b; @@ -111,11 +111,11 @@ i64_rem(i64 a, i64 b) // float to integer conversion methods // In C, float => int conversions always truncate // If a int2float(int::min_value) <= float <= int2float(int::max_value), it must always be safe to truncate it -u32 +uint32_t u32_trunc_f32(float f) { assert(0 <= f && f <= UINT32_MAX); - return (u32)f; + return (uint32_t)f; } i32 @@ -125,11 +125,11 @@ i32_trunc_f32(float f) return (i32)f; } -u32 +uint32_t u32_trunc_f64(double f) { assert(0 <= f && f <= UINT32_MAX); - return (u32)f; + return (uint32_t)f; } i32 diff --git a/runtime/compiletime/memory/64bit_nix.c b/runtime/compiletime/memory/64bit_nix.c index 4734eea..75e12f9 100644 --- a/runtime/compiletime/memory/64bit_nix.c +++ b/runtime/compiletime/memory/64bit_nix.c @@ -151,7 +151,7 @@ set_global_i64(i32 offset, i64 v) // Table handling functionality INLINE char * -get_function_from_table(u32 idx, u32 type_id) +get_function_from_table(uint32_t idx, uint32_t type_id) { assert(idx < INDIRECT_TABLE_SIZE); diff --git a/runtime/include/module.h b/runtime/include/module.h index bbb0a6a..b8495d4 100644 --- a/runtime/include/module.h +++ b/runtime/include/module.h @@ -9,10 +9,10 @@ struct module { char path[MODULE_MAX_PATH_LENGTH]; void * dynamic_library_handle; /* Handle to the *.so of the serverless function */ i32 argument_count; - u32 stack_size; /* a specification? */ + uint32_t stack_size; /* a specification? */ uint64_t max_memory; /* perhaps a specification of the module. (max 4GB) */ - u32 relative_deadline_us; - u32 reference_count; /* ref count how many instances exist here. */ + uint32_t relative_deadline_us; + uint32_t reference_count; /* ref count how many instances exist here. */ struct indirect_table_entry indirect_table[INDIRECT_TABLE_SIZE]; struct sockaddr_in socket_address; int socket_descriptor; @@ -186,6 +186,6 @@ module_set_http_info(struct module *module, int request_count, char *request_hea *******************************/ 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 relative_deadline_us, int port, int req_sz, int resp_sz); +struct module *module_new(char *mod_name, char *mod_path, i32 argument_count, uint32_t stack_sz, uint32_t max_heap, + uint32_t relative_deadline_us, int port, int req_sz, int resp_sz); int module_new_from_json(char *filename); diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index b8d20a5..e5db9ec 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -3,13 +3,13 @@ #include /* for epoll_create1(), epoll_ctl(), struct epoll_event */ #include "types.h" -extern int runtime_epoll_file_descriptor; -extern u32 runtime_total_worker_processors; +extern int runtime_epoll_file_descriptor; +extern uint32_t runtime_total_worker_processors; void alloc_linear_memory(void); void expand_memory(void); -INLINE char *get_function_from_table(u32 idx, u32 type_id); -INLINE char *get_memory_ptr_for_runtime(u32 offset, u32 bounds_check); +INLINE char *get_function_from_table(uint32_t idx, uint32_t type_id); +INLINE char *get_memory_ptr_for_runtime(uint32_t offset, uint32_t bounds_check); void runtime_initialize(void); void listener_thread_initialize(void); void stub_init(i32 offset); diff --git a/runtime/include/sandbox.h b/runtime/include/sandbox.h index 34fef5f..bbb4a88 100644 --- a/runtime/include/sandbox.h +++ b/runtime/include/sandbox.h @@ -33,14 +33,14 @@ typedef enum struct sandbox { sandbox_state_t state; - u32 sandbox_size; /* The struct plus enough buffer to hold the request or response (sized off largest) */ + uint32_t sandbox_size; /* The struct plus enough buffer to hold the request or response (sized off largest) */ void * linear_memory_start; /* after sandbox struct */ - u32 linear_memory_size; /* from after sandbox struct */ + uint32_t linear_memory_size; /* from after sandbox struct */ uint64_t linear_memory_max_size; - void *stack_start; - u32 stack_size; + void * stack_start; + uint32_t stack_size; arch_context_t ctxt; /* register context for context switch. */ diff --git a/runtime/include/types.h b/runtime/include/types.h index 0688d3b..2a97401 100644 --- a/runtime/include/types.h +++ b/runtime/include/types.h @@ -41,7 +41,6 @@ typedef unsigned char u8; typedef int16_t i16; typedef uint16_t u16; typedef int32_t i32; -typedef uint32_t u32; typedef int64_t i64; /* FIXME: per-module configuration? */ @@ -56,8 +55,8 @@ macros. The code generator compiles in the starting number of wasm pages, and th and allocate more than max_pages, we should fault */ // TODO: Should this be deleted? -// extern u32 starting_pages; -// extern u32 max_pages; +// extern uint32_t starting_pages; +// extern uint32_t max_pages; /* The code generator also compiles in stubs that populate the linear memory and function table */ void populate_memory(void); @@ -67,15 +66,15 @@ void populate_table(void); #define INDIRECT_TABLE_SIZE (1 << 10) struct indirect_table_entry { - u32 type_id; - void *func_pointer; + uint32_t type_id; + void * func_pointer; }; /* Cache of Frequently Accessed Members used to avoid pointer chasing */ struct sandbox_context_cache { struct indirect_table_entry *module_indirect_table; void * linear_memory_start; - u32 linear_memory_size; + uint32_t linear_memory_size; }; extern __thread struct sandbox_context_cache local_sandbox_context_cache; diff --git a/runtime/include/worker_thread.h b/runtime/include/worker_thread.h index 381a28d..c4747b1 100644 --- a/runtime/include/worker_thread.h +++ b/runtime/include/worker_thread.h @@ -15,7 +15,7 @@ void *worker_thread_main(void *return_code); * @return void pointer to something in WebAssembly linear memory */ static inline void * -worker_thread_get_memory_ptr_void(u32 offset, u32 bounds_check) +worker_thread_get_memory_ptr_void(uint32_t offset, uint32_t bounds_check) { return (void *)get_memory_ptr_for_runtime(offset, bounds_check); } @@ -26,7 +26,7 @@ worker_thread_get_memory_ptr_void(u32 offset, u32 bounds_check) * @return char at the offset */ static inline char -worker_thread_get_memory_character(u32 offset) +worker_thread_get_memory_character(uint32_t offset) { return get_memory_ptr_for_runtime(offset, 1)[0]; } @@ -38,7 +38,7 @@ worker_thread_get_memory_character(u32 offset) * @return pointer to the string or NULL if max_length is reached without finding null-terminator */ static inline char * -worker_thread_get_memory_string(u32 offset, u32 max_length) +worker_thread_get_memory_string(uint32_t offset, uint32_t max_length) { for (int i = 0; i < max_length; i++) { if (worker_thread_get_memory_character(offset + i) == '\0') { diff --git a/runtime/src/env.c b/runtime/src/env.c index 414cc13..02bcb9b 100644 --- a/runtime/src/env.c +++ b/runtime/src/env.c @@ -21,7 +21,7 @@ env___syscall(i32 n, i32 a, i32 b, i32 c, i32 d, i32 e, i32 f) } void -env___unmapself(u32 base, u32 size) +env___unmapself(uint32_t base, uint32_t size) { /* Just do some no op */ } diff --git a/runtime/src/libc/uvio.c b/runtime/src/libc/uvio.c index b3558ec..13ccaf2 100644 --- a/runtime/src/libc/uvio.c +++ b/runtime/src/libc/uvio.c @@ -105,7 +105,7 @@ wasm_fs_callback(uv_fs_t *req) // We define our own syscall numbers, because WASM uses x86_64 values even on systems that are not x86_64 #define SYS_READ 0 -u32 +uint32_t wasm_read(i32 filedes, i32 buf_offset, i32 nbyte) { if (filedes == 0) { @@ -251,12 +251,12 @@ wasm_close(i32 file_descriptor) struct wasm_stat { i64 st_dev; uint64_t st_ino; - u32 st_nlink; + uint32_t st_nlink; - u32 st_mode; - u32 st_uid; - u32 st_gid; - u32 __pad0; + uint32_t st_mode; + uint32_t st_uid; + uint32_t st_gid; + uint32_t __pad0; uint64_t st_rdev; uint64_t st_size; i32 st_blksize; @@ -298,7 +298,7 @@ struct wasm_stat { // }; i32 -wasm_stat(u32 path_str_offset, i32 stat_offset) +wasm_stat(uint32_t path_str_offset, i32 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)); @@ -448,7 +448,7 @@ wasm_lseek(i32 filedes, i32 file_offset, i32 whence) } #define SYS_MMAP 9 -u32 +uint32_t wasm_mmap(i32 addr, i32 len, i32 prot, i32 flags, i32 file_descriptor, i32 offset) { int d = current_sandbox_get_file_descriptor(file_descriptor); @@ -593,10 +593,10 @@ wasm_writev(i32 file_descriptor, i32 iov_offset, i32 iovcnt) #define SYS_MADVISE 28 #define SYS_GETPID 39 -u32 +uint32_t wasm_getpid() { - return (u32)getpid(); + return (uint32_t)getpid(); } @@ -616,8 +616,8 @@ wasm_getpid() #define WF_SETLKW 7 #define SYS_FCNTL 72 -u32 -wasm_fcntl(u32 file_descriptor, u32 cmd, u32 arg_or_lock_ptr) +uint32_t +wasm_fcntl(uint32_t file_descriptor, uint32_t cmd, uint32_t arg_or_lock_ptr) { int d = current_sandbox_get_file_descriptor(file_descriptor); switch (cmd) { @@ -632,8 +632,8 @@ wasm_fcntl(u32 file_descriptor, u32 cmd, u32 arg_or_lock_ptr) } #define SYS_FSYNC 74 -u32 -wasm_fsync(u32 file_descriptor) +uint32_t +wasm_fsync(uint32_t file_descriptor) { int d = current_sandbox_get_file_descriptor(file_descriptor); uv_fs_t req = UV_FS_REQ_INIT(); @@ -649,8 +649,8 @@ wasm_fsync(u32 file_descriptor) } #define SYS_GETCWD 79 -u32 -wasm_getcwd(u32 buf_offset, u32 buf_size) +uint32_t +wasm_getcwd(uint32_t buf_offset, uint32_t buf_size) { char *buffer = worker_thread_get_memory_ptr_void(buf_offset, buf_size); char *res = getcwd(buffer, buf_size); @@ -660,8 +660,8 @@ wasm_getcwd(u32 buf_offset, u32 buf_size) } #define SYS_UNLINK 87 -u32 -wasm_unlink(u32 path_str_offset) +uint32_t +wasm_unlink(uint32_t path_str_offset) { char * path = worker_thread_get_memory_string(path_str_offset, MODULE_MAX_PATH_LENGTH); uv_fs_t req = UV_FS_REQ_INIT(); @@ -677,10 +677,10 @@ wasm_unlink(u32 path_str_offset) } #define SYS_GETEUID 107 -u32 +uint32_t wasm_geteuid() { - return (u32)geteuid(); + return (uint32_t)geteuid(); } #define SYS_SET_THREAD_AREA 205 @@ -690,7 +690,7 @@ wasm_geteuid() #define SYS_GET_TIME 228 struct wasm_time_spec { uint64_t sec; - u32 nanosec; + uint32_t nanosec; }; i32 @@ -734,7 +734,7 @@ wasm_exit_group(i32 status) #define SYS_FCHOWN 93 i32 -wasm_fchown(i32 file_descriptor, u32 owner, u32 group) +wasm_fchown(i32 file_descriptor, uint32_t owner, uint32_t group) { int d = current_sandbox_get_file_descriptor(file_descriptor); uv_fs_t req = UV_FS_REQ_INIT(); diff --git a/runtime/src/main.c b/runtime/src/main.c index d4547d1..81e0494 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -20,10 +20,10 @@ i32 runtime_log_file_descriptor = -1; #endif -float runtime_processor_speed_MHz = 0; -u32 runtime_total_online_processors = 0; -u32 runtime_total_worker_processors = 0; -u32 runtime_first_worker_processor = 0; +float runtime_processor_speed_MHz = 0; +uint32_t runtime_total_online_processors = 0; +uint32_t runtime_total_worker_processors = 0; +uint32_t runtime_first_worker_processor = 0; int runtime_worker_threads_argument[WORKER_THREAD_CORE_COUNT] = { 0 }; /* The worker sets its argument to -1 on error */ pthread_t runtime_worker_threads[WORKER_THREAD_CORE_COUNT]; @@ -80,7 +80,7 @@ runtime_allocate_available_cores() runtime_first_worker_processor = 1; /* WORKER_THREAD_CORE_COUNT can be used as a cap on the number of cores to use, but if there are few * cores that WORKER_THREAD_CORE_COUNT, just use what is available */ - u32 max_possible_workers = runtime_total_online_processors - 1; + uint32_t max_possible_workers = runtime_total_online_processors - 1; runtime_total_worker_processors = max_possible_workers; if (max_possible_workers >= WORKER_THREAD_CORE_COUNT) runtime_total_worker_processors = WORKER_THREAD_CORE_COUNT; diff --git a/runtime/src/memory/64bit_nix.c b/runtime/src/memory/64bit_nix.c index 286ede4..fb3bfd4 100644 --- a/runtime/src/memory/64bit_nix.c +++ b/runtime/src/memory/64bit_nix.c @@ -18,7 +18,7 @@ alloc_linear_memory(void) } void -free_linear_memory(void *base, u32 bound, u32 max) +free_linear_memory(void *base, uint32_t bound, uint32_t max) { // frees on sandbox_free } @@ -49,7 +49,7 @@ expand_memory(void) } INLINE char * -get_memory_ptr_for_runtime(u32 offset, u32 bounds_check) +get_memory_ptr_for_runtime(uint32_t offset, uint32_t bounds_check) { // Due to how we setup memory for x86, the virtual memory mechanism will catch the error, if bounds < // WASM_PAGE_SIZE diff --git a/runtime/src/memory/common.c b/runtime/src/memory/common.c index 7a54df7..fa120fe 100644 --- a/runtime/src/memory/common.c +++ b/runtime/src/memory/common.c @@ -3,7 +3,7 @@ /* Region initialization helper function */ EXPORT void -initialize_region(u32 offset, u32 data_count, char *data) +initialize_region(uint32_t offset, uint32_t data_count, char *data) { assert(local_sandbox_context_cache.linear_memory_size >= data_count); assert(offset < local_sandbox_context_cache.linear_memory_size - data_count); @@ -13,7 +13,7 @@ initialize_region(u32 offset, u32 data_count, char *data) } void -add_function_to_table(u32 idx, u32 type_id, char *pointer) +add_function_to_table(uint32_t idx, uint32_t type_id, char *pointer) { assert(idx < INDIRECT_TABLE_SIZE); assert(local_sandbox_context_cache.module_indirect_table != NULL); diff --git a/runtime/src/module.c b/runtime/src/module.c index 753ed08..c7c9ac1 100644 --- a/runtime/src/module.c +++ b/runtime/src/module.c @@ -103,8 +103,8 @@ module_free(struct module *module) */ struct module * -module_new(char *name, char *path, i32 argument_count, u32 stack_size, u32 max_memory, u32 relative_deadline_us, - int port, int request_size, int response_size) +module_new(char *name, char *path, i32 argument_count, uint32_t stack_size, uint32_t max_memory, + uint32_t relative_deadline_us, int port, int request_size, int response_size) { errno = 0; struct module *module = (struct module *)malloc(sizeof(struct module)); @@ -316,18 +316,18 @@ module_new_from_json(char *file_name) } memset(reponse_headers, 0, HTTP_MAX_HEADER_LENGTH * HTTP_MAX_HEADER_COUNT); - i32 request_size = 0; - i32 response_size = 0; - i32 argument_count = 0; - u32 port = 0; - u32 relative_deadline_us = 0; - bool is_active = false; - i32 request_count = 0; - i32 response_count = 0; - int j = 1; - int ntoks = 2 * tokens[i].size; - char request_content_type[HTTP_MAX_HEADER_VALUE_LENGTH] = { 0 }; - char response_content_type[HTTP_MAX_HEADER_VALUE_LENGTH] = { 0 }; + i32 request_size = 0; + i32 response_size = 0; + i32 argument_count = 0; + uint32_t port = 0; + uint32_t relative_deadline_us = 0; + bool is_active = false; + i32 request_count = 0; + i32 response_count = 0; + int j = 1; + int ntoks = 2 * tokens[i].size; + char request_content_type[HTTP_MAX_HEADER_VALUE_LENGTH] = { 0 }; + char response_content_type[HTTP_MAX_HEADER_VALUE_LENGTH] = { 0 }; for (; j < ntoks;) { int ntks = 1;