File indexing completed on 2025-01-18 09:30:24
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_CONTEXT_PROTECTED_FIXEDSIZE_H
0008 #define BOOST_CONTEXT_PROTECTED_FIXEDSIZE_H
0009
0010 extern "C" {
0011 #include <windows.h>
0012 }
0013
0014 #include <cmath>
0015 #include <cstddef>
0016 #include <new>
0017
0018 #include <boost/assert.hpp>
0019 #include <boost/config.hpp>
0020 #include <boost/core/ignore_unused.hpp>
0021
0022 #include <boost/context/detail/config.hpp>
0023 #include <boost/context/stack_context.hpp>
0024 #include <boost/context/stack_traits.hpp>
0025
0026 #ifdef BOOST_HAS_ABI_HEADERS
0027 # include BOOST_ABI_PREFIX
0028 #endif
0029
0030 namespace boost {
0031 namespace context {
0032
0033 template< typename traitsT >
0034 class basic_protected_fixedsize_stack {
0035 private:
0036 std::size_t size_;
0037
0038 public:
0039 typedef traitsT traits_type;
0040
0041 basic_protected_fixedsize_stack( std::size_t size = traits_type::default_size() ) BOOST_NOEXCEPT_OR_NOTHROW :
0042 size_( size) {
0043 }
0044
0045 stack_context allocate() {
0046
0047 const std::size_t pages = (size_ + traits_type::page_size() - 1) / traits_type::page_size();
0048
0049 const std::size_t size__ = ( pages + 1) * traits_type::page_size();
0050
0051 void * vp = ::VirtualAlloc( 0, size__, MEM_COMMIT, PAGE_READWRITE);
0052 if ( ! vp) throw std::bad_alloc();
0053
0054 DWORD old_options;
0055 const BOOL result = ::VirtualProtect(
0056 vp, traits_type::page_size(), PAGE_READWRITE | PAGE_GUARD , & old_options);
0057 boost::ignore_unused(result);
0058 BOOST_ASSERT( FALSE != result);
0059
0060 stack_context sctx;
0061 sctx.size = size__;
0062 sctx.sp = static_cast< char * >( vp) + sctx.size;
0063 return sctx;
0064 }
0065
0066 void deallocate( stack_context & sctx) BOOST_NOEXCEPT_OR_NOTHROW {
0067 BOOST_ASSERT( sctx.sp);
0068
0069 void * vp = static_cast< char * >( sctx.sp) - sctx.size;
0070 ::VirtualFree( vp, 0, MEM_RELEASE);
0071 }
0072 };
0073
0074 typedef basic_protected_fixedsize_stack< stack_traits > protected_fixedsize_stack;
0075
0076 }}
0077
0078 #ifdef BOOST_HAS_ABI_HEADERS
0079 # include BOOST_ABI_SUFFIX
0080 #endif
0081
0082 #endif