From: Andrew Ng Date: Wed, 27 Mar 2019 10:26:21 +0000 (+0000) Subject: [Support] MemoryBlock size should reflect the requested size X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a7d2ce067912933b66549f58c4d89bcb5dd15f30;p=llvm [Support] MemoryBlock size should reflect the requested size This patch mirrors the change made to the Unix equivalent in r351916. This in turn fixes bugs related to the use of FileOutputBuffer to output to "-", i.e. stdout, on Windows. Differential Revision: https://reviews.llvm.org/D59663 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357058 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/Windows/Memory.inc b/lib/Support/Windows/Memory.inc index 0e961fdeaad..b1d68596f5c 100644 --- a/lib/Support/Windows/Memory.inc +++ b/lib/Support/Windows/Memory.inc @@ -135,8 +135,9 @@ MemoryBlock Memory::allocateMappedMemory(size_t NumBytes, DWORD Protect = getWindowsProtectionFlags(Flags); + size_t AllocSize = NumBlocks * Granularity; void *PA = ::VirtualAlloc(reinterpret_cast(Start), - NumBlocks * Granularity, AllocType, Protect); + AllocSize, AllocType, Protect); if (PA == NULL) { if (NearBlock || HugePages) { // Try again without the NearBlock hint and without large memory pages @@ -148,11 +149,11 @@ MemoryBlock Memory::allocateMappedMemory(size_t NumBytes, MemoryBlock Result; Result.Address = PA; - Result.Size = NumBlocks*Granularity; + Result.Size = NumBytes; Result.Flags = (Flags & ~MF_HUGE_HINT) | (HugePages ? MF_HUGE_HINT : 0); if (Flags & MF_EXEC) - Memory::InvalidateInstructionCache(Result.Address, Result.Size); + Memory::InvalidateInstructionCache(Result.Address, AllocSize); return Result; }