/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include "GuardPageAllocator.h"
+#ifndef _WIN32
+#include <dlfcn.h>
+#endif
#include <signal.h>
+#include <iostream>
#include <mutex>
#include <folly/Singleton.h>
// Use a read lock for reading.
SYNCHRONIZED_CONST(pages, protectedPages()) {
for (const auto& page : pages) {
- intptr_t pageEnd = page + pagesize();
+ intptr_t pageEnd = intptr_t(page + pagesize());
if (page <= addr && addr < pageEnd) {
return true;
}
std::vector<std::pair<unsigned char*, bool>> freeList_;
static size_t pagesize() {
- static const size_t pagesize = sysconf(_SC_PAGESIZE);
+ static const size_t pagesize = size_t(sysconf(_SC_PAGESIZE));
return pagesize;
}
raise(signum);
}
+bool isInJVM() {
+ auto getCreated = dlsym(RTLD_DEFAULT, "JNI_GetCreatedJavaVMs");
+ return getCreated;
+}
+
void installSignalHandler() {
static std::once_flag onceFlag;
std::call_once(onceFlag, []() {
+ if (isInJVM()) {
+ // Don't install signal handler, since JVM internal signal handler doesn't
+ // work with SA_ONSTACK
+ return;
+ }
+
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sigaction(SIGSEGV, &sa, &oldSigsegvAction);
});
}
-}
+} // namespace
#endif
std::lock_guard<folly::SpinLock> lg(lock_);
if (inUse_ < kMaxInUse) {
++inUse_;
- return folly::make_unique<StackCacheEntry>(stackSize);
+ return std::make_unique<StackCacheEntry>(stackSize);
}
return nullptr;
class StackCacheEntry {
public:
explicit StackCacheEntry(size_t stackSize)
- : stackCache_(folly::make_unique<StackCache>(stackSize)) {}
+ : stackCache_(std::make_unique<StackCache>(stackSize)) {}
StackCache& cache() const noexcept {
return *stackCache_;
fallbackAllocator_.deallocate(limit, size);
}
}
-}
-} // folly::fibers
+} // namespace fibers
+} // namespace folly