32 #include <glog/logging.h> 66 PROT_READ | PROT_WRITE,
67 MAP_PRIVATE | MAP_ANONYMOUS,
70 PCHECK(p != (
void*)(-1));
71 storage_ =
reinterpret_cast<unsigned char*
>(p);
76 freeList_.emplace_back(allocBegin,
false);
81 std::lock_guard<folly::SpinLock> lg(
lock_);
92 PCHECK(0 == ::mprotect(p,
pagesize(), PROT_NONE));
114 std::lock_guard<folly::SpinLock> lg(
lock_);
119 if (std::less_equal<void*>{}(limit,
storage_) ||
125 auto p = limit + size -
as;
136 pages.erase(reinterpret_cast<intptr_t>(item.first));
145 for (
const auto& page : pages) {
146 intptr_t pageEnd = intptr_t(page +
pagesize());
147 if (page <= addr && addr < pageEnd) {
166 static const size_t pagesize = size_t(sysconf(_SC_PAGESIZE));
176 static auto instance =
186 struct sigaction oldSigsegvAction;
188 void sigsegvSignalHandler(
int signum, siginfo_t*
info,
void*) {
189 if (signum != SIGSEGV) {
190 std::cerr <<
"GuardPageAllocator signal handler called for signal: " 197 std::cerr <<
"folly::fibers Fiber stack overflow detected." << std::endl;
201 sigaction(signum, &oldSigsegvAction,
nullptr);
206 auto getCreated = dlsym(RTLD_DEFAULT,
"JNI_GetCreatedJavaVMs");
210 void installSignalHandler() {
220 memset(&sa, 0,
sizeof(sa));
221 sigemptyset(&sa.sa_mask);
227 sa.sa_flags |= SA_SIGINFO | SA_ONSTACK;
228 sa.sa_sigaction = &sigsegvSignalHandler;
229 sigaction(SIGSEGV, &sa, &oldSigsegvAction);
244 std::lock_guard<folly::SpinLock> lg(
lock_);
245 if (inUse_ < kMaxInUse) {
247 return std::make_unique<StackCacheEntry>(stackSize);
294 : useGuardPages_(useGuardPages) {
296 installSignalHandler();
std::vector< std::pair< unsigned char *, bool > > freeList_
std::unique_ptr< StackCache > stackCache_
std::unique_ptr< StackCacheEntry > stackCache_
StackCache(size_t stackSize)
void deallocate(unsigned char *limit, size_t size)
constexpr size_t kNumGuarded
constexpr detail::Map< Move > move
unsigned char * borrow(size_t size)
static folly::Synchronized< std::unordered_set< intptr_t > > & protectedPages()
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
std::unique_ptr< StackCacheEntry > getStackCache(size_t stackSize)
FOLLY_ALWAYS_INLINE void call_once(basic_once_flag< Mutex, Atom > &flag, F &&f, Args &&...args)
static size_t allocSize(size_t size)
constexpr auto size(C const &c) -> decltype(c.size())
static bool isProtected(intptr_t addr)
bool giveBack(unsigned char *limit, size_t size)
void giveBack(std::unique_ptr< StackCache >)
basic_once_flag< TimedMutex > once_flag
std::allocator< unsigned char > fallbackAllocator_
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
GuardPageAllocator(bool useGuardPages)
unsigned char * allocate(size_t size)
constexpr size_t kMaxInUse
StackCache & cache() const noexcept
ThreadPoolListHook * addr
static CacheManager & instance()
StackCacheEntry(size_t stackSize)