From 22be4b157046b78e6bb9648c47b724f96ba9ab48 Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Tue, 13 Feb 2024 10:57:26 +0100 Subject: [PATCH] Add the BOOST_CONTEXT_USE_MAP_STACK logic to test_fcontext.cpp Without this test_fcontext.cpp fails on OpenBSD with a not-on-stack OS error. --- test/test_fcontext.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/test/test_fcontext.cpp b/test/test_fcontext.cpp index 51732426..6bbd9ed6 100644 --- a/test/test_fcontext.cpp +++ b/test/test_fcontext.cpp @@ -23,6 +23,12 @@ #include #include +#if defined(BOOST_CONTEXT_USE_MAP_STACK) +extern "C" { +#include +} +#endif + #define BOOST_CHECK(x) BOOST_TEST(x) #define BOOST_CHECK_EQUAL(a, b) BOOST_TEST_EQ(a, b) @@ -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; } @@ -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 } };