mdbx: check sys-pagesize for power-of-2.

This commit is contained in:
Leo Yuriev 2017-04-05 18:33:19 +03:00
parent b558757cf1
commit 095cd25e23
2 changed files with 9 additions and 7 deletions

View File

@ -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);
}

View File

@ -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) {