diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2018-12-13 11:44:21 -0500 |
---|---|---|
committer | Henrik Edin <henrik.edin@mongodb.com> | 2018-12-18 09:12:51 -0500 |
commit | c28cb6852fca219d6f0262000c378e982b7ca9ff (patch) | |
tree | e06e74d1729e644db7c4dc2e5ecd529145b2f34c /src/third_party/boost-1.69.0/boost/coroutine/posix/protected_stack_allocator.hpp | |
parent | 05ebfef11161b96ba0e8374f34c359a403097f60 (diff) | |
download | mongo-c28cb6852fca219d6f0262000c378e982b7ca9ff.tar.gz |
SERVER-38458 Upgrade boost to version 1.69
Diffstat (limited to 'src/third_party/boost-1.69.0/boost/coroutine/posix/protected_stack_allocator.hpp')
-rw-r--r-- | src/third_party/boost-1.69.0/boost/coroutine/posix/protected_stack_allocator.hpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/third_party/boost-1.69.0/boost/coroutine/posix/protected_stack_allocator.hpp b/src/third_party/boost-1.69.0/boost/coroutine/posix/protected_stack_allocator.hpp new file mode 100644 index 00000000000..649248b57da --- /dev/null +++ b/src/third_party/boost-1.69.0/boost/coroutine/posix/protected_stack_allocator.hpp @@ -0,0 +1,105 @@ + +// Copyright Oliver Kowalke 2009. +// 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) + +#ifndef BOOST_COROUTINES_PROTECTED_STACK_ALLOCATOR_H +#define BOOST_COROUTINES_PROTECTED_STACK_ALLOCATOR_H + +extern "C" { +#include <fcntl.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <unistd.h> +} + +#if defined(BOOST_USE_VALGRIND) +#include <valgrind/valgrind.h> +#endif + +#include <cmath> +#include <cstddef> +#include <new> + +#include <boost/assert.hpp> +#include <boost/config.hpp> + +#include <boost/coroutine/detail/config.hpp> +#include <boost/coroutine/stack_context.hpp> +#include <boost/coroutine/stack_traits.hpp> + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_PREFIX +#endif + +namespace boost { +namespace coroutines { + +template< typename traitsT > +struct basic_protected_stack_allocator +{ + typedef traitsT traits_type; + + void allocate( stack_context & ctx, std::size_t size = traits_type::minimum_size() ) + { + BOOST_ASSERT( traits_type::minimum_size() <= size); + BOOST_ASSERT( traits_type::is_unbounded() || ( traits_type::maximum_size() >= size) ); + + // page at bottom will be used as guard-page + const std::size_t pages( + static_cast< std::size_t >( + std::floor( + static_cast< float >( size) / traits_type::page_size() ) ) ); + BOOST_ASSERT_MSG( 2 <= pages, "at least two pages must fit into stack (one page is guard-page)"); + const std::size_t size_( pages * traits_type::page_size() ); + BOOST_ASSERT( 0 != size && 0 != size_); + BOOST_ASSERT( size_ <= size); + + // conform to POSIX.4 (POSIX.1b-1993, _POSIX_C_SOURCE=199309L) +#if defined(MAP_ANON) + void * limit = ::mmap( 0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); +#else + void * limit = ::mmap( 0, size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +#endif + if ( MAP_FAILED == limit) throw std::bad_alloc(); + + // conforming to POSIX.1-2001 +#if defined(BOOST_DISABLE_ASSERTS) + ::mprotect( limit, traits_type::page_size(), PROT_NONE); +#else + const int result( ::mprotect( limit, traits_type::page_size(), PROT_NONE) ); + BOOST_ASSERT( 0 == result); +#endif + + ctx.size = size_; + ctx.sp = static_cast< char * >( limit) + ctx.size; +#if defined(BOOST_USE_VALGRIND) + ctx.valgrind_stack_id = VALGRIND_STACK_REGISTER( ctx.sp, limit); +#endif + } + + void deallocate( stack_context & ctx) + { + BOOST_ASSERT( ctx.sp); + BOOST_ASSERT( traits_type::minimum_size() <= ctx.size); + BOOST_ASSERT( traits_type::is_unbounded() || ( traits_type::maximum_size() >= ctx.size) ); + +#if defined(BOOST_USE_VALGRIND) + VALGRIND_STACK_DEREGISTER( ctx.valgrind_stack_id); +#endif + void * limit = static_cast< char * >( ctx.sp) - ctx.size; + // conform to POSIX.4 (POSIX.1b-1993, _POSIX_C_SOURCE=199309L) + ::munmap( limit, ctx.size); + } +}; + +typedef basic_protected_stack_allocator< stack_traits > protected_stack_allocator; + +}} + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_SUFFIX +#endif + +#endif // BOOST_COROUTINES_PROTECTED_STACK_ALLOCATOR_H |