aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJán Jančár2021-09-23 13:59:42 +0200
committerGitHub2021-09-23 13:59:42 +0200
commitc26a14d988a45dd529e9217339bf27da772c2e3c (patch)
tree8974ecc6dc76e8064d8abcc4361c5364e929c3e2
parentd41953bcbedced945a82d1bc6c30ad690f12eaa9 (diff)
parent9d67fed63c6d493eeea99d2fd5bd078c7926da98 (diff)
downloadecgen-c26a14d988a45dd529e9217339bf27da772c2e3c.tar.gz
ecgen-c26a14d988a45dd529e9217339bf27da772c2e3c.tar.zst
ecgen-c26a14d988a45dd529e9217339bf27da772c2e3c.zip
-rw-r--r--CMakeLists.txt12
-rw-r--r--README.md1
-rw-r--r--src/util/timeout.c4
-rw-r--r--src/util/timeout.h16
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 <posix-macos-timer.h>
+#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}, \