mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-18 21:19:31 +03:00
add inline structure definitions for MEM_EXTENDED_PARAMETER2
This commit is contained in:
parent
a73daf1804
commit
56de13535a
1 changed files with 39 additions and 4 deletions
43
src/os.c
43
src/os.c
|
@ -85,10 +85,45 @@ static size_t mi_os_good_alloc_size(size_t size, size_t alignment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
// Structures from Windows 10 winnt.h
|
||||||
|
typedef struct _MEM_ADDRESS_REQUIREMENTS2 {
|
||||||
|
PVOID LowestStartingAddress;
|
||||||
|
PVOID HighestEndingAddress;
|
||||||
|
SIZE_T Alignment;
|
||||||
|
} MEM_ADDRESS_REQUIREMENTS2, *PMEM_ADDRESS_REQUIREMENTS2;
|
||||||
|
|
||||||
|
#define MEM_EXTENDED_PARAMETER_GRAPHICS 0x00000001
|
||||||
|
|
||||||
|
typedef enum MEM_EXTENDED_PARAMETER2_TYPE {
|
||||||
|
MemExtendedParameter2InvalidType = 0,
|
||||||
|
MemExtendedParameter2AddressRequirements,
|
||||||
|
MemExtendedParameter2NumaNode,
|
||||||
|
MemExtendedParameter2PartitionHandle,
|
||||||
|
MemExtendedParameter2Max,
|
||||||
|
MemExtendedParameter2UserPhysicalHandle,
|
||||||
|
MemExtendedParameter2AttributeFlags
|
||||||
|
} *PMEM_EXTENDED_PARAMETER2_TYPE;
|
||||||
|
|
||||||
|
#define MEM_EXTENDED_PARAMETER2_TYPE_BITS 8
|
||||||
|
|
||||||
|
typedef struct DECLSPEC_ALIGN(8) MEM_EXTENDED_PARAMETER2 {
|
||||||
|
struct {
|
||||||
|
DWORD64 Type : MEM_EXTENDED_PARAMETER2_TYPE_BITS;
|
||||||
|
DWORD64 Reserved : 64 - MEM_EXTENDED_PARAMETER2_TYPE_BITS;
|
||||||
|
} DUMMYSTRUCTNAME;
|
||||||
|
union {
|
||||||
|
DWORD64 ULong64;
|
||||||
|
PVOID Pointer;
|
||||||
|
SIZE_T Size;
|
||||||
|
HANDLE Handle;
|
||||||
|
DWORD ULong;
|
||||||
|
} DUMMYUNIONNAME;
|
||||||
|
} MEM_EXTENDED_PARAMETER2, *PMEM_EXTENDED_PARAMETER2;
|
||||||
|
|
||||||
// We use VirtualAlloc2 for aligned allocation, but it is only supported on Windows 10 and Windows Server 2016.
|
// We use VirtualAlloc2 for aligned allocation, but it is only supported on Windows 10 and Windows Server 2016.
|
||||||
// So, we need to look it up dynamically to run on older systems. (use __stdcall for 32-bit compatibility)
|
// So, we need to look it up dynamically to run on older systems. (use __stdcall for 32-bit compatibility)
|
||||||
// Same for DiscardVirtualMemory
|
// Same for DiscardVirtualMemory
|
||||||
typedef PVOID(__stdcall *PVirtualAlloc2)(HANDLE, PVOID, SIZE_T, ULONG, ULONG, MEM_EXTENDED_PARAMETER*, ULONG);
|
typedef PVOID(__stdcall *PVirtualAlloc2)(HANDLE, PVOID, SIZE_T, ULONG, ULONG, MEM_EXTENDED_PARAMETER2*, ULONG);
|
||||||
typedef DWORD(__stdcall *PDiscardVirtualMemory)(PVOID,SIZE_T);
|
typedef DWORD(__stdcall *PDiscardVirtualMemory)(PVOID,SIZE_T);
|
||||||
static PVirtualAlloc2 pVirtualAlloc2 = NULL;
|
static PVirtualAlloc2 pVirtualAlloc2 = NULL;
|
||||||
static PDiscardVirtualMemory pDiscardVirtualMemory = NULL;
|
static PDiscardVirtualMemory pDiscardVirtualMemory = NULL;
|
||||||
|
@ -193,10 +228,10 @@ static void* mi_win_virtual_allocx(void* addr, size_t size, size_t try_alignment
|
||||||
#if defined(MEM_EXTENDED_PARAMETER_TYPE_BITS)
|
#if defined(MEM_EXTENDED_PARAMETER_TYPE_BITS)
|
||||||
if (try_alignment > 0 && (try_alignment % _mi_os_page_size()) == 0 && pVirtualAlloc2 != NULL) {
|
if (try_alignment > 0 && (try_alignment % _mi_os_page_size()) == 0 && pVirtualAlloc2 != NULL) {
|
||||||
// on modern Windows try use VirtualAlloc2 for aligned allocation
|
// on modern Windows try use VirtualAlloc2 for aligned allocation
|
||||||
MEM_ADDRESS_REQUIREMENTS reqs = { 0 };
|
MEM_ADDRESS_REQUIREMENTS2 reqs = { 0 };
|
||||||
reqs.Alignment = try_alignment;
|
reqs.Alignment = try_alignment;
|
||||||
MEM_EXTENDED_PARAMETER param = { 0 };
|
MEM_EXTENDED_PARAMETER2 param = { 0 };
|
||||||
param.Type = MemExtendedParameterAddressRequirements;
|
param.Type = MemExtendedParameter2AddressRequirements;
|
||||||
param.Pointer = &reqs;
|
param.Pointer = &reqs;
|
||||||
return (*pVirtualAlloc2)(addr, NULL, size, flags, PAGE_READWRITE, ¶m, 1);
|
return (*pVirtualAlloc2)(addr, NULL, size, flags, PAGE_READWRITE, ¶m, 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue