From 7c2981fc559e93131c845164907cec6cae11ce48 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 12 Jun 2024 10:02:20 -0400 Subject: [PATCH] Fix FreeBSD build This restores some CPP'd code that was added in c18911602eb4260d59acf8c17f1c3b4c7fcf7cee and accidentally lost in 2477e4e3b84b23b091befa1869a1fc6186fe74dc. Co-authored-by: Eelco Dolstra --- configure.ac | 8 +++++++ src/libexpr/eval.cc | 29 +++++++++++++++++++------- src/libstore/build/derivation-goal.cc | 6 +++++- tests/unit/libstore/worker-protocol.cc | 1 + 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 90a6d45d5..8211bec0b 100644 --- a/configure.ac +++ b/configure.ac @@ -369,6 +369,14 @@ if test "$gc" = yes; then PKG_CHECK_MODULES([BDW_GC], [bdw-gc]) CXXFLAGS="$BDW_GC_CFLAGS $CXXFLAGS" AC_DEFINE(HAVE_BOEHMGC, 1, [Whether to use the Boehm garbage collector.]) + + # See `fixupBoehmStackPointer`, for the integration between Boehm GC + # and Boost coroutines. + old_CFLAGS="$CFLAGS" + # Temporary set `-pthread` just for the next check + CFLAGS="$CFLAGS -pthread" + AC_CHECK_FUNCS([pthread_attr_get_np pthread_getattr_np]) + CFLAGS="$old_CFLAGS" fi AS_IF([test "$ENABLE_UNIT_TESTS" == "yes"],[ diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index f441977a5..42b26834c 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -48,6 +48,9 @@ #define GC_INCLUDE_NEW #include +#if __FreeBSD__ +# include +#endif #include #include @@ -264,30 +267,42 @@ static BoehmGCStackAllocator boehmGCStackAllocator; * However, the implementation is quite lean, and usually we don't have active * coroutines during evaluation, so this is acceptable. */ -void fixupBoehmStackPointer(void ** sp_ptr, void * pthread_id) { +void fixupBoehmStackPointer(void ** sp_ptr, void * _pthread_id) { void *& sp = *sp_ptr; + auto pthread_id = reinterpret_cast(_pthread_id); pthread_attr_t pattr; size_t osStackSize; void * osStackLow; void * osStackBase; - #ifdef __APPLE__ - osStackSize = pthread_get_stacksize_np((pthread_t)pthread_id); - osStackLow = pthread_get_stackaddr_np((pthread_t)pthread_id); - #else +# ifdef __APPLE__ + osStackSize = pthread_get_stacksize_np(pthread_id); + osStackLow = pthread_get_stackaddr_np(pthread_id); +# else if (pthread_attr_init(&pattr)) { throw Error("fixupBoehmStackPointer: pthread_attr_init failed"); } - if (pthread_getattr_np((pthread_t)pthread_id, &pattr)) { +# ifdef HAVE_PTHREAD_GETATTR_NP + if (pthread_getattr_np(pthread_id, &pattr)) { throw Error("fixupBoehmStackPointer: pthread_getattr_np failed"); } +# elif HAVE_PTHREAD_ATTR_GET_NP + if (!pthread_attr_init(&pattr)) { + throw Error("fixupBoehmStackPointer: pthread_attr_init failed"); + } + if (!pthread_attr_get_np(pthread_id, &pattr)) { + throw Error("fixupBoehmStackPointer: pthread_attr_get_np failed"); + } +# else +# error "Need one of `pthread_attr_get_np` or `pthread_getattr_np`" +# endif if (pthread_attr_getstack(&pattr, &osStackLow, &osStackSize)) { throw Error("fixupBoehmStackPointer: pthread_attr_getstack failed"); } if (pthread_attr_destroy(&pattr)) { throw Error("fixupBoehmStackPointer: pthread_attr_destroy failed"); } - #endif +# endif osStackBase = (char *)osStackLow + osStackSize; // NOTE: We assume the stack grows down, as it does on all architectures we support. // Architectures that grow the stack up are rare. diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index 4226fb61a..e72ef4cf9 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -25,6 +25,10 @@ #include #include +#ifndef _WIN32 // TODO abstract over proc exit status +# include +#endif + #include namespace nix { @@ -1033,7 +1037,7 @@ void DerivationGoal::buildDone() BuildResult::Status st = BuildResult::MiscFailure; -#ifndef _WIN32 +#ifndef _WIN32 // TODO abstract over proc exit status if (hook && WIFEXITED(status) && WEXITSTATUS(status) == 101) st = BuildResult::TimedOut; diff --git a/tests/unit/libstore/worker-protocol.cc b/tests/unit/libstore/worker-protocol.cc index 5907ea5a4..70e03a8ab 100644 --- a/tests/unit/libstore/worker-protocol.cc +++ b/tests/unit/libstore/worker-protocol.cc @@ -1,4 +1,5 @@ #include +#include #include #include