mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 02:14:13 +08:00
mdbx: check sys-pagesize for power-of-2.
This commit is contained in:
parent
b558757cf1
commit
095cd25e23
@ -780,3 +780,10 @@ void mdbx_rthc_unlock(void);
|
|||||||
int mdbx_rthc_alloc(mdbx_thread_key_t *key, MDB_reader *begin, MDB_reader *end);
|
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_remove(mdbx_thread_key_t key);
|
||||||
void mdbx_rthc_cleanup(void);
|
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);
|
||||||
|
}
|
||||||
|
@ -3631,6 +3631,8 @@ int __cold mdbx_env_create(MDB_env **env) {
|
|||||||
e->me_lfd = INVALID_HANDLE_VALUE;
|
e->me_lfd = INVALID_HANDLE_VALUE;
|
||||||
e->me_pid = mdbx_getpid();
|
e->me_pid = mdbx_getpid();
|
||||||
mdbx_env_setup_limits(e, e->me_os_psize = mdbx_syspagesize());
|
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);
|
VALGRIND_CREATE_MEMPOOL(e, 0, 0);
|
||||||
e->me_signature = MDBX_ME_SIGNATURE;
|
e->me_signature = MDBX_ME_SIGNATURE;
|
||||||
*env = e;
|
*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. */
|
/* Open and/or initialize the lock region for the environment. */
|
||||||
static int __cold mdbx_env_setup_locks(MDB_env *env, char *lpath, int mode,
|
static int __cold mdbx_env_setup_locks(MDB_env *env, char *lpath, int mode,
|
||||||
int *excl) {
|
int *excl) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user