mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 01:04:13 +08:00
mdbx-windows: check ability of address space for growth before umnap.
Change-Id: Ibb62dae26ebab8f3efdbf6aed1b26d88ed63a2b7
This commit is contained in:
parent
373d4ad81d
commit
5c058287d5
21
src/osal.c
21
src/osal.c
@ -97,12 +97,12 @@ extern NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle,
|
||||
extern NTSTATUS NTAPI NtClose(HANDLE Handle);
|
||||
|
||||
extern NTSTATUS NTAPI NtAllocateVirtualMemory(
|
||||
IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN ULONG ZeroBits,
|
||||
IN OUT PULONG RegionSize, IN ULONG AllocationType, IN ULONG Protect);
|
||||
IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits,
|
||||
IN OUT PSIZE_T RegionSize, IN ULONG AllocationType, IN ULONG Protect);
|
||||
|
||||
extern NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle,
|
||||
IN PVOID *BaseAddress,
|
||||
IN OUT PULONG RegionSize,
|
||||
IN OUT PSIZE_T RegionSize,
|
||||
IN ULONG FreeType);
|
||||
|
||||
#ifndef FILE_PROVIDER_CURRENT_VERSION
|
||||
@ -954,6 +954,21 @@ int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t size, size_t limit) {
|
||||
return ntstatus2errcode(status);
|
||||
}
|
||||
|
||||
if (limit > map->length) {
|
||||
/* check ability of address space for growth before umnap */
|
||||
PVOID BaseAddress = (PBYTE)map->address + map->length;
|
||||
SIZE_T RegionSize = limit - map->length;
|
||||
status = NtAllocateVirtualMemory(GetCurrentProcess(), &BaseAddress, 0,
|
||||
&RegionSize, MEM_RESERVE, PAGE_NOACCESS);
|
||||
if (!NT_SUCCESS(status))
|
||||
return ntstatus2errcode(status);
|
||||
|
||||
status = NtFreeVirtualMemory(GetCurrentProcess(), &BaseAddress, &RegionSize,
|
||||
MEM_RELEASE);
|
||||
if (!NT_SUCCESS(status))
|
||||
return ntstatus2errcode(status);
|
||||
}
|
||||
|
||||
/* Windows unable:
|
||||
* - shrinking a mapped file;
|
||||
* - change size of mapped view;
|
||||
|
Loading…
x
Reference in New Issue
Block a user