]> git.sur5r.net Git - openldap/commitdiff
ITS#8324 fix for read-only envs
authorHoward Chu <hyc@openldap.org>
Tue, 8 Dec 2015 19:35:59 +0000 (19:35 +0000)
committerHoward Chu <hyc@openldap.org>
Tue, 8 Dec 2015 19:35:59 +0000 (19:35 +0000)
libraries/liblmdb/mdb.c

index c603654bcd9777cb5efa469ee9b9cebb9d44aaf0..728da9b7091bc7e0916fcc9f8e24f47e609f1949 100644 (file)
@@ -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;