diff --git a/.clang-format b/.clang-format index 80b850d..b10603d 100644 --- a/.clang-format +++ b/.clang-format @@ -6,6 +6,7 @@ Language: Cpp AlignAfterOpenBracket: Align AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: true +AlignConsecutiveMacros: true AlignEscapedNewlines: Left AlignTrailingComments: true diff --git a/runtime/include/types.h b/runtime/include/types.h index a78b6e6..c9a21be 100644 --- a/runtime/include/types.h +++ b/runtime/include/types.h @@ -21,7 +21,7 @@ #define IMPORT __attribute__((visibility("default"))) #define INLINE __attribute__((always_inline)) -#define WEAK __attribute__((weak)) +#define WEAK __attribute__((weak)) #ifndef CACHELINE_SIZE #define CACHELINE_SIZE 32 @@ -32,13 +32,13 @@ #endif #define CACHE_ALIGNED __attribute__((aligned(CACHELINE_SIZE))) -#define PAGE_ALIGNED __attribute__((aligned(PAGE_SIZE))) +#define PAGE_ALIGNED __attribute__((aligned(PAGE_SIZE))) /* For this family of macros, do NOT pass zero as the pow2 */ -#define round_to_pow2(x, pow2) (((unsigned long)(x)) & (~((pow2)-1))) +#define round_to_pow2(x, pow2) (((unsigned long)(x)) & (~((pow2)-1))) #define round_up_to_pow2(x, pow2) (round_to_pow2(((unsigned long)x) + (pow2)-1, (pow2))) -#define round_to_page(x) round_to_pow2(x, PAGE_SIZE) +#define round_to_page(x) round_to_pow2(x, PAGE_SIZE) #define round_up_to_page(x) round_up_to_pow2(x, PAGE_SIZE) // Type alias's so I don't have to write uint32_t a million times @@ -52,11 +52,11 @@ typedef int64_t i64; typedef uint64_t u64; // FIXME: per-module configuration? -#define WASM_PAGE_SIZE (1024 * 64) // 64KB -#define WASM_START_PAGES (1 << 8) // 16MB -#define WASM_MAX_PAGES (1 << 15) // 4GB -#define WASM_STACK_SIZE (1 << 19) // 512KB. -#define SBOX_MAX_MEM (1L << 32) // 4GB +#define WASM_PAGE_SIZE (1024 * 64) // 64KB +#define WASM_START_PAGES (1 << 8) // 16MB +#define WASM_MAX_PAGES (1 << 15) // 4GB +#define WASM_STACK_SIZE (1 << 19) // 512KB. +#define SBOX_MAX_MEM (1L << 32) // 4GB // These are per module symbols and I'd need to dlsym for each module. instead just use global constants, see above // macros. The code generator compiles in the starting number of wasm pages, and the maximum number of pages If we try @@ -117,43 +117,43 @@ typedef enum #define debuglog(fmt, ...) #endif // DEBUG -#define HTTP__MAX_HEADER_COUNT 16 -#define HTTP__MAX_HEADER_LENGTH 32 -#define HTTP__MAX_HEADER_VALUE_LENGTH 64 -#define HTTP__RESPONSE_200_OK "HTTP/1.1 200 OK\r\n" -#define HTTP__RESPONSE_CONTENT_LENGTH "Content-length: \r\n\r\n" // content body follows this -#define HTTP__RESPONSE_CONTENT_TYPE "Content-type: \r\n" +#define HTTP__MAX_HEADER_COUNT 16 +#define HTTP__MAX_HEADER_LENGTH 32 +#define HTTP__MAX_HEADER_VALUE_LENGTH 64 +#define HTTP__RESPONSE_200_OK "HTTP/1.1 200 OK\r\n" +#define HTTP__RESPONSE_CONTENT_LENGTH "Content-length: \r\n\r\n" // content body follows this +#define HTTP__RESPONSE_CONTENT_TYPE "Content-type: \r\n" #define HTTP__RESPONSE_CONTENT_TYPE_PLAIN "text/plain" -#define JSON__MAX_ELEMENT_COUNT 16 // Max number of elements defined in JSON -#define JSON__MAX_ELEMENT_SIZE 1024 // Max size of a single module in JSON +#define JSON__MAX_ELEMENT_COUNT 16 // Max number of elements defined in JSON +#define JSON__MAX_ELEMENT_SIZE 1024 // Max size of a single module in JSON -#define LISTENER_THREAD__CORE_ID 0 // Dedicated Listener Core +#define LISTENER_THREAD__CORE_ID 0 // Dedicated Listener Core #define LISTENER_THREAD__MAX_EPOLL_EVENTS 1024 #define MODULE__DEFAULT_REQUEST_RESPONSE_SIZE (PAGE_SIZE) -#define MODULE__INITIALIZE_GLOBALS "populate_globals" // From Silverfish -#define MODULE__INITIALIZE_MEMORY "populate_memory" // From Silverfish -#define MODULE__INITIALIZE_TABLE "populate_table" // From Silverfish -#define MODULE__INITIALIZE_LIBC "wasmf___init_libc" // From Silverfish -#define MODULE__MAIN "wasmf_main" // From Silverfish -#define MODULE__MAX_ARGUMENT_COUNT 16 // Max number of arguments -#define MODULE__MAX_ARGUMENT_SIZE 64 // Max size of a single argument -#define MODULE__MAX_MODULE_COUNT 128 // Max number of modules -#define MODULE__MAX_NAME_LENGTH 32 // Max module name length -#define MODULE__MAX_PATH_LENGTH 256 // Max length of path string -#define MODULE__MAX_PENDING_CLIENT_REQUESTS 1000 - -#define RUNTIME__LOG_FILE "awesome.log" -#define RUNTIME__READ_WRITE_VECTOR_LENGTH 16 +#define MODULE__INITIALIZE_GLOBALS "populate_globals" // From Silverfish +#define MODULE__INITIALIZE_MEMORY "populate_memory" // From Silverfish +#define MODULE__INITIALIZE_TABLE "populate_table" // From Silverfish +#define MODULE__INITIALIZE_LIBC "wasmf___init_libc" // From Silverfish +#define MODULE__MAIN "wasmf_main" // From Silverfish +#define MODULE__MAX_ARGUMENT_COUNT 16 // Max number of arguments +#define MODULE__MAX_ARGUMENT_SIZE 64 // Max size of a single argument +#define MODULE__MAX_MODULE_COUNT 128 // Max number of modules +#define MODULE__MAX_NAME_LENGTH 32 // Max module name length +#define MODULE__MAX_PATH_LENGTH 256 // Max length of path string +#define MODULE__MAX_PENDING_CLIENT_REQUESTS 1000 + +#define RUNTIME__LOG_FILE "awesome.log" +#define RUNTIME__READ_WRITE_VECTOR_LENGTH 16 #define RUNTIME__MAX_SANDBOX_REQUEST_COUNT (1 << 19) // random! #define SANDBOX__FILE_DESCRIPTOR_PREOPEN_MAGIC (707707707) // reads lol lol lol upside down -#define SANDBOX__MAX_IO_HANDLE_COUNT 32 -#define SANDBOX__PULL_BATCH_SIZE 1 // Max # standboxes pulled onto the local runqueue in a single batch +#define SANDBOX__MAX_IO_HANDLE_COUNT 32 +#define SANDBOX__PULL_BATCH_SIZE 1 // Max # standboxes pulled onto the local runqueue in a single batch -#define SOFTWARE_INTERRUPT__TIME_TO_START_IN_USEC (10 * 1000) // start timers 10 ms from now. -#define SOFTWARE_INTERRUPT__INTERVAL_DURATION_IN_USEC (1000 * 5) // and execute every 5ms +#define SOFTWARE_INTERRUPT__TIME_TO_START_IN_USEC (10 * 1000) // start timers 10 ms from now. +#define SOFTWARE_INTERRUPT__INTERVAL_DURATION_IN_USEC (1000 * 5) // and execute every 5ms // If multicore, use all but the dedicated listener core diff --git a/runtime/src/libc/uvio.c b/runtime/src/libc/uvio.c index 244a71e..543abb6 100644 --- a/runtime/src/libc/uvio.c +++ b/runtime/src/libc/uvio.c @@ -9,25 +9,25 @@ #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_PAGESZ 6 -#define AT_BASE 7 -#define AT_FLAGS 8 -#define AT_ENTRY 9 -#define AT_NOTELF 10 -#define AT_UID 11 -#define AT_EUID 12 -#define AT_GID 13 -#define AT_EGID 14 -#define AT_CLKTCK 17 -#define AT_SECURE 23 +#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 +#define AT_ENTRY 9 +#define AT_NOTELF 10 +#define AT_UID 11 +#define AT_EUID 12 +#define AT_GID 13 +#define AT_EGID 14 +#define AT_CLKTCK 17 +#define AT_SECURE 23 #define AT_BASE_PLATFORM 24 -#define AT_RANDOM 25 +#define AT_RANDOM 25 // offset = a WASM ptr to memory the runtime can use void @@ -162,21 +162,21 @@ wasm_write(i32 file_descriptor, i32 buf_offset, i32 buf_size) return ret; } -#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_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 -#define WO_CLOEXEC 02000000 +#define WO_NOFOLLOW 0400000 +#define WO_CLOEXEC 02000000 #define SYS_OPEN 2 i32 @@ -616,8 +616,8 @@ wasm_getpid() #define WF_SETSIG 10 #define WF_GETSIG 11 -#define WF_GETLK 5 -#define WF_SETLK 6 +#define WF_GETLK 5 +#define WF_SETLK 6 #define WF_SETLKW 7 #define SYS_FCNTL 72 @@ -755,11 +755,11 @@ wasm_fchown(i32 file_descriptor, u32 owner, u32 group) } // networking syscalls -#define SYS_SOCKET 41 +#define SYS_SOCKET 41 #define SYS_CONNECT 42 -#define SYS_ACCEPT 43 -#define SYS_BIND 49 -#define SYS_LISTEN 50 +#define SYS_ACCEPT 43 +#define SYS_BIND 49 +#define SYS_LISTEN 50 static void wasm_connection_callback(uv_stream_t *srv, int status) @@ -924,7 +924,7 @@ wasm_listen(i32 sockfd, i32 backlog) return c->return_value; } -#define SYS_SENDTO 44 +#define SYS_SENDTO 44 #define SYS_RECVFROM 45 void