mdbx: more for ASAN.

Change-Id: I2bd0573cfe4c7822fa8f3cf94db60b684964a40d
This commit is contained in:
Leo Yuriev 2016-05-19 22:05:46 +03:00
parent 856f30b52c
commit f943bbf91c

13
mdb.c
View File

@ -1505,6 +1505,7 @@ mdb_page_malloc(MDB_txn *txn, unsigned num)
size_t size = env->me_psize;
MDB_page *np = env->me_dpages;
if (likely(num == 1 && np)) {
ASAN_UNPOISON_MEMORY_REGION(np, size);
VALGRIND_MEMPOOL_ALLOC(env, np, size);
VALGRIND_MAKE_MEM_DEFINED(&np->mp_next, sizeof(np->mp_next));
env->me_dpages = np->mp_next;
@ -1583,6 +1584,7 @@ mdb_kill_page(MDB_env *env, pgno_t pgno)
MDB_page *mp = (MDB_page *)(env->me_map + offs);
memset(&mp->mp_pb, 0x6F /* 'o', 111 */, env->me_psize - shift);
VALGRIND_MAKE_MEM_NOACCESS(&mp->mp_pb, env->me_psize - shift);
ASAN_POISON_MEMORY_REGION(&mp->mp_pb, env->me_psize - shift);
} else {
struct iovec iov[1];
iov[0].iov_len = env->me_psize - shift;
@ -1636,9 +1638,13 @@ mdb_page_loose(MDB_cursor *mc, MDB_page *mp)
}
if (loose) {
mdb_debug("loosen db %d page %zu", DDBI(mc), mp->mp_pgno);
if (unlikely(txn->mt_env->me_flags & MDBX_PAGEPERTURB))
MDB_page **link = &NEXT_LOOSE_PAGE(mp);
if (unlikely(txn->mt_env->me_flags & MDBX_PAGEPERTURB)) {
mdb_kill_page(txn->mt_env, pgno);
NEXT_LOOSE_PAGE(mp) = txn->mt_loose_pgs;
VALGRIND_MAKE_MEM_UNDEFINED(link, sizeof(MDB_page*));
ASAN_UNPOISON_MEMORY_REGION(link, sizeof(MDB_page*));
}
*link = txn->mt_loose_pgs;
txn->mt_loose_pgs = mp;
txn->mt_loose_count++;
mp->mp_flags |= P_LOOSE;
@ -2110,6 +2116,7 @@ mdb_page_alloc(MDB_cursor *mc, int num, MDB_page **mp, int flags)
txn->mt_loose_pgs = NEXT_LOOSE_PAGE(np);
txn->mt_loose_count--;
mdb_debug("db %d use loose page %zu", DDBI(mc), np->mp_pgno);
ASAN_UNPOISON_MEMORY_REGION(np, env->me_psize);
*mp = np;
return MDB_SUCCESS;
}
@ -2361,6 +2368,7 @@ done:
np = (MDB_page *)(env->me_map + env->me_psize * pgno);
/* LY: reset no-access flag from mdb_kill_page() */
VALGRIND_MAKE_MEM_UNDEFINED(np, env->me_psize * num);
ASAN_UNPOISON_MEMORY_REGION(np, env->me_psize * num);
} else {
if (unlikely(!(np = mdb_page_malloc(txn, num)))) {
rc = ENOMEM;
@ -5110,6 +5118,7 @@ mdbx_env_close_ex(MDB_env *env, int dont_sync)
VALGRIND_DESTROY_MEMPOOL(env);
while ((dp = env->me_dpages) != NULL) {
ASAN_UNPOISON_MEMORY_REGION(&dp->mp_next, sizeof(dp->mp_next));
VALGRIND_MAKE_MEM_DEFINED(&dp->mp_next, sizeof(dp->mp_next));
env->me_dpages = dp->mp_next;
free(dp);