From 52aa6eed0df0c6217b89db77fd076ec8ece99609 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 8 Nov 2023 03:36:08 +0000 Subject: [PATCH] Builds for OpenBSD! git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4620 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- Makefile | 20 ++++++++++++++++++++ deps/quickjs/quickjs.c | 4 ++-- src/main.c | 11 +++++++---- src/mem.c | 12 ++++++++++++ src/task.c | 2 +- src/tests.c | 4 ++++ 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index dcae5bb3..8c89f3b2 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,16 @@ CFLAGS += -Dstatic_assert=_Static_assert LDFLAGS += \ -lbsd \ -lnetwork +else ifeq ($(UNAME_S),OpenBSD) +BUILD_TYPES := debug release +CFLAGS += \ + -Wno-unknown-warning-option +LDFLAGS += \ + -lexecinfo \ + -lc++abi +HAVE_ANDROID := 0 +HAVE_LINUX_IOS := 0 +HAVE_WIN := 0 else $(error Unexpected host platform $(UNAME_S).) endif @@ -292,6 +302,14 @@ else ifeq ($(UNAME_S),Haiku) deps/libuv/src/unix/no-proctitle.c \ deps/libuv/src/unix/posix-hrtime.c \ deps/libuv/src/unix/posix-poll.c +else ifeq ($(UNAME_S),OpenBSD) + UV_SOURCES_unix += \ + deps/libuv/src/unix/bsd-ifaddrs.c \ + deps/libuv/src/unix/kqueue.c \ + deps/libuv/src/unix/no-proctitle.c \ + deps/libuv/src/unix/openbsd.c \ + deps/libuv/src/unix/posix-hrtime.c \ + deps/libuv/src/unix/random-getentropy.c endif UV_SOURCES_android := \ deps/libuv/src/unix/random-getentropy.c @@ -558,9 +576,11 @@ debug release $(MACOS_TARGETS) $(IOS_TARGETS) $(IOSSIM_TARGETS): LDFLAGS += \ -lssl \ -lcrypto ifneq ($(UNAME_S),Haiku) +ifneq ($(UNAME_S),OpenBSD) debug release $(MACOS_TARGETS) $(IOS_TARGETS) $(IOSSIM_TARGETS): LDFLAGS += \ -ldl endif +endif $(WINDOWS_TARGETS): LDFLAGS += \ -lssl \ -lcrypto \ diff --git a/deps/quickjs/quickjs.c b/deps/quickjs/quickjs.c index a0d5863d..88b331c4 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) || defined(__HAIKU__) +#elif defined(EMSCRIPTEN) || defined(__HAIKU__) || defined(__OpenBSD__) 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) || defined(__HAIKU__) +#elif defined(EMSCRIPTEN) || defined(__HAIKU__) || defined(__OpenBSD__) NULL, #elif defined(__linux__) (size_t (*)(const void *))malloc_usable_size, diff --git a/src/main.c b/src/main.c index a6348655..4e5f438f 100644 --- a/src/main.c +++ b/src/main.c @@ -18,10 +18,13 @@ #if !defined(_WIN32) && !defined(__APPLE__) && !defined(__HAIKU__) #include -#include #include #endif +#if defined(__linux__) +#include +#endif + #if defined(__APPLE__) #include #endif @@ -362,7 +365,7 @@ static void _shed_privileges() perror("setrlimit(RLIMIT_NPROC, {0, 0})"); exit(-1); } -#if !defined(__MACH__) +#if !defined(__MACH__) && !defined(__OpenBSD__) if (setrlimit(RLIMIT_LOCKS, &zeroLimit) != 0) { perror("setrlimit(RLIMIT_LOCKS, {0, 0})"); @@ -484,7 +487,7 @@ static int _tf_command_sandbox(const char* file, int argc, char* argv[]) return 2; } -#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__HAIKU__) +#if defined(__linux__) prctl(PR_SET_PDEATHSIG, SIGHUP); #endif tf_task_t* task = tf_task_create(); @@ -607,7 +610,7 @@ static void _startup(int argc, char* argv[]) _backtrace_error, NULL); -#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__HAIKU__) +#if defined(__linux__) prctl(PR_SET_PDEATHSIG, SIGKILL); #endif tf_mem_replace_uv_allocator(); diff --git a/src/mem.c b/src/mem.c index 0f9eed09..10439826 100644 --- a/src/mem.c +++ b/src/mem.c @@ -394,17 +394,29 @@ size_t tf_mem_get_uv_malloc_size() return s_uv_malloc_size; } +#if defined(__OpenBSD__) +void* _tf_tls_alloc(size_t size) +#else void* _tf_tls_alloc(size_t size, const char* file, int line) +#endif { return _tf_alloc(&s_tls_malloc_size, size); } +#if defined(__OpenBSD__) +void* _tf_tls_realloc(void* ptr, size_t size) +#else void* _tf_tls_realloc(void* ptr, size_t size, const char* file, int line) +#endif { return _tf_realloc(&s_tls_malloc_size, ptr, size); } +#if defined(__OpenBSD__) +void _tf_tls_free(void* ptr) +#else void _tf_tls_free(void* ptr, const char* file, int line) +#endif { _tf_free(&s_tls_malloc_size, ptr); } diff --git a/src/task.c b/src/task.c index 6e1b771a..e45bec40 100644 --- a/src/task.c +++ b/src/task.c @@ -33,7 +33,7 @@ #include #endif -#if !defined(__APPLE__) +#if !defined(__APPLE__) && !defined(__OpenBSD__) #include #endif diff --git a/src/tests.c b/src/tests.c index 9afaf817..9c9ead8b 100644 --- a/src/tests.c +++ b/src/tests.c @@ -16,6 +16,10 @@ #define WEXITSTATUS(x) (x) #endif +#if defined(__OpenBSD__) +#include +#endif + #if defined(__APPLE__) #include #endif