[newlib-cygwin] Cygwin: memory: declare extended memory API

Corinna Vinschen corinna@sourceware.org
Tue Apr 7 16:07:50 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=e18f7f99cc63520eca72b990cb73952ed22208e6

commit e18f7f99cc63520eca72b990cb73952ed22208e6
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Tue Apr 7 14:13:50 2020 +0200

    Cygwin: memory: declare extended memory API
    
    Windows 10 1803 introduced an extended memory API allowing
    to specify memory regions allocations are to be taken off.
    
    In preparation of using this API, define the struct
    MEM_EXTENDED_PARAMETER and friends.  Declare and allow to
    autoload the functions VirtualAlloc2 and NtMapViewOfSectionEx.
    
    Introduce a wincap flag has_extended_mem_api.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/autoload.cc |  3 +++
 winsup/cygwin/ntdll.h     |  3 +++
 winsup/cygwin/wincap.cc   | 10 ++++++++++
 winsup/cygwin/wincap.h    |  2 ++
 winsup/cygwin/winlean.h   | 51 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 69 insertions(+)

diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index 8f2fcc1cd..613a0199c 100644
--- a/winsup/cygwin/autoload.cc
+++ b/winsup/cygwin/autoload.cc
@@ -597,6 +597,9 @@ LoadDLLfunc (QueryInterruptTime, 4, KernelBase)
 LoadDLLfunc (QueryInterruptTimePrecise, 4, KernelBase)
 LoadDLLfunc (QueryUnbiasedInterruptTime, 4, KernelBase)
 LoadDLLfunc (QueryUnbiasedInterruptTimePrecise, 4, KernelBase)
+LoadDLLfunc (VirtualAlloc2, 28, kernelbase)
+
+LoadDLLfunc (NtMapViewOfSectionEx, 36, ntdll)
 
 /* ldap functions are cdecl! */
 #pragma push_macro ("mangle")
diff --git a/winsup/cygwin/ntdll.h b/winsup/cygwin/ntdll.h
index af1ed5f8d..5c6552751 100644
--- a/winsup/cygwin/ntdll.h
+++ b/winsup/cygwin/ntdll.h
@@ -1427,6 +1427,9 @@ extern "C"
   NTSTATUS NTAPI NtMapViewOfSection (HANDLE, HANDLE, PVOID *, ULONG_PTR, SIZE_T,
 				     PLARGE_INTEGER, PSIZE_T, SECTION_INHERIT,
 				     ULONG, ULONG);
+  NTSTATUS NTAPI NtMapViewOfSectionEx (HANDLE, HANDLE, PVOID *, PLARGE_INTEGER,
+				       PSIZE_T, ULONG, ULONG,
+				       PMEM_EXTENDED_PARAMETER, ULONG);
   NTSTATUS NTAPI NtNotifyChangeDirectoryFile (HANDLE, HANDLE, PIO_APC_ROUTINE,
 					      PVOID, PIO_STATUS_BLOCK,
 					      PFILE_NOTIFY_INFORMATION, ULONG,
diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc
index 922705e65..4d136007f 100644
--- a/winsup/cygwin/wincap.cc
+++ b/winsup/cygwin/wincap.cc
@@ -45,6 +45,7 @@ wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = {
     has_con_broken_csi3j:false,
     has_con_broken_il_dl:false,
     has_con_esc_rep:false,
+    has_extended_mem_api:false,
   },
 };
 
@@ -75,6 +76,7 @@ wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = {
     has_con_broken_csi3j:false,
     has_con_broken_il_dl:false,
     has_con_esc_rep:false,
+    has_extended_mem_api:false,
   },
 };
 
@@ -105,6 +107,7 @@ wincaps wincap_8 __attribute__((section (".cygwin_dll_common"), shared)) = {
     has_con_broken_csi3j:false,
     has_con_broken_il_dl:false,
     has_con_esc_rep:false,
+    has_extended_mem_api:false,
   },
 };
 
@@ -135,6 +138,7 @@ wincaps wincap_8_1 __attribute__((section (".cygwin_dll_common"), shared)) = {
     has_con_broken_csi3j:false,
     has_con_broken_il_dl:false,
     has_con_esc_rep:false,
+    has_extended_mem_api:false,
   },
 };
 
@@ -165,6 +169,7 @@ wincaps  wincap_10_1507 __attribute__((section (".cygwin_dll_common"), shared))
     has_con_broken_csi3j:false,
     has_con_broken_il_dl:false,
     has_con_esc_rep:false,
+    has_extended_mem_api:false,
   },
 };
 
