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
9extern "C" {
10#include <signal.h>
11#include <sys/resource.h>
12#include <sys/time.h>
13#include <unistd.h>
14}
15
16//#if _POSIX_C_SOURCE >= 200112L
17
18#include <algorithm>
19#include <cmath>
20
21#include <boost/assert.hpp>
22#include <boost/config.hpp>
23
24#if !defined (SIGSTKSZ)
25# define SIGSTKSZ (32768) // 32kb minimum allowable stack
26# define UDEF_SIGSTKSZ
27#endif
28
29#if !defined (MINSIGSTKSZ)
30# define MINSIGSTKSZ (131072) // 128kb recommended stack size
31# define UDEF_MINSIGSTKSZ
32#endif
33
34#ifdef BOOST_HAS_ABI_HEADERS
35# include BOOST_ABI_PREFIX
36#endif
37
38namespace {
39
40std::size_t pagesize() BOOST_NOEXCEPT_OR_NOTHROW {
41 // conform to POSIX.1-2001
42 return static_cast<std::size_t>(::sysconf( _SC_PAGESIZE));
43}
44
45rlim_t stacksize_limit_() BOOST_NOEXCEPT_OR_NOTHROW {
46 rlimit limit;
47 // conforming to POSIX.1-2001
48 ::getrlimit( RLIMIT_STACK, rlimits: & limit);
49 return limit.rlim_max;
50}
51
52rlim_t stacksize_limit() BOOST_NOEXCEPT_OR_NOTHROW {
53 static rlim_t limit = stacksize_limit_();
54 return limit;
55}
56
57}
58
59namespace boost {
60namespace context {
61
62bool
63stack_traits::is_unbounded() BOOST_NOEXCEPT_OR_NOTHROW {
64 return RLIM_INFINITY == stacksize_limit();
65}
66
67std::size_t
68stack_traits::page_size() BOOST_NOEXCEPT_OR_NOTHROW {
69 static std::size_t size = pagesize();
70 return size;
71}
72
73std::size_t
74stack_traits::default_size() BOOST_NOEXCEPT_OR_NOTHROW {
75 return 128 * 1024;
76}
77
78std::size_t
79stack_traits::minimum_size() BOOST_NOEXCEPT_OR_NOTHROW {
80 return static_cast<std::size_t>(MINSIGSTKSZ);
81}
82
83std::size_t
84stack_traits::maximum_size() BOOST_NOEXCEPT_OR_NOTHROW {
85 BOOST_ASSERT( ! is_unbounded() );
86 return static_cast< std::size_t >( stacksize_limit() );
87}
88
89}}
90
91#ifdef BOOST_HAS_ABI_HEADERS
92# include BOOST_ABI_SUFFIX
93#endif
94
95#ifdef UDEF_SIGSTKSZ
96# undef SIGSTKSZ
97#endif
98
99#ifdef UDEF_MINSIGSTKSZ
100# undef MINSIGSTKSZ
101#endif
102

source code of boost/libs/context/src/posix/stack_traits.cpp