From 32df0ad1ebcb7d36ec744c94d8fa134873e7f011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Fri, 12 Jul 2024 11:40:47 +0300 Subject: [PATCH] =?UTF-8?q?mdbx:=20=D1=83=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B5=D0=B3=D1=80=D0=B5=D1=81?= =?UTF-8?q?=D1=81=D0=B0=20`SIGSEGV`=20=D0=BF=D1=80=D0=B8=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D0=B8=20=D0=91=D0=94=20=D1=81=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=BD=D1=8B=D0=BC=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=D0=BE=D0=BC=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api-env.c | 5 ----- src/dxb.c | 6 ++++++ src/env.c | 19 +++++++++++-------- src/meta.c | 5 +---- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/api-env.c b/src/api-env.c index 852d3394..4aa7bd2e 100644 --- a/src/api-env.c +++ b/src/api-env.c @@ -530,12 +530,7 @@ __cold int mdbx_env_openW(MDBX_env *env, const wchar_t *pathname, base + bitmap_bytes + env->max_dbi * (sizeof(txn->dbs[0]) + sizeof(txn->cursors[0]) + sizeof(txn->dbi_seqs[0]) + sizeof(txn->dbi_state[0])); - rc = env_page_auxbuffer(env); - if (unlikely(rc != MDBX_SUCCESS)) - goto bailout; - memset(env->page_auxbuf, -1, env->ps * (size_t)2); - memset(ptr_disp(env->page_auxbuf, env->ps * (size_t)2), 0, env->ps); txn = osal_calloc(1, size); if (unlikely(!txn)) { rc = MDBX_ENOMEM; diff --git a/src/dxb.c b/src/dxb.c index 401115d9..c91880fe 100644 --- a/src/dxb.c +++ b/src/dxb.c @@ -641,6 +641,12 @@ __cold int dxb_setup(MDBX_env *env, const int lck_rc, if (env->ps != header.pagesize) env_setup_pagesize(env, header.pagesize); + if ((env->flags & MDBX_RDONLY) == 0) { + err = env_page_auxbuffer(env); + if (unlikely(err != MDBX_SUCCESS)) + return err; + } + const size_t used_bytes = pgno2bytes(env, header.geometry.first_unallocated); const size_t used_aligned2os_bytes = ceil_powerof2(used_bytes, globals.sys_pagesize); diff --git a/src/env.c b/src/env.c index 2d5dadc5..c4902765 100644 --- a/src/env.c +++ b/src/env.c @@ -10,10 +10,16 @@ bool env_txn0_owned(const MDBX_env *env) { } int env_page_auxbuffer(MDBX_env *env) { - return env->page_auxbuf ? MDBX_SUCCESS - : osal_memalign_alloc(globals.sys_pagesize, - env->ps * (size_t)NUM_METAS, - &env->page_auxbuf); + const int err = + env->page_auxbuf + ? MDBX_SUCCESS + : osal_memalign_alloc(globals.sys_pagesize, + env->ps * (size_t)NUM_METAS, &env->page_auxbuf); + if (likely(err == MDBX_SUCCESS)) { + memset(env->page_auxbuf, -1, env->ps * (size_t)2); + memset(ptr_disp(env->page_auxbuf, env->ps * (size_t)2), 0, env->ps); + } + return err; } __cold unsigned env_setup_pagesize(MDBX_env *env, const size_t pagesize) { @@ -22,11 +28,8 @@ __cold unsigned env_setup_pagesize(MDBX_env *env, const size_t pagesize) { ENSURE(env, is_powerof2(pagesize)); ENSURE(env, pagesize >= MDBX_MIN_PAGESIZE); ENSURE(env, pagesize <= MDBX_MAX_PAGESIZE); + ENSURE(env, !env->page_auxbuf && env->ps != pagesize); env->ps = (unsigned)pagesize; - if (env->page_auxbuf) { - osal_memalign_free(env->page_auxbuf); - env->page_auxbuf = nullptr; - } STATIC_ASSERT(MAX_GC1OVPAGE(MDBX_MIN_PAGESIZE) > 4); STATIC_ASSERT(MAX_GC1OVPAGE(MDBX_MAX_PAGESIZE) < PAGELIST_LIMIT); diff --git a/src/meta.c b/src/meta.c index ee2a5aef..7214335b 100644 --- a/src/meta.c +++ b/src/meta.c @@ -392,9 +392,6 @@ __cold meta_t *meta_init_triplet(const MDBX_env *env, void *buffer) { __cold int __must_check_result meta_override(MDBX_env *env, size_t target, txnid_t txnid, const meta_t *shape) { - int rc = env_page_auxbuffer(env); - if (unlikely(rc != MDBX_SUCCESS)) - return rc; page_t *const page = env->page_auxbuf; meta_model(env, page, target, &((target == 0 && shape) ? shape : METAPAGE(env, 0))->dxbid); @@ -440,7 +437,7 @@ __cold int __must_check_result meta_override(MDBX_env *env, size_t target, } meta_sign_as_steady(model); - rc = meta_validate(env, model, page, (pgno_t)target, nullptr); + int rc = meta_validate(env, model, page, (pgno_t)target, nullptr); if (unlikely(MDBX_IS_ERROR(rc))) return MDBX_PROBLEM;