diff options
author | George Hazan <ghazan@miranda.im> | 2018-06-21 19:14:56 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-06-21 19:14:56 +0300 |
commit | 983debf2db56122f1f3b63288dd1d683f4d516cb (patch) | |
tree | b06b85f72fb00726a0e6a4d64e117cd69378743a /plugins/Dbx_mdbx | |
parent | 271367ab3879f748ab3b5791042f2faeb238a7dd (diff) |
non-local check & MDBX_EXCLUSIVE are mutually exclusive
Diffstat (limited to 'plugins/Dbx_mdbx')
-rw-r--r-- | plugins/Dbx_mdbx/src/libmdbx/src/mdbx.c | 8 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/libmdbx/src/osal.c | 34 |
2 files changed, 24 insertions, 18 deletions
diff --git a/plugins/Dbx_mdbx/src/libmdbx/src/mdbx.c b/plugins/Dbx_mdbx/src/libmdbx/src/mdbx.c index 44b2093d0b..ce3d7a52ce 100644 --- a/plugins/Dbx_mdbx/src/libmdbx/src/mdbx.c +++ b/plugins/Dbx_mdbx/src/libmdbx/src/mdbx.c @@ -5580,8 +5580,9 @@ static int __cold mdbx_setup_lck(MDBX_env *env, char *lck_pathname, assert(env->me_fd != INVALID_HANDLE_VALUE); assert(env->me_lfd == INVALID_HANDLE_VALUE); + uint32_t bExclusive = (env->me_flags & MDBX_EXCLUSIVE); int err = mdbx_openfile(lck_pathname, O_RDWR | O_CREAT, mode, &env->me_lfd, - (env->me_flags & MDBX_EXCLUSIVE) ? true : false); + (bExclusive) ? true : false); if (err != MDBX_SUCCESS) { if (err != MDBX_EROFS || (env->me_flags & MDBX_RDONLY) == 0) return err; @@ -5625,7 +5626,7 @@ static int __cold mdbx_setup_lck(MDBX_env *env, char *lck_pathname, size = wanna; } } else { - if (env->me_flags & MDBX_EXCLUSIVE) + if (bExclusive) return MDBX_BUSY; if (size > SSIZE_MAX || (size & (env->me_os_psize - 1)) || size < env->me_os_psize) { @@ -5642,7 +5643,8 @@ static int __cold mdbx_setup_lck(MDBX_env *env, char *lck_pathname, } env->me_maxreaders = (unsigned)maxreaders; - err = mdbx_mmap(MDBX_WRITEMAP, &env->me_lck_mmap, (size_t)size, (size_t)size); + err = mdbx_mmap(MDBX_WRITEMAP | bExclusive, &env->me_lck_mmap, (size_t)size, + (size_t)size); if (unlikely(err != MDBX_SUCCESS)) return err; diff --git a/plugins/Dbx_mdbx/src/libmdbx/src/osal.c b/plugins/Dbx_mdbx/src/libmdbx/src/osal.c index 33c755af99..8b6094d55b 100644 --- a/plugins/Dbx_mdbx/src/libmdbx/src/osal.c +++ b/plugins/Dbx_mdbx/src/libmdbx/src/osal.c @@ -191,7 +191,7 @@ __cold void mdbx_panic(const char *fmt, ...) { abort(); } -/*----------------------------------------------------------------------------*/ + /*----------------------------------------------------------------------------*/ #ifndef mdbx_asprintf int mdbx_asprintf(char **strp, const char *fmt, ...) { @@ -856,11 +856,13 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t size, size_t limit) { map->section = NULL; map->address = nullptr; - NTSTATUS rc = mdbx_check4nonlocal(map->fd, flags); - if (rc != MDBX_SUCCESS) - return rc; + if (flags & MDBX_EXCLUSIVE) { + NTSTATUS rc = mdbx_check4nonlocal(map->fd, flags); + if (rc != MDBX_SUCCESS) + return rc; + } - rc = mdbx_filesize(map->fd, &map->filesize); + NTSTATUS rc = mdbx_filesize(map->fd, &map->filesize); if (rc != MDBX_SUCCESS) return rc; if ((flags & MDBX_RDONLY) == 0 && map->filesize != size) { @@ -875,13 +877,14 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t size, size_t limit) { SectionSize.QuadPart = size; rc = NtCreateSection( &map->section, - /* DesiredAccess */ (flags & MDBX_WRITEMAP) + /* DesiredAccess */ + (flags & MDBX_WRITEMAP) ? SECTION_QUERY | SECTION_MAP_READ | SECTION_EXTEND_SIZE | SECTION_MAP_WRITE : SECTION_QUERY | SECTION_MAP_READ | SECTION_EXTEND_SIZE, /* ObjectAttributes */ NULL, /* MaximumSize (InitialSize) */ &SectionSize, - /* SectionPageProtection */ (flags & MDBX_RDONLY) ? PAGE_READONLY - : PAGE_READWRITE, + /* SectionPageProtection */ + (flags & MDBX_RDONLY) ? PAGE_READONLY : PAGE_READWRITE, /* AllocationAttributes */ SEC_RESERVE, map->fd); if (!NT_SUCCESS(rc)) return ntstatus2errcode(rc); @@ -894,8 +897,8 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t size, size_t limit) { /* SectionOffset */ NULL, &ViewSize, /* InheritDisposition */ ViewUnmap, /* AllocationType */ (flags & MDBX_RDONLY) ? 0 : MEM_RESERVE, - /* Win32Protect */ (flags & MDBX_WRITEMAP) ? PAGE_READWRITE - : PAGE_READONLY); + /* Win32Protect */ + (flags & MDBX_WRITEMAP) ? PAGE_READWRITE : PAGE_READONLY); if (!NT_SUCCESS(rc)) { NtClose(map->section); map->section = 0; @@ -1036,14 +1039,15 @@ retry_file_and_section: SectionSize.QuadPart = size; status = NtCreateSection( &map->section, - /* DesiredAccess */ (flags & MDBX_WRITEMAP) + /* DesiredAccess */ + (flags & MDBX_WRITEMAP) ? SECTION_QUERY | SECTION_MAP_READ | SECTION_EXTEND_SIZE | SECTION_MAP_WRITE : SECTION_QUERY | SECTION_MAP_READ | SECTION_EXTEND_SIZE, /* ObjectAttributes */ NULL, /* MaximumSize (InitialSize) */ &SectionSize, - /* SectionPageProtection */ (flags & MDBX_RDONLY) ? PAGE_READONLY - : PAGE_READWRITE, + /* SectionPageProtection */ + (flags & MDBX_RDONLY) ? PAGE_READONLY : PAGE_READWRITE, /* AllocationAttributes */ SEC_RESERVE, map->fd); if (!NT_SUCCESS(status)) @@ -1067,8 +1071,8 @@ retry_mapview:; /* SectionOffset */ NULL, &ViewSize, /* InheritDisposition */ ViewUnmap, /* AllocationType */ (flags & MDBX_RDONLY) ? 0 : MEM_RESERVE, - /* Win32Protect */ (flags & MDBX_WRITEMAP) ? PAGE_READWRITE - : PAGE_READONLY); + /* Win32Protect */ + (flags & MDBX_WRITEMAP) ? PAGE_READWRITE : PAGE_READONLY); if (!NT_SUCCESS(status)) { if (status == /* STATUS_CONFLICTING_ADDRESSES */ 0xC0000018 && |