diff --git a/runtime/compiletime/instr.c b/runtime/compiletime/instr.c index 7ed486a..afc72d0 100644 --- a/runtime/compiletime/instr.c +++ b/runtime/compiletime/instr.c @@ -66,15 +66,15 @@ u32_rem(uint32_t a, uint32_t b) return a % b; } -INLINE i32 -i32_div(i32 a, i32 b) +INLINE int32_t +i32_div(int32_t a, int32_t b) { assert(b && (a != INT32_MIN || b != -1)); return a / b; } -INLINE i32 -i32_rem(i32 a, i32 b) +INLINE int32_t +i32_rem(int32_t a, int32_t b) { assert(b && (a != INT32_MIN || b != -1)); return a % b; @@ -118,11 +118,11 @@ u32_trunc_f32(float f) return (uint32_t)f; } -i32 +int32_t i32_trunc_f32(float f) { assert(INT32_MIN <= f && f <= INT32_MAX); - return (i32)f; + return (int32_t)f; } uint32_t @@ -132,11 +132,11 @@ u32_trunc_f64(double f) return (uint32_t)f; } -i32 +int32_t i32_trunc_f64(double f) { assert(INT32_MIN <= f && f <= INT32_MAX); - return (i32)f; + return (int32_t)f; } uint64_t diff --git a/runtime/compiletime/memory/64bit_nix.c b/runtime/compiletime/memory/64bit_nix.c index 3a4e5ca..ea41fc3 100644 --- a/runtime/compiletime/memory/64bit_nix.c +++ b/runtime/compiletime/memory/64bit_nix.c @@ -5,7 +5,7 @@ // All of these are pretty generic INLINE float -get_f32(i32 offset) +get_f32(int32_t offset) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; @@ -14,7 +14,7 @@ get_f32(i32 offset) } INLINE double -get_f64(i32 offset) +get_f64(int32_t offset) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; @@ -23,7 +23,7 @@ get_f64(i32 offset) } INLINE i8 -get_i8(i32 offset) +get_i8(int32_t offset) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; @@ -32,7 +32,7 @@ get_i8(i32 offset) } INLINE i16 -get_i16(i32 offset) +get_i16(int32_t offset) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; @@ -40,17 +40,17 @@ get_i16(i32 offset) return *(i16 *)address; } -INLINE i32 -get_i32(i32 offset) +INLINE int32_t +get_i32(int32_t offset) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; - return *(i32 *)address; + return *(int32_t *)address; } INLINE int64_t -get_i64(i32 offset) +get_i64(int32_t offset) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; @@ -58,17 +58,17 @@ get_i64(i32 offset) return *(int64_t *)address; } -INLINE i32 -get_global_i32(i32 offset) +INLINE int32_t +get_global_i32(int32_t offset) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; - return *(i32 *)address; + return *(int32_t *)address; } INLINE int64_t -get_global_i64(i32 offset) +get_global_i64(int32_t offset) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; @@ -78,7 +78,7 @@ get_global_i64(i32 offset) // Now setting routines INLINE void -set_f32(i32 offset, float v) +set_f32(int32_t offset, float v) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; @@ -87,7 +87,7 @@ set_f32(i32 offset, float v) } INLINE void -set_f64(i32 offset, double v) +set_f64(int32_t offset, double v) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; @@ -96,7 +96,7 @@ set_f64(i32 offset, double v) } INLINE void -set_i8(i32 offset, i8 v) +set_i8(int32_t offset, i8 v) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; @@ -105,7 +105,7 @@ set_i8(i32 offset, i8 v) } INLINE void -set_i16(i32 offset, i16 v) +set_i16(int32_t offset, i16 v) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; @@ -114,16 +114,16 @@ set_i16(i32 offset, i16 v) } INLINE void -set_i32(i32 offset, i32 v) +set_i32(int32_t offset, int32_t v) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; - *(i32 *)address = v; + *(int32_t *)address = v; } INLINE void -set_i64(i32 offset, int64_t v) +set_i64(int32_t offset, int64_t v) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; @@ -132,16 +132,16 @@ set_i64(i32 offset, int64_t v) } INLINE void -set_global_i32(i32 offset, i32 v) +set_global_i32(int32_t offset, int32_t v) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; - *(i32 *)address = v; + *(int32_t *)address = v; } INLINE void -set_global_i64(i32 offset, int64_t v) +set_global_i64(int32_t offset, int64_t v) { char *mem_as_chars = (char *)local_sandbox_context_cache.linear_memory_start; void *address = &mem_as_chars[offset]; diff --git a/runtime/include/module.h b/runtime/include/module.h index b8495d4..3a4d6b6 100644 --- a/runtime/include/module.h +++ b/runtime/include/module.h @@ -8,7 +8,7 @@ struct module { char name[MODULE_MAX_NAME_LENGTH]; char path[MODULE_MAX_PATH_LENGTH]; void * dynamic_library_handle; /* Handle to the *.so of the serverless function */ - i32 argument_count; + int32_t argument_count; uint32_t stack_size; /* a specification? */ uint64_t max_memory; /* perhaps a specification of the module. (max 4GB) */ uint32_t relative_deadline_us; @@ -72,7 +72,7 @@ module_acquire(struct module *module) * @param module * @returns the number of arguments */ -static inline i32 +static inline int32_t module_get_argument_count(struct module *module) { return module->argument_count; @@ -107,7 +107,7 @@ module_initialize_table(struct module *module) * @param arguments - address? */ static inline void -module_initialize_libc(struct module *module, i32 env, i32 arguments) +module_initialize_libc(struct module *module, int32_t env, int32_t arguments) { /* called in a sandbox. */ module->initialize_libc(env, arguments); @@ -142,8 +142,8 @@ module_is_valid(struct module *module) * @param argv standard UNIX vector of arguments * @return return code of module's main function */ -static inline i32 -module_main(struct module *module, i32 argc, i32 argv) +static inline int32_t +module_main(struct module *module, int32_t argc, int32_t argv) { return module->main(argc, argv); } @@ -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, uint32_t stack_sz, uint32_t max_heap, +struct module *module_new(char *mod_name, char *mod_path, int32_t 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 e5db9ec..2547377 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -12,6 +12,6 @@ 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); +void stub_init(int32_t offset); unsigned long long __getcycles(void); diff --git a/runtime/include/sandbox.h b/runtime/include/sandbox.h index bbb4a88..e62d898 100644 --- a/runtime/include/sandbox.h +++ b/runtime/include/sandbox.h @@ -50,9 +50,9 @@ struct sandbox { struct module *module; /* the module this is an instance of */ - i32 arguments_offset; /* actual placement of arguments in the sandbox. */ - void *arguments; /* arguments from request, must be of module->argument_count size. */ - i32 return_value; + int32_t arguments_offset; /* actual placement of arguments in the sandbox. */ + void * arguments; /* arguments from request, must be of module->argument_count size. */ + int32_t return_value; struct sandbox_io_handle io_handles[SANDBOX_MAX_IO_HANDLE_COUNT]; struct sockaddr client_address; /* client requesting connection! */ diff --git a/runtime/include/types.h b/runtime/include/types.h index 6412d11..d021c1f 100644 --- a/runtime/include/types.h +++ b/runtime/include/types.h @@ -40,7 +40,6 @@ typedef signed char i8; typedef unsigned char u8; typedef int16_t i16; typedef uint16_t u16; -typedef int32_t i32; /* FIXME: per-module configuration? */ #define WASM_PAGE_SIZE (1024 * 64) /* 64KB */ @@ -79,14 +78,14 @@ struct sandbox_context_cache { extern __thread struct sandbox_context_cache local_sandbox_context_cache; /* TODO: LOG_TO_FILE logic is untested */ -extern i32 runtime_log_file_descriptor; +extern int32_t runtime_log_file_descriptor; /* functions in the module to lookup and call per sandbox. */ -typedef i32 (*mod_main_fn_t)(i32 a, i32 b); +typedef int32_t (*mod_main_fn_t)(int32_t a, int32_t b); typedef void (*mod_glb_fn_t)(void); typedef void (*mod_mem_fn_t)(void); typedef void (*mod_tbl_fn_t)(void); -typedef void (*mod_libc_fn_t)(i32, i32); +typedef void (*mod_libc_fn_t)(int32_t, int32_t); /** * debuglog is a macro that behaves based on the macros DEBUG and LOG_TO_FILE diff --git a/runtime/src/env.c b/runtime/src/env.c index f262795..c15acfd 100644 --- a/runtime/src/env.c +++ b/runtime/src/env.c @@ -4,18 +4,18 @@ #include "runtime.h" #include "worker_thread.h" -extern i32 inner_syscall_handler(i32 n, i32 a, i32 b, i32 c, i32 d, i32 e, i32 f); +extern 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); -i32 -env_syscall_handler(i32 n, i32 a, i32 b, i32 c, i32 d, i32 e, i32 f) +int32_t +env_syscall_handler(int32_t n, int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, int32_t f) { - i32 i = inner_syscall_handler(n, a, b, c, d, e, f); + int32_t i = inner_syscall_handler(n, a, b, c, d, e, f); return i; } -i32 -env___syscall(i32 n, i32 a, i32 b, i32 c, i32 d, i32 e, i32 f) +int32_t +env___syscall(int32_t n, int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, int32_t f) { return env_syscall_handler(n, a, b, c, d, e, f); } @@ -26,49 +26,49 @@ env___unmapself(uint32_t base, uint32_t size) /* Just do some no op */ } -i32 +int32_t env_a_ctz_64(uint64_t x) { return __builtin_ctzll(x); } INLINE void -env_a_and_64(i32 p_off, uint64_t v) +env_a_and_64(int32_t p_off, uint64_t v) { uint64_t *p = worker_thread_get_memory_ptr_void(p_off, sizeof(uint64_t)); ck_pr_and_64(p, v); } INLINE void -env_a_or_64(i32 p_off, int64_t v) +env_a_or_64(int32_t p_off, int64_t v) { assert(sizeof(int64_t) == sizeof(uint64_t)); uint64_t *p = worker_thread_get_memory_ptr_void(p_off, sizeof(int64_t)); ck_pr_or_64(p, v); } -i32 -env_a_cas(i32 p_off, i32 t, i32 s) +int32_t +env_a_cas(int32_t p_off, int32_t t, int32_t s) { - assert(sizeof(i32) == sizeof(volatile int)); - int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(i32)); + assert(sizeof(int32_t) == sizeof(volatile int)); + int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(int32_t)); return ck_pr_cas_int(p, t, s); } void -env_a_or(i32 p_off, i32 v) +env_a_or(int32_t p_off, int32_t v) { - assert(sizeof(i32) == sizeof(volatile int)); - int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(i32)); + assert(sizeof(int32_t) == sizeof(volatile int)); + int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(int32_t)); ck_pr_or_int(p, v); } -i32 -env_a_swap(i32 x_off, i32 v) +int32_t +env_a_swap(int32_t x_off, int32_t v) { - assert(sizeof(i32) == sizeof(volatile int)); - int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32)); + assert(sizeof(int32_t) == sizeof(volatile int)); + int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(int32_t)); int p; do { @@ -79,59 +79,59 @@ env_a_swap(i32 x_off, i32 v) return v; } -i32 -env_a_fetch_add(i32 x_off, i32 v) +int32_t +env_a_fetch_add(int32_t x_off, int32_t v) { - assert(sizeof(i32) == sizeof(volatile int)); - int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32)); + assert(sizeof(int32_t) == sizeof(volatile int)); + int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(int32_t)); return ck_pr_faa_int(x, v); } void -env_a_inc(i32 x_off) +env_a_inc(int32_t x_off) { - assert(sizeof(i32) == sizeof(volatile int)); - int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32)); + assert(sizeof(int32_t) == sizeof(volatile int)); + int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(int32_t)); ck_pr_inc_int(x); } void -env_a_dec(i32 x_off) +env_a_dec(int32_t x_off) { - assert(sizeof(i32) == sizeof(volatile int)); - int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32)); + assert(sizeof(int32_t) == sizeof(volatile int)); + int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(int32_t)); ck_pr_dec_int(x); } void -env_a_store(i32 p_off, i32 x) +env_a_store(int32_t p_off, int32_t x) { - assert(sizeof(i32) == sizeof(volatile int)); - int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(i32)); + assert(sizeof(int32_t) == sizeof(volatile int)); + int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(int32_t)); ck_pr_store_int(p, x); } int -env_a_ctz_32(i32 x) +env_a_ctz_32(int32_t x) { return __builtin_ctz(x); } void -env_do_spin(i32 i) +env_do_spin(int32_t i) { ck_pr_stall(); } void -env_do_crash(i32 i) +env_do_crash(int32_t i) { printf("crashing: %d\n", i); assert(0); } void -env_do_barrier(i32 x) +env_do_barrier(int32_t x) { ck_pr_barrier(); } diff --git a/runtime/src/libc/uvio.c b/runtime/src/libc/uvio.c index 441c1f4..514c8f8 100644 --- a/runtime/src/libc/uvio.c +++ b/runtime/src/libc/uvio.c @@ -35,18 +35,18 @@ // offset = a WASM ptr to memory the runtime can use void -stub_init(i32 offset) +stub_init(int32_t offset) { // What program name will we put in the auxiliary vectors char *program_name = current_sandbox_get()->module->name; // Copy the program name into WASM accessible memory - i32 program_name_offset = offset; + int32_t program_name_offset = offset; strcpy(get_memory_ptr_for_runtime(offset, sizeof(program_name)), program_name); offset += sizeof(program_name); // The construction of this is: // evn1, env2, ..., NULL, auxv_n1, auxv_1, auxv_n2, auxv_2 ..., NULL - i32 env_vec[] = { + int32_t env_vec[] = { // Env variables would live here, but we don't supply any 0, // We supply only the bare minimum AUX vectors @@ -63,10 +63,10 @@ stub_init(i32 offset) AT_SECURE, 0, AT_RANDOM, - (i32)rand(), // It's pretty stupid to use rand here, but w/e + (int32_t)rand(), // It's pretty stupid to use rand here, but w/e 0, }; - i32 env_vec_offset = offset; + int32_t env_vec_offset = offset; memcpy(get_memory_ptr_for_runtime(env_vec_offset, sizeof(env_vec)), env_vec, sizeof(env_vec)); module_initialize_libc(current_sandbox_get()->module, env_vec_offset, program_name_offset); @@ -106,7 +106,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 uint32_t -wasm_read(i32 filedes, i32 buf_offset, i32 nbyte) +wasm_read(int32_t filedes, int32_t buf_offset, int32_t nbyte) { if (filedes == 0) { char * buffer = worker_thread_get_memory_ptr_void(buf_offset, nbyte); @@ -137,8 +137,8 @@ wasm_read(i32 filedes, i32 buf_offset, i32 nbyte) } #define SYS_WRITE 1 -i32 -wasm_write(i32 file_descriptor, i32 buf_offset, i32 buf_size) +int32_t +wasm_write(int32_t file_descriptor, int32_t buf_offset, int32_t buf_size) { if (file_descriptor == 1 || file_descriptor == 2) { char * buffer = worker_thread_get_memory_ptr_void(buf_offset, buf_size); @@ -183,15 +183,15 @@ wasm_write(i32 file_descriptor, i32 buf_offset, i32 buf_size) #define WO_CLOEXEC 02000000 #define SYS_OPEN 2 -i32 -wasm_open(i32 path_off, i32 flags, i32 mode) +int32_t +wasm_open(int32_t path_off, int32_t flags, int32_t mode) { uv_fs_t req = UV_FS_REQ_INIT(); char * path = worker_thread_get_memory_string(path_off, MODULE_MAX_PATH_LENGTH); int iofd = current_sandbox_initialize_io_handle(); if (iofd < 0) return -1; - i32 modified_flags = 0; + int32_t modified_flags = 0; if (flags & WO_RDONLY) modified_flags |= O_RDONLY; if (flags & WO_WRONLY) modified_flags |= O_WRONLY; if (flags & WO_RDWR) modified_flags |= O_RDWR; @@ -215,8 +215,8 @@ wasm_open(i32 path_off, i32 flags, i32 mode) } #define SYS_CLOSE 3 -i32 -wasm_close(i32 file_descriptor) +int32_t +wasm_close(int32_t file_descriptor) { if (file_descriptor >= 0 && file_descriptor <= 2) { return 0; } struct sandbox * c = current_sandbox_get(); @@ -259,22 +259,22 @@ struct wasm_stat { uint32_t __pad0; uint64_t st_rdev; uint64_t st_size; - i32 st_blksize; + int32_t st_blksize; int64_t st_blocks; struct { - i32 tv_sec; - i32 tv_nsec; + int32_t tv_sec; + int32_t tv_nsec; } st_atim; struct { - i32 tv_sec; - i32 tv_nsec; + int32_t tv_sec; + int32_t tv_nsec; } st_mtim; struct { - i32 tv_sec; - i32 tv_nsec; + int32_t tv_sec; + int32_t tv_nsec; } st_ctim; - i32 __pad1[3]; + int32_t __pad1[3]; }; #define SYS_STAT 4 @@ -297,14 +297,14 @@ struct wasm_stat { // u_long st_gen; /* file generation number */ // }; -i32 -wasm_stat(uint32_t path_str_offset, i32 stat_offset) +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; - i32 res = lstat(path, &stat); + int32_t res = lstat(path, &stat); if (res == -1) return -errno; *stat_ptr = (struct wasm_stat){ @@ -343,14 +343,14 @@ wasm_stat(uint32_t path_str_offset, i32 stat_offset) } #define SYS_FSTAT 5 -i32 -wasm_fstat(i32 filedes, i32 stat_offset) +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; int d = current_sandbox_get_file_descriptor(filedes); - i32 res = fstat(d, &stat); + int32_t res = fstat(d, &stat); if (res == -1) return -errno; *stat_ptr = (struct wasm_stat){ @@ -389,14 +389,14 @@ wasm_fstat(i32 filedes, i32 stat_offset) } #define SYS_LSTAT 6 -i32 -wasm_lstat(i32 path_str_offset, i32 stat_offset) +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; - i32 res = lstat(path, &stat); + int32_t res = lstat(path, &stat); if (res == -1) return -errno; *stat_ptr = (struct wasm_stat){ @@ -436,11 +436,11 @@ wasm_lstat(i32 path_str_offset, i32 stat_offset) #define SYS_LSEEK 8 -i32 -wasm_lseek(i32 filedes, i32 file_offset, i32 whence) +int32_t +wasm_lseek(int32_t filedes, int32_t file_offset, int32_t whence) { - int d = current_sandbox_get_file_descriptor(filedes); - i32 res = (i32)lseek(d, file_offset, whence); + int d = current_sandbox_get_file_descriptor(filedes); + int32_t res = (int32_t)lseek(d, file_offset, whence); if (res == -1) return -errno; @@ -449,7 +449,7 @@ wasm_lseek(i32 filedes, i32 file_offset, i32 whence) #define SYS_MMAP 9 uint32_t -wasm_mmap(i32 addr, i32 len, i32 prot, i32 flags, i32 file_descriptor, i32 offset) +wasm_mmap(int32_t addr, int32_t len, int32_t prot, int32_t flags, int32_t file_descriptor, int32_t offset) { int d = current_sandbox_get_file_descriptor(file_descriptor); if (file_descriptor >= 0) assert(d >= 0); @@ -458,7 +458,7 @@ wasm_mmap(i32 addr, i32 len, i32 prot, i32 flags, i32 file_descriptor, i32 offse assert(len % WASM_PAGE_SIZE == 0); - i32 result = local_sandbox_context_cache.linear_memory_size; + int32_t result = local_sandbox_context_cache.linear_memory_size; for (int i = 0; i < len / WASM_PAGE_SIZE; i++) { expand_memory(); } return result; @@ -473,8 +473,8 @@ wasm_mmap(i32 addr, i32 len, i32 prot, i32 flags, i32 file_descriptor, i32 offse #define SYS_RT_SIGPROGMASK 14 #define SYS_IOCTL 16 -i32 -wasm_ioctl(i32 file_descriptor, i32 request, i32 data_offet) +int32_t +wasm_ioctl(int32_t file_descriptor, int32_t request, int32_t data_offet) { // int d = current_sandbox_get_file_descriptor(file_descriptor); // musl libc does some ioctls to stdout, so just allow these to silently go through @@ -485,12 +485,12 @@ wasm_ioctl(i32 file_descriptor, i32 request, i32 data_offet) #define SYS_READV 19 struct wasm_iovec { - i32 base_offset; - i32 len; + int32_t base_offset; + int32_t len; }; -i32 -wasm_readv(i32 file_descriptor, i32 iov_offset, i32 iovcnt) +int32_t +wasm_readv(int32_t file_descriptor, int32_t iov_offset, int32_t iovcnt) { if (file_descriptor == 0) { // both 1 and 2 go to client. @@ -543,8 +543,8 @@ wasm_readv(i32 file_descriptor, i32 iov_offset, i32 iovcnt) } #define SYS_WRITEV 20 -i32 -wasm_writev(i32 file_descriptor, i32 iov_offset, i32 iovcnt) +int32_t +wasm_writev(int32_t file_descriptor, int32_t iov_offset, int32_t iovcnt) { struct sandbox *c = current_sandbox_get(); if (file_descriptor == 1 || file_descriptor == 2) { @@ -693,8 +693,8 @@ struct wasm_time_spec { uint32_t nanosec; }; -i32 -wasm_get_time(i32 clock_id, i32 timespec_off) +int32_t +wasm_get_time(int32_t clock_id, int32_t timespec_off) { clockid_t real_clock; switch (clock_id) { @@ -725,16 +725,16 @@ wasm_get_time(i32 clock_id, i32 timespec_off) } #define SYS_EXIT_GROUP 231 -i32 -wasm_exit_group(i32 status) +int32_t +wasm_exit_group(int32_t status) { exit(status); return 0; } #define SYS_FCHOWN 93 -i32 -wasm_fchown(i32 file_descriptor, uint32_t owner, uint32_t group) +int32_t +wasm_fchown(int32_t 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(); @@ -775,8 +775,8 @@ wasm_connect_callback(uv_connect_t *req, int status) worker_thread_wakeup_sandbox(s); } -i32 -wasm_socket(i32 domain, i32 type, i32 protocol) +int32_t +wasm_socket(int32_t domain, int32_t type, int32_t protocol) { struct sandbox *c = current_sandbox_get(); int pfd = current_sandbox_initialize_io_handle(), file_descriptor = -1; @@ -802,8 +802,8 @@ wasm_socket(i32 domain, i32 type, i32 protocol) return pfd; } -i32 -wasm_connect(i32 sockfd, i32 sockaddr_offset, i32 addrlen) +int32_t +wasm_connect(int32_t sockfd, int32_t sockaddr_offset, int32_t addrlen) { struct sandbox *c = current_sandbox_get(); int file_descriptor = current_sandbox_get_file_descriptor(sockfd); @@ -830,8 +830,8 @@ wasm_connect(i32 sockfd, i32 sockaddr_offset, i32 addrlen) return -1; } -i32 -wasm_accept(i32 sockfd, i32 sockaddr_offset, i32 addrlen_offset) +int32_t +wasm_accept(int32_t sockfd, int32_t sockaddr_offset, int32_t addrlen_offset) { // what do we do with the sockaddr TODO: ???? socklen_t * addrlen = worker_thread_get_memory_ptr_void(addrlen_offset, sizeof(socklen_t)); @@ -862,8 +862,8 @@ wasm_accept(i32 sockfd, i32 sockaddr_offset, i32 addrlen_offset) return cfd; } -i32 -wasm_bind(i32 sockfd, i32 sockaddr_offset, i32 addrlen) +int32_t +wasm_bind(int32_t sockfd, int32_t sockaddr_offset, int32_t addrlen) { struct sandbox *c = current_sandbox_get(); int file_descriptor = current_sandbox_get_file_descriptor(sockfd); @@ -899,8 +899,8 @@ wasm_bind(i32 sockfd, i32 sockaddr_offset, i32 addrlen) return -1; } -i32 -wasm_listen(i32 sockfd, i32 backlog) +int32_t +wasm_listen(int32_t sockfd, int32_t backlog) { struct sandbox * c = current_sandbox_get(); union uv_any_handle *h = current_sandbox_get_libuv_handle(sockfd); @@ -968,8 +968,9 @@ wasm_udp_send_callback(uv_udp_send_t *req, int status) worker_thread_wakeup_sandbox(c); } -i32 -wasm_sendto(i32 file_descriptor, i32 buff_offset, i32 len, i32 flags, i32 sockaddr_offset, i32 sockaddr_len) +int32_t +wasm_sendto(int32_t file_descriptor, int32_t buff_offset, int32_t len, int32_t flags, int32_t sockaddr_offset, + int32_t sockaddr_len) { char *buffer = worker_thread_get_memory_ptr_void(buff_offset, len); // TODO: only support "send" api for now @@ -1018,8 +1019,9 @@ wasm_alloc_callback(uv_handle_t *h, size_t suggested, uv_buf_t *buffer) buffer->len = s->read_size; } -i32 -wasm_recvfrom(i32 file_descriptor, i32 buff_offset, i32 size, i32 flags, i32 sockaddr_offset, i32 socklen_offset) +int32_t +wasm_recvfrom(int32_t file_descriptor, int32_t buff_offset, int32_t size, int32_t flags, int32_t sockaddr_offset, + int32_t socklen_offset) { char * buffer = worker_thread_get_memory_ptr_void(buff_offset, size); socklen_t *len = worker_thread_get_memory_ptr_void(socklen_offset, sizeof(socklen_t)); @@ -1068,10 +1070,10 @@ wasm_recvfrom(i32 file_descriptor, i32 buff_offset, i32 size, i32 flags, i32 soc return 0; } -i32 -inner_syscall_handler(i32 n, i32 a, i32 b, i32 c, i32 d, i32 e, i32 f) +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) { - i32 res; + int32_t res; switch (n) { case SYS_READ: return wasm_read(a, b, c); diff --git a/runtime/src/main.c b/runtime/src/main.c index 81e0494..27cc4dd 100644 --- a/runtime/src/main.c +++ b/runtime/src/main.c @@ -17,7 +17,7 @@ /* Conditionally used by debuglog when DEBUG is set */ #ifdef DEBUG -i32 runtime_log_file_descriptor = -1; +int32_t runtime_log_file_descriptor = -1; #endif float runtime_processor_speed_MHz = 0; diff --git a/runtime/src/module.c b/runtime/src/module.c index c7c9ac1..c5b1839 100644 --- a/runtime/src/module.c +++ b/runtime/src/module.c @@ -103,7 +103,7 @@ module_free(struct module *module) */ struct module * -module_new(char *name, char *path, i32 argument_count, uint32_t stack_size, uint32_t max_memory, +module_new(char *name, char *path, int32_t 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; @@ -316,14 +316,14 @@ 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; + int32_t request_size = 0; + int32_t response_size = 0; + int32_t 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; + int32_t request_count = 0; + int32_t response_count = 0; int j = 1; int ntoks = 2 * tokens[i].size; char request_content_type[HTTP_MAX_HEADER_VALUE_LENGTH] = { 0 }; diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index 1aec382..c5b85c8 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -20,16 +20,17 @@ static inline void sandbox_setup_arguments(struct sandbox *sandbox) { assert(sandbox != NULL); - char *arguments = sandbox_get_arguments(sandbox); - i32 argument_count = module_get_argument_count(sandbox->module); + char * arguments = sandbox_get_arguments(sandbox); + int32_t argument_count = module_get_argument_count(sandbox->module); /* whatever gregor has, to be able to pass arguments to a module! */ sandbox->arguments_offset = local_sandbox_context_cache.linear_memory_size; assert(local_sandbox_context_cache.linear_memory_start == sandbox->linear_memory_start); expand_memory(); - i32 *array_ptr = worker_thread_get_memory_ptr_void(sandbox->arguments_offset, argument_count * sizeof(i32)); - i32 string_off = sandbox->arguments_offset + (argument_count * sizeof(i32)); + int32_t *array_ptr = worker_thread_get_memory_ptr_void(sandbox->arguments_offset, + argument_count * sizeof(int32_t)); + int32_t string_off = sandbox->arguments_offset + (argument_count * sizeof(int32_t)); for (int i = 0; i < argument_count; i++) { char * arg = arguments + (i * MODULE_MAX_ARGUMENT_SIZE);