From 095cd25e2337d00f866d95b81dfe6fc29bc99f59 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Wed, 5 Apr 2017 18:33:19 +0300 Subject: [PATCH] mdbx: check sys-pagesize for power-of-2. --- src/bits.h | 7 +++++++ src/mdbx.c | 9 ++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/bits.h b/src/bits.h index 45c0d69c..57551a48 100644 --- a/src/bits.h +++ b/src/bits.h @@ -780,3 +780,10 @@ void mdbx_rthc_unlock(void); int mdbx_rthc_alloc(mdbx_thread_key_t *key, MDB_reader *begin, MDB_reader *end); void mdbx_rthc_remove(mdbx_thread_key_t key); void mdbx_rthc_cleanup(void); + +static __inline bool is_power2(size_t x) { return (x & (x - 1)) == 0; } + +static __inline size_t roundup2(size_t value, size_t granularity) { + assert(is_power2(granularity)); + return (value + granularity - 1) & ~(granularity - 1); +} diff --git a/src/mdbx.c b/src/mdbx.c index af89676a..1af8aec8 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -3631,6 +3631,8 @@ int __cold mdbx_env_create(MDB_env **env) { e->me_lfd = INVALID_HANDLE_VALUE; e->me_pid = mdbx_getpid(); mdbx_env_setup_limits(e, e->me_os_psize = mdbx_syspagesize()); + if (!is_power2(e->me_os_psize)) + return MDB_INCOMPATIBLE; VALGRIND_CREATE_MEMPOOL(e, 0, 0); e->me_signature = MDBX_ME_SIGNATURE; *env = e; @@ -3848,13 +3850,6 @@ static int __cold mdbx_env_open2(MDB_env *env, MDB_meta *meta) { /****************************************************************************/ -static __inline bool is_powerof2(size_t x) { return (x & (x - 1)) == 0; } - -static __inline size_t roundup2(size_t value, size_t granularity) { - assert(is_powerof2(granularity)); - return (value + granularity - 1) & ~(granularity - 1); -} - /* Open and/or initialize the lock region for the environment. */ static int __cold mdbx_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl) {