aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/boost/context/src/posix/stack_traits.cpp
blob: 4dd1829f7037151f906be00fa7ad5d1b7cb71db5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//          Copyright Oliver Kowalke 2014.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#include "boost/context/stack_traits.hpp"

extern "C" {
#include <signal.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>
}

//#if _POSIX_C_SOURCE >= 200112L

#include <algorithm>
#include <cmath>

#include <boost/assert.hpp>
#include <boost/config.hpp>

#if !defined (SIGSTKSZ)
# define SIGSTKSZ (32768) // 32kb minimum allowable stack
# define UDEF_SIGSTKSZ
#endif

#if !defined (MINSIGSTKSZ)
# define MINSIGSTKSZ (131072) // 128kb recommended stack size
# define UDEF_MINSIGSTKSZ
#endif

#ifdef BOOST_HAS_ABI_HEADERS
#  include BOOST_ABI_PREFIX
#endif

namespace {

std::size_t pagesize() BOOST_NOEXCEPT_OR_NOTHROW {
    // conform to POSIX.1-2001
    return ::sysconf( _SC_PAGESIZE);
}

rlim_t stacksize_limit_() BOOST_NOEXCEPT_OR_NOTHROW {
    rlimit limit;
    // conforming to POSIX.1-2001
    ::getrlimit( RLIMIT_STACK, & limit);
    return limit.rlim_max;
}

rlim_t stacksize_limit() BOOST_NOEXCEPT_OR_NOTHROW {
    static rlim_t limit = stacksize_limit_();
    return limit;
}

}

namespace boost {
namespace context {

bool
stack_traits::is_unbounded() BOOST_NOEXCEPT_OR_NOTHROW {
    return RLIM_INFINITY == stacksize_limit();
}

std::size_t
stack_traits::page_size() BOOST_NOEXCEPT_OR_NOTHROW {
    static std::size_t size = pagesize();
    return size;
}

std::size_t
stack_traits::default_size() BOOST_NOEXCEPT_OR_NOTHROW {
    return 128 * 1024;
}

std::size_t
stack_traits::minimum_size() BOOST_NOEXCEPT_OR_NOTHROW {
    return MINSIGSTKSZ;
}

std::size_t
stack_traits::maximum_size() BOOST_NOEXCEPT_OR_NOTHROW {
    BOOST_ASSERT( ! is_unbounded() );
    return static_cast< std::size_t >( stacksize_limit() );
}

}}

#ifdef BOOST_HAS_ABI_HEADERS
#  include BOOST_ABI_SUFFIX
#endif

#ifdef UDEF_SIGSTKSZ
# undef SIGSTKSZ
#endif

#ifdef UDEF_MINSIGSTKSZ
# undef MINSIGSTKSZ
#endif