]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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> | |
7c673cae FG |
23 | |
24 | #include <boost/context/stack_context.hpp> | |
25 | ||
26 | // x86_64 | |
27 | // test x86_64 before i386 because icc might | |
28 | // define __i686__ for x86_64 too | |
29 | #if defined(__x86_64__) || defined(__x86_64) \ | |
30 | || defined(__amd64__) || defined(__amd64) \ | |
31 | || defined(_M_X64) || defined(_M_AMD64) | |
32 | ||
33 | // Windows seams not to provide a constant or function | |
34 | // telling the minimal stacksize | |
35 | # define MIN_STACKSIZE 8 * 1024 | |
36 | #else | |
37 | # define MIN_STACKSIZE 4 * 1024 | |
38 | #endif | |
39 | ||
40 | #ifdef BOOST_HAS_ABI_HEADERS | |
41 | # include BOOST_ABI_PREFIX | |
42 | #endif | |
43 | ||
44 | namespace { | |
45 | ||
7c673cae | 46 | std::size_t pagesize() BOOST_NOEXCEPT_OR_NOTHROW { |
1e59de90 TL |
47 | SYSTEM_INFO si; |
48 | ::GetSystemInfo(&si); | |
49 | return static_cast< std::size_t >( si.dwPageSize ); | |
7c673cae FG |
50 | } |
51 | ||
7c673cae FG |
52 | } |
53 | ||
54 | namespace boost { | |
55 | namespace context { | |
56 | ||
57 | // Windows seams not to provide a limit for the stacksize | |
58 | // libcoco uses 32k+4k bytes as minimum | |
59 | BOOST_CONTEXT_DECL | |
60 | bool | |
61 | stack_traits::is_unbounded() BOOST_NOEXCEPT_OR_NOTHROW { | |
62 | return true; | |
63 | } | |
64 | ||
65 | BOOST_CONTEXT_DECL | |
66 | std::size_t | |
67 | stack_traits::page_size() BOOST_NOEXCEPT_OR_NOTHROW { | |
1e59de90 TL |
68 | static std::size_t size = pagesize(); |
69 | return size; | |
7c673cae FG |
70 | } |
71 | ||
72 | BOOST_CONTEXT_DECL | |
73 | std::size_t | |
74 | stack_traits::default_size() BOOST_NOEXCEPT_OR_NOTHROW { | |
b32b8144 | 75 | return 128 * 1024; |
7c673cae FG |
76 | } |
77 | ||
78 | // because Windows seams not to provide a limit for minimum stacksize | |
79 | BOOST_CONTEXT_DECL | |
80 | std::size_t | |
81 | stack_traits::minimum_size() BOOST_NOEXCEPT_OR_NOTHROW { | |
82 | return MIN_STACKSIZE; | |
83 | } | |
84 | ||
85 | // because Windows seams not to provide a limit for maximum stacksize | |
86 | // maximum_size() can never be called (pre-condition ! is_unbounded() ) | |
87 | BOOST_CONTEXT_DECL | |
88 | std::size_t | |
89 | stack_traits::maximum_size() BOOST_NOEXCEPT_OR_NOTHROW { | |
90 | BOOST_ASSERT( ! is_unbounded() ); | |
91 | return 1 * 1024 * 1024 * 1024; // 1GB | |
92 | } | |
93 | ||
94 | }} | |
95 | ||
96 | #ifdef BOOST_HAS_ABI_HEADERS | |
97 | # include BOOST_ABI_SUFFIX | |
98 | #endif |