Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / context / fixedsize_stack.hpp
index 756b260..c309347 100644 (file)
 #include <boost/context/stack_context.hpp>
 #include <boost/context/stack_traits.hpp>
 
+#if defined(BOOST_CONTEXT_USE_MAP_STACK)
+extern "C" {
+#include <sys/mman.h>
+}
+#endif
+
 #if defined(BOOST_USE_VALGRIND)
 #include <valgrind/valgrind.h>
 #endif
@@ -42,10 +48,17 @@ public:
     }
 
     stack_context allocate() {
+#if defined(BOOST_CONTEXT_USE_MAP_STACK)
+        void * vp = ::mmap( 0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_STACK, -1, 0);
+        if ( vp == MAP_FAILED) {
+            throw std::bad_alloc();
+        }
+#else
         void * vp = std::malloc( size_);
         if ( ! vp) {
             throw std::bad_alloc();
         }
+#endif
         stack_context sctx;
         sctx.size = size_;
         sctx.sp = static_cast< char * >( vp) + sctx.size;
@@ -62,7 +75,11 @@ public:
         VALGRIND_STACK_DEREGISTER( sctx.valgrind_stack_id);
 #endif
         void * vp = static_cast< char * >( sctx.sp) - sctx.size;
+#if defined(BOOST_CONTEXT_USE_MAP_STACK)
+        ::munmap( vp, sctx.size);
+#else
         std::free( vp);
+#endif
     }
 };