From 6248b67f753e7831921669b2f9072d3031a1ac26 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Mon, 24 Feb 2020 20:46:36 +0300 Subject: [PATCH] mdbx-windows: more for running under Wine. Wine unable create mapped-view large tran secton size. More for https://github.com/erthink/libmdbx/issues/83 Change-Id: I93e98d58a827c785f8257cd9cac387a333e59621 --- src/elements/core.c | 9 ++++++++- src/elements/osal.c | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/elements/core.c b/src/elements/core.c index d1a6cac3..f2d1c06f 100644 --- a/src/elements/core.c +++ b/src/elements/core.c @@ -4662,6 +4662,8 @@ static __cold int mdbx_mapresize(MDBX_env *env, const pgno_t used_pgno, * the local threads for safe remap. * 2) At least on Windows 10 1803 the entire mapped section is unavailable * for short time during NtExtendSection() or VirtualAlloc() execution. + * 3) Under Wine runtime environment on Linux a section extending is not + * supported. Therefore thread suspending is always required. * * THEREFORE LOCAL THREADS SUSPENDING IS ALWAYS REQUIRED! */ array_onstack.limit = ARRAY_LENGTH(array_onstack.handles); @@ -6062,7 +6064,12 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) { } if (txn->mt_flags & MDBX_RDONLY) { #if defined(_WIN32) || defined(_WIN64) - if (size > env->me_dbgeo.lower && env->me_dbgeo.shrink) { + if ((size > env->me_dbgeo.lower && env->me_dbgeo.shrink) || + (mdbx_RunningUnderWine() && + /* under Wine acquisition of remap_guard is always required, + * since Wine don't support section extending, + * i.e. in both cases unmap+map are required. */ + size < env->me_dbgeo.upper && env->me_dbgeo.grow)) { txn->mt_flags |= MDBX_SHRINK_ALLOWED; mdbx_srwlock_AcquireShared(&env->me_remap_guard); } diff --git a/src/elements/osal.c b/src/elements/osal.c index e32cfb22..8be91b1c 100644 --- a/src/elements/osal.c +++ b/src/elements/osal.c @@ -1300,7 +1300,8 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map, if (!NT_SUCCESS(err)) return ntstatus2errcode(err); - SIZE_T ViewSize = (flags & MDBX_RDONLY) ? 0 : limit; + SIZE_T ViewSize = + (flags & MDBX_RDONLY) ? 0 : mdbx_RunningUnderWine() ? size : limit; err = NtMapViewOfSection( map->section, GetCurrentProcess(), &map->address, /* ZeroBits */ 0,