diff --git a/Makefile b/Makefile index a0ded3be..cec09bd4 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,12 @@ BUILD_TYPES := debug release HAVE_ANDROID = $(if $(shell which $(ANDROID_SDK)/platform-tools/adb),1,0) HAVE_LINUX_IOS = $(if $(shell which deps/ios_toolchain/target/bin deps/ios_toolchain/target/bin/arm-apple-darwin11-clang),1,0) HAVE_WIN = $(if $(shell which x86_64-w64-mingw32-gcc-win32),1,0) +else ifeq ($(UNAME_S),Haiku) +BUILD_TYPES := debug release +CFLAGS += -Dstatic_assert=_Static_assert +LDFLAGS += \ + -lbsd \ + -lnetwork else $(error Unexpected host platform $(UNAME_S).) endif @@ -190,9 +196,11 @@ $(IOSSIM_TARGETS): CFLAGS += -Ideps/openssl/ios/iossimulator-xcrun/usr/local/inc $(IOSSIM_TARGETS): LDFLAGS += -Ldeps/openssl/ios/iossimulator-xcrun/usr/local/lib ifeq ($(UNAME_M),x86_64) +ifneq ($(UNAME_S),Haiku) debug: CFLAGS += -fsanitize=address -fsanitize=undefined -fno-common debug: LDFLAGS += -fsanitize=address -fsanitize=undefined endif +endif get_objs = \ $(foreach build_type,$(BUILD_TYPES),$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)))))) \ @@ -257,23 +265,34 @@ UV_SOURCES_unix := \ deps/libuv/src/unix/fs.c \ deps/libuv/src/unix/getaddrinfo.c \ deps/libuv/src/unix/getnameinfo.c \ - deps/libuv/src/unix/linux.c \ deps/libuv/src/unix/loop-watcher.c \ deps/libuv/src/unix/loop.c \ deps/libuv/src/unix/pipe.c \ deps/libuv/src/unix/poll.c \ deps/libuv/src/unix/process.c \ - deps/libuv/src/unix/procfs-exepath.c \ - deps/libuv/src/unix/proctitle.c \ deps/libuv/src/unix/random-devurandom.c \ deps/libuv/src/unix/random-getrandom.c \ - deps/libuv/src/unix/random-sysctl-linux.c \ deps/libuv/src/unix/signal.c \ deps/libuv/src/unix/stream.c \ deps/libuv/src/unix/tcp.c \ deps/libuv/src/unix/thread.c \ deps/libuv/src/unix/tty.c \ deps/libuv/src/unix/udp.c +ifeq ($(UNAME_S),Linux) + UV_SOURCES_unix += \ + deps/libuv/src/unix/linux.c \ + deps/libuv/src/unix/procfs-exepath.c \ + deps/libuv/src/unix/proctitle.c \ + deps/libuv/src/unix/random-sysctl-linux.c +else ifeq ($(UNAME_S),Haiku) + UV_SOURCES_unix += \ + deps/libuv/src/unix/bsd-ifaddrs.c \ + deps/libuv/src/unix/haiku.c \ + deps/libuv/src/unix/no-fsevents.c \ + deps/libuv/src/unix/no-proctitle.c \ + deps/libuv/src/unix/posix-hrtime.c \ + deps/libuv/src/unix/posix-poll.c +endif UV_SOURCES_android := \ deps/libuv/src/unix/random-getentropy.c UV_SOURCES_win := \ @@ -338,8 +357,15 @@ $(UV_OBJS): CFLAGS += \ -Wno-sign-compare \ -Wno-unused-but-set-variable \ -Wno-unused-result \ - -Wno-unused-variable \ + -Wno-unused-variable +ifeq ($(UNAME_S),Linux) +$(UV_OBJS): CFLAGS += \ -D_GNU_SOURCE +else ifeq ($(UNAME_S),Haiku) +$(UV_OBJS): CFLAGS += \ + -D_BSD_SOURCE \ + -Wno-format-truncation +endif SODIUM_SOURCES := \ deps/libsodium/src/libsodium/crypto_aead/aegis128l/aead_aegis128l.c \ @@ -528,9 +554,12 @@ LDFLAGS += \ -pthread \ -lm debug release $(MACOS_TARGETS) $(IOS_TARGETS) $(IOSSIM_TARGETS): LDFLAGS += \ - -ldl \ -lssl \ -lcrypto +ifneq ($(UNAME_S),Haiku) +debug release $(MACOS_TARGETS) $(IOS_TARGETS) $(IOSSIM_TARGETS): LDFLAGS += \ + -ldl +endif $(WINDOWS_TARGETS): LDFLAGS += \ -lssl \ -lcrypto \ @@ -605,7 +634,7 @@ $(foreach build_type,$(BUILD_TYPES),$(eval $(call build_rules,$(build_type)))) src/version.h : $(firstword $(MAKEFILE_LIST)) @echo [version] $@ - @echo "#define VERSION_NUMBER \"$(VERSION_NUMBER)\"\n#define VERSION_NAME \"$(VERSION_NAME)\"\n" > $@ + @echo -e "#define VERSION_NUMBER \"$(VERSION_NUMBER)\"\n#define VERSION_NAME \"$(VERSION_NAME)\"\n" > $@ src/android/AndroidManifest.xml : $(firstword $(MAKEFILE_LIST)) @echo [android_version] $@ diff --git a/deps/quickjs/quickjs.c b/deps/quickjs/quickjs.c index 48aeffc6..a0d5863d 100644 --- a/deps/quickjs/quickjs.c +++ b/deps/quickjs/quickjs.c @@ -1680,7 +1680,7 @@ static inline size_t js_def_malloc_usable_size(void *ptr) return malloc_size(ptr); #elif defined(_WIN32) return _msize(ptr); -#elif defined(EMSCRIPTEN) +#elif defined(EMSCRIPTEN) || defined(__HAIKU__) return 0; #elif defined(__linux__) return malloc_usable_size(ptr); @@ -1754,7 +1754,7 @@ static const JSMallocFunctions def_malloc_funcs = { malloc_size, #elif defined(_WIN32) (size_t (*)(const void *))_msize, -#elif defined(EMSCRIPTEN) +#elif defined(EMSCRIPTEN) || defined(__HAIKU__) NULL, #elif defined(__linux__) (size_t (*)(const void *))malloc_usable_size, diff --git a/src/main.c b/src/main.c index 8793c4fa..a6348655 100644 --- a/src/main.c +++ b/src/main.c @@ -16,7 +16,7 @@ #include #include -#if !defined(_WIN32) && !defined(__APPLE__) +#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__HAIKU__) #include #include #include @@ -331,7 +331,7 @@ static void _tf_run_task_thread(void* data) #if !TARGET_OS_IPHONE static void _shed_privileges() { -#if !defined(_WIN32) +#if !defined(_WIN32) && !defined(__HAIKU__) struct rlimit zeroLimit; zeroLimit.rlim_cur = 0; zeroLimit.rlim_max = 0; @@ -484,7 +484,7 @@ static int _tf_command_sandbox(const char* file, int argc, char* argv[]) return 2; } -#if !defined(_WIN32) && !defined(__APPLE__) +#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__HAIKU__) prctl(PR_SET_PDEATHSIG, SIGHUP); #endif tf_task_t* task = tf_task_create(); @@ -607,7 +607,7 @@ static void _startup(int argc, char* argv[]) _backtrace_error, NULL); -#if !defined(_WIN32) && !defined(__APPLE__) +#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__HAIKU__) prctl(PR_SET_PDEATHSIG, SIGKILL); #endif tf_mem_replace_uv_allocator(); diff --git a/src/mem.c b/src/mem.c index 88e621af..0f9eed09 100644 --- a/src/mem.c +++ b/src/mem.c @@ -436,6 +436,10 @@ void tf_free(void* ptr) char* tf_strdup(const char* string) { + if (!string) + { + return NULL; + } size_t len = strlen(string); char* buffer = tf_malloc(len + 1); if ( buffer) diff --git a/src/ssb.import.c b/src/ssb.import.c index 00a9d4a6..cf0e226f 100644 --- a/src/ssb.import.c +++ b/src/ssb.import.c @@ -282,7 +282,7 @@ static char* _tf_ssb_import_read_current_file_from_zip(unzFile zip, size_t* size static void _tf_ssb_import_recursive_add_files_from_zip(tf_ssb_t* ssb, unzFile zip, JSContext* context, JSValue files, const char* root) { - if (unzGoToFirstFile(zip) == UNZ_OK) + if (root && unzGoToFirstFile(zip) == UNZ_OK) { do { @@ -355,7 +355,7 @@ static void _tf_ssb_import_app_json_from_zip(tf_ssb_t* ssb, unzFile zip, JSConte void tf_ssb_import_from_zip(tf_ssb_t* ssb, const char* zip_path, const char* user, const char* path) { unzFile zip = unzOpen(zip_path); - if (zip) + if (zip && path) { tf_printf("Importing from %s.\n", zip_path); if (unzGoToFirstFile(zip) == UNZ_OK) diff --git a/src/ssb.tests.c b/src/ssb.tests.c index b82911fb..c1e70a5b 100644 --- a/src/ssb.tests.c +++ b/src/ssb.tests.c @@ -685,13 +685,16 @@ void tf_ssb_test_bench(const tf_test_options_t* options) uv_run(&loop, UV_RUN_DEFAULT); char* trace_data = tf_trace_export(trace); - FILE* file = fopen("out/trace.json", "wb"); - if (file) + if (trace_data) { - fwrite(trace_data, 1, strlen(trace_data), file); - fclose(file); + FILE* file = fopen("out/trace.json", "wb"); + if (file) + { + fwrite(trace_data, 1, strlen(trace_data), file); + fclose(file); + } + tf_free(trace_data); } - tf_free(trace_data); tf_ssb_destroy(ssb1); tf_ssb_destroy(ssb0); diff --git a/src/util.js.c b/src/util.js.c index 89ee31d9..916d3e5a 100644 --- a/src/util.js.c +++ b/src/util.js.c @@ -15,7 +15,7 @@ #if defined(__ANDROID__) #include -#elif !defined(_WIN32) +#elif !defined(_WIN32) && !defined(__HAIKU__) #include #endif @@ -497,9 +497,9 @@ static int _tf_util_backtrace_callback(void* data, uintptr_t pc, const char* fil static void _tf_util_backtrace_error(void* data, const char* message, int error) { char** stack = data; - int length = strlen(message); if (message) { + int length = strlen(message); int current = *stack ? strlen(*stack) : 0; *stack = tf_resize_vec(*stack, current + length + 1); memcpy(*stack + current, message, length + 1); @@ -587,6 +587,8 @@ int tf_util_backtrace(void** buffer, int count) android_backtrace_t state = { .current = buffer, .end = buffer + count }; _Unwind_Backtrace(_android_unwind_callback, &state); return state.current - buffer; +#elif defined(__HAIKU__) + return 0; #else return backtrace(buffer, count); #endif