Skip to content

Commit

Permalink
Fix FreeBSD build
Browse files Browse the repository at this point in the history
This restores some CPP'd code that was added in
c189116 and accidentally lost in
2477e4e.

Co-authored-by: Eelco Dolstra <[email protected]>
  • Loading branch information
Ericson2314 and edolstra committed Jun 12, 2024
1 parent e74ce01 commit 7c2981f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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"],[
Expand Down
29 changes: 22 additions & 7 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
#define GC_INCLUDE_NEW

#include <pthread.h>
#if __FreeBSD__
# include <pthread_np.h>
#endif

#include <gc/gc.h>
#include <gc/gc_cpp.h>
Expand Down Expand Up @@ -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_t>(_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.
Expand Down
6 changes: 5 additions & 1 deletion src/libstore/build/derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <fcntl.h>
#include <unistd.h>

#ifndef _WIN32 // TODO abstract over proc exit status
# include <sys/wait.h>
#endif

#include <nlohmann/json.hpp>

namespace nix {
Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions tests/unit/libstore/worker-protocol.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <regex>
#include <thread>

#include <nlohmann/json.hpp>
#include <gtest/gtest.h>
Expand Down

0 comments on commit 7c2981f

Please sign in to comment.