mdbx-windws: refine/fix handling STATUS_CONFLICTING_ADDRESSES.

Change-Id: I501acb2d5d653c74ab210907dd955d7167956af8
This commit is contained in:
Leonid Yuriev 2020-01-05 22:01:47 +03:00
parent 230e4654f1
commit 995a26cf19
2 changed files with 24 additions and 18 deletions

View File

@ -5135,9 +5135,13 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
txn->mt_flags |= MDBX_SHRINK_ALLOWED; txn->mt_flags |= MDBX_SHRINK_ALLOWED;
mdbx_srwlock_AcquireShared(&env->me_remap_guard); mdbx_srwlock_AcquireShared(&env->me_remap_guard);
} }
#endif #endif /* Windows */
} else { } else {
env->me_dxb_mmap.current = size; env->me_dxb_mmap.current = size;
#if defined(_WIN32) || defined(_WIN64)
env->me_dxb_mmap.filesize =
(env->me_dxb_mmap.filesize < size) ? size : env->me_dxb_mmap.filesize;
#endif /* Windows */
} }
#if defined(MDBX_USE_VALGRIND) || defined(__SANITIZE_ADDRESS__) #if defined(MDBX_USE_VALGRIND) || defined(__SANITIZE_ADDRESS__)
mdbx_txn_valgrind(env, txn); mdbx_txn_valgrind(env, txn);

View File

@ -1417,12 +1417,12 @@ MDBX_INTERNAL_FUNC int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t size,
/* growth rw-section */ /* growth rw-section */
SectionSize.QuadPart = size; SectionSize.QuadPart = size;
status = NtExtendSection(map->section, &SectionSize); status = NtExtendSection(map->section, &SectionSize);
if (NT_SUCCESS(status)) { if (!NT_SUCCESS(status))
map->current = size; return ntstatus2errcode(status);
if (map->filesize < size) map->current = size;
map->filesize = size; if (map->filesize < size)
} map->filesize = size;
return ntstatus2errcode(status); return MDBX_SUCCESS;
} }
if (limit > map->limit) { if (limit > map->limit) {
@ -1431,11 +1431,10 @@ MDBX_INTERNAL_FUNC int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t size,
SIZE_T RegionSize = limit - map->limit; SIZE_T RegionSize = limit - map->limit;
status = NtAllocateVirtualMemory(GetCurrentProcess(), &BaseAddress, 0, status = NtAllocateVirtualMemory(GetCurrentProcess(), &BaseAddress, 0,
&RegionSize, MEM_RESERVE, PAGE_NOACCESS); &RegionSize, MEM_RESERVE, PAGE_NOACCESS);
if (!NT_SUCCESS(status)) { if (status == /* STATUS_CONFLICTING_ADDRESSES */ 0xC0000018)
if (status == /* STATUS_INVALID_ADDRESS */ 0xC0000141) return MDBX_RESULT_TRUE;
status = /* STATUS_CONFLICTING_ADDRESSES */ 0xC0000018; if (!NT_SUCCESS(status))
return ntstatus2errcode(status); return ntstatus2errcode(status);
}
status = NtFreeVirtualMemory(GetCurrentProcess(), &BaseAddress, &RegionSize, status = NtFreeVirtualMemory(GetCurrentProcess(), &BaseAddress, &RegionSize,
MEM_RELEASE); MEM_RELEASE);
@ -1462,9 +1461,13 @@ MDBX_INTERNAL_FUNC int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t size,
bailout: bailout:
map->address = NULL; map->address = NULL;
map->current = map->limit = 0; map->current = map->limit = 0;
if (ReservedAddress) if (ReservedAddress) {
(void)NtFreeVirtualMemory(GetCurrentProcess(), &ReservedAddress, ReservedSize = 0;
&ReservedSize, MEM_RELEASE); status = NtFreeVirtualMemory(GetCurrentProcess(), &ReservedAddress,
&ReservedSize, MEM_RELEASE);
assert(NT_SUCCESS(status));
(void)status;
}
return err; return err;
} }
@ -1475,8 +1478,7 @@ MDBX_INTERNAL_FUNC int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t size,
&ReservedSize, MEM_RESERVE, PAGE_NOACCESS); &ReservedSize, MEM_RESERVE, PAGE_NOACCESS);
if (!NT_SUCCESS(status)) { if (!NT_SUCCESS(status)) {
ReservedAddress = NULL; ReservedAddress = NULL;
if (status != /* STATUS_CONFLICTING_ADDRESSES */ 0xC0000018 && if (status != /* STATUS_CONFLICTING_ADDRESSES */ 0xC0000018)
status != /* STATUS_INVALID_ADDRESS */ 0xC0000141)
goto bailout_ntstatus /* no way to recovery */; goto bailout_ntstatus /* no way to recovery */;
/* assume we can change base address if mapping size changed or prev address /* assume we can change base address if mapping size changed or prev address
@ -1516,6 +1518,7 @@ retry_file_and_section:
if (ReservedAddress) { if (ReservedAddress) {
/* release reserved address space */ /* release reserved address space */
ReservedSize = 0;
status = NtFreeVirtualMemory(GetCurrentProcess(), &ReservedAddress, status = NtFreeVirtualMemory(GetCurrentProcess(), &ReservedAddress,
&ReservedSize, MEM_RELEASE); &ReservedSize, MEM_RELEASE);
ReservedAddress = NULL; ReservedAddress = NULL;
@ -1536,8 +1539,7 @@ retry_mapview:;
(flags & MDBX_WRITEMAP) ? PAGE_READWRITE : PAGE_READONLY); (flags & MDBX_WRITEMAP) ? PAGE_READWRITE : PAGE_READONLY);
if (!NT_SUCCESS(status)) { if (!NT_SUCCESS(status)) {
if ((status == /* STATUS_CONFLICTING_ADDRESSES */ 0xC0000018 || if (status == /* STATUS_CONFLICTING_ADDRESSES */ 0xC0000018 &&
status == /* STATUS_INVALID_ADDRESS */ 0xC0000141) &&
map->address) { map->address) {
/* try remap at another base address */ /* try remap at another base address */
map->address = NULL; map->address = NULL;