Skip to content

Commit

Permalink
Merge pull request #250 from cjeker/fix_test_fcontext_for_map_stack
Browse files Browse the repository at this point in the history
Add the BOOST_CONTEXT_USE_MAP_STACK logic to test_fcontext.cpp
  • Loading branch information
olk authored Mar 10, 2024
2 parents d811245 + 22be4b1 commit f5d062c
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 f5d062c

Please sign in to comment.