Title: [286377] trunk/Source/WTF
Revision
286377
Author
hironori.fu...@sony.com
Date
2021-12-01 12:29:49 -0800 (Wed, 01 Dec 2021)

Log Message

[Win] OSAllocator::reserveUncommittedAligned should use aligned allocation
https://bugs.webkit.org/show_bug.cgi?id=233674

Reviewed by Keith Miller.

OSAllocator::reserveUncommittedAligned reserved 2GiB for 1GiB
aligned allocation request.

Windows 10 (Desktop) has VirtualAlloc2 API to aligned allocation.

* wtf/win/OSAllocatorWin.cpp:
(WTF::OSAllocator::reserveUncommittedAligned): Use VirtualAlloc2
API if available. Use SOFT_LINK_OPTIONAL for VirtualAlloc2.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (286376 => 286377)


--- trunk/Source/WTF/ChangeLog	2021-12-01 19:36:54 UTC (rev 286376)
+++ trunk/Source/WTF/ChangeLog	2021-12-01 20:29:49 UTC (rev 286377)
@@ -1,3 +1,19 @@
+2021-12-01  Fujii Hironori  <hironori.fu...@sony.com>
+
+        [Win] OSAllocator::reserveUncommittedAligned should use aligned allocation
+        https://bugs.webkit.org/show_bug.cgi?id=233674
+
+        Reviewed by Keith Miller.
+
+        OSAllocator::reserveUncommittedAligned reserved 2GiB for 1GiB
+        aligned allocation request.
+
+        Windows 10 (Desktop) has VirtualAlloc2 API to aligned allocation.
+
+        * wtf/win/OSAllocatorWin.cpp:
+        (WTF::OSAllocator::reserveUncommittedAligned): Use VirtualAlloc2
+        API if available. Use SOFT_LINK_OPTIONAL for VirtualAlloc2.
+
 2021-12-01  Lauro Moura  <lmo...@igalia.com>
 
         Unreviewed. Fix -Wformat warning after in ThreadingPosix logging

Modified: trunk/Source/WTF/wtf/win/OSAllocatorWin.cpp (286376 => 286377)


--- trunk/Source/WTF/wtf/win/OSAllocatorWin.cpp	2021-12-01 19:36:54 UTC (rev 286376)
+++ trunk/Source/WTF/wtf/win/OSAllocatorWin.cpp	2021-12-01 20:29:49 UTC (rev 286377)
@@ -30,7 +30,11 @@
 #include <wtf/Assertions.h>
 #include <wtf/MathExtras.h>
 #include <wtf/PageBlock.h>
+#include <wtf/SoftLinking.h>
 
+SOFT_LINK_LIBRARY(kernelbase)
+SOFT_LINK_OPTIONAL(kernelbase, VirtualAlloc2, void*, WINAPI, (HANDLE, PVOID, SIZE_T, ULONG, ULONG, MEM_EXTENDED_PARAMETER *, ULONG))
+
 namespace WTF {
 
 static inline DWORD protection(bool writable, bool executable)
@@ -51,7 +55,17 @@
 void* OSAllocator::reserveUncommittedAligned(size_t bytes, Usage usage, bool writable, bool executable, bool, bool)
 {
     ASSERT(hasOneBitSet(bytes) && bytes >= pageSize());
-    // FIXME: Is there a way to do this where we can either release the excess reservation or not reserve it at all?
+    if (VirtualAlloc2Ptr()) {
+        MEM_ADDRESS_REQUIREMENTS addressReqs = { };
+        MEM_EXTENDED_PARAMETER param = { };
+        addressReqs.Alignment = bytes;
+        param.Type = MemExtendedParameterAddressRequirements;
+        param.Pointer = &addressReqs;
+        void* result = VirtualAlloc2Ptr()(nullptr, nullptr, bytes, MEM_RESERVE, protection(writable, executable), &param, 1);
+        if (!result)
+            CRASH();
+        return result;
+    }
     void* result = reserveUncommitted(2 * bytes, usage, writable, executable);
 
     char* aligned = reinterpret_cast<char*>(roundUpToMultipleOf(bytes, reinterpret_cast<uintptr_t>(result)));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to