Skip to content

Commit

Permalink
Add the BOOST_CONTEXT_USE_MAP_STACK logic to test_fcontext.cpp
Browse files Browse the repository at this point in the history
Without this test_fcontext.cpp fails on OpenBSD with a not-on-stack OS error.
  • Loading branch information
cjeker committed Feb 13, 2024
1 parent 77de3d5 commit 22be4b1
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/test_fcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
#include <boost/context/detail/config.hpp>
#include <boost/context/detail/fcontext.hpp>

#if defined(BOOST_CONTEXT_USE_MAP_STACK)
extern "C" {
#include <sys/mman.h>
}
#endif

#define BOOST_CHECK(x) BOOST_TEST(x)
#define BOOST_CHECK_EQUAL(a, b) BOOST_TEST_EQ(a, b)

Expand All @@ -44,8 +50,17 @@ class simple_stack_allocator
BOOST_ASSERT( minimum_stacksize() <= size);
BOOST_ASSERT( maximum_stacksize() >= size);

void * limit = malloc( size);
if ( ! limit) throw std::bad_alloc();
#if defined(BOOST_CONTEXT_USE_MAP_STACK)
void * limit = ::mmap( 0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_STACK, -1, 0);
if ( limit == MAP_FAILED) {
throw std::bad_alloc();
}
#else
void * limit = std::malloc( size);
if ( ! limit) {
throw std::bad_alloc();
}
#endif

return static_cast< char * >( limit) + size;
}
Expand All @@ -57,7 +72,11 @@ class simple_stack_allocator
BOOST_ASSERT( maximum_stacksize() >= size);

void * limit = static_cast< char * >( vp) - size;
#if defined(BOOST_CONTEXT_USE_MAP_STACK)
::munmap( vp, size);
#else
free( limit);
#endif
}
};

Expand Down

0 comments on commit 22be4b1

Please sign in to comment.