summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/ExecutionEngine/JITLink/JITLink.cpp4
-rw-r--r--llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp10
-rw-r--r--llvm/lib/ExecutionEngine/SectionMemoryManager.cpp4
-rw-r--r--llvm/lib/Support/MemoryBuffer.cpp2
-rw-r--r--llvm/lib/Support/Unix/Memory.inc4
-rw-r--r--llvm/lib/Support/Unix/Path.inc2
-rw-r--r--llvm/lib/Support/Unix/Process.inc5
-rw-r--r--llvm/lib/Support/Windows/Process.inc2
8 files changed, 18 insertions, 15 deletions
diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
index 3169011f082..1cea043f761 100644
--- a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
@@ -194,12 +194,12 @@ InProcessMemoryManager::allocate(const SegmentsRequestMap &Request) {
for (auto &KV : Request) {
auto &Seg = KV.second;
- if (Seg.getContentAlignment() > sys::Process::getPageSize())
+ if (Seg.getContentAlignment() > sys::Process::getPageSizeEstimate())
return make_error<StringError>("Cannot request higher than page "
"alignment",
inconvertibleErrorCode());
- if (sys::Process::getPageSize() % Seg.getContentAlignment() != 0)
+ if (sys::Process::getPageSizeEstimate() % Seg.getContentAlignment() != 0)
return make_error<StringError>("Page size is not a multiple of "
"alignment",
inconvertibleErrorCode());
diff --git a/llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp b/llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp
index 4bf52864107..8ed23de419d 100644
--- a/llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/OrcABISupport.cpp
@@ -147,7 +147,7 @@ Error OrcAArch64::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
const unsigned StubSize = IndirectStubsInfo::StubSize;
// Emit at least MinStubs, rounded up to fill the pages allocated.
- unsigned PageSize = sys::Process::getPageSize();
+ static const unsigned PageSize = sys::Process::getPageSizeEstimate();
unsigned NumPages = ((MinStubs * StubSize) + (PageSize - 1)) / PageSize;
unsigned NumStubs = (NumPages * PageSize) / StubSize;
@@ -229,7 +229,7 @@ Error OrcX86_64_Base::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
const unsigned StubSize = IndirectStubsInfo::StubSize;
// Emit at least MinStubs, rounded up to fill the pages allocated.
- unsigned PageSize = sys::Process::getPageSize();
+ static const unsigned PageSize = sys::Process::getPageSizeEstimate();
unsigned NumPages = ((MinStubs * StubSize) + (PageSize - 1)) / PageSize;
unsigned NumStubs = (NumPages * PageSize) / StubSize;
@@ -497,7 +497,7 @@ Error OrcI386::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
const unsigned StubSize = IndirectStubsInfo::StubSize;
// Emit at least MinStubs, rounded up to fill the pages allocated.
- unsigned PageSize = sys::Process::getPageSize();
+ static const unsigned PageSize = sys::Process::getPageSizeEstimate();
unsigned NumPages = ((MinStubs * StubSize) + (PageSize - 1)) / PageSize;
unsigned NumStubs = (NumPages * PageSize) / StubSize;
@@ -683,7 +683,7 @@ Error OrcMips32_Base::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
const unsigned StubSize = IndirectStubsInfo::StubSize;
// Emit at least MinStubs, rounded up to fill the pages allocated.
- unsigned PageSize = sys::Process::getPageSize();
+ static const unsigned PageSize = sys::Process::getPageSizeEstimate();
unsigned NumPages = ((MinStubs * StubSize) + (PageSize - 1)) / PageSize;
unsigned NumStubs = (NumPages * PageSize) / StubSize;
@@ -929,7 +929,7 @@ Error OrcMips64::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
const unsigned StubSize = IndirectStubsInfo::StubSize;
// Emit at least MinStubs, rounded up to fill the pages allocated.
- unsigned PageSize = sys::Process::getPageSize();
+ static const unsigned PageSize = sys::Process::getPageSizeEstimate();
unsigned NumPages = ((MinStubs * StubSize) + (PageSize - 1)) / PageSize;
unsigned NumStubs = (NumPages * PageSize) / StubSize;
diff --git a/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp b/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
index ba277796dd5..2c0cfeb8a9a 100644
--- a/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
+++ b/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
@@ -172,7 +172,7 @@ bool SectionMemoryManager::finalizeMemory(std::string *ErrMsg) {
}
static sys::MemoryBlock trimBlockToPageSize(sys::MemoryBlock M) {
- static const size_t PageSize = sys::Process::getPageSize();
+ static const size_t PageSize = sys::Process::getPageSizeEstimate();
size_t StartOverlap =
(PageSize - ((uintptr_t)M.base() % PageSize)) % PageSize;
@@ -244,7 +244,7 @@ public:
unsigned Flags, std::error_code &EC) override {
// allocateMappedMemory calls mmap(2). We round up a request size
// to page size to get extra space for free.
- static const size_t PageSize = sys::Process::getPageSize();
+ static const size_t PageSize = sys::Process::getPageSizeEstimate();
size_t ReqBytes = (NumBytes + PageSize - 1) & ~(PageSize - 1);
return sys::Memory::allocateMappedMemory(ReqBytes, NearBlock, Flags, EC);
}
diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp
index 3f13d4d3552..92e39e118b9 100644
--- a/llvm/lib/Support/MemoryBuffer.cpp
+++ b/llvm/lib/Support/MemoryBuffer.cpp
@@ -417,7 +417,7 @@ static ErrorOr<std::unique_ptr<MB>>
getOpenFileImpl(int FD, const Twine &Filename, uint64_t FileSize,
uint64_t MapSize, int64_t Offset, bool RequiresNullTerminator,
bool IsVolatile) {
- static int PageSize = sys::Process::getPageSize();
+ static int PageSize = sys::Process::getPageSizeEstimate();
// Default is to map the full file.
if (MapSize == uint64_t(-1)) {
diff --git a/llvm/lib/Support/Unix/Memory.inc b/llvm/lib/Support/Unix/Memory.inc
index b8f5df5f72e..affdb7e70d9 100644
--- a/llvm/lib/Support/Unix/Memory.inc
+++ b/llvm/lib/Support/Unix/Memory.inc
@@ -103,7 +103,7 @@ Memory::allocateMappedMemory(size_t NumBytes,
// Use any near hint and the page size to set a page-aligned starting address
uintptr_t Start = NearBlock ? reinterpret_cast<uintptr_t>(NearBlock->base()) +
NearBlock->size() : 0;
- static const size_t PageSize = Process::getPageSize();
+ static const size_t PageSize = Process::getPageSizeEstimate();
if (Start && Start % PageSize)
Start += PageSize - Start % PageSize;
@@ -149,7 +149,7 @@ Memory::releaseMappedMemory(MemoryBlock &M) {
std::error_code
Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) {
- static const size_t PageSize = Process::getPageSize();
+ static const size_t PageSize = Process::getPageSizeEstimate();
if (M.Address == nullptr || M.Size == 0)
return std::error_code();
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index fb14422ba33..c2f78e79b87 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -786,7 +786,7 @@ const char *mapped_file_region::const_data() const {
}
int mapped_file_region::alignment() {
- return Process::getPageSize();
+ return Process::getPageSizeEstimate();
}
std::error_code detail::directory_iterator_construct(detail::DirIterState &it,
diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 7c834f97114..78c123493e1 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -69,7 +69,7 @@ static std::pair<std::chrono::microseconds, std::chrono::microseconds> getRUsage
// On Cygwin, getpagesize() returns 64k(AllocationGranularity) and
// offset in mmap(3) should be aligned to the AllocationGranularity.
-unsigned Process::getPageSize() {
+Expected<unsigned> Process::getPageSize() {
#if defined(HAVE_GETPAGESIZE)
static const int page_size = ::getpagesize();
#elif defined(HAVE_SYSCONF)
@@ -77,6 +77,9 @@ unsigned Process::getPageSize() {
#else
#error Cannot get the page size on this machine
#endif
+ if (page_size == -1)
+ return errorCodeToError(std::error_code(errno, std::generic_category()));
+
return static_cast<unsigned>(page_size);
}
diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc
index b3c9aa0b83c..4b91f9f7fc6 100644
--- a/llvm/lib/Support/Windows/Process.inc
+++ b/llvm/lib/Support/Windows/Process.inc
@@ -56,7 +56,7 @@ static unsigned computePageSize() {
return static_cast<unsigned>(info.dwPageSize);
}
-unsigned Process::getPageSize() {
+Expected<unsigned> Process::getPageSize() {
static unsigned Ret = computePageSize();
return Ret;
}
OpenPOWER on IntegriCloud