From 9d67fed63c6d493eeea99d2fd5bd078c7926da98 Mon Sep 17 00:00:00 2001 From: Kirill A. Korinsky Date: Wed, 22 Sep 2021 20:22:50 +0200 Subject: Fixed build on macOS via posix-macos-addons This commit introduced support of macOS by using [posix-macos-addons](https://github.com/stanislaw/posix-macos-addons). Closes: https://github.com/J08nY/ecgen/issues/7 --- CMakeLists.txt | 12 +++++++++++- README.md | 1 + src/util/timeout.c | 4 ++-- src/util/timeout.h | 16 ++++++++++++++-- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 929ef0b..04d8f36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,16 @@ include_directories(lib) add_executable(ecgen ${ECGEN_SRC}) -target_link_libraries(ecgen pthread rt pari parson sha1) +set(PLATFORM_SPECIFIC_LIBS) +if (APPLE) + find_library(LIB_ARGP argp) + find_library(LIB_POSIX_MACOS_TIMER posix-macos-timer) + + set(PLATFORM_SPECIFIC_LIBS ${LIB_ARGP} ${LIB_POSIX_MACOS_TIMER}) +else () + set(PLATFORM_SPECIFIC_LIBS rt) +endif() + +target_link_libraries(ecgen pthread pari parson sha1 ${PLATFORM_SPECIFIC_LIBS}) diff --git a/README.md b/README.md index 6caab9c..ee248d3 100644 --- a/README.md +++ b/README.md @@ -249,6 +249,7 @@ these need to be initialized for `make test` to work. - PARI/GP - gcc / clang + - [posix-macos-addons](https://github.com/stanislaw/posix-macos-addons) for macOS ecgen uses the [PARI/GP](http://pari.math.u-bordeaux.fr/) library for elliptic curve arithmetic and it's SEA point counting algorithm implementation. It also requires the diff --git a/src/util/timeout.c b/src/util/timeout.c index 21f9591..6fdbf16 100644 --- a/src/util/timeout.c +++ b/src/util/timeout.c @@ -5,7 +5,7 @@ #include "timeout.h" #include "util/memory.h" -__thread jmp_buf timeout_ptr; +__thread sigjmp_buf timeout_ptr; __thread bool timeout_in = false; __thread timer_t *timeout_timer; __thread struct sigevent *sevp; @@ -45,4 +45,4 @@ bool timeout_init() { void timeout_quit() { // deinit the main thread. timeout_thread_quit(); -} \ No newline at end of file +} diff --git a/src/util/timeout.h b/src/util/timeout.h index 5a5c0d2..57e3d22 100644 --- a/src/util/timeout.h +++ b/src/util/timeout.h @@ -15,6 +15,19 @@ #include "io/output.h" #include "misc/config.h" +#ifdef __APPLE__ + +#include +#define SIGEV_THREAD_ID 0 +#define SIGEV_UN_TID_SYS_GETTID + +#else + +#define SIGEV_UN_TID_SYS_GETTID \ + sevp->_sigev_un._tid = (__pid_t)syscall(SYS_gettid); + +#endif + extern __thread sigjmp_buf timeout_ptr; extern __thread bool timeout_in; extern __thread timer_t *timeout_timer; @@ -35,8 +48,7 @@ extern __thread struct sigevent *sevp; sevp->sigev_notify = SIGEV_THREAD_ID; \ sevp->sigev_signo = SIGALRM; \ sevp->sigev_value.sival_int = 0; \ - sevp->_sigev_un._tid = (__pid_t)syscall(SYS_gettid); \ - \ + SIGEV_UN_TID_SYS_GETTID \ timer_create(CLOCK_MONOTONIC, sevp, timeout_timer); \ struct itimerspec timer_time = { \ .it_interval = {.tv_sec = 0, .tv_nsec = 0}, \ -- cgit v1.2.3-70-g09d2