[PATCH] D59663: [Support] MemoryBlock size should reflect the requested size

Andrew Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 21 12:20:52 PDT 2019


andrewng created this revision.
andrewng added a reviewer: ruiu.

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.


https://reviews.llvm.org/D59663

Files:
  lib/Support/Windows/Memory.inc


Index: lib/Support/Windows/Memory.inc
===================================================================
--- lib/Support/Windows/Memory.inc
+++ lib/Support/Windows/Memory.inc
@@ -135,8 +135,9 @@
 
   DWORD Protect = getWindowsProtectionFlags(Flags);
 
+  size_t AllocSize = NumBlocks * Granularity;
   void *PA = ::VirtualAlloc(reinterpret_cast<void *>(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 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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59663.191760.patch
Type: text/x-patch
Size: 1033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190321/2a270909/attachment.bin>


More information about the llvm-commits mailing list