@@ -195,6 +200,7 @@ wincaps wincap_10_1703 __attribute__((section (".cygwin_dll_common"), shared)) =
     has_con_broken_csi3j:false,
     has_con_broken_il_dl:false,
     has_con_esc_rep:false,
+    has_extended_mem_api:false,
   },
 };
 
@@ -225,6 +231,7 @@ wincaps wincap_10_1709 __attribute__((section (".cygwin_dll_common"), shared)) =
     has_con_broken_csi3j:false,
     has_con_broken_il_dl:false,
     has_con_esc_rep:false,
+    has_extended_mem_api:false,
   },
 };
 
@@ -255,6 +262,7 @@ wincaps wincap_10_1803 __attribute__((section (".cygwin_dll_common"), shared)) =
     has_con_broken_csi3j:false,
     has_con_broken_il_dl:false,
     has_con_esc_rep:false,
+    has_extended_mem_api:true,
   },
 };
 
@@ -285,6 +293,7 @@ wincaps wincap_10_1809 __attribute__((section (".cygwin_dll_common"), shared)) =
     has_con_broken_csi3j:true,
     has_con_broken_il_dl:false,
     has_con_esc_rep:false,
+    has_extended_mem_api:true,
   },
 };
 
@@ -315,6 +324,7 @@ wincaps wincap_10_1903 __attribute__((section (".cygwin_dll_common"), shared)) =
     has_con_broken_csi3j:false,
     has_con_broken_il_dl:true,
     has_con_esc_rep:true,
+    has_extended_mem_api:true,
   },
 };
 
diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h
index 6d7a1eae6..cf13de535 100644
--- a/winsup/cygwin/wincap.h
+++ b/winsup/cygwin/wincap.h
@@ -39,6 +39,7 @@ struct wincaps
     unsigned has_con_broken_csi3j		: 1;
     unsigned has_con_broken_il_dl		: 1;
     unsigned has_con_esc_rep			: 1;
+    unsigned has_extended_mem_api		: 1;
   };
 };
 
@@ -101,6 +102,7 @@ public:
   bool	IMPLEMENT (has_con_broken_csi3j)
   bool	IMPLEMENT (has_con_broken_il_dl)
   bool	IMPLEMENT (has_con_esc_rep)
+  bool	IMPLEMENT (has_extended_mem_api)
 
   void disable_case_sensitive_dirs ()
   {
diff --git a/winsup/cygwin/winlean.h b/winsup/cygwin/winlean.h
index 9b30b6557..2ee4aaff4 100644
--- a/winsup/cygwin/winlean.h
+++ b/winsup/cygwin/winlean.h
@@ -94,4 +94,55 @@ details. */
 #define GetWindowsDirectoryW dont_use_GetWindowsDirectory
 #define GetWindowsDirectoryA dont_use_GetWindowsDirectory
 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Define extended memory API here as long as not available from mingw-w64. */
+
+typedef struct _MEM_ADDRESS_REQUIREMENTS
+{
+  PVOID LowestStartingAddress;
+  PVOID HighestEndingAddress;
+  SIZE_T Alignment;
+} MEM_ADDRESS_REQUIREMENTS, *PMEM_ADDRESS_REQUIREMENTS;
+
+typedef enum MEM_EXTENDED_PARAMETER_TYPE
+{
+  MemExtendedParameterInvalidType = 0,
+  MemExtendedParameterAddressRequirements,
+  MemExtendedParameterNumaNode,
+  MemExtendedParameterPartitionHandle,
+  MemExtendedParameterUserPhysicalHandle,
+  MemExtendedParameterAttributeFlags,
+  MemExtendedParameterMax
+} MEM_EXTENDED_PARAMETER_TYPE, *PMEM_EXTENDED_PARAMETER_TYPE;
+
+#define MEM_EXTENDED_PARAMETER_TYPE_BITS 8
+
+typedef struct DECLSPEC_ALIGN(8) MEM_EXTENDED_PARAMETER
+{
+  struct
+  {
+      DWORD64 Type : MEM_EXTENDED_PARAMETER_TYPE_BITS;
+      DWORD64 Reserved : 64 - MEM_EXTENDED_PARAMETER_TYPE_BITS;
+  };
+  union
+  {
+      DWORD64 ULong64;
+      PVOID Pointer;
+      SIZE_T Size;
+      HANDLE Handle;
+      DWORD ULong;
+  };
+} MEM_EXTENDED_PARAMETER, *PMEM_EXTENDED_PARAMETER;
+
+PVOID VirtualAlloc2 (HANDLE, PVOID, SIZE_T, ULONG, ULONG,
+		     PMEM_EXTENDED_PARAMETER, ULONG);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*_WINLEAN_H*/


More information about the Cygwin-cvs mailing list