1 2 // Copyright Oliver Kowalke 2014. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 7 #include "boost/context/stack_traits.hpp" 8 9 extern "C" { 10 #include <windows.h> 11 } 12 13 //#if defined (BOOST_WINDOWS) || _POSIX_C_SOURCE >= 200112L 14 15 #include <algorithm> 16 #include <cmath> 17 #include <cstddef> 18 #include <cstring> 19 #include <stdexcept> 20 21 #include <boost/assert.hpp> 22 #include <boost/context/detail/config.hpp> 23 #if defined(BOOST_NO_CXX11_HDR_MUTEX) 24 # include <boost/thread.hpp> 25 #else 26 # include <mutex> 27 #endif 28 29 #include <boost/context/stack_context.hpp> 30 31 // x86_64 32 // test x86_64 before i386 because icc might 33 // define __i686__ for x86_64 too 34 #if defined(__x86_64__) || defined(__x86_64) \ 35 || defined(__amd64__) || defined(__amd64) \ 36 || defined(_M_X64) || defined(_M_AMD64) 37 38 // Windows seams not to provide a constant or function 39 // telling the minimal stacksize 40 # define MIN_STACKSIZE 8 * 1024 41 #else 42 # define MIN_STACKSIZE 4 * 1024 43 #endif 44 45 #ifdef BOOST_HAS_ABI_HEADERS 46 # include BOOST_ABI_PREFIX 47 #endif 48 49 namespace { 50 system_info_(SYSTEM_INFO * si)51void system_info_( SYSTEM_INFO * si) BOOST_NOEXCEPT_OR_NOTHROW { 52 ::GetSystemInfo( si); 53 } 54 system_info()55SYSTEM_INFO system_info() BOOST_NOEXCEPT_OR_NOTHROW { 56 static SYSTEM_INFO si; 57 #if defined(BOOST_NO_CXX11_HDR_MUTEX) 58 static boost::once_flag flag = BOOST_ONCE_INIT; 59 boost::call_once( flag, static_cast< void(*)( SYSTEM_INFO *) >( system_info_), & si); 60 #else 61 static std::once_flag flag; 62 std::call_once( flag, static_cast< void(*)( SYSTEM_INFO *) >( system_info_), & si); 63 #endif 64 return si; 65 } 66 pagesize()67std::size_t pagesize() BOOST_NOEXCEPT_OR_NOTHROW { 68 return static_cast< std::size_t >( system_info().dwPageSize); 69 } 70 71 } 72 73 namespace boost { 74 namespace context { 75 76 // Windows seams not to provide a limit for the stacksize 77 // libcoco uses 32k+4k bytes as minimum 78 BOOST_CONTEXT_DECL 79 bool is_unbounded()80stack_traits::is_unbounded() BOOST_NOEXCEPT_OR_NOTHROW { 81 return true; 82 } 83 84 BOOST_CONTEXT_DECL 85 std::size_t page_size()86stack_traits::page_size() BOOST_NOEXCEPT_OR_NOTHROW { 87 return pagesize(); 88 } 89 90 BOOST_CONTEXT_DECL 91 std::size_t default_size()92stack_traits::default_size() BOOST_NOEXCEPT_OR_NOTHROW { 93 return 128 * 1024; 94 } 95 96 // because Windows seams not to provide a limit for minimum stacksize 97 BOOST_CONTEXT_DECL 98 std::size_t minimum_size()99stack_traits::minimum_size() BOOST_NOEXCEPT_OR_NOTHROW { 100 return MIN_STACKSIZE; 101 } 102 103 // because Windows seams not to provide a limit for maximum stacksize 104 // maximum_size() can never be called (pre-condition ! is_unbounded() ) 105 BOOST_CONTEXT_DECL 106 std::size_t maximum_size()107stack_traits::maximum_size() BOOST_NOEXCEPT_OR_NOTHROW { 108 BOOST_ASSERT( ! is_unbounded() ); 109 return 1 * 1024 * 1024 * 1024; // 1GB 110 } 111 112 }} 113 114 #ifdef BOOST_HAS_ABI_HEADERS 115 # include BOOST_ABI_SUFFIX 116 #endif 117