From 8b95e7d13e1cc354888a68dc520fd428b859679c Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Tue, 8 Dec 2015 19:35:59 +0000 Subject: [PATCH] ITS#8324 fix for read-only envs --- libraries/liblmdb/mdb.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index c603654bcd..728da9b709 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -4003,19 +4003,28 @@ mdb_env_map(MDB_env *env, void *addr) int access = SECTION_MAP_READ; HANDLE mh; void *map; - size_t msize = 0; - ULONG pageprot = PAGE_READONLY; + size_t msize; + ULONG pageprot = PAGE_READONLY, secprot, alloctype; + if (flags & MDB_WRITEMAP) { access |= SECTION_MAP_WRITE; pageprot = PAGE_READWRITE; } + if (flags & MDB_RDONLY) { + secprot = PAGE_READONLY; + msize = 0; + alloctype = 0; + } else { + secprot = PAGE_READWRITE; + msize = env->me_mapsize; + alloctype = MEM_RESERVE; + } - rc = NtCreateSection(&mh, access, NULL, NULL, PAGE_READWRITE, SEC_RESERVE, env->me_fd); + rc = NtCreateSection(&mh, access, NULL, NULL, secprot, SEC_RESERVE, env->me_fd); if (rc) return rc; map = addr; - msize = env->me_mapsize; - rc = NtMapViewOfSection(mh, GetCurrentProcess(), &map, 0, 0, NULL, &msize, ViewUnmap, MEM_RESERVE, pageprot); + rc = NtMapViewOfSection(mh, GetCurrentProcess(), &map, 0, 0, NULL, &msize, ViewUnmap, alloctype, pageprot); NtClose(mh); if (rc) return rc; -- 2.39.5