summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2019-05-20 20:53:05 +0000
committerLang Hames <lhames@gmail.com>2019-05-20 20:53:05 +0000
commit93d2bdda6bfe287de7825cfac9224dcfe051b1c5 (patch)
tree7b876090b9f6357dc81e5c09f63addfe0993e528 /llvm/lib/Support/Unix
parent52fa90a348c1bed5ecbcc0965c57d67e5ec45d5a (diff)
downloadbcm5719-llvm-93d2bdda6bfe287de7825cfac9224dcfe051b1c5.tar.gz
bcm5719-llvm-93d2bdda6bfe287de7825cfac9224dcfe051b1c5.zip
[Support] Renamed member 'Size' to 'AllocatedSize' in MemoryBlock and OwningMemoryBlock.
Rename member 'Size' to 'AllocatedSize' in order to provide a hint that the allocated size may be different than the requested size. Comments are added to clarify this point. Updated the InMemoryBuffer in FileOutputBuffer.cpp to track the requested buffer size. Patch by Machiel van Hooren. Thanks Machiel! https://reviews.llvm.org/D61599 llvm-svn: 361195
Diffstat (limited to 'llvm/lib/Support/Unix')
-rw-r--r--llvm/lib/Support/Unix/Memory.inc22
1 files changed, 12 insertions, 10 deletions
diff --git a/llvm/lib/Support/Unix/Memory.inc b/llvm/lib/Support/Unix/Memory.inc
index 05c5ccbdb3d..3b003362959 100644
--- a/llvm/lib/Support/Unix/Memory.inc
+++ b/llvm/lib/Support/Unix/Memory.inc
@@ -117,13 +117,15 @@ 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;
+ NearBlock->allocatedSize() : 0;
static const size_t PageSize = Process::getPageSizeEstimate();
+ const size_t NumPages = (NumBytes+PageSize-1)/PageSize;
+
if (Start && Start % PageSize)
Start += PageSize - Start % PageSize;
// FIXME: Handle huge page requests (MF_HUGE_HINT).
- void *Addr = ::mmap(reinterpret_cast<void *>(Start), NumBytes, Protect,
+ void *Addr = ::mmap(reinterpret_cast<void *>(Start), PageSize*NumPages, Protect,
MMFlags, fd, 0);
if (Addr == MAP_FAILED) {
if (NearBlock) { //Try again without a near hint
@@ -146,7 +148,7 @@ Memory::allocateMappedMemory(size_t NumBytes,
MemoryBlock Result;
Result.Address = Addr;
- Result.Size = NumBytes;
+ Result.AllocatedSize = PageSize*NumPages;
Result.Flags = PFlags;
// Rely on protectMappedMemory to invalidate instruction cache.
@@ -161,14 +163,14 @@ Memory::allocateMappedMemory(size_t NumBytes,
std::error_code
Memory::releaseMappedMemory(MemoryBlock &M) {
- if (M.Address == nullptr || M.Size == 0)
+ if (M.Address == nullptr || M.AllocatedSize == 0)
return std::error_code();
- if (0 != ::munmap(M.Address, M.Size))
+ if (0 != ::munmap(M.Address, M.AllocatedSize))
return std::error_code(errno, std::generic_category());
M.Address = nullptr;
- M.Size = 0;
+ M.AllocatedSize = 0;
return std::error_code();
}
@@ -176,7 +178,7 @@ Memory::releaseMappedMemory(MemoryBlock &M) {
std::error_code
Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) {
static const size_t PageSize = Process::getPageSizeEstimate();
- if (M.Address == nullptr || M.Size == 0)
+ if (M.Address == nullptr || M.AllocatedSize == 0)
return std::error_code();
if (!Flags)
@@ -184,7 +186,7 @@ Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) {
int Protect = getPosixProtectionFlags(Flags);
uintptr_t Start = alignAddr((uint8_t *)M.Address - PageSize + 1, PageSize);
- uintptr_t End = alignAddr((uint8_t *)M.Address + M.Size, PageSize);
+ uintptr_t End = alignAddr((uint8_t *)M.Address + M.AllocatedSize, PageSize);
bool InvalidateCache = (Flags & MF_EXEC);
@@ -197,7 +199,7 @@ Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) {
if (Result != 0)
return std::error_code(errno, std::generic_category());
- Memory::InvalidateInstructionCache(M.Address, M.Size);
+ Memory::InvalidateInstructionCache(M.Address, M.AllocatedSize);
InvalidateCache = false;
}
#endif
@@ -208,7 +210,7 @@ Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) {
return std::error_code(errno, std::generic_category());
if (InvalidateCache)
- Memory::InvalidateInstructionCache(M.Address, M.Size);
+ Memory::InvalidateInstructionCache(M.Address, M.AllocatedSize);
return std::error_code();
}
OpenPOWER on IntegriCloud