mdbx: rename internal functions, types and macros (to be closer to MithrilDB).

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2022-08-11 01:03:15 +03:00
parent 096d6a9bd6
commit 18e557c6e8
15 changed files with 3754 additions and 3933 deletions

6521
src/core.c

File diff suppressed because it is too large Load Diff

View File

@ -285,15 +285,15 @@ typedef union {
#ifndef __cplusplus #ifndef __cplusplus
#ifdef MDBX_HAVE_C11ATOMICS #ifdef MDBX_HAVE_C11ATOMICS
#define mdbx_memory_fence(order, write) \ #define osal_memory_fence(order, write) \
atomic_thread_fence((write) ? mo_c11_store(order) : mo_c11_load(order)) atomic_thread_fence((write) ? mo_c11_store(order) : mo_c11_load(order))
#else /* MDBX_HAVE_C11ATOMICS */ #else /* MDBX_HAVE_C11ATOMICS */
#define mdbx_memory_fence(order, write) \ #define osal_memory_fence(order, write) \
do { \ do { \
mdbx_compiler_barrier(); \ osal_compiler_barrier(); \
if (write && order > (MDBX_CPU_WRITEBACK_INCOHERENT ? mo_Relaxed \ if (write && order > (MDBX_CPU_WRITEBACK_INCOHERENT ? mo_Relaxed \
: mo_AcquireRelease)) \ : mo_AcquireRelease)) \
mdbx_memory_barrier(); \ osal_memory_barrier(); \
} while (0) } while (0)
#endif /* MDBX_HAVE_C11ATOMICS */ #endif /* MDBX_HAVE_C11ATOMICS */
@ -328,9 +328,9 @@ atomic_store32(MDBX_atomic_uint32_t *p, const uint32_t value,
atomic_store_explicit(MDBX_c11a_rw(uint32_t, p), value, mo_c11_store(order)); atomic_store_explicit(MDBX_c11a_rw(uint32_t, p), value, mo_c11_store(order));
#else /* MDBX_HAVE_C11ATOMICS */ #else /* MDBX_HAVE_C11ATOMICS */
if (order != mo_Relaxed) if (order != mo_Relaxed)
mdbx_compiler_barrier(); osal_compiler_barrier();
p->weak = value; p->weak = value;
mdbx_memory_fence(order, true); osal_memory_fence(order, true);
#endif /* MDBX_HAVE_C11ATOMICS */ #endif /* MDBX_HAVE_C11ATOMICS */
return value; return value;
} }
@ -344,10 +344,10 @@ atomic_load32(const MDBX_atomic_uint32_t *p, enum MDBX_memory_order order) {
assert(atomic_is_lock_free(MDBX_c11a_ro(uint32_t, p))); assert(atomic_is_lock_free(MDBX_c11a_ro(uint32_t, p)));
return atomic_load_explicit(MDBX_c11a_ro(uint32_t, p), mo_c11_load(order)); return atomic_load_explicit(MDBX_c11a_ro(uint32_t, p), mo_c11_load(order));
#else /* MDBX_HAVE_C11ATOMICS */ #else /* MDBX_HAVE_C11ATOMICS */
mdbx_memory_fence(order, false); osal_memory_fence(order, false);
const uint32_t value = p->weak; const uint32_t value = p->weak;
if (order != mo_Relaxed) if (order != mo_Relaxed)
mdbx_compiler_barrier(); osal_compiler_barrier();
return value; return value;
#endif /* MDBX_HAVE_C11ATOMICS */ #endif /* MDBX_HAVE_C11ATOMICS */
} }
@ -584,17 +584,17 @@ typedef struct {
wops; /* Number of explicit write operations (not a pages) to a disk */ wops; /* Number of explicit write operations (not a pages) to a disk */
MDBX_atomic_uint64_t MDBX_atomic_uint64_t
gcrtime; /* Time spending for reading/searching GC (aka FreeDB). The gcrtime; /* Time spending for reading/searching GC (aka FreeDB). The
unit/scale is platform-depended, see mdbx_osal_monotime(). */ unit/scale is platform-depended, see osal_monotime(). */
} MDBX_pgop_stat_t; } MDBX_pgop_stat_t;
#endif /* MDBX_ENABLE_PGOP_STAT */ #endif /* MDBX_ENABLE_PGOP_STAT */
#if MDBX_LOCKING == MDBX_LOCKING_WIN32FILES #if MDBX_LOCKING == MDBX_LOCKING_WIN32FILES
#define MDBX_CLOCK_SIGN UINT32_C(0xF10C) #define MDBX_CLOCK_SIGN UINT32_C(0xF10C)
typedef void mdbx_ipclock_t; typedef void osal_ipclock_t;
#elif MDBX_LOCKING == MDBX_LOCKING_SYSV #elif MDBX_LOCKING == MDBX_LOCKING_SYSV
#define MDBX_CLOCK_SIGN UINT32_C(0xF18D) #define MDBX_CLOCK_SIGN UINT32_C(0xF18D)
typedef mdbx_pid_t mdbx_ipclock_t; typedef mdbx_pid_t osal_ipclock_t;
#ifndef EOWNERDEAD #ifndef EOWNERDEAD
#define EOWNERDEAD MDBX_RESULT_TRUE #define EOWNERDEAD MDBX_RESULT_TRUE
#endif #endif
@ -602,17 +602,17 @@ typedef mdbx_pid_t mdbx_ipclock_t;
#elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \ #elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \
MDBX_LOCKING == MDBX_LOCKING_POSIX2008 MDBX_LOCKING == MDBX_LOCKING_POSIX2008
#define MDBX_CLOCK_SIGN UINT32_C(0x8017) #define MDBX_CLOCK_SIGN UINT32_C(0x8017)
typedef pthread_mutex_t mdbx_ipclock_t; typedef pthread_mutex_t osal_ipclock_t;
#elif MDBX_LOCKING == MDBX_LOCKING_POSIX1988 #elif MDBX_LOCKING == MDBX_LOCKING_POSIX1988
#define MDBX_CLOCK_SIGN UINT32_C(0xFC29) #define MDBX_CLOCK_SIGN UINT32_C(0xFC29)
typedef sem_t mdbx_ipclock_t; typedef sem_t osal_ipclock_t;
#else #else
#error "FIXME" #error "FIXME"
#endif /* MDBX_LOCKING */ #endif /* MDBX_LOCKING */
#if MDBX_LOCKING > MDBX_LOCKING_SYSV && !defined(__cplusplus) #if MDBX_LOCKING > MDBX_LOCKING_SYSV && !defined(__cplusplus)
MDBX_INTERNAL_FUNC int mdbx_ipclock_stub(mdbx_ipclock_t *ipc); MDBX_INTERNAL_FUNC int osal_ipclock_stub(osal_ipclock_t *ipc);
MDBX_INTERNAL_FUNC int mdbx_ipclock_destroy(mdbx_ipclock_t *ipc); MDBX_INTERNAL_FUNC int osal_ipclock_destroy(osal_ipclock_t *ipc);
#endif /* MDBX_LOCKING */ #endif /* MDBX_LOCKING */
/* Reader Lock Table /* Reader Lock Table
@ -729,7 +729,7 @@ typedef struct MDBX_lockinfo {
/* Write transaction lock. */ /* Write transaction lock. */
#if MDBX_LOCKING > 0 #if MDBX_LOCKING > 0
mdbx_ipclock_t mti_wlock; osal_ipclock_t mti_wlock;
#endif /* MDBX_LOCKING > 0 */ #endif /* MDBX_LOCKING > 0 */
atomic_txnid_t mti_oldest_reader; atomic_txnid_t mti_oldest_reader;
@ -755,7 +755,7 @@ typedef struct MDBX_lockinfo {
/* Readeaders registration lock. */ /* Readeaders registration lock. */
#if MDBX_LOCKING > 0 #if MDBX_LOCKING > 0
mdbx_ipclock_t mti_rlock; osal_ipclock_t mti_rlock;
#endif /* MDBX_LOCKING > 0 */ #endif /* MDBX_LOCKING > 0 */
/* The number of slots that have been used in the reader table. /* The number of slots that have been used in the reader table.
@ -924,7 +924,7 @@ struct MDBX_txn {
#define MDBX_TXN_RO_BEGIN_FLAGS (MDBX_TXN_RDONLY | MDBX_TXN_RDONLY_PREPARE) #define MDBX_TXN_RO_BEGIN_FLAGS (MDBX_TXN_RDONLY | MDBX_TXN_RDONLY_PREPARE)
#define MDBX_TXN_RW_BEGIN_FLAGS \ #define MDBX_TXN_RW_BEGIN_FLAGS \
(MDBX_TXN_NOMETASYNC | MDBX_TXN_NOSYNC | MDBX_TXN_TRY) (MDBX_TXN_NOMETASYNC | MDBX_TXN_NOSYNC | MDBX_TXN_TRY)
/* Additional flag for mdbx_sync_locked() */ /* Additional flag for sync_locked() */
#define MDBX_SHRINK_ALLOWED UINT32_C(0x40000000) #define MDBX_SHRINK_ALLOWED UINT32_C(0x40000000)
#define TXN_FLAGS \ #define TXN_FLAGS \
@ -1123,11 +1123,11 @@ struct MDBX_env {
#define MDBX_DEPRECATED_COALESCE UINT32_C(0x2000000) #define MDBX_DEPRECATED_COALESCE UINT32_C(0x2000000)
#define ENV_INTERNAL_FLAGS (MDBX_FATAL_ERROR | MDBX_ENV_ACTIVE | MDBX_ENV_TXKEY) #define ENV_INTERNAL_FLAGS (MDBX_FATAL_ERROR | MDBX_ENV_ACTIVE | MDBX_ENV_TXKEY)
uint32_t me_flags; uint32_t me_flags;
mdbx_mmap_t me_dxb_mmap; /* The main data file */ osal_mmap_t me_dxb_mmap; /* The main data file */
#define me_map me_dxb_mmap.dxb #define me_map me_dxb_mmap.dxb
#define me_lazy_fd me_dxb_mmap.fd #define me_lazy_fd me_dxb_mmap.fd
mdbx_filehandle_t me_dsync_fd; mdbx_filehandle_t me_dsync_fd;
mdbx_mmap_t me_lck_mmap; /* The lock file */ osal_mmap_t me_lck_mmap; /* The lock file */
#define me_lfd me_lck_mmap.fd #define me_lfd me_lck_mmap.fd
struct MDBX_lockinfo *me_lck; struct MDBX_lockinfo *me_lck;
@ -1138,11 +1138,11 @@ struct MDBX_env {
uint16_t me_merge_threshold, uint16_t me_merge_threshold,
me_merge_threshold_gc; /* pages emptier than this are candidates for me_merge_threshold_gc; /* pages emptier than this are candidates for
merging */ merging */
unsigned me_os_psize; /* OS page size, from mdbx_syspagesize() */ unsigned me_os_psize; /* OS page size, from osal_syspagesize() */
unsigned me_maxreaders; /* size of the reader table */ unsigned me_maxreaders; /* size of the reader table */
MDBX_dbi me_maxdbs; /* size of the DB table */ MDBX_dbi me_maxdbs; /* size of the DB table */
uint32_t me_pid; /* process ID of this env */ uint32_t me_pid; /* process ID of this env */
mdbx_thread_key_t me_txkey; /* thread-key for readers */ osal_thread_key_t me_txkey; /* thread-key for readers */
pathchar_t *me_pathname; /* path to the DB files */ pathchar_t *me_pathname; /* path to the DB files */
void *me_pbuf; /* scratch area for DUPSORT put() */ void *me_pbuf; /* scratch area for DUPSORT put() */
MDBX_txn *me_txn0; /* preallocated write transaction */ MDBX_txn *me_txn0; /* preallocated write transaction */
@ -1198,7 +1198,7 @@ struct MDBX_env {
/* --------------------------------------------------- mostly volatile part */ /* --------------------------------------------------- mostly volatile part */
MDBX_txn *me_txn; /* current write transaction */ MDBX_txn *me_txn; /* current write transaction */
mdbx_fastmutex_t me_dbi_lock; osal_fastmutex_t me_dbi_lock;
#if MDBX_CACHE_METAPTR #if MDBX_CACHE_METAPTR
volatile const MDBX_meta *cache_last_meta; volatile const MDBX_meta *cache_last_meta;
volatile const MDBX_meta *cache_steady_meta; volatile const MDBX_meta *cache_steady_meta;
@ -1211,11 +1211,11 @@ struct MDBX_env {
MDBX_PNL me_retired_pages; MDBX_PNL me_retired_pages;
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
MDBX_srwlock me_remap_guard; osal_srwlock_t me_remap_guard;
/* Workaround for LockFileEx and WriteFile multithread bug */ /* Workaround for LockFileEx and WriteFile multithread bug */
CRITICAL_SECTION me_windowsbug_lock; CRITICAL_SECTION me_windowsbug_lock;
#else #else
mdbx_fastmutex_t me_remap_guard; osal_fastmutex_t me_remap_guard;
#endif #endif
/* -------------------------------------------------------------- debugging */ /* -------------------------------------------------------------- debugging */
@ -1250,142 +1250,138 @@ struct MDBX_env {
#define MDBX_RUNTIME_FLAGS_INIT \ #define MDBX_RUNTIME_FLAGS_INIT \
((MDBX_DEBUG) > 0) * MDBX_DBG_ASSERT + ((MDBX_DEBUG) > 1) * MDBX_DBG_AUDIT ((MDBX_DEBUG) > 0) * MDBX_DBG_ASSERT + ((MDBX_DEBUG) > 1) * MDBX_DBG_AUDIT
extern uint8_t mdbx_runtime_flags; extern uint8_t runtime_flags;
extern uint8_t mdbx_loglevel; extern uint8_t loglevel;
extern MDBX_debug_func *mdbx_debug_logger; extern MDBX_debug_func *debug_logger;
MDBX_MAYBE_UNUSED static __inline void mdbx_jitter4testing(bool tiny) { MDBX_MAYBE_UNUSED static __inline void jitter4testing(bool tiny) {
#if MDBX_DEBUG #if MDBX_DEBUG
if (MDBX_DBG_JITTER & mdbx_runtime_flags) if (MDBX_DBG_JITTER & runtime_flags)
mdbx_osal_jitter(tiny); osal_jitter(tiny);
#else #else
(void)tiny; (void)tiny;
#endif #endif
} }
MDBX_INTERNAL_FUNC void MDBX_PRINTF_ARGS(4, 5) MDBX_INTERNAL_FUNC void MDBX_PRINTF_ARGS(4, 5)
mdbx_debug_log(int level, const char *function, int line, const char *fmt, debug_log(int level, const char *function, int line, const char *fmt, ...)
...) MDBX_PRINTF_ARGS(4, 5); MDBX_PRINTF_ARGS(4, 5);
MDBX_INTERNAL_FUNC void mdbx_debug_log_va(int level, const char *function, MDBX_INTERNAL_FUNC void debug_log_va(int level, const char *function, int line,
int line, const char *fmt, const char *fmt, va_list args);
va_list args);
#if MDBX_DEBUG #if MDBX_DEBUG
#define mdbx_log_enabled(msg) unlikely(msg <= mdbx_loglevel) #define LOG_ENABLED(msg) unlikely(msg <= loglevel)
#define mdbx_audit_enabled() unlikely((mdbx_runtime_flags & MDBX_DBG_AUDIT)) #define AUDIT_ENABLED() unlikely((runtime_flags & MDBX_DBG_AUDIT))
#else /* MDBX_DEBUG */ #else /* MDBX_DEBUG */
#define mdbx_log_enabled(msg) (msg < MDBX_LOG_VERBOSE && msg <= mdbx_loglevel) #define LOG_ENABLED(msg) (msg < MDBX_LOG_VERBOSE && msg <= loglevel)
#define mdbx_audit_enabled() (0) #define AUDIT_ENABLED() (0)
#endif /* MDBX_DEBUG */ #endif /* MDBX_DEBUG */
#if MDBX_FORCE_ASSERTIONS #if MDBX_FORCE_ASSERTIONS
#define mdbx_assert_enabled() (1) #define ASSERT_ENABLED() (1)
#elif MDBX_DEBUG #elif MDBX_DEBUG
#define mdbx_assert_enabled() likely((mdbx_runtime_flags & MDBX_DBG_ASSERT)) #define ASSERT_ENABLED() likely((runtime_flags & MDBX_DBG_ASSERT))
#else #else
#define mdbx_assert_enabled() (0) #define ASSERT_ENABLED() (0)
#endif /* assertions */ #endif /* assertions */
#define mdbx_debug_extra(fmt, ...) \ #define DEBUG_EXTRA(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_EXTRA)) \ if (LOG_ENABLED(MDBX_LOG_EXTRA)) \
mdbx_debug_log(MDBX_LOG_EXTRA, __func__, __LINE__, fmt, __VA_ARGS__); \ debug_log(MDBX_LOG_EXTRA, __func__, __LINE__, fmt, __VA_ARGS__); \
} while (0) } while (0)
#define mdbx_debug_extra_print(fmt, ...) \ #define DEBUG_EXTRA_PRINT(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_EXTRA)) \ if (LOG_ENABLED(MDBX_LOG_EXTRA)) \
mdbx_debug_log(MDBX_LOG_EXTRA, NULL, 0, fmt, __VA_ARGS__); \ debug_log(MDBX_LOG_EXTRA, NULL, 0, fmt, __VA_ARGS__); \
} while (0) } while (0)
#define mdbx_trace(fmt, ...) \ #define TRACE(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_TRACE)) \ if (LOG_ENABLED(MDBX_LOG_TRACE)) \
mdbx_debug_log(MDBX_LOG_TRACE, __func__, __LINE__, fmt "\n", \ debug_log(MDBX_LOG_TRACE, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
__VA_ARGS__); \
} while (0) } while (0)
#define mdbx_debug(fmt, ...) \ #define DEBUG(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_DEBUG)) \ if (LOG_ENABLED(MDBX_LOG_DEBUG)) \
mdbx_debug_log(MDBX_LOG_DEBUG, __func__, __LINE__, fmt "\n", \ debug_log(MDBX_LOG_DEBUG, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
__VA_ARGS__); \
} while (0) } while (0)
#define mdbx_verbose(fmt, ...) \ #define VERBOSE(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_VERBOSE)) \ if (LOG_ENABLED(MDBX_LOG_VERBOSE)) \
mdbx_debug_log(MDBX_LOG_VERBOSE, __func__, __LINE__, fmt "\n", \ debug_log(MDBX_LOG_VERBOSE, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
__VA_ARGS__); \
} while (0) } while (0)
#define mdbx_notice(fmt, ...) \ #define NOTICE(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_NOTICE)) \ if (LOG_ENABLED(MDBX_LOG_NOTICE)) \
mdbx_debug_log(MDBX_LOG_NOTICE, __func__, __LINE__, fmt "\n", \ debug_log(MDBX_LOG_NOTICE, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
__VA_ARGS__); \
} while (0) } while (0)
#define mdbx_warning(fmt, ...) \ #define WARNING(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_WARN)) \ if (LOG_ENABLED(MDBX_LOG_WARN)) \
mdbx_debug_log(MDBX_LOG_WARN, __func__, __LINE__, fmt "\n", \ debug_log(MDBX_LOG_WARN, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
__VA_ARGS__); \
} while (0) } while (0)
#define mdbx_error(fmt, ...) \ #undef ERROR /* wingdi.h \
Yeah, morons from M$ put such definition to the public header. */
#define ERROR(fmt, ...) \
do { \ do { \
if (mdbx_log_enabled(MDBX_LOG_ERROR)) \ if (LOG_ENABLED(MDBX_LOG_ERROR)) \
mdbx_debug_log(MDBX_LOG_ERROR, __func__, __LINE__, fmt "\n", \ debug_log(MDBX_LOG_ERROR, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
__VA_ARGS__); \
} while (0) } while (0)
#define mdbx_fatal(fmt, ...) \ #define FATAL(fmt, ...) \
mdbx_debug_log(MDBX_LOG_FATAL, __func__, __LINE__, fmt "\n", __VA_ARGS__); debug_log(MDBX_LOG_FATAL, __func__, __LINE__, fmt "\n", __VA_ARGS__);
#define mdbx_ensure_msg(env, expr, msg) \ #define ENSURE_MSG(env, expr, msg) \
do { \ do { \
if (unlikely(!(expr))) \ if (unlikely(!(expr))) \
mdbx_assert_fail(env, msg, __func__, __LINE__); \ mdbx_assert_fail(env, msg, __func__, __LINE__); \
} while (0) } while (0)
#define mdbx_ensure(env, expr) mdbx_ensure_msg(env, expr, #expr) #define ENSURE(env, expr) ENSURE_MSG(env, expr, #expr)
/* assert(3) variant in environment context */ /* assert(3) variant in environment context */
#define mdbx_assert(env, expr) \ #define eASSERT(env, expr) \
do { \ do { \
if (mdbx_assert_enabled()) \ if (ASSERT_ENABLED()) \
mdbx_ensure(env, expr); \ ENSURE(env, expr); \
} while (0) } while (0)
/* assert(3) variant in cursor context */ /* assert(3) variant in cursor context */
#define mdbx_cassert(mc, expr) mdbx_assert((mc)->mc_txn->mt_env, expr) #define cASSERT(mc, expr) eASSERT((mc)->mc_txn->mt_env, expr)
/* assert(3) variant in transaction context */ /* assert(3) variant in transaction context */
#define mdbx_tassert(txn, expr) mdbx_assert((txn)->mt_env, expr) #define tASSERT(txn, expr) eASSERT((txn)->mt_env, expr)
#ifndef xMDBX_TOOLS /* Avoid using internal mdbx_assert() */ #ifndef xMDBX_TOOLS /* Avoid using internal eASSERT() */
#undef assert #undef assert
#define assert(expr) mdbx_assert(NULL, expr) #define assert(expr) eASSERT(NULL, expr)
#endif #endif
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Cache coherence and mmap invalidation */ /* Cache coherence and mmap invalidation */
#if MDBX_CPU_WRITEBACK_INCOHERENT #if MDBX_CPU_WRITEBACK_INCOHERENT
#define mdbx_flush_incoherent_cpu_writeback() mdbx_memory_barrier() #define osal_flush_incoherent_cpu_writeback() osal_memory_barrier()
#else #else
#define mdbx_flush_incoherent_cpu_writeback() mdbx_compiler_barrier() #define osal_flush_incoherent_cpu_writeback() osal_compiler_barrier()
#endif /* MDBX_CPU_WRITEBACK_INCOHERENT */ #endif /* MDBX_CPU_WRITEBACK_INCOHERENT */
MDBX_MAYBE_UNUSED static __inline void MDBX_MAYBE_UNUSED static __inline void
mdbx_flush_incoherent_mmap(void *addr, size_t nbytes, const intptr_t pagesize) { osal_flush_incoherent_mmap(void *addr, size_t nbytes, const intptr_t pagesize) {
#if MDBX_MMAP_INCOHERENT_FILE_WRITE #if MDBX_MMAP_INCOHERENT_FILE_WRITE
char *const begin = (char *)(-pagesize & (intptr_t)addr); char *const begin = (char *)(-pagesize & (intptr_t)addr);
char *const end = char *const end =
(char *)(-pagesize & (intptr_t)((char *)addr + nbytes + pagesize - 1)); (char *)(-pagesize & (intptr_t)((char *)addr + nbytes + pagesize - 1));
int err = msync(begin, end - begin, MS_SYNC | MS_INVALIDATE) ? errno : 0; int err = msync(begin, end - begin, MS_SYNC | MS_INVALIDATE) ? errno : 0;
mdbx_assert(nullptr, err == 0); eASSERT(nullptr, err == 0);
(void)err; (void)err;
#else #else
(void)pagesize; (void)pagesize;
@ -1410,15 +1406,15 @@ mdbx_flush_incoherent_mmap(void *addr, size_t nbytes, const intptr_t pagesize) {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Internal prototypes */ /* Internal prototypes */
MDBX_INTERNAL_FUNC int mdbx_cleanup_dead_readers(MDBX_env *env, int rlocked, MDBX_INTERNAL_FUNC int cleanup_dead_readers(MDBX_env *env, int rlocked,
int *dead); int *dead);
MDBX_INTERNAL_FUNC int mdbx_rthc_alloc(mdbx_thread_key_t *key, MDBX_INTERNAL_FUNC int rthc_alloc(osal_thread_key_t *key, MDBX_reader *begin,
MDBX_reader *begin, MDBX_reader *end); MDBX_reader *end);
MDBX_INTERNAL_FUNC void mdbx_rthc_remove(const mdbx_thread_key_t key); MDBX_INTERNAL_FUNC void rthc_remove(const osal_thread_key_t key);
MDBX_INTERNAL_FUNC void mdbx_rthc_global_init(void); MDBX_INTERNAL_FUNC void global_ctor(void);
MDBX_INTERNAL_FUNC void mdbx_rthc_global_dtor(void); MDBX_INTERNAL_FUNC void global_dtor(void);
MDBX_INTERNAL_FUNC void mdbx_rthc_thread_dtor(void *ptr); MDBX_INTERNAL_FUNC void thread_dtor(void *ptr);
#endif /* !__cplusplus */ #endif /* !__cplusplus */
@ -1648,14 +1644,14 @@ MDBX_MAYBE_UNUSED static void static_checks(void) {
#define MDBX_ASAN_POISON_MEMORY_REGION(addr, size) \ #define MDBX_ASAN_POISON_MEMORY_REGION(addr, size) \
do { \ do { \
mdbx_trace("POISON_MEMORY_REGION(%p, %zu) at %u", (void *)(addr), \ TRACE("POISON_MEMORY_REGION(%p, %zu) at %u", (void *)(addr), \
(size_t)(size), __LINE__); \ (size_t)(size), __LINE__); \
ASAN_POISON_MEMORY_REGION(addr, size); \ ASAN_POISON_MEMORY_REGION(addr, size); \
} while (0) } while (0)
#define MDBX_ASAN_UNPOISON_MEMORY_REGION(addr, size) \ #define MDBX_ASAN_UNPOISON_MEMORY_REGION(addr, size) \
do { \ do { \
mdbx_trace("UNPOISON_MEMORY_REGION(%p, %zu) at %u", (void *)(addr), \ TRACE("UNPOISON_MEMORY_REGION(%p, %zu) at %u", (void *)(addr), \
(size_t)(size), __LINE__); \ (size_t)(size), __LINE__); \
ASAN_UNPOISON_MEMORY_REGION(addr, size); \ ASAN_UNPOISON_MEMORY_REGION(addr, size); \
} while (0) } while (0)

View File

@ -28,7 +28,7 @@
#include <sys/utsname.h> #include <sys/utsname.h>
#ifndef xMDBX_ALLOY #ifndef xMDBX_ALLOY
uint32_t mdbx_linux_kernel_version; uint32_t linux_kernel_version;
bool mdbx_RunningOnWSL1; bool mdbx_RunningOnWSL1;
#endif /* xMDBX_ALLOY */ #endif /* xMDBX_ALLOY */
@ -43,7 +43,7 @@ __cold static uint8_t probe_for_WSL(const char *tag) {
if (WSL || wsl || strcasestr(tag, "Microsoft")) if (WSL || wsl || strcasestr(tag, "Microsoft"))
/* Expecting no new kernel within WSL1, either it will explicitly /* Expecting no new kernel within WSL1, either it will explicitly
* marked by an appropriate WSL-version hint. */ * marked by an appropriate WSL-version hint. */
return (mdbx_linux_kernel_version < /* 4.19.x */ 0x04130000) ? 1 : 2; return (linux_kernel_version < /* 4.19.x */ 0x04130000) ? 1 : 2;
return 0; return 0;
} }
@ -76,7 +76,7 @@ mdbx_global_constructor(void) {
if (number > 0) { if (number > 0) {
if (number > 255) if (number > 255)
number = 255; number = 255;
mdbx_linux_kernel_version += number << (24 - i * 8); linux_kernel_version += number << (24 - i * 8);
} }
++i; ++i;
} else { } else {
@ -96,13 +96,13 @@ mdbx_global_constructor(void) {
} }
#endif /* Linux */ #endif /* Linux */
mdbx_rthc_global_init(); global_ctor();
} }
MDBX_EXCLUDE_FOR_GPROF MDBX_EXCLUDE_FOR_GPROF
__cold static __attribute__((__destructor__)) void __cold static __attribute__((__destructor__)) void
mdbx_global_destructor(void) { mdbx_global_destructor(void) {
mdbx_rthc_global_dtor(); global_dtor();
#ifdef ENABLE_GPROF #ifdef ENABLE_GPROF
if (!&__gmon_start__) if (!&__gmon_start__)
_mcleanup(); _mcleanup();
@ -118,15 +118,15 @@ mdbx_global_destructor(void) {
* размещаются совместно используемые posix-мьютексы (futex). Посредством * размещаются совместно используемые posix-мьютексы (futex). Посредством
* этих мьютексов (см struct MDBX_lockinfo) реализуются: * этих мьютексов (см struct MDBX_lockinfo) реализуются:
* - Блокировка таблицы читателей для регистрации, * - Блокировка таблицы читателей для регистрации,
* т.е. функции mdbx_rdt_lock() и mdbx_rdt_unlock(). * т.е. функции osal_rdt_lock() и osal_rdt_unlock().
* - Блокировка БД для пишущих транзакций, * - Блокировка БД для пишущих транзакций,
* т.е. функции mdbx_txn_lock() и mdbx_txn_unlock(). * т.е. функции mdbx_txn_lock() и mdbx_txn_unlock().
* *
* Остальной функционал реализуется отдельно посредством файловых блокировок: * Остальной функционал реализуется отдельно посредством файловых блокировок:
* - Первоначальный захват БД в режиме exclusive/shared и последующий перевод * - Первоначальный захват БД в режиме exclusive/shared и последующий перевод
* в операционный режим, функции mdbx_lck_seize() и mdbx_lck_downgrade(). * в операционный режим, функции osal_lck_seize() и osal_lck_downgrade().
* - Проверка присутствие процессов-читателей, * - Проверка присутствие процессов-читателей,
* т.е. функции mdbx_rpid_set(), mdbx_rpid_clear() и mdbx_rpid_check(). * т.е. функции osal_rpid_set(), osal_rpid_clear() и osal_rpid_check().
* *
* Для блокировки файлов используется fcntl(F_SETLK), так как: * Для блокировки файлов используется fcntl(F_SETLK), так как:
* - lockf() оперирует только эксклюзивной блокировкой и требует * - lockf() оперирует только эксклюзивной блокировкой и требует
@ -170,9 +170,9 @@ mdbx_global_destructor(void) {
static int op_setlk, op_setlkw, op_getlk; static int op_setlk, op_setlkw, op_getlk;
__cold static void choice_fcntl(void) { __cold static void choice_fcntl(void) {
assert(!op_setlk && !op_setlkw && !op_getlk); assert(!op_setlk && !op_setlkw && !op_getlk);
if ((mdbx_runtime_flags & MDBX_DBG_LEGACY_MULTIOPEN) == 0 if ((runtime_flags & MDBX_DBG_LEGACY_MULTIOPEN) == 0
#if defined(__linux__) || defined(__gnu_linux__) #if defined(__linux__) || defined(__gnu_linux__)
&& mdbx_linux_kernel_version > && linux_kernel_version >
0x030f0000 /* OFD locks are available since 3.15, but engages here 0x030f0000 /* OFD locks are available since 3.15, but engages here
only for 3.16 and later kernels (i.e. LTS) because only for 3.16 and later kernels (i.e. LTS) because
of reliability reasons */ of reliability reasons */
@ -207,7 +207,7 @@ static int lck_op(const mdbx_filehandle_t fd, int cmd, const int lck,
"The bitness of system `off_t` type is mismatch. Please " "The bitness of system `off_t` type is mismatch. Please "
"fix build and/or NDK configuration."); "fix build and/or NDK configuration.");
#endif /* Android */ #endif /* Android */
mdbx_jitter4testing(true); jitter4testing(true);
assert(offset >= 0 && len > 0); assert(offset >= 0 && len > 0);
assert((uint64_t)offset < (uint64_t)INT64_MAX && assert((uint64_t)offset < (uint64_t)INT64_MAX &&
(uint64_t)len < (uint64_t)INT64_MAX && (uint64_t)len < (uint64_t)INT64_MAX &&
@ -230,7 +230,7 @@ static int lck_op(const mdbx_filehandle_t fd, int cmd, const int lck,
lock_op.l_start = offset; lock_op.l_start = offset;
lock_op.l_len = len; lock_op.l_len = len;
int rc = fcntl(fd, cmd, &lock_op); int rc = fcntl(fd, cmd, &lock_op);
mdbx_jitter4testing(true); jitter4testing(true);
if (rc != -1) { if (rc != -1) {
if (cmd == op_getlk) { if (cmd == op_getlk) {
/* Checks reader by pid. Returns: /* Checks reader by pid. Returns:
@ -265,7 +265,7 @@ static int lck_op(const mdbx_filehandle_t fd, int cmd, const int lck,
} }
} }
MDBX_INTERNAL_FUNC int mdbx_lockfile(mdbx_filehandle_t fd, bool wait) { MDBX_INTERNAL_FUNC int osal_lockfile(mdbx_filehandle_t fd, bool wait) {
#if MDBX_USE_OFDLOCKS #if MDBX_USE_OFDLOCKS
if (unlikely(op_setlk == 0)) if (unlikely(op_setlk == 0))
choice_fcntl(); choice_fcntl();
@ -273,21 +273,21 @@ MDBX_INTERNAL_FUNC int mdbx_lockfile(mdbx_filehandle_t fd, bool wait) {
return lck_op(fd, wait ? op_setlkw : op_setlk, F_WRLCK, 0, OFF_T_MAX); return lck_op(fd, wait ? op_setlkw : op_setlk, F_WRLCK, 0, OFF_T_MAX);
} }
MDBX_INTERNAL_FUNC int mdbx_rpid_set(MDBX_env *env) { MDBX_INTERNAL_FUNC int osal_rpid_set(MDBX_env *env) {
assert(env->me_lfd != INVALID_HANDLE_VALUE); assert(env->me_lfd != INVALID_HANDLE_VALUE);
assert(env->me_pid > 0); assert(env->me_pid > 0);
if (unlikely(mdbx_getpid() != env->me_pid)) if (unlikely(osal_getpid() != env->me_pid))
return MDBX_PANIC; return MDBX_PANIC;
return lck_op(env->me_lfd, op_setlk, F_WRLCK, env->me_pid, 1); return lck_op(env->me_lfd, op_setlk, F_WRLCK, env->me_pid, 1);
} }
MDBX_INTERNAL_FUNC int mdbx_rpid_clear(MDBX_env *env) { MDBX_INTERNAL_FUNC int osal_rpid_clear(MDBX_env *env) {
assert(env->me_lfd != INVALID_HANDLE_VALUE); assert(env->me_lfd != INVALID_HANDLE_VALUE);
assert(env->me_pid > 0); assert(env->me_pid > 0);
return lck_op(env->me_lfd, op_setlk, F_UNLCK, env->me_pid, 1); return lck_op(env->me_lfd, op_setlk, F_UNLCK, env->me_pid, 1);
} }
MDBX_INTERNAL_FUNC int mdbx_rpid_check(MDBX_env *env, uint32_t pid) { MDBX_INTERNAL_FUNC int osal_rpid_check(MDBX_env *env, uint32_t pid) {
assert(env->me_lfd != INVALID_HANDLE_VALUE); assert(env->me_lfd != INVALID_HANDLE_VALUE);
assert(pid > 0); assert(pid > 0);
return lck_op(env->me_lfd, op_getlk, F_WRLCK, pid, 1); return lck_op(env->me_lfd, op_getlk, F_WRLCK, pid, 1);
@ -296,7 +296,7 @@ MDBX_INTERNAL_FUNC int mdbx_rpid_check(MDBX_env *env, uint32_t pid) {
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if MDBX_LOCKING > MDBX_LOCKING_SYSV #if MDBX_LOCKING > MDBX_LOCKING_SYSV
MDBX_INTERNAL_FUNC int mdbx_ipclock_stub(mdbx_ipclock_t *ipc) { MDBX_INTERNAL_FUNC int osal_ipclock_stub(osal_ipclock_t *ipc) {
#if MDBX_LOCKING == MDBX_LOCKING_POSIX1988 #if MDBX_LOCKING == MDBX_LOCKING_POSIX1988
return sem_init(ipc, false, 1) ? errno : 0; return sem_init(ipc, false, 1) ? errno : 0;
#elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \ #elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \
@ -307,7 +307,7 @@ MDBX_INTERNAL_FUNC int mdbx_ipclock_stub(mdbx_ipclock_t *ipc) {
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_ipclock_destroy(mdbx_ipclock_t *ipc) { MDBX_INTERNAL_FUNC int osal_ipclock_destroy(osal_ipclock_t *ipc) {
#if MDBX_LOCKING == MDBX_LOCKING_POSIX1988 #if MDBX_LOCKING == MDBX_LOCKING_POSIX1988
return sem_destroy(ipc) ? errno : 0; return sem_destroy(ipc) ? errno : 0;
#elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \ #elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \
@ -325,7 +325,7 @@ static int check_fstat(MDBX_env *env) {
int rc = MDBX_SUCCESS; int rc = MDBX_SUCCESS;
if (fstat(env->me_lazy_fd, &st)) { if (fstat(env->me_lazy_fd, &st)) {
rc = errno; rc = errno;
mdbx_error("fstat(%s), err %d", "DXB", rc); ERROR("fstat(%s), err %d", "DXB", rc);
return rc; return rc;
} }
@ -335,15 +335,14 @@ static int check_fstat(MDBX_env *env) {
#else #else
rc = EPERM; rc = EPERM;
#endif #endif
mdbx_error("%s %s, err %d", "DXB", ERROR("%s %s, err %d", "DXB",
(st.st_nlink < 1) ? "file was removed" : "not a regular file", (st.st_nlink < 1) ? "file was removed" : "not a regular file", rc);
rc);
return rc; return rc;
} }
if (st.st_size < (off_t)(MDBX_MIN_PAGESIZE * NUM_METAS)) { if (st.st_size < (off_t)(MDBX_MIN_PAGESIZE * NUM_METAS)) {
mdbx_verbose("dxb-file is too short (%u), exclusive-lock needed", VERBOSE("dxb-file is too short (%u), exclusive-lock needed",
(unsigned)st.st_size); (unsigned)st.st_size);
rc = MDBX_RESULT_TRUE; rc = MDBX_RESULT_TRUE;
} }
@ -351,7 +350,7 @@ static int check_fstat(MDBX_env *env) {
if (fstat(env->me_lfd, &st)) { if (fstat(env->me_lfd, &st)) {
rc = errno; rc = errno;
mdbx_error("fstat(%s), err %d", "LCK", rc); ERROR("fstat(%s), err %d", "LCK", rc);
return rc; return rc;
} }
@ -361,26 +360,25 @@ static int check_fstat(MDBX_env *env) {
#else #else
rc = EPERM; rc = EPERM;
#endif #endif
mdbx_error("%s %s, err %d", "LCK", ERROR("%s %s, err %d", "LCK",
(st.st_nlink < 1) ? "file was removed" : "not a regular file", (st.st_nlink < 1) ? "file was removed" : "not a regular file", rc);
rc);
return rc; return rc;
} }
/* Checking file size for detect the situation when we got the shared lock /* Checking file size for detect the situation when we got the shared lock
* immediately after mdbx_lck_destroy(). */ * immediately after osal_lck_destroy(). */
if (st.st_size < (off_t)(sizeof(MDBX_lockinfo) + sizeof(MDBX_reader))) { if (st.st_size < (off_t)(sizeof(MDBX_lockinfo) + sizeof(MDBX_reader))) {
mdbx_verbose("lck-file is too short (%u), exclusive-lock needed", VERBOSE("lck-file is too short (%u), exclusive-lock needed",
(unsigned)st.st_size); (unsigned)st.st_size);
rc = MDBX_RESULT_TRUE; rc = MDBX_RESULT_TRUE;
} }
return rc; return rc;
} }
__cold MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) { __cold MDBX_INTERNAL_FUNC int osal_lck_seize(MDBX_env *env) {
assert(env->me_lazy_fd != INVALID_HANDLE_VALUE); assert(env->me_lazy_fd != INVALID_HANDLE_VALUE);
if (unlikely(mdbx_getpid() != env->me_pid)) if (unlikely(osal_getpid() != env->me_pid))
return MDBX_PANIC; return MDBX_PANIC;
#if MDBX_USE_OFDLOCKS #if MDBX_USE_OFDLOCKS
if (unlikely(op_setlk == 0)) if (unlikely(op_setlk == 0))
@ -391,10 +389,10 @@ __cold MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) {
#if defined(__linux__) || defined(__gnu_linux__) #if defined(__linux__) || defined(__gnu_linux__)
if (unlikely(mdbx_RunningOnWSL1)) { if (unlikely(mdbx_RunningOnWSL1)) {
rc = ENOLCK /* No record locks available */; rc = ENOLCK /* No record locks available */;
mdbx_error("%s, err %u", ERROR("%s, err %u",
"WSL1 (Windows Subsystem for Linux) is mad and trouble-full, " "WSL1 (Windows Subsystem for Linux) is mad and trouble-full, "
"injecting failure to avoid data loss", "injecting failure to avoid data loss",
rc); rc);
return rc; return rc;
} }
#endif /* Linux */ #endif /* Linux */
@ -405,8 +403,8 @@ __cold MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) {
lck_op(env->me_lazy_fd, op_setlk, lck_op(env->me_lazy_fd, op_setlk,
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0, OFF_T_MAX); (env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0, OFF_T_MAX);
if (rc != MDBX_SUCCESS) { if (rc != MDBX_SUCCESS) {
mdbx_error("%s, err %u", "without-lck", rc); ERROR("%s, err %u", "without-lck", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); eASSERT(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
return MDBX_RESULT_TRUE /* Done: return with exclusive locking. */; return MDBX_RESULT_TRUE /* Done: return with exclusive locking. */;
@ -419,8 +417,8 @@ retry:
if (rc == MDBX_RESULT_TRUE) { if (rc == MDBX_RESULT_TRUE) {
rc = lck_op(env->me_lfd, op_setlk, F_UNLCK, 0, 1); rc = lck_op(env->me_lfd, op_setlk, F_UNLCK, 0, 1);
if (rc != MDBX_SUCCESS) { if (rc != MDBX_SUCCESS) {
mdbx_error("%s, err %u", "unlock-before-retry", rc); ERROR("%s, err %u", "unlock-before-retry", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); eASSERT(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
} }
@ -446,23 +444,23 @@ retry:
/* the cause may be a collision with POSIX's file-lock recovery. */ /* the cause may be a collision with POSIX's file-lock recovery. */
if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY || rc == EWOULDBLOCK || if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY || rc == EWOULDBLOCK ||
rc == EDEADLK)) { rc == EDEADLK)) {
mdbx_error("%s, err %u", "dxb-exclusive", rc); ERROR("%s, err %u", "dxb-exclusive", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); eASSERT(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
/* Fallback to lck-shared */ /* Fallback to lck-shared */
} else if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY || } else if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY ||
rc == EWOULDBLOCK || rc == EDEADLK)) { rc == EWOULDBLOCK || rc == EDEADLK)) {
mdbx_error("%s, err %u", "try-exclusive", rc); ERROR("%s, err %u", "try-exclusive", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); eASSERT(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
/* Here could be one of two: /* Here could be one of two:
* - mdbx_lck_destroy() from the another process was hold the lock * - osal_lck_destroy() from the another process was hold the lock
* during a destruction. * during a destruction.
* - either mdbx_lck_seize() from the another process was got the exclusive * - either osal_lck_seize() from the another process was got the exclusive
* lock and doing initialization. * lock and doing initialization.
* For distinguish these cases will use size of the lck-file later. */ * For distinguish these cases will use size of the lck-file later. */
@ -471,8 +469,8 @@ retry:
* competing process doesn't call lck_downgrade(). */ * competing process doesn't call lck_downgrade(). */
rc = lck_op(env->me_lfd, op_setlkw, F_RDLCK, 0, 1); rc = lck_op(env->me_lfd, op_setlkw, F_RDLCK, 0, 1);
if (rc != MDBX_SUCCESS) { if (rc != MDBX_SUCCESS) {
mdbx_error("%s, err %u", "try-shared", rc); ERROR("%s, err %u", "try-shared", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); eASSERT(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
@ -480,7 +478,7 @@ retry:
if (rc == MDBX_RESULT_TRUE) if (rc == MDBX_RESULT_TRUE)
goto retry; goto retry;
if (rc != MDBX_SUCCESS) { if (rc != MDBX_SUCCESS) {
mdbx_error("%s, err %u", "lck_fstat", rc); ERROR("%s, err %u", "lck_fstat", rc);
return rc; return rc;
} }
@ -491,8 +489,8 @@ retry:
if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY || rc == EWOULDBLOCK || if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY || rc == EWOULDBLOCK ||
rc == EDEADLK)) { rc == EDEADLK)) {
mdbx_error("%s, err %u", "try-exclusive", rc); ERROR("%s, err %u", "try-exclusive", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); eASSERT(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
@ -501,8 +499,8 @@ retry:
lck_op(env->me_lazy_fd, op_setlk, lck_op(env->me_lazy_fd, op_setlk,
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, env->me_pid, 1); (env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, env->me_pid, 1);
if (rc != MDBX_SUCCESS) { if (rc != MDBX_SUCCESS) {
mdbx_error("%s, err %u", "lock-against-without-lck", rc); ERROR("%s, err %u", "lock-against-without-lck", rc);
mdbx_assert(env, MDBX_IS_ERROR(rc)); eASSERT(env, MDBX_IS_ERROR(rc));
return rc; return rc;
} }
@ -510,9 +508,9 @@ retry:
return MDBX_RESULT_FALSE; return MDBX_RESULT_FALSE;
} }
MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env) { MDBX_INTERNAL_FUNC int osal_lck_downgrade(MDBX_env *env) {
assert(env->me_lfd != INVALID_HANDLE_VALUE); assert(env->me_lfd != INVALID_HANDLE_VALUE);
if (unlikely(mdbx_getpid() != env->me_pid)) if (unlikely(osal_getpid() != env->me_pid))
return MDBX_PANIC; return MDBX_PANIC;
int rc = MDBX_SUCCESS; int rc = MDBX_SUCCESS;
@ -525,15 +523,15 @@ MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env) {
if (rc == MDBX_SUCCESS) if (rc == MDBX_SUCCESS)
rc = lck_op(env->me_lfd, op_setlk, F_RDLCK, 0, 1); rc = lck_op(env->me_lfd, op_setlk, F_RDLCK, 0, 1);
if (unlikely(rc != 0)) { if (unlikely(rc != 0)) {
mdbx_error("%s, err %u", "lck", rc); ERROR("%s, err %u", "lck", rc);
assert(MDBX_IS_ERROR(rc)); assert(MDBX_IS_ERROR(rc));
} }
return rc; return rc;
} }
__cold MDBX_INTERNAL_FUNC int mdbx_lck_destroy(MDBX_env *env, __cold MDBX_INTERNAL_FUNC int osal_lck_destroy(MDBX_env *env,
MDBX_env *inprocess_neighbor) { MDBX_env *inprocess_neighbor) {
if (unlikely(mdbx_getpid() != env->me_pid)) if (unlikely(osal_getpid() != env->me_pid))
return MDBX_PANIC; return MDBX_PANIC;
int rc = MDBX_SUCCESS; int rc = MDBX_SUCCESS;
@ -548,25 +546,25 @@ __cold MDBX_INTERNAL_FUNC int mdbx_lck_destroy(MDBX_env *env,
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0, (env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0,
OFF_T_MAX) == 0) { OFF_T_MAX) == 0) {
mdbx_verbose("%p got exclusive, drown locks", (void *)env); VERBOSE("%p got exclusive, drown locks", (void *)env);
#if MDBX_LOCKING == MDBX_LOCKING_SYSV #if MDBX_LOCKING == MDBX_LOCKING_SYSV
if (env->me_sysv_ipc.semid != -1) if (env->me_sysv_ipc.semid != -1)
rc = semctl(env->me_sysv_ipc.semid, 2, IPC_RMID) ? errno : 0; rc = semctl(env->me_sysv_ipc.semid, 2, IPC_RMID) ? errno : 0;
#else #else
rc = mdbx_ipclock_destroy(&lck->mti_rlock); rc = osal_ipclock_destroy(&lck->mti_rlock);
if (rc == 0) if (rc == 0)
rc = mdbx_ipclock_destroy(&lck->mti_wlock); rc = osal_ipclock_destroy(&lck->mti_wlock);
#endif /* MDBX_LOCKING */ #endif /* MDBX_LOCKING */
mdbx_assert(env, rc == 0); eASSERT(env, rc == 0);
if (rc == 0) { if (rc == 0) {
const bool synced = lck->mti_unsynced_pages.weak == 0; const bool synced = lck->mti_unsynced_pages.weak == 0;
mdbx_munmap(&env->me_lck_mmap); osal_munmap(&env->me_lck_mmap);
if (synced) if (synced)
rc = ftruncate(env->me_lfd, 0) ? errno : 0; rc = ftruncate(env->me_lfd, 0) ? errno : 0;
} }
mdbx_jitter4testing(false); jitter4testing(false);
} }
/* 1) POSIX's fcntl() locks (i.e. when op_setlk == F_SETLK) should be restored /* 1) POSIX's fcntl() locks (i.e. when op_setlk == F_SETLK) should be restored
@ -607,7 +605,7 @@ __cold MDBX_INTERNAL_FUNC int mdbx_lck_destroy(MDBX_env *env,
/* restore file-locks */ /* restore file-locks */
rc = lck_op(inprocess_neighbor->me_lfd, F_SETLKW, F_RDLCK, 0, 1); rc = lck_op(inprocess_neighbor->me_lfd, F_SETLKW, F_RDLCK, 0, 1);
if (rc == MDBX_SUCCESS && inprocess_neighbor->me_live_reader) if (rc == MDBX_SUCCESS && inprocess_neighbor->me_live_reader)
rc = mdbx_rpid_set(inprocess_neighbor); rc = osal_rpid_set(inprocess_neighbor);
} }
} }
@ -618,7 +616,7 @@ __cold MDBX_INTERNAL_FUNC int mdbx_lck_destroy(MDBX_env *env,
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
__cold MDBX_INTERNAL_FUNC int mdbx_lck_init(MDBX_env *env, __cold MDBX_INTERNAL_FUNC int osal_lck_init(MDBX_env *env,
MDBX_env *inprocess_neighbor, MDBX_env *inprocess_neighbor,
int global_uniqueness_flag) { int global_uniqueness_flag) {
#if MDBX_LOCKING == MDBX_LOCKING_SYSV #if MDBX_LOCKING == MDBX_LOCKING_SYSV
@ -765,7 +763,7 @@ bailout:
#endif /* MDBX_LOCKING > 0 */ #endif /* MDBX_LOCKING > 0 */
} }
__cold static int mdbx_ipclock_failed(MDBX_env *env, mdbx_ipclock_t *ipc, __cold static int mdbx_ipclock_failed(MDBX_env *env, osal_ipclock_t *ipc,
const int err) { const int err) {
int rc = err; int rc = err;
#if MDBX_LOCKING == MDBX_LOCKING_POSIX2008 || MDBX_LOCKING == MDBX_LOCKING_SYSV #if MDBX_LOCKING == MDBX_LOCKING_POSIX2008 || MDBX_LOCKING == MDBX_LOCKING_SYSV
@ -782,10 +780,10 @@ __cold static int mdbx_ipclock_failed(MDBX_env *env, mdbx_ipclock_t *ipc,
rc = MDBX_PANIC; rc = MDBX_PANIC;
} }
} }
mdbx_warning("%clock owner died, %s", (rlocked ? 'r' : 'w'), WARNING("%clock owner died, %s", (rlocked ? 'r' : 'w'),
(rc ? "this process' env is hosed" : "recovering")); (rc ? "this process' env is hosed" : "recovering"));
int check_rc = mdbx_cleanup_dead_readers(env, rlocked, NULL); int check_rc = cleanup_dead_readers(env, rlocked, NULL);
check_rc = (check_rc == MDBX_SUCCESS) ? MDBX_RESULT_TRUE : check_rc; check_rc = (check_rc == MDBX_SUCCESS) ? MDBX_RESULT_TRUE : check_rc;
#if MDBX_LOCKING == MDBX_LOCKING_SYSV #if MDBX_LOCKING == MDBX_LOCKING_SYSV
@ -803,7 +801,7 @@ __cold static int mdbx_ipclock_failed(MDBX_env *env, mdbx_ipclock_t *ipc,
check_rc = (mreco_rc == 0) ? check_rc : mreco_rc; check_rc = (mreco_rc == 0) ? check_rc : mreco_rc;
if (unlikely(mreco_rc)) if (unlikely(mreco_rc))
mdbx_error("lock recovery failed, %s", mdbx_strerror(mreco_rc)); ERROR("lock recovery failed, %s", mdbx_strerror(mreco_rc));
rc = (rc == MDBX_SUCCESS) ? check_rc : rc; rc = (rc == MDBX_SUCCESS) ? check_rc : rc;
if (MDBX_IS_ERROR(rc)) if (MDBX_IS_ERROR(rc))
@ -826,24 +824,24 @@ __cold static int mdbx_ipclock_failed(MDBX_env *env, mdbx_ipclock_t *ipc,
#error "FIXME" #error "FIXME"
#endif /* MDBX_LOCKING */ #endif /* MDBX_LOCKING */
mdbx_error("mutex (un)lock failed, %s", mdbx_strerror(err)); ERROR("mutex (un)lock failed, %s", mdbx_strerror(err));
if (rc != EDEADLK) if (rc != EDEADLK)
env->me_flags |= MDBX_FATAL_ERROR; env->me_flags |= MDBX_FATAL_ERROR;
return rc; return rc;
} }
#if defined(__ANDROID_API__) || defined(ANDROID) || defined(BIONIC) #if defined(__ANDROID_API__) || defined(ANDROID) || defined(BIONIC)
MDBX_INTERNAL_FUNC int mdbx_check_tid4bionic(void) { MDBX_INTERNAL_FUNC int osal_check_tid4bionic(void) {
/* avoid 32-bit Bionic bug/hang with 32-pit TID */ /* avoid 32-bit Bionic bug/hang with 32-pit TID */
if (sizeof(pthread_mutex_t) < sizeof(pid_t) + sizeof(unsigned)) { if (sizeof(pthread_mutex_t) < sizeof(pid_t) + sizeof(unsigned)) {
pid_t tid = gettid(); pid_t tid = gettid();
if (unlikely(tid > 0xffff)) { if (unlikely(tid > 0xffff)) {
mdbx_fatal("Raise the ENOSYS(%d) error to avoid hang due " FATAL("Raise the ENOSYS(%d) error to avoid hang due "
"the 32-bit Bionic/Android bug with tid/thread_id 0x%08x(%i) " "the 32-bit Bionic/Android bug with tid/thread_id 0x%08x(%i) "
"that dont fit in 16 bits, see " "that dont fit in 16 bits, see "
"https://android.googlesource.com/platform/bionic/+/master/" "https://android.googlesource.com/platform/bionic/+/master/"
"docs/32-bit-abi.md#is-too-small-for-large-pids", "docs/32-bit-abi.md#is-too-small-for-large-pids",
ENOSYS, tid, tid); ENOSYS, tid, tid);
return ENOSYS; return ENOSYS;
} }
} }
@ -851,11 +849,11 @@ MDBX_INTERNAL_FUNC int mdbx_check_tid4bionic(void) {
} }
#endif /* __ANDROID_API__ || ANDROID) || BIONIC */ #endif /* __ANDROID_API__ || ANDROID) || BIONIC */
static int mdbx_ipclock_lock(MDBX_env *env, mdbx_ipclock_t *ipc, static int mdbx_ipclock_lock(MDBX_env *env, osal_ipclock_t *ipc,
const bool dont_wait) { const bool dont_wait) {
#if MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \ #if MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \
MDBX_LOCKING == MDBX_LOCKING_POSIX2008 MDBX_LOCKING == MDBX_LOCKING_POSIX2008
int rc = mdbx_check_tid4bionic(); int rc = osal_check_tid4bionic();
if (likely(rc == 0)) if (likely(rc == 0))
rc = dont_wait ? pthread_mutex_trylock(ipc) : pthread_mutex_lock(ipc); rc = dont_wait ? pthread_mutex_trylock(ipc) : pthread_mutex_lock(ipc);
rc = (rc == EBUSY && dont_wait) ? MDBX_BUSY : rc; rc = (rc == EBUSY && dont_wait) ? MDBX_BUSY : rc;
@ -891,7 +889,7 @@ static int mdbx_ipclock_lock(MDBX_env *env, mdbx_ipclock_t *ipc,
return rc; return rc;
} }
static int mdbx_ipclock_unlock(MDBX_env *env, mdbx_ipclock_t *ipc) { static int mdbx_ipclock_unlock(MDBX_env *env, osal_ipclock_t *ipc) {
#if MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \ #if MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \
MDBX_LOCKING == MDBX_LOCKING_POSIX2008 MDBX_LOCKING == MDBX_LOCKING_POSIX2008
int rc = pthread_mutex_unlock(ipc); int rc = pthread_mutex_unlock(ipc);
@ -913,38 +911,38 @@ static int mdbx_ipclock_unlock(MDBX_env *env, mdbx_ipclock_t *ipc) {
return rc; return rc;
} }
MDBX_INTERNAL_FUNC int mdbx_rdt_lock(MDBX_env *env) { MDBX_INTERNAL_FUNC int osal_rdt_lock(MDBX_env *env) {
mdbx_trace("%s", ">>"); TRACE("%s", ">>");
mdbx_jitter4testing(true); jitter4testing(true);
int rc = mdbx_ipclock_lock(env, &env->me_lck->mti_rlock, false); int rc = mdbx_ipclock_lock(env, &env->me_lck->mti_rlock, false);
mdbx_trace("<< rc %d", rc); TRACE("<< rc %d", rc);
return rc; return rc;
} }
MDBX_INTERNAL_FUNC void mdbx_rdt_unlock(MDBX_env *env) { MDBX_INTERNAL_FUNC void osal_rdt_unlock(MDBX_env *env) {
mdbx_trace("%s", ">>"); TRACE("%s", ">>");
int rc = mdbx_ipclock_unlock(env, &env->me_lck->mti_rlock); int rc = mdbx_ipclock_unlock(env, &env->me_lck->mti_rlock);
mdbx_trace("<< rc %d", rc); TRACE("<< rc %d", rc);
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
mdbx_panic("%s() failed: err %d\n", __func__, rc); mdbx_panic("%s() failed: err %d\n", __func__, rc);
mdbx_jitter4testing(true); jitter4testing(true);
} }
int mdbx_txn_lock(MDBX_env *env, bool dont_wait) { int mdbx_txn_lock(MDBX_env *env, bool dont_wait) {
mdbx_trace("%swait %s", dont_wait ? "dont-" : "", ">>"); TRACE("%swait %s", dont_wait ? "dont-" : "", ">>");
mdbx_jitter4testing(true); jitter4testing(true);
int rc = mdbx_ipclock_lock(env, &env->me_lck->mti_wlock, dont_wait); int rc = mdbx_ipclock_lock(env, &env->me_lck->mti_wlock, dont_wait);
mdbx_trace("<< rc %d", rc); TRACE("<< rc %d", rc);
return MDBX_IS_ERROR(rc) ? rc : MDBX_SUCCESS; return MDBX_IS_ERROR(rc) ? rc : MDBX_SUCCESS;
} }
void mdbx_txn_unlock(MDBX_env *env) { void mdbx_txn_unlock(MDBX_env *env) {
mdbx_trace("%s", ">>"); TRACE("%s", ">>");
int rc = mdbx_ipclock_unlock(env, &env->me_lck->mti_wlock); int rc = mdbx_ipclock_unlock(env, &env->me_lck->mti_wlock);
mdbx_trace("<< rc %d", rc); TRACE("<< rc %d", rc);
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
mdbx_panic("%s() failed: err %d\n", __func__, rc); mdbx_panic("%s() failed: err %d\n", __func__, rc);
mdbx_jitter4testing(true); jitter4testing(true);
} }
#else #else

View File

@ -48,16 +48,16 @@ static
switch (reason) { switch (reason) {
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
mdbx_winnt_import(); mdbx_winnt_import();
mdbx_rthc_global_init(); global_ctor();
break; break;
case DLL_PROCESS_DETACH: case DLL_PROCESS_DETACH:
mdbx_rthc_global_dtor(); global_dtor();
break; break;
case DLL_THREAD_ATTACH: case DLL_THREAD_ATTACH:
break; break;
case DLL_THREAD_DETACH: case DLL_THREAD_DETACH:
mdbx_rthc_thread_dtor(module); thread_dtor(module);
break; break;
} }
#if MDBX_BUILD_SHARED_LIBRARY #if MDBX_BUILD_SHARED_LIBRARY
@ -186,8 +186,8 @@ void mdbx_txn_unlock(MDBX_env *env) {
#define LCK_LOWER LCK_LO_OFFSET, LCK_LO_LEN #define LCK_LOWER LCK_LO_OFFSET, LCK_LO_LEN
#define LCK_UPPER LCK_UP_OFFSET, LCK_UP_LEN #define LCK_UPPER LCK_UP_OFFSET, LCK_UP_LEN
MDBX_INTERNAL_FUNC int mdbx_rdt_lock(MDBX_env *env) { MDBX_INTERNAL_FUNC int osal_rdt_lock(MDBX_env *env) {
mdbx_srwlock_AcquireShared(&env->me_remap_guard); osal_srwlock_AcquireShared(&env->me_remap_guard);
if (env->me_lfd == INVALID_HANDLE_VALUE) if (env->me_lfd == INVALID_HANDLE_VALUE)
return MDBX_SUCCESS; /* readonly database in readonly filesystem */ return MDBX_SUCCESS; /* readonly database in readonly filesystem */
@ -198,21 +198,21 @@ MDBX_INTERNAL_FUNC int mdbx_rdt_lock(MDBX_env *env) {
return MDBX_SUCCESS; return MDBX_SUCCESS;
int rc = (int)GetLastError(); int rc = (int)GetLastError();
mdbx_srwlock_ReleaseShared(&env->me_remap_guard); osal_srwlock_ReleaseShared(&env->me_remap_guard);
return rc; return rc;
} }
MDBX_INTERNAL_FUNC void mdbx_rdt_unlock(MDBX_env *env) { MDBX_INTERNAL_FUNC void osal_rdt_unlock(MDBX_env *env) {
if (env->me_lfd != INVALID_HANDLE_VALUE) { if (env->me_lfd != INVALID_HANDLE_VALUE) {
/* transition from S-E (locked) to S-? (used), e.g. unlock upper-part */ /* transition from S-E (locked) to S-? (used), e.g. unlock upper-part */
if ((env->me_flags & MDBX_EXCLUSIVE) == 0 && if ((env->me_flags & MDBX_EXCLUSIVE) == 0 &&
!funlock(env->me_lfd, LCK_UPPER)) !funlock(env->me_lfd, LCK_UPPER))
mdbx_panic("%s failed: err %u", __func__, (int)GetLastError()); mdbx_panic("%s failed: err %u", __func__, (int)GetLastError());
} }
mdbx_srwlock_ReleaseShared(&env->me_remap_guard); osal_srwlock_ReleaseShared(&env->me_remap_guard);
} }
MDBX_INTERNAL_FUNC int mdbx_lockfile(mdbx_filehandle_t fd, bool wait) { MDBX_INTERNAL_FUNC int osal_lockfile(mdbx_filehandle_t fd, bool wait) {
return flock(fd, return flock(fd,
wait ? LCK_EXCLUSIVE | LCK_WAITFOR wait ? LCK_EXCLUSIVE | LCK_WAITFOR
: LCK_EXCLUSIVE | LCK_DONTWAIT, : LCK_EXCLUSIVE | LCK_DONTWAIT,
@ -225,7 +225,7 @@ static int suspend_and_append(mdbx_handle_array_t **array,
const DWORD ThreadId) { const DWORD ThreadId) {
const unsigned limit = (*array)->limit; const unsigned limit = (*array)->limit;
if ((*array)->count == limit) { if ((*array)->count == limit) {
void *ptr = mdbx_realloc( void *ptr = osal_realloc(
(limit > ARRAY_LENGTH((*array)->handles)) (limit > ARRAY_LENGTH((*array)->handles))
? *array ? *array
: /* don't free initial array on the stack */ NULL, : /* don't free initial array on the stack */ NULL,
@ -259,8 +259,8 @@ static int suspend_and_append(mdbx_handle_array_t **array,
} }
MDBX_INTERNAL_FUNC int MDBX_INTERNAL_FUNC int
mdbx_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) { osal_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) {
mdbx_assert(env, (env->me_flags & MDBX_NOTLS) == 0); eASSERT(env, (env->me_flags & MDBX_NOTLS) == 0);
const uintptr_t CurrentTid = GetCurrentThreadId(); const uintptr_t CurrentTid = GetCurrentThreadId();
int rc; int rc;
if (env->me_lck_mmap.lck) { if (env->me_lck_mmap.lck) {
@ -282,7 +282,7 @@ mdbx_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) {
rc = suspend_and_append(array, (mdbx_tid_t)reader->mr_tid.weak); rc = suspend_and_append(array, (mdbx_tid_t)reader->mr_tid.weak);
if (rc != MDBX_SUCCESS) { if (rc != MDBX_SUCCESS) {
bailout_lck: bailout_lck:
(void)mdbx_resume_threads_after_remap(*array); (void)osal_resume_threads_after_remap(*array);
return rc; return rc;
} }
} }
@ -294,7 +294,7 @@ mdbx_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) {
} else { } else {
/* Without LCK (i.e. read-only mode). /* Without LCK (i.e. read-only mode).
* Walk through a snapshot of all running threads */ * Walk through a snapshot of all running threads */
mdbx_assert(env, env->me_flags & (MDBX_EXCLUSIVE | MDBX_RDONLY)); eASSERT(env, env->me_flags & (MDBX_EXCLUSIVE | MDBX_RDONLY));
const HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); const HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) if (hSnapshot == INVALID_HANDLE_VALUE)
return (int)GetLastError(); return (int)GetLastError();
@ -306,7 +306,7 @@ mdbx_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) {
rc = (int)GetLastError(); rc = (int)GetLastError();
bailout_toolhelp: bailout_toolhelp:
CloseHandle(hSnapshot); CloseHandle(hSnapshot);
(void)mdbx_resume_threads_after_remap(*array); (void)osal_resume_threads_after_remap(*array);
return rc; return rc;
} }
@ -331,7 +331,7 @@ mdbx_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) {
} }
MDBX_INTERNAL_FUNC int MDBX_INTERNAL_FUNC int
mdbx_resume_threads_after_remap(mdbx_handle_array_t *array) { osal_resume_threads_after_remap(mdbx_handle_array_t *array) {
int rc = MDBX_SUCCESS; int rc = MDBX_SUCCESS;
for (unsigned i = 0; i < array->count; ++i) { for (unsigned i = 0; i < array->count; ++i) {
const HANDLE hThread = array->handles[i]; const HANDLE hThread = array->handles[i];
@ -370,11 +370,11 @@ mdbx_resume_threads_after_remap(mdbx_handle_array_t *array) {
* E-S * E-S
* E-E = exclusive-write, i.e. exclusive due (re)initialization * E-E = exclusive-write, i.e. exclusive due (re)initialization
* *
* The mdbx_lck_seize() moves the locking-FSM from the initial free/unlocked * The osal_lck_seize() moves the locking-FSM from the initial free/unlocked
* state to the "exclusive write" (and returns MDBX_RESULT_TRUE) if possible, * state to the "exclusive write" (and returns MDBX_RESULT_TRUE) if possible,
* or to the "used" (and returns MDBX_RESULT_FALSE). * or to the "used" (and returns MDBX_RESULT_FALSE).
* *
* The mdbx_lck_downgrade() moves the locking-FSM from "exclusive write" * The osal_lck_downgrade() moves the locking-FSM from "exclusive write"
* state to the "used" (i.e. shared) state. * state to the "used" (i.e. shared) state.
* *
* The mdbx_lck_upgrade() moves the locking-FSM from "used" (i.e. shared) * The mdbx_lck_upgrade() moves the locking-FSM from "used" (i.e. shared)
@ -432,21 +432,21 @@ static int internal_seize_lck(HANDLE lfd) {
assert(lfd != INVALID_HANDLE_VALUE); assert(lfd != INVALID_HANDLE_VALUE);
/* 1) now on ?-? (free), get ?-E (middle) */ /* 1) now on ?-? (free), get ?-E (middle) */
mdbx_jitter4testing(false); jitter4testing(false);
if (!flock(lfd, LCK_EXCLUSIVE | LCK_WAITFOR, LCK_UPPER)) { if (!flock(lfd, LCK_EXCLUSIVE | LCK_WAITFOR, LCK_UPPER)) {
rc = (int)GetLastError() /* 2) something went wrong, give up */; rc = (int)GetLastError() /* 2) something went wrong, give up */;
mdbx_error("%s, err %u", "?-?(free) >> ?-E(middle)", rc); ERROR("%s, err %u", "?-?(free) >> ?-E(middle)", rc);
return rc; return rc;
} }
/* 3) now on ?-E (middle), try E-E (exclusive-write) */ /* 3) now on ?-E (middle), try E-E (exclusive-write) */
mdbx_jitter4testing(false); jitter4testing(false);
if (flock(lfd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_LOWER)) if (flock(lfd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_LOWER))
return MDBX_RESULT_TRUE /* 4) got E-E (exclusive-write), done */; return MDBX_RESULT_TRUE /* 4) got E-E (exclusive-write), done */;
/* 5) still on ?-E (middle) */ /* 5) still on ?-E (middle) */
rc = (int)GetLastError(); rc = (int)GetLastError();
mdbx_jitter4testing(false); jitter4testing(false);
if (rc != ERROR_SHARING_VIOLATION && rc != ERROR_LOCK_VIOLATION) { if (rc != ERROR_SHARING_VIOLATION && rc != ERROR_LOCK_VIOLATION) {
/* 6) something went wrong, give up */ /* 6) something went wrong, give up */
if (!funlock(lfd, LCK_UPPER)) if (!funlock(lfd, LCK_UPPER))
@ -456,13 +456,13 @@ static int internal_seize_lck(HANDLE lfd) {
} }
/* 7) still on ?-E (middle), try S-E (locked) */ /* 7) still on ?-E (middle), try S-E (locked) */
mdbx_jitter4testing(false); jitter4testing(false);
rc = flock(lfd, LCK_SHARED | LCK_DONTWAIT, LCK_LOWER) ? MDBX_RESULT_FALSE rc = flock(lfd, LCK_SHARED | LCK_DONTWAIT, LCK_LOWER) ? MDBX_RESULT_FALSE
: (int)GetLastError(); : (int)GetLastError();
mdbx_jitter4testing(false); jitter4testing(false);
if (rc != MDBX_RESULT_FALSE) if (rc != MDBX_RESULT_FALSE)
mdbx_error("%s, err %u", "?-E(middle) >> S-E(locked)", rc); ERROR("%s, err %u", "?-E(middle) >> S-E(locked)", rc);
/* 8) now on S-E (locked) or still on ?-E (middle), /* 8) now on S-E (locked) or still on ?-E (middle),
* transition to S-? (used) or ?-? (free) */ * transition to S-? (used) or ?-? (free) */
@ -474,7 +474,7 @@ static int internal_seize_lck(HANDLE lfd) {
return rc; return rc;
} }
MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) { MDBX_INTERNAL_FUNC int osal_lck_seize(MDBX_env *env) {
int rc; int rc;
assert(env->me_lazy_fd != INVALID_HANDLE_VALUE); assert(env->me_lazy_fd != INVALID_HANDLE_VALUE);
@ -485,17 +485,17 @@ MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) {
if (env->me_lfd == INVALID_HANDLE_VALUE) { if (env->me_lfd == INVALID_HANDLE_VALUE) {
/* LY: without-lck mode (e.g. on read-only filesystem) */ /* LY: without-lck mode (e.g. on read-only filesystem) */
mdbx_jitter4testing(false); jitter4testing(false);
if (!flock(env->me_lazy_fd, LCK_SHARED | LCK_DONTWAIT, LCK_WHOLE)) { if (!flock(env->me_lazy_fd, LCK_SHARED | LCK_DONTWAIT, LCK_WHOLE)) {
rc = (int)GetLastError(); rc = (int)GetLastError();
mdbx_error("%s, err %u", "without-lck", rc); ERROR("%s, err %u", "without-lck", rc);
return rc; return rc;
} }
return MDBX_RESULT_FALSE; return MDBX_RESULT_FALSE;
} }
rc = internal_seize_lck(env->me_lfd); rc = internal_seize_lck(env->me_lfd);
mdbx_jitter4testing(false); jitter4testing(false);
if (rc == MDBX_RESULT_TRUE && (env->me_flags & MDBX_RDONLY) == 0) { if (rc == MDBX_RESULT_TRUE && (env->me_flags & MDBX_RDONLY) == 0) {
/* Check that another process don't operates in without-lck mode. /* Check that another process don't operates in without-lck mode.
* Doing such check by exclusive locking the body-part of db. Should be * Doing such check by exclusive locking the body-part of db. Should be
@ -505,11 +505,11 @@ MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) {
* while opening db in valid (non-conflict) mode. */ * while opening db in valid (non-conflict) mode. */
if (!flock(env->me_lazy_fd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_BODY)) { if (!flock(env->me_lazy_fd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_BODY)) {
rc = (int)GetLastError(); rc = (int)GetLastError();
mdbx_error("%s, err %u", "lock-against-without-lck", rc); ERROR("%s, err %u", "lock-against-without-lck", rc);
mdbx_jitter4testing(false); jitter4testing(false);
lck_unlock(env); lck_unlock(env);
} else { } else {
mdbx_jitter4testing(false); jitter4testing(false);
if (!funlock(env->me_lazy_fd, LCK_BODY)) if (!funlock(env->me_lazy_fd, LCK_BODY))
mdbx_panic("%s(%s) failed: err %u", __func__, mdbx_panic("%s(%s) failed: err %u", __func__,
"unlock-against-without-lck", (int)GetLastError()); "unlock-against-without-lck", (int)GetLastError());
@ -519,7 +519,7 @@ MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) {
return rc; return rc;
} }
MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env) { MDBX_INTERNAL_FUNC int osal_lck_downgrade(MDBX_env *env) {
/* Transite from exclusive-write state (E-E) to used (S-?) */ /* Transite from exclusive-write state (E-E) to used (S-?) */
assert(env->me_lazy_fd != INVALID_HANDLE_VALUE); assert(env->me_lazy_fd != INVALID_HANDLE_VALUE);
assert(env->me_lfd != INVALID_HANDLE_VALUE); assert(env->me_lfd != INVALID_HANDLE_VALUE);
@ -535,7 +535,7 @@ MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env) {
/* 2) now at ?-E (middle), transition to S-E (locked) */ /* 2) now at ?-E (middle), transition to S-E (locked) */
if (!flock(env->me_lfd, LCK_SHARED | LCK_DONTWAIT, LCK_LOWER)) { if (!flock(env->me_lfd, LCK_SHARED | LCK_DONTWAIT, LCK_LOWER)) {
int rc = (int)GetLastError() /* 3) something went wrong, give up */; int rc = (int)GetLastError() /* 3) something went wrong, give up */;
mdbx_error("%s, err %u", "?-E(middle) >> S-E(locked)", rc); ERROR("%s, err %u", "?-E(middle) >> S-E(locked)", rc);
return rc; return rc;
} }
@ -557,10 +557,10 @@ MDBX_INTERNAL_FUNC int mdbx_lck_upgrade(MDBX_env *env) {
int rc; int rc;
/* 1) now on S-? (used), try S-E (locked) */ /* 1) now on S-? (used), try S-E (locked) */
mdbx_jitter4testing(false); jitter4testing(false);
if (!flock(env->me_lfd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_UPPER)) { if (!flock(env->me_lfd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_UPPER)) {
rc = (int)GetLastError() /* 2) something went wrong, give up */; rc = (int)GetLastError() /* 2) something went wrong, give up */;
mdbx_verbose("%s, err %u", "S-?(used) >> S-E(locked)", rc); VERBOSE("%s, err %u", "S-?(used) >> S-E(locked)", rc);
return rc; return rc;
} }
@ -570,17 +570,17 @@ MDBX_INTERNAL_FUNC int mdbx_lck_upgrade(MDBX_env *env) {
(int)GetLastError()); (int)GetLastError());
/* 4) now on ?-E (middle), try E-E (exclusive-write) */ /* 4) now on ?-E (middle), try E-E (exclusive-write) */
mdbx_jitter4testing(false); jitter4testing(false);
if (!flock(env->me_lfd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_LOWER)) { if (!flock(env->me_lfd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_LOWER)) {
rc = (int)GetLastError() /* 5) something went wrong, give up */; rc = (int)GetLastError() /* 5) something went wrong, give up */;
mdbx_verbose("%s, err %u", "?-E(middle) >> E-E(exclusive-write)", rc); VERBOSE("%s, err %u", "?-E(middle) >> E-E(exclusive-write)", rc);
return rc; return rc;
} }
return MDBX_SUCCESS /* 6) now at E-E (exclusive-write), done */; return MDBX_SUCCESS /* 6) now at E-E (exclusive-write), done */;
} }
MDBX_INTERNAL_FUNC int mdbx_lck_init(MDBX_env *env, MDBX_INTERNAL_FUNC int osal_lck_init(MDBX_env *env,
MDBX_env *inprocess_neighbor, MDBX_env *inprocess_neighbor,
int global_uniqueness_flag) { int global_uniqueness_flag) {
(void)env; (void)env;
@ -589,19 +589,19 @@ MDBX_INTERNAL_FUNC int mdbx_lck_init(MDBX_env *env,
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL_FUNC int mdbx_lck_destroy(MDBX_env *env, MDBX_INTERNAL_FUNC int osal_lck_destroy(MDBX_env *env,
MDBX_env *inprocess_neighbor) { MDBX_env *inprocess_neighbor) {
/* LY: should unmap before releasing the locks to avoid race condition and /* LY: should unmap before releasing the locks to avoid race condition and
* STATUS_USER_MAPPED_FILE/ERROR_USER_MAPPED_FILE */ * STATUS_USER_MAPPED_FILE/ERROR_USER_MAPPED_FILE */
if (env->me_map) if (env->me_map)
mdbx_munmap(&env->me_dxb_mmap); osal_munmap(&env->me_dxb_mmap);
if (env->me_lck_mmap.lck) { if (env->me_lck_mmap.lck) {
const bool synced = env->me_lck_mmap.lck->mti_unsynced_pages.weak == 0; const bool synced = env->me_lck_mmap.lck->mti_unsynced_pages.weak == 0;
mdbx_munmap(&env->me_lck_mmap); osal_munmap(&env->me_lck_mmap);
if (synced && !inprocess_neighbor && env->me_lfd != INVALID_HANDLE_VALUE && if (synced && !inprocess_neighbor && env->me_lfd != INVALID_HANDLE_VALUE &&
mdbx_lck_upgrade(env) == MDBX_SUCCESS) mdbx_lck_upgrade(env) == MDBX_SUCCESS)
/* this will fail if LCK is used/mmapped by other process(es) */ /* this will fail if LCK is used/mmapped by other process(es) */
mdbx_ftruncate(env->me_lfd, 0); osal_ftruncate(env->me_lfd, 0);
} }
lck_unlock(env); lck_unlock(env);
return MDBX_SUCCESS; return MDBX_SUCCESS;
@ -610,12 +610,12 @@ MDBX_INTERNAL_FUNC int mdbx_lck_destroy(MDBX_env *env,
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* reader checking (by pid) */ /* reader checking (by pid) */
MDBX_INTERNAL_FUNC int mdbx_rpid_set(MDBX_env *env) { MDBX_INTERNAL_FUNC int osal_rpid_set(MDBX_env *env) {
(void)env; (void)env;
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL_FUNC int mdbx_rpid_clear(MDBX_env *env) { MDBX_INTERNAL_FUNC int osal_rpid_clear(MDBX_env *env) {
(void)env; (void)env;
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
@ -626,7 +626,7 @@ MDBX_INTERNAL_FUNC int mdbx_rpid_clear(MDBX_env *env) {
* MDBX_RESULT_TRUE, if pid is live (unable to acquire lock) * MDBX_RESULT_TRUE, if pid is live (unable to acquire lock)
* MDBX_RESULT_FALSE, if pid is dead (lock acquired) * MDBX_RESULT_FALSE, if pid is dead (lock acquired)
* or otherwise the errcode. */ * or otherwise the errcode. */
MDBX_INTERNAL_FUNC int mdbx_rpid_check(MDBX_env *env, uint32_t pid) { MDBX_INTERNAL_FUNC int osal_rpid_check(MDBX_env *env, uint32_t pid) {
(void)env; (void)env;
HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, pid); HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, pid);
int rc; int rc;
@ -663,11 +663,11 @@ MDBX_INTERNAL_FUNC int mdbx_rpid_check(MDBX_env *env, uint32_t pid) {
// Stub for slim read-write lock // Stub for slim read-write lock
// Copyright (C) 1995-2002 Brad Wilson // Copyright (C) 1995-2002 Brad Wilson
static void WINAPI stub_srwlock_Init(MDBX_srwlock *srwl) { static void WINAPI stub_srwlock_Init(osal_srwlock_t *srwl) {
srwl->readerCount = srwl->writerCount = 0; srwl->readerCount = srwl->writerCount = 0;
} }
static void WINAPI stub_srwlock_AcquireShared(MDBX_srwlock *srwl) { static void WINAPI stub_srwlock_AcquireShared(osal_srwlock_t *srwl) {
while (true) { while (true) {
assert(srwl->writerCount >= 0 && srwl->readerCount >= 0); assert(srwl->writerCount >= 0 && srwl->readerCount >= 0);
@ -692,12 +692,12 @@ static void WINAPI stub_srwlock_AcquireShared(MDBX_srwlock *srwl) {
} }
} }
static void WINAPI stub_srwlock_ReleaseShared(MDBX_srwlock *srwl) { static void WINAPI stub_srwlock_ReleaseShared(osal_srwlock_t *srwl) {
assert(srwl->readerCount > 0); assert(srwl->readerCount > 0);
_InterlockedDecrement(&srwl->readerCount); _InterlockedDecrement(&srwl->readerCount);
} }
static void WINAPI stub_srwlock_AcquireExclusive(MDBX_srwlock *srwl) { static void WINAPI stub_srwlock_AcquireExclusive(osal_srwlock_t *srwl) {
while (true) { while (true) {
assert(srwl->writerCount >= 0 && srwl->readerCount >= 0); assert(srwl->writerCount >= 0 && srwl->readerCount >= 0);
@ -723,7 +723,7 @@ static void WINAPI stub_srwlock_AcquireExclusive(MDBX_srwlock *srwl) {
} }
} }
static void WINAPI stub_srwlock_ReleaseExclusive(MDBX_srwlock *srwl) { static void WINAPI stub_srwlock_ReleaseExclusive(osal_srwlock_t *srwl) {
assert(srwl->writerCount == 1 && srwl->readerCount >= 0); assert(srwl->writerCount == 1 && srwl->readerCount >= 0);
srwl->writerCount = 0; srwl->writerCount = 0;
} }
@ -739,9 +739,9 @@ static uint64_t WINAPI stub_GetTickCount64(void) {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
#ifndef xMDBX_ALLOY #ifndef xMDBX_ALLOY
MDBX_srwlock_function mdbx_srwlock_Init, mdbx_srwlock_AcquireShared, osal_srwlock_t_function osal_srwlock_Init, osal_srwlock_AcquireShared,
mdbx_srwlock_ReleaseShared, mdbx_srwlock_AcquireExclusive, osal_srwlock_ReleaseShared, osal_srwlock_AcquireExclusive,
mdbx_srwlock_ReleaseExclusive; osal_srwlock_ReleaseExclusive;
MDBX_NtExtendSection mdbx_NtExtendSection; MDBX_NtExtendSection mdbx_NtExtendSection;
MDBX_GetFileInformationByHandleEx mdbx_GetFileInformationByHandleEx; MDBX_GetFileInformationByHandleEx mdbx_GetFileInformationByHandleEx;
@ -789,24 +789,24 @@ static void mdbx_winnt_import(void) {
GET_PROC_ADDR(hAdvapi32dll, RegGetValueA); GET_PROC_ADDR(hAdvapi32dll, RegGetValueA);
#undef GET_PROC_ADDR #undef GET_PROC_ADDR
const MDBX_srwlock_function init = const osal_srwlock_t_function init = (osal_srwlock_t_function)GetProcAddress(
(MDBX_srwlock_function)GetProcAddress(hKernel32dll, "InitializeSRWLock"); hKernel32dll, "InitializeSRWLock");
if (init != NULL) { if (init != NULL) {
mdbx_srwlock_Init = init; osal_srwlock_Init = init;
mdbx_srwlock_AcquireShared = (MDBX_srwlock_function)GetProcAddress( osal_srwlock_AcquireShared = (osal_srwlock_t_function)GetProcAddress(
hKernel32dll, "AcquireSRWLockShared"); hKernel32dll, "AcquireSRWLockShared");
mdbx_srwlock_ReleaseShared = (MDBX_srwlock_function)GetProcAddress( osal_srwlock_ReleaseShared = (osal_srwlock_t_function)GetProcAddress(
hKernel32dll, "ReleaseSRWLockShared"); hKernel32dll, "ReleaseSRWLockShared");
mdbx_srwlock_AcquireExclusive = (MDBX_srwlock_function)GetProcAddress( osal_srwlock_AcquireExclusive = (osal_srwlock_t_function)GetProcAddress(
hKernel32dll, "AcquireSRWLockExclusive"); hKernel32dll, "AcquireSRWLockExclusive");
mdbx_srwlock_ReleaseExclusive = (MDBX_srwlock_function)GetProcAddress( osal_srwlock_ReleaseExclusive = (osal_srwlock_t_function)GetProcAddress(
hKernel32dll, "ReleaseSRWLockExclusive"); hKernel32dll, "ReleaseSRWLockExclusive");
} else { } else {
mdbx_srwlock_Init = stub_srwlock_Init; osal_srwlock_Init = stub_srwlock_Init;
mdbx_srwlock_AcquireShared = stub_srwlock_AcquireShared; osal_srwlock_AcquireShared = stub_srwlock_AcquireShared;
mdbx_srwlock_ReleaseShared = stub_srwlock_ReleaseShared; osal_srwlock_ReleaseShared = stub_srwlock_ReleaseShared;
mdbx_srwlock_AcquireExclusive = stub_srwlock_AcquireExclusive; osal_srwlock_AcquireExclusive = stub_srwlock_AcquireExclusive;
mdbx_srwlock_ReleaseExclusive = stub_srwlock_ReleaseExclusive; osal_srwlock_ReleaseExclusive = stub_srwlock_ReleaseExclusive;
} }
} }

View File

@ -20,7 +20,7 @@
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */ #pragma warning(disable : 4996) /* The POSIX name is deprecated... */
#endif /* _MSC_VER (warnings) */ #endif /* _MSC_VER (warnings) */
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */ #define xMDBX_TOOLS /* Avoid using internal eASSERT() */
#include "internals.h" #include "internals.h"
typedef struct flagbit { typedef struct flagbit {
@ -193,12 +193,12 @@ static void pagemap_cleanup(void) {
for (size_t i = CORE_DBS + /* account pseudo-entry for meta */ 1; for (size_t i = CORE_DBS + /* account pseudo-entry for meta */ 1;
i < ARRAY_LENGTH(walk.dbi); ++i) { i < ARRAY_LENGTH(walk.dbi); ++i) {
if (walk.dbi[i].name) { if (walk.dbi[i].name) {
mdbx_free((void *)walk.dbi[i].name); osal_free((void *)walk.dbi[i].name);
walk.dbi[i].name = nullptr; walk.dbi[i].name = nullptr;
} }
} }
mdbx_free(walk.pagemap); osal_free(walk.pagemap);
walk.pagemap = nullptr; walk.pagemap = nullptr;
} }
@ -229,7 +229,7 @@ static walk_dbi_t *pagemap_lookup_dbi(const char *dbi_name, bool silent) {
if (dbi == ARRAY_END(walk.dbi)) if (dbi == ARRAY_END(walk.dbi))
return nullptr; return nullptr;
dbi->name = mdbx_strdup(dbi_name); dbi->name = osal_strdup(dbi_name);
return last = dbi; return last = dbi;
} }
@ -247,7 +247,7 @@ static void MDBX_PRINTF_ARGS(4, 5)
break; break;
if (!p) { if (!p) {
p = mdbx_calloc(1, sizeof(*p)); p = osal_calloc(1, sizeof(*p));
if (unlikely(!p)) if (unlikely(!p))
return; return;
p->caption = msg; p->caption = msg;
@ -292,7 +292,7 @@ static size_t problems_pop(struct problem *list) {
count += problems_list->count; count += problems_list->count;
print("%s%s (%" PRIuPTR ")", i ? ", " : "", problems_list->caption, print("%s%s (%" PRIuPTR ")", i ? ", " : "", problems_list->caption,
problems_list->count); problems_list->count);
mdbx_free(problems_list); osal_free(problems_list);
problems_list = p; problems_list = p;
} }
print("\n"); print("\n");
@ -529,7 +529,7 @@ static int handle_freedb(const uint64_t record_number, const MDBX_val *key,
number = data->iov_len / sizeof(pgno_t) - 1; number = data->iov_len / sizeof(pgno_t) - 1;
} else if (data->iov_len - (number + 1) * sizeof(pgno_t) >= } else if (data->iov_len - (number + 1) * sizeof(pgno_t) >=
/* LY: allow gap up to one page. it is ok /* LY: allow gap up to one page. it is ok
* and better than shink-and-retry inside mdbx_update_gc() */ * and better than shink-and-retry inside update_gc() */
envinfo.mi_dxb_pagesize) envinfo.mi_dxb_pagesize)
problem_add("entry", txnid, "extra idl space", problem_add("entry", txnid, "extra idl space",
"%" PRIuSIZE " < %" PRIuSIZE " (minor, not a trouble)", "%" PRIuSIZE " < %" PRIuSIZE " (minor, not a trouble)",
@ -626,7 +626,7 @@ static int handle_maindb(const uint64_t record_number, const MDBX_val *key,
return handle_userdb(record_number, key, data); return handle_userdb(record_number, key, data);
} }
name = mdbx_malloc(key->iov_len + 1); name = osal_malloc(key->iov_len + 1);
if (unlikely(!name)) if (unlikely(!name))
return MDBX_ENOMEM; return MDBX_ENOMEM;
memcpy(name, key->iov_base, key->iov_len); memcpy(name, key->iov_base, key->iov_len);
@ -634,7 +634,7 @@ static int handle_maindb(const uint64_t record_number, const MDBX_val *key,
userdb_count++; userdb_count++;
rc = process_db(~0u, name, handle_userdb, false); rc = process_db(~0u, name, handle_userdb, false);
mdbx_free(name); osal_free(name);
if (rc != MDBX_INCOMPATIBLE) if (rc != MDBX_INCOMPATIBLE)
return rc; return rc;
@ -1340,7 +1340,7 @@ int main(int argc, char *argv[]) {
} }
#endif #endif
if (rc) { if (rc) {
error("mdbx_filesize() failed, error %d %s\n", rc, mdbx_strerror(rc)); error("osal_filesize() failed, error %d %s\n", rc, mdbx_strerror(rc));
goto bailout; goto bailout;
} }
@ -1504,7 +1504,7 @@ int main(int argc, char *argv[]) {
print("Traversal b-tree by txn#%" PRIaTXN "...\n", txn->mt_txnid); print("Traversal b-tree by txn#%" PRIaTXN "...\n", txn->mt_txnid);
fflush(nullptr); fflush(nullptr);
walk.pagemap = mdbx_calloc((size_t)backed_pages, sizeof(*walk.pagemap)); walk.pagemap = osal_calloc((size_t)backed_pages, sizeof(*walk.pagemap));
if (!walk.pagemap) { if (!walk.pagemap) {
rc = errno ? errno : MDBX_ENOMEM; rc = errno ? errno : MDBX_ENOMEM;
error("calloc() failed, error %d %s\n", rc, mdbx_strerror(rc)); error("calloc() failed, error %d %s\n", rc, mdbx_strerror(rc));

View File

@ -20,7 +20,7 @@
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */ #pragma warning(disable : 4996) /* The POSIX name is deprecated... */
#endif /* _MSC_VER (warnings) */ #endif /* _MSC_VER (warnings) */
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */ #define xMDBX_TOOLS /* Avoid using internal eASSERT() */
#include "internals.h" #include "internals.h"
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)

View File

@ -22,7 +22,7 @@
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */ #pragma warning(disable : 4996) /* The POSIX name is deprecated... */
#endif /* _MSC_VER (warnings) */ #endif /* _MSC_VER (warnings) */
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */ #define xMDBX_TOOLS /* Avoid using internal eASSERT() */
#include "internals.h" #include "internals.h"
#include <ctype.h> #include <ctype.h>

View File

@ -20,7 +20,7 @@
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */ #pragma warning(disable : 4996) /* The POSIX name is deprecated... */
#endif /* _MSC_VER (warnings) */ #endif /* _MSC_VER (warnings) */
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */ #define xMDBX_TOOLS /* Avoid using internal eASSERT() */
#include "internals.h" #include "internals.h"
#include <ctype.h> #include <ctype.h>
@ -403,7 +403,7 @@ int main(int argc, char *argv[]) {
if (memchr(key.iov_base, '\0', key.iov_len)) if (memchr(key.iov_base, '\0', key.iov_len))
continue; continue;
subname = mdbx_realloc(buf4free, key.iov_len + 1); subname = osal_realloc(buf4free, key.iov_len + 1);
if (!subname) { if (!subname) {
rc = MDBX_ENOMEM; rc = MDBX_ENOMEM;
break; break;

View File

@ -20,7 +20,7 @@
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */ #pragma warning(disable : 4996) /* The POSIX name is deprecated... */
#endif /* _MSC_VER (warnings) */ #endif /* _MSC_VER (warnings) */
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */ #define xMDBX_TOOLS /* Avoid using internal eASSERT() */
#include "internals.h" #include "internals.h"
#include <ctype.h> #include <ctype.h>
@ -213,7 +213,7 @@ static int readhdr(void) {
if (str) { if (str) {
if (*str) { if (*str) {
free(subname); free(subname);
subname = mdbx_strdup(str); subname = osal_strdup(str);
if (!subname) { if (!subname) {
if (!quiet) if (!quiet)
perror("strdup()"); perror("strdup()");
@ -421,7 +421,7 @@ __hot static int readline(MDBX_val *out, MDBX_val *buf) {
/* Is buffer too short? */ /* Is buffer too short? */
while (c1[len - 1] != '\n') { while (c1[len - 1] != '\n') {
buf->iov_base = mdbx_realloc(buf->iov_base, buf->iov_len * 2); buf->iov_base = osal_realloc(buf->iov_base, buf->iov_len * 2);
if (!buf->iov_base) { if (!buf->iov_base) {
if (!quiet) if (!quiet)
fprintf(stderr, fprintf(stderr,
@ -560,7 +560,7 @@ int main(int argc, char *argv[]) {
envflags |= MDBX_NOSUBDIR; envflags |= MDBX_NOSUBDIR;
break; break;
case 's': case 's':
subname = mdbx_strdup(optarg); subname = osal_strdup(optarg);
break; break;
case 'N': case 'N':
putflags |= MDBX_NOOVERWRITE | MDBX_NODUPDATA; putflags |= MDBX_NOOVERWRITE | MDBX_NODUPDATA;
@ -606,7 +606,7 @@ int main(int argc, char *argv[]) {
fflush(nullptr); fflush(nullptr);
dbuf.iov_len = 4096; dbuf.iov_len = 4096;
dbuf.iov_base = mdbx_malloc(dbuf.iov_len); dbuf.iov_base = osal_malloc(dbuf.iov_len);
if (!dbuf.iov_base) { if (!dbuf.iov_base) {
rc = MDBX_ENOMEM; rc = MDBX_ENOMEM;
error("value-buffer", rc); error("value-buffer", rc);

View File

@ -20,7 +20,7 @@
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */ #pragma warning(disable : 4996) /* The POSIX name is deprecated... */
#endif /* _MSC_VER (warnings) */ #endif /* _MSC_VER (warnings) */
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */ #define xMDBX_TOOLS /* Avoid using internal eASSERT() */
#include "internals.h" #include "internals.h"
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -469,13 +469,13 @@ int main(int argc, char *argv[]) {
MDBX_dbi subdbi; MDBX_dbi subdbi;
if (memchr(key.iov_base, '\0', key.iov_len)) if (memchr(key.iov_base, '\0', key.iov_len))
continue; continue;
subname = mdbx_malloc(key.iov_len + 1); subname = osal_malloc(key.iov_len + 1);
memcpy(subname, key.iov_base, key.iov_len); memcpy(subname, key.iov_base, key.iov_len);
subname[key.iov_len] = '\0'; subname[key.iov_len] = '\0';
rc = mdbx_dbi_open(txn, subname, MDBX_DB_ACCEDE, &subdbi); rc = mdbx_dbi_open(txn, subname, MDBX_DB_ACCEDE, &subdbi);
if (rc == MDBX_SUCCESS) if (rc == MDBX_SUCCESS)
printf("Status of %s\n", subname); printf("Status of %s\n", subname);
mdbx_free(subname); osal_free(subname);
if (unlikely(rc != MDBX_SUCCESS)) { if (unlikely(rc != MDBX_SUCCESS)) {
if (rc == MDBX_INCOMPATIBLE) if (rc == MDBX_INCOMPATIBLE)
continue; continue;

View File

@ -232,12 +232,12 @@ __cold void mdbx_assert_fail(const MDBX_env *env, const char *msg,
(void)env; (void)env;
#endif /* MDBX_DEBUG */ #endif /* MDBX_DEBUG */
if (mdbx_debug_logger) if (debug_logger)
mdbx_debug_log(MDBX_LOG_FATAL, func, line, "assert: %s\n", msg); debug_log(MDBX_LOG_FATAL, func, line, "assert: %s\n", msg);
else { else {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
char *message = nullptr; char *message = nullptr;
const int num = mdbx_asprintf(&message, "\r\nMDBX-ASSERTION: %s, %s:%u", const int num = osal_asprintf(&message, "\r\nMDBX-ASSERTION: %s, %s:%u",
msg, func ? func : "unknown", line); msg, func ? func : "unknown", line);
if (num < 1 || !message) if (num < 1 || !message)
message = "<troubles with assertion-message preparation>"; message = "<troubles with assertion-message preparation>";
@ -261,7 +261,7 @@ __cold void mdbx_panic(const char *fmt, ...) {
va_start(ap, fmt); va_start(ap, fmt);
char *message = nullptr; char *message = nullptr;
const int num = mdbx_vasprintf(&message, fmt, ap); const int num = osal_vasprintf(&message, fmt, ap);
va_end(ap); va_end(ap);
const char *const const_message = const char *const const_message =
(num < 1 || !message) ? "<troubles with panic-message preparation>" (num < 1 || !message) ? "<troubles with panic-message preparation>"
@ -281,8 +281,8 @@ __cold void mdbx_panic(const char *fmt, ...) {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
#ifndef mdbx_vasprintf #ifndef osal_vasprintf
MDBX_INTERNAL_FUNC int mdbx_vasprintf(char **strp, const char *fmt, MDBX_INTERNAL_FUNC int osal_vasprintf(char **strp, const char *fmt,
va_list ap) { va_list ap) {
va_list ones; va_list ones;
va_copy(ones, ap); va_copy(ones, ap);
@ -294,7 +294,7 @@ MDBX_INTERNAL_FUNC int mdbx_vasprintf(char **strp, const char *fmt,
return needed; return needed;
} }
*strp = mdbx_malloc(needed + 1); *strp = osal_malloc(needed + 1);
if (unlikely(*strp == nullptr)) { if (unlikely(*strp == nullptr)) {
va_end(ones); va_end(ones);
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -310,25 +310,25 @@ MDBX_INTERNAL_FUNC int mdbx_vasprintf(char **strp, const char *fmt,
assert(actual == needed); assert(actual == needed);
if (unlikely(actual < 0)) { if (unlikely(actual < 0)) {
mdbx_free(*strp); osal_free(*strp);
*strp = nullptr; *strp = nullptr;
} }
return actual; return actual;
} }
#endif /* mdbx_vasprintf */ #endif /* osal_vasprintf */
#ifndef mdbx_asprintf #ifndef osal_asprintf
MDBX_INTERNAL_FUNC int mdbx_asprintf(char **strp, const char *fmt, ...) { MDBX_INTERNAL_FUNC int osal_asprintf(char **strp, const char *fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
int rc = mdbx_vasprintf(strp, fmt, ap); int rc = osal_vasprintf(strp, fmt, ap);
va_end(ap); va_end(ap);
return rc; return rc;
} }
#endif /* mdbx_asprintf */ #endif /* osal_asprintf */
#ifndef mdbx_memalign_alloc #ifndef osal_memalign_alloc
MDBX_INTERNAL_FUNC int mdbx_memalign_alloc(size_t alignment, size_t bytes, MDBX_INTERNAL_FUNC int osal_memalign_alloc(size_t alignment, size_t bytes,
void **result) { void **result) {
assert(is_powerof2(alignment) && alignment >= sizeof(void *)); assert(is_powerof2(alignment) && alignment >= sizeof(void *));
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -349,35 +349,35 @@ MDBX_INTERNAL_FUNC int mdbx_memalign_alloc(size_t alignment, size_t bytes,
#error FIXME #error FIXME
#endif #endif
} }
#endif /* mdbx_memalign_alloc */ #endif /* osal_memalign_alloc */
#ifndef mdbx_memalign_free #ifndef osal_memalign_free
MDBX_INTERNAL_FUNC void mdbx_memalign_free(void *ptr) { MDBX_INTERNAL_FUNC void osal_memalign_free(void *ptr) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
VirtualFree(ptr, 0, MEM_RELEASE); VirtualFree(ptr, 0, MEM_RELEASE);
#else #else
mdbx_free(ptr); osal_free(ptr);
#endif #endif
} }
#endif /* mdbx_memalign_free */ #endif /* osal_memalign_free */
#ifndef mdbx_strdup #ifndef osal_strdup
char *mdbx_strdup(const char *str) { char *osal_strdup(const char *str) {
if (!str) if (!str)
return NULL; return NULL;
size_t bytes = strlen(str) + 1; size_t bytes = strlen(str) + 1;
char *dup = mdbx_malloc(bytes); char *dup = osal_malloc(bytes);
if (dup) if (dup)
memcpy(dup, str, bytes); memcpy(dup, str, bytes);
return dup; return dup;
} }
#endif /* mdbx_strdup */ #endif /* osal_strdup */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
MDBX_INTERNAL_FUNC int mdbx_condpair_init(mdbx_condpair_t *condpair) { MDBX_INTERNAL_FUNC int osal_condpair_init(osal_condpair_t *condpair) {
int rc; int rc;
memset(condpair, 0, sizeof(mdbx_condpair_t)); memset(condpair, 0, sizeof(osal_condpair_t));
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if ((condpair->mutex = CreateMutexW(NULL, FALSE, NULL)) == NULL) { if ((condpair->mutex = CreateMutexW(NULL, FALSE, NULL)) == NULL) {
rc = (int)GetLastError(); rc = (int)GetLastError();
@ -410,11 +410,11 @@ bailout_cond:
(void)pthread_mutex_destroy(&condpair->mutex); (void)pthread_mutex_destroy(&condpair->mutex);
#endif #endif
bailout_mutex: bailout_mutex:
memset(condpair, 0, sizeof(mdbx_condpair_t)); memset(condpair, 0, sizeof(osal_condpair_t));
return rc; return rc;
} }
MDBX_INTERNAL_FUNC int mdbx_condpair_destroy(mdbx_condpair_t *condpair) { MDBX_INTERNAL_FUNC int osal_condpair_destroy(osal_condpair_t *condpair) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
int rc = CloseHandle(condpair->mutex) ? MDBX_SUCCESS : (int)GetLastError(); int rc = CloseHandle(condpair->mutex) ? MDBX_SUCCESS : (int)GetLastError();
rc = CloseHandle(condpair->event[0]) ? rc : (int)GetLastError(); rc = CloseHandle(condpair->event[0]) ? rc : (int)GetLastError();
@ -424,20 +424,20 @@ MDBX_INTERNAL_FUNC int mdbx_condpair_destroy(mdbx_condpair_t *condpair) {
rc = (err = pthread_cond_destroy(&condpair->cond[0])) ? err : rc; rc = (err = pthread_cond_destroy(&condpair->cond[0])) ? err : rc;
rc = (err = pthread_cond_destroy(&condpair->cond[1])) ? err : rc; rc = (err = pthread_cond_destroy(&condpair->cond[1])) ? err : rc;
#endif #endif
memset(condpair, 0, sizeof(mdbx_condpair_t)); memset(condpair, 0, sizeof(osal_condpair_t));
return rc; return rc;
} }
MDBX_INTERNAL_FUNC int mdbx_condpair_lock(mdbx_condpair_t *condpair) { MDBX_INTERNAL_FUNC int osal_condpair_lock(osal_condpair_t *condpair) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
DWORD code = WaitForSingleObject(condpair->mutex, INFINITE); DWORD code = WaitForSingleObject(condpair->mutex, INFINITE);
return waitstatus2errcode(code); return waitstatus2errcode(code);
#else #else
return mdbx_pthread_mutex_lock(&condpair->mutex); return osal_pthread_mutex_lock(&condpair->mutex);
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_condpair_unlock(mdbx_condpair_t *condpair) { MDBX_INTERNAL_FUNC int osal_condpair_unlock(osal_condpair_t *condpair) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
return ReleaseMutex(condpair->mutex) ? MDBX_SUCCESS : (int)GetLastError(); return ReleaseMutex(condpair->mutex) ? MDBX_SUCCESS : (int)GetLastError();
#else #else
@ -445,7 +445,7 @@ MDBX_INTERNAL_FUNC int mdbx_condpair_unlock(mdbx_condpair_t *condpair) {
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_condpair_signal(mdbx_condpair_t *condpair, MDBX_INTERNAL_FUNC int osal_condpair_signal(osal_condpair_t *condpair,
bool part) { bool part) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
return SetEvent(condpair->event[part]) ? MDBX_SUCCESS : (int)GetLastError(); return SetEvent(condpair->event[part]) ? MDBX_SUCCESS : (int)GetLastError();
@ -454,7 +454,7 @@ MDBX_INTERNAL_FUNC int mdbx_condpair_signal(mdbx_condpair_t *condpair,
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_condpair_wait(mdbx_condpair_t *condpair, MDBX_INTERNAL_FUNC int osal_condpair_wait(osal_condpair_t *condpair,
bool part) { bool part) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
DWORD code = SignalObjectAndWait(condpair->mutex, condpair->event[part], DWORD code = SignalObjectAndWait(condpair->mutex, condpair->event[part],
@ -472,7 +472,7 @@ MDBX_INTERNAL_FUNC int mdbx_condpair_wait(mdbx_condpair_t *condpair,
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
MDBX_INTERNAL_FUNC int mdbx_fastmutex_init(mdbx_fastmutex_t *fastmutex) { MDBX_INTERNAL_FUNC int osal_fastmutex_init(osal_fastmutex_t *fastmutex) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
InitializeCriticalSection(fastmutex); InitializeCriticalSection(fastmutex);
return MDBX_SUCCESS; return MDBX_SUCCESS;
@ -481,7 +481,7 @@ MDBX_INTERNAL_FUNC int mdbx_fastmutex_init(mdbx_fastmutex_t *fastmutex) {
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_fastmutex_destroy(mdbx_fastmutex_t *fastmutex) { MDBX_INTERNAL_FUNC int osal_fastmutex_destroy(osal_fastmutex_t *fastmutex) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
DeleteCriticalSection(fastmutex); DeleteCriticalSection(fastmutex);
return MDBX_SUCCESS; return MDBX_SUCCESS;
@ -490,7 +490,7 @@ MDBX_INTERNAL_FUNC int mdbx_fastmutex_destroy(mdbx_fastmutex_t *fastmutex) {
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_fastmutex_acquire(mdbx_fastmutex_t *fastmutex) { MDBX_INTERNAL_FUNC int osal_fastmutex_acquire(osal_fastmutex_t *fastmutex) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
__try { __try {
EnterCriticalSection(fastmutex); EnterCriticalSection(fastmutex);
@ -503,11 +503,11 @@ MDBX_INTERNAL_FUNC int mdbx_fastmutex_acquire(mdbx_fastmutex_t *fastmutex) {
} }
return MDBX_SUCCESS; return MDBX_SUCCESS;
#else #else
return mdbx_pthread_mutex_lock(fastmutex); return osal_pthread_mutex_lock(fastmutex);
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_fastmutex_release(mdbx_fastmutex_t *fastmutex) { MDBX_INTERNAL_FUNC int osal_fastmutex_release(osal_fastmutex_t *fastmutex) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
LeaveCriticalSection(fastmutex); LeaveCriticalSection(fastmutex);
return MDBX_SUCCESS; return MDBX_SUCCESS;
@ -527,7 +527,7 @@ static const DWORD WC_ERR_INVALID_CHARS =
: 0; : 0;
#endif /* WC_ERR_INVALID_CHARS */ #endif /* WC_ERR_INVALID_CHARS */
MDBX_INTERNAL_FUNC size_t mdbx_mb2w(wchar_t *dst, size_t dst_n, const char *src, MDBX_INTERNAL_FUNC size_t osal_mb2w(wchar_t *dst, size_t dst_n, const char *src,
size_t src_n) { size_t src_n) {
return MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, src, return MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, src,
(int)src_n, dst, (int)dst_n); (int)src_n, dst, (int)dst_n);
@ -537,7 +537,7 @@ MDBX_INTERNAL_FUNC size_t mdbx_mb2w(wchar_t *dst, size_t dst_n, const char *src,
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
MDBX_INTERNAL_FUNC int mdbx_removefile(const pathchar_t *pathname) { MDBX_INTERNAL_FUNC int osal_removefile(const pathchar_t *pathname) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
return DeleteFileW(pathname) ? MDBX_SUCCESS : (int)GetLastError(); return DeleteFileW(pathname) ? MDBX_SUCCESS : (int)GetLastError();
#else #else
@ -549,7 +549,7 @@ MDBX_INTERNAL_FUNC int mdbx_removefile(const pathchar_t *pathname) {
static bool is_valid_fd(int fd) { return !(isatty(fd) < 0 && errno == EBADF); } static bool is_valid_fd(int fd) { return !(isatty(fd) < 0 && errno == EBADF); }
#endif /*! Windows */ #endif /*! Windows */
MDBX_INTERNAL_FUNC int mdbx_removedirectory(const pathchar_t *pathname) { MDBX_INTERNAL_FUNC int osal_removedirectory(const pathchar_t *pathname) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
return RemoveDirectoryW(pathname) ? MDBX_SUCCESS : (int)GetLastError(); return RemoveDirectoryW(pathname) ? MDBX_SUCCESS : (int)GetLastError();
#else #else
@ -557,7 +557,7 @@ MDBX_INTERNAL_FUNC int mdbx_removedirectory(const pathchar_t *pathname) {
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_openfile(const enum mdbx_openfile_purpose purpose, MDBX_INTERNAL_FUNC int osal_openfile(const enum osal_openfile_purpose purpose,
const MDBX_env *env, const MDBX_env *env,
const pathchar_t *pathname, const pathchar_t *pathname,
mdbx_filehandle_t *fd, mdbx_filehandle_t *fd,
@ -687,18 +687,18 @@ MDBX_INTERNAL_FUNC int mdbx_openfile(const enum mdbx_openfile_purpose purpose,
int stub_fd0 = -1, stub_fd1 = -1, stub_fd2 = -1; int stub_fd0 = -1, stub_fd1 = -1, stub_fd2 = -1;
static const char dev_null[] = "/dev/null"; static const char dev_null[] = "/dev/null";
if (!is_valid_fd(STDIN_FILENO)) { if (!is_valid_fd(STDIN_FILENO)) {
mdbx_warning("STD%s_FILENO/%d is invalid, open %s for temporary stub", "IN", WARNING("STD%s_FILENO/%d is invalid, open %s for temporary stub", "IN",
STDIN_FILENO, dev_null); STDIN_FILENO, dev_null);
stub_fd0 = open(dev_null, O_RDONLY | O_NOCTTY); stub_fd0 = open(dev_null, O_RDONLY | O_NOCTTY);
} }
if (!is_valid_fd(STDOUT_FILENO)) { if (!is_valid_fd(STDOUT_FILENO)) {
mdbx_warning("STD%s_FILENO/%d is invalid, open %s for temporary stub", WARNING("STD%s_FILENO/%d is invalid, open %s for temporary stub", "OUT",
"OUT", STDOUT_FILENO, dev_null); STDOUT_FILENO, dev_null);
stub_fd1 = open(dev_null, O_WRONLY | O_NOCTTY); stub_fd1 = open(dev_null, O_WRONLY | O_NOCTTY);
} }
if (!is_valid_fd(STDERR_FILENO)) { if (!is_valid_fd(STDERR_FILENO)) {
mdbx_warning("STD%s_FILENO/%d is invalid, open %s for temporary stub", WARNING("STD%s_FILENO/%d is invalid, open %s for temporary stub", "ERR",
"ERR", STDERR_FILENO, dev_null); STDERR_FILENO, dev_null);
stub_fd2 = open(dev_null, O_WRONLY | O_NOCTTY); stub_fd2 = open(dev_null, O_WRONLY | O_NOCTTY);
} }
#else #else
@ -723,20 +723,20 @@ MDBX_INTERNAL_FUNC int mdbx_openfile(const enum mdbx_openfile_purpose purpose,
/* Safeguard for todo4recovery://erased_by_github/libmdbx/issues/144 */ /* Safeguard for todo4recovery://erased_by_github/libmdbx/issues/144 */
#if STDIN_FILENO == 0 && STDOUT_FILENO == 1 && STDERR_FILENO == 2 #if STDIN_FILENO == 0 && STDOUT_FILENO == 1 && STDERR_FILENO == 2
if (*fd == STDIN_FILENO) { if (*fd == STDIN_FILENO) {
mdbx_warning("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "IN", WARNING("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "IN",
STDIN_FILENO); STDIN_FILENO);
assert(stub_fd0 == -1); assert(stub_fd0 == -1);
*fd = dup(stub_fd0 = *fd); *fd = dup(stub_fd0 = *fd);
} }
if (*fd == STDOUT_FILENO) { if (*fd == STDOUT_FILENO) {
mdbx_warning("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "OUT", WARNING("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "OUT",
STDOUT_FILENO); STDOUT_FILENO);
assert(stub_fd1 == -1); assert(stub_fd1 == -1);
*fd = dup(stub_fd1 = *fd); *fd = dup(stub_fd1 = *fd);
} }
if (*fd == STDERR_FILENO) { if (*fd == STDERR_FILENO) {
mdbx_warning("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "ERR", WARNING("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "ERR",
STDERR_FILENO); STDERR_FILENO);
assert(stub_fd2 == -1); assert(stub_fd2 == -1);
*fd = dup(stub_fd2 = *fd); *fd = dup(stub_fd2 = *fd);
} }
@ -747,10 +747,9 @@ MDBX_INTERNAL_FUNC int mdbx_openfile(const enum mdbx_openfile_purpose purpose,
if (stub_fd2 != -1) if (stub_fd2 != -1)
close(stub_fd2); close(stub_fd2);
if (*fd >= STDIN_FILENO && *fd <= STDERR_FILENO) { if (*fd >= STDIN_FILENO && *fd <= STDERR_FILENO) {
mdbx_error( ERROR("Rejecting the use of a FD in the range "
"Rejecting the use of a FD in the range " "STDIN_FILENO/%d..STDERR_FILENO/%d to prevent database corruption",
"STDIN_FILENO/%d..STDERR_FILENO/%d to prevent database corruption", STDIN_FILENO, STDERR_FILENO);
STDIN_FILENO, STDERR_FILENO);
close(*fd); close(*fd);
return EBADF; return EBADF;
} }
@ -777,7 +776,7 @@ MDBX_INTERNAL_FUNC int mdbx_openfile(const enum mdbx_openfile_purpose purpose,
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL_FUNC int mdbx_closefile(mdbx_filehandle_t fd) { MDBX_INTERNAL_FUNC int osal_closefile(mdbx_filehandle_t fd) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
return CloseHandle(fd) ? MDBX_SUCCESS : (int)GetLastError(); return CloseHandle(fd) ? MDBX_SUCCESS : (int)GetLastError();
#else #else
@ -786,7 +785,7 @@ MDBX_INTERNAL_FUNC int mdbx_closefile(mdbx_filehandle_t fd) {
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, MDBX_INTERNAL_FUNC int osal_pread(mdbx_filehandle_t fd, void *buf, size_t bytes,
uint64_t offset) { uint64_t offset) {
if (bytes > MAX_WRITE) if (bytes > MAX_WRITE)
return MDBX_EINVAL; return MDBX_EINVAL;
@ -813,7 +812,7 @@ MDBX_INTERNAL_FUNC int mdbx_pread(mdbx_filehandle_t fd, void *buf, size_t bytes,
return (bytes == (size_t)read) ? MDBX_SUCCESS : MDBX_ENODATA; return (bytes == (size_t)read) ? MDBX_SUCCESS : MDBX_ENODATA;
} }
MDBX_INTERNAL_FUNC int mdbx_pwrite(mdbx_filehandle_t fd, const void *buf, MDBX_INTERNAL_FUNC int osal_pwrite(mdbx_filehandle_t fd, const void *buf,
size_t bytes, uint64_t offset) { size_t bytes, uint64_t offset) {
while (true) { while (true) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -849,7 +848,7 @@ MDBX_INTERNAL_FUNC int mdbx_pwrite(mdbx_filehandle_t fd, const void *buf,
} }
} }
MDBX_INTERNAL_FUNC int mdbx_write(mdbx_filehandle_t fd, const void *buf, MDBX_INTERNAL_FUNC int osal_write(mdbx_filehandle_t fd, const void *buf,
size_t bytes) { size_t bytes) {
while (true) { while (true) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -879,13 +878,13 @@ MDBX_INTERNAL_FUNC int mdbx_write(mdbx_filehandle_t fd, const void *buf,
} }
} }
int mdbx_pwritev(mdbx_filehandle_t fd, struct iovec *iov, int iovcnt, int osal_pwritev(mdbx_filehandle_t fd, struct iovec *iov, int iovcnt,
uint64_t offset, size_t expected_written) { uint64_t offset, size_t expected_written) {
#if defined(_WIN32) || defined(_WIN64) || defined(__APPLE__) || \ #if defined(_WIN32) || defined(_WIN64) || defined(__APPLE__) || \
(defined(__ANDROID_API__) && __ANDROID_API__ < 24) (defined(__ANDROID_API__) && __ANDROID_API__ < 24)
size_t written = 0; size_t written = 0;
for (int i = 0; i < iovcnt; ++i) { for (int i = 0; i < iovcnt; ++i) {
int rc = mdbx_pwrite(fd, iov[i].iov_base, iov[i].iov_len, offset); int rc = osal_pwrite(fd, iov[i].iov_base, iov[i].iov_len, offset);
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
return rc; return rc;
written += iov[i].iov_len; written += iov[i].iov_len;
@ -908,8 +907,8 @@ int mdbx_pwritev(mdbx_filehandle_t fd, struct iovec *iov, int iovcnt,
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_fsync(mdbx_filehandle_t fd, MDBX_INTERNAL_FUNC int osal_fsync(mdbx_filehandle_t fd,
enum mdbx_syncmode_bits mode_bits) { enum osal_syncmode_bits mode_bits) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if ((mode_bits & (MDBX_SYNC_DATA | MDBX_SYNC_IODQ)) && !FlushFileBuffers(fd)) if ((mode_bits & (MDBX_SYNC_DATA | MDBX_SYNC_IODQ)) && !FlushFileBuffers(fd))
return (int)GetLastError(); return (int)GetLastError();
@ -938,7 +937,7 @@ MDBX_INTERNAL_FUNC int mdbx_fsync(mdbx_filehandle_t fd,
break /* error */; break /* error */;
#if defined(__linux__) || defined(__gnu_linux__) #if defined(__linux__) || defined(__gnu_linux__)
case MDBX_SYNC_SIZE: case MDBX_SYNC_SIZE:
if (mdbx_linux_kernel_version >= 0x03060000) if (linux_kernel_version >= 0x03060000)
return MDBX_SUCCESS; return MDBX_SUCCESS;
__fallthrough /* fall through */; __fallthrough /* fall through */;
#endif /* Linux */ #endif /* Linux */
@ -955,7 +954,7 @@ MDBX_INTERNAL_FUNC int mdbx_fsync(mdbx_filehandle_t fd,
#endif #endif
} }
int mdbx_filesize(mdbx_filehandle_t fd, uint64_t *length) { int osal_filesize(mdbx_filehandle_t fd, uint64_t *length) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
BY_HANDLE_FILE_INFORMATION info; BY_HANDLE_FILE_INFORMATION info;
if (!GetFileInformationByHandle(fd, &info)) if (!GetFileInformationByHandle(fd, &info))
@ -974,7 +973,7 @@ int mdbx_filesize(mdbx_filehandle_t fd, uint64_t *length) {
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL_FUNC int mdbx_is_pipe(mdbx_filehandle_t fd) { MDBX_INTERNAL_FUNC int osal_is_pipe(mdbx_filehandle_t fd) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
switch (GetFileType(fd)) { switch (GetFileType(fd)) {
case FILE_TYPE_DISK: case FILE_TYPE_DISK:
@ -1005,7 +1004,7 @@ MDBX_INTERNAL_FUNC int mdbx_is_pipe(mdbx_filehandle_t fd) {
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_ftruncate(mdbx_filehandle_t fd, uint64_t length) { MDBX_INTERNAL_FUNC int osal_ftruncate(mdbx_filehandle_t fd, uint64_t length) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if (mdbx_SetFileInformationByHandle) { if (mdbx_SetFileInformationByHandle) {
FILE_END_OF_FILE_INFO EndOfFileInfo; FILE_END_OF_FILE_INFO EndOfFileInfo;
@ -1029,7 +1028,7 @@ MDBX_INTERNAL_FUNC int mdbx_ftruncate(mdbx_filehandle_t fd, uint64_t length) {
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_fseek(mdbx_filehandle_t fd, uint64_t pos) { MDBX_INTERNAL_FUNC int osal_fseek(mdbx_filehandle_t fd, uint64_t pos) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
LARGE_INTEGER li; LARGE_INTEGER li;
li.QuadPart = pos; li.QuadPart = pos;
@ -1045,7 +1044,7 @@ MDBX_INTERNAL_FUNC int mdbx_fseek(mdbx_filehandle_t fd, uint64_t pos) {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
MDBX_INTERNAL_FUNC int MDBX_INTERNAL_FUNC int
mdbx_thread_create(mdbx_thread_t *thread, osal_thread_create(osal_thread_t *thread,
THREAD_RESULT(THREAD_CALL *start_routine)(void *), THREAD_RESULT(THREAD_CALL *start_routine)(void *),
void *arg) { void *arg) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -1056,7 +1055,7 @@ mdbx_thread_create(mdbx_thread_t *thread,
#endif #endif
} }
MDBX_INTERNAL_FUNC int mdbx_thread_join(mdbx_thread_t thread) { MDBX_INTERNAL_FUNC int osal_thread_join(osal_thread_t thread) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
DWORD code = WaitForSingleObject(thread, INFINITE); DWORD code = WaitForSingleObject(thread, INFINITE);
return waitstatus2errcode(code); return waitstatus2errcode(code);
@ -1068,16 +1067,16 @@ MDBX_INTERNAL_FUNC int mdbx_thread_join(mdbx_thread_t thread) {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
MDBX_INTERNAL_FUNC int mdbx_msync(mdbx_mmap_t *map, size_t offset, MDBX_INTERNAL_FUNC int osal_msync(osal_mmap_t *map, size_t offset,
size_t length, size_t length,
enum mdbx_syncmode_bits mode_bits) { enum osal_syncmode_bits mode_bits) {
uint8_t *ptr = (uint8_t *)map->address + offset; uint8_t *ptr = (uint8_t *)map->address + offset;
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if (!FlushViewOfFile(ptr, length)) if (!FlushViewOfFile(ptr, length))
return (int)GetLastError(); return (int)GetLastError();
#else #else
#if defined(__linux__) || defined(__gnu_linux__) #if defined(__linux__) || defined(__gnu_linux__)
if (mode_bits == MDBX_SYNC_NONE && mdbx_linux_kernel_version > 0x02061300) if (mode_bits == MDBX_SYNC_NONE && linux_kernel_version > 0x02061300)
/* Since Linux 2.6.19, MS_ASYNC is in fact a no-op. The kernel properly /* Since Linux 2.6.19, MS_ASYNC is in fact a no-op. The kernel properly
* tracks dirty pages and flushes them to storage as necessary. */ * tracks dirty pages and flushes them to storage as necessary. */
return MDBX_SUCCESS; return MDBX_SUCCESS;
@ -1086,10 +1085,10 @@ MDBX_INTERNAL_FUNC int mdbx_msync(mdbx_mmap_t *map, size_t offset,
return errno; return errno;
mode_bits &= ~MDBX_SYNC_DATA; mode_bits &= ~MDBX_SYNC_DATA;
#endif #endif
return mdbx_fsync(map->fd, mode_bits); return osal_fsync(map->fd, mode_bits);
} }
MDBX_INTERNAL_FUNC int mdbx_check_fs_rdonly(mdbx_filehandle_t handle, MDBX_INTERNAL_FUNC int osal_check_fs_rdonly(mdbx_filehandle_t handle,
const pathchar_t *pathname, const pathchar_t *pathname,
int err) { int err) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -1119,7 +1118,7 @@ MDBX_INTERNAL_FUNC int mdbx_check_fs_rdonly(mdbx_filehandle_t handle,
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) { static int osal_check_fs_local(mdbx_filehandle_t handle, int flags) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if (mdbx_RunningUnderWine() && !(flags & MDBX_EXCLUSIVE)) if (mdbx_RunningUnderWine() && !(flags & MDBX_EXCLUSIVE))
return ERROR_NOT_CAPABLE /* workaround for Wine */; return ERROR_NOT_CAPABLE /* workaround for Wine */;
@ -1166,7 +1165,7 @@ static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) {
} }
if (mdbx_GetVolumeInformationByHandleW && mdbx_GetFinalPathNameByHandleW) { if (mdbx_GetVolumeInformationByHandleW && mdbx_GetFinalPathNameByHandleW) {
WCHAR *PathBuffer = mdbx_malloc(sizeof(WCHAR) * INT16_MAX); WCHAR *PathBuffer = osal_malloc(sizeof(WCHAR) * INT16_MAX);
if (!PathBuffer) if (!PathBuffer)
return MDBX_ENOMEM; return MDBX_ENOMEM;
@ -1234,7 +1233,7 @@ static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) {
} }
bailout: bailout:
mdbx_free(PathBuffer); osal_free(PathBuffer);
return rc; return rc;
} }
@ -1411,11 +1410,10 @@ static int check_mmap_limit(const size_t limit) {
const int log2page = log2n_powerof2(pagesize); const int log2page = log2n_powerof2(pagesize);
if ((limit >> (log2page + 7)) > (size_t)total_ram_pages || if ((limit >> (log2page + 7)) > (size_t)total_ram_pages ||
(limit >> (log2page + 6)) > (size_t)avail_ram_pages) { (limit >> (log2page + 6)) > (size_t)avail_ram_pages) {
mdbx_error( ERROR("%s (%zu pages) is too large for available (%zu pages) or total "
"%s (%zu pages) is too large for available (%zu pages) or total " "(%zu pages) system RAM",
"(%zu pages) system RAM", "database upper size limit", limit >> log2page, avail_ram_pages,
"database upper size limit", limit >> log2page, avail_ram_pages, total_ram_pages);
total_ram_pages);
return MDBX_TOO_LARGE; return MDBX_TOO_LARGE;
} }
} }
@ -1423,7 +1421,7 @@ static int check_mmap_limit(const size_t limit) {
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map, MDBX_INTERNAL_FUNC int osal_mmap(const int flags, osal_mmap_t *map,
const size_t size, const size_t limit, const size_t size, const size_t limit,
const unsigned options) { const unsigned options) {
assert(size <= limit); assert(size <= limit);
@ -1435,7 +1433,7 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
map->section = NULL; map->section = NULL;
#endif /* Windows */ #endif /* Windows */
int err = mdbx_check_fs_local(map->fd, flags); int err = osal_check_fs_local(map->fd, flags);
if (unlikely(err != MDBX_SUCCESS)) if (unlikely(err != MDBX_SUCCESS))
return err; return err;
@ -1444,7 +1442,7 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
return err; return err;
if ((flags & MDBX_RDONLY) == 0 && (options & MMAP_OPTION_TRUNCATE) != 0) { if ((flags & MDBX_RDONLY) == 0 && (options & MMAP_OPTION_TRUNCATE) != 0) {
err = mdbx_ftruncate(map->fd, size); err = osal_ftruncate(map->fd, size);
if (err != MDBX_SUCCESS) if (err != MDBX_SUCCESS)
return err; return err;
map->filesize = size; map->filesize = size;
@ -1452,7 +1450,7 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
map->current = size; map->current = size;
#endif /* !Windows */ #endif /* !Windows */
} else { } else {
err = mdbx_filesize(map->fd, &map->filesize); err = osal_filesize(map->fd, &map->filesize);
if (err != MDBX_SUCCESS) if (err != MDBX_SUCCESS)
return err; return err;
#if !(defined(_WIN32) || defined(_WIN64)) #if !(defined(_WIN32) || defined(_WIN64))
@ -1559,7 +1557,7 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL_FUNC int mdbx_munmap(mdbx_mmap_t *map) { MDBX_INTERNAL_FUNC int osal_munmap(osal_mmap_t *map) {
VALGRIND_MAKE_MEM_NOACCESS(map->address, map->current); VALGRIND_MAKE_MEM_NOACCESS(map->address, map->current);
/* Unpoisoning is required for ASAN to avoid false-positive diagnostic /* Unpoisoning is required for ASAN to avoid false-positive diagnostic
* when this memory will re-used by malloc or another mmapping. * when this memory will re-used by malloc or another mmapping.
@ -1586,7 +1584,7 @@ MDBX_INTERNAL_FUNC int mdbx_munmap(mdbx_mmap_t *map) {
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL_FUNC int mdbx_mresize(const int flags, mdbx_mmap_t *map, MDBX_INTERNAL_FUNC int osal_mresize(const int flags, osal_mmap_t *map,
size_t size, size_t limit) { size_t size, size_t limit) {
assert(size <= limit); assert(size <= limit);
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -1683,12 +1681,12 @@ retry_file_and_section:
map->address = NULL; map->address = NULL;
} }
err = mdbx_filesize(map->fd, &map->filesize); err = osal_filesize(map->fd, &map->filesize);
if (err != MDBX_SUCCESS) if (err != MDBX_SUCCESS)
goto bailout; goto bailout;
if ((flags & MDBX_RDONLY) == 0 && map->filesize != size) { if ((flags & MDBX_RDONLY) == 0 && map->filesize != size) {
err = mdbx_ftruncate(map->fd, size); err = osal_ftruncate(map->fd, size);
if (err == MDBX_SUCCESS) if (err == MDBX_SUCCESS)
map->filesize = size; map->filesize = size;
/* ignore error, because Windows unable shrink file /* ignore error, because Windows unable shrink file
@ -1764,7 +1762,7 @@ retry_mapview:;
#else /* Windows */ #else /* Windows */
map->filesize = 0; map->filesize = 0;
int rc = mdbx_filesize(map->fd, &map->filesize); int rc = osal_filesize(map->fd, &map->filesize);
if (rc != MDBX_SUCCESS) if (rc != MDBX_SUCCESS)
return rc; return rc;
@ -1774,7 +1772,7 @@ retry_mapview:;
rc = (size > map->current) ? MDBX_UNABLE_EXTEND_MAPSIZE : MDBX_EPERM; rc = (size > map->current) ? MDBX_UNABLE_EXTEND_MAPSIZE : MDBX_EPERM;
} else { } else {
if (map->filesize != size) { if (map->filesize != size) {
rc = mdbx_ftruncate(map->fd, size); rc = osal_ftruncate(map->fd, size);
if (rc != MDBX_SUCCESS) if (rc != MDBX_SUCCESS)
return rc; return rc;
map->filesize = size; map->filesize = size;
@ -1956,7 +1954,7 @@ retry_mapview:;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
__cold MDBX_INTERNAL_FUNC void mdbx_osal_jitter(bool tiny) { __cold MDBX_INTERNAL_FUNC void osal_jitter(bool tiny) {
for (;;) { for (;;) {
#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \ #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \
defined(__x86_64__) defined(__x86_64__)
@ -2011,8 +2009,7 @@ static LARGE_INTEGER performance_frequency;
static uint64_t ratio_16dot16_to_monotine; static uint64_t ratio_16dot16_to_monotine;
#endif #endif
MDBX_INTERNAL_FUNC uint64_t MDBX_INTERNAL_FUNC uint64_t osal_16dot16_to_monotime(uint32_t seconds_16dot16) {
mdbx_osal_16dot16_to_monotime(uint32_t seconds_16dot16) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if (unlikely(performance_frequency.QuadPart == 0)) if (unlikely(performance_frequency.QuadPart == 0))
QueryPerformanceFrequency(&performance_frequency); QueryPerformanceFrequency(&performance_frequency);
@ -2031,12 +2028,12 @@ mdbx_osal_16dot16_to_monotime(uint32_t seconds_16dot16) {
return likely(ret || seconds_16dot16 == 0) ? ret : /* fix underflow */ 1; return likely(ret || seconds_16dot16 == 0) ? ret : /* fix underflow */ 1;
} }
MDBX_INTERNAL_FUNC uint32_t mdbx_osal_monotime_to_16dot16(uint64_t monotime) { MDBX_INTERNAL_FUNC uint32_t osal_monotime_to_16dot16(uint64_t monotime) {
static uint64_t limit; static uint64_t limit;
if (unlikely(monotime > limit)) { if (unlikely(monotime > limit)) {
if (likely(limit != 0)) if (likely(limit != 0))
return UINT32_MAX; return UINT32_MAX;
limit = mdbx_osal_16dot16_to_monotime(UINT32_MAX - 1); limit = osal_16dot16_to_monotime(UINT32_MAX - 1);
if (unlikely(monotime > limit)) if (unlikely(monotime > limit))
return UINT32_MAX; return UINT32_MAX;
} }
@ -2053,7 +2050,7 @@ MDBX_INTERNAL_FUNC uint32_t mdbx_osal_monotime_to_16dot16(uint64_t monotime) {
return monotime > 0 /* fix underflow */; return monotime > 0 /* fix underflow */;
} }
MDBX_INTERNAL_FUNC uint64_t mdbx_osal_monotime(void) { MDBX_INTERNAL_FUNC uint64_t osal_monotime(void) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
LARGE_INTEGER counter; LARGE_INTEGER counter;
counter.QuadPart = 0; counter.QuadPart = 0;
@ -2222,7 +2219,7 @@ bootid_parse_uuid(bin128_t *s, const void *p, const size_t n) {
return false; return false;
} }
__cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) { __cold MDBX_INTERNAL_FUNC bin128_t osal_bootid(void) {
bin128_t bin = {{0, 0}}; bin128_t bin = {{0, 0}};
bool got_machineid = false, got_boottime = false, got_bootseq = false; bool got_machineid = false, got_boottime = false, got_bootseq = false;
@ -2535,7 +2532,7 @@ __cold int mdbx_get_sysraminfo(intptr_t *page_size, intptr_t *total_pages,
if (avail_pages) if (avail_pages)
*avail_pages = -1; *avail_pages = -1;
const intptr_t pagesize = mdbx_syspagesize(); const intptr_t pagesize = osal_syspagesize();
if (page_size) if (page_size)
*page_size = pagesize; *page_size = pagesize;
if (unlikely(pagesize < MIN_PAGESIZE || !is_powerof2(pagesize))) if (unlikely(pagesize < MIN_PAGESIZE || !is_powerof2(pagesize)))

View File

@ -58,7 +58,7 @@
#include <sys/cachectl.h> #include <sys/cachectl.h>
#endif #endif
MDBX_MAYBE_UNUSED static __inline void mdbx_compiler_barrier(void) { MDBX_MAYBE_UNUSED static __inline void osal_compiler_barrier(void) {
#if defined(__clang__) || defined(__GNUC__) #if defined(__clang__) || defined(__GNUC__)
__asm__ __volatile__("" ::: "memory"); __asm__ __volatile__("" ::: "memory");
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
@ -78,7 +78,7 @@ MDBX_MAYBE_UNUSED static __inline void mdbx_compiler_barrier(void) {
#endif #endif
} }
MDBX_MAYBE_UNUSED static __inline void mdbx_memory_barrier(void) { MDBX_MAYBE_UNUSED static __inline void osal_memory_barrier(void) {
#ifdef MDBX_HAVE_C11ATOMICS #ifdef MDBX_HAVE_C11ATOMICS
atomic_thread_fence(memory_order_seq_cst); atomic_thread_fence(memory_order_seq_cst);
#elif defined(__ATOMIC_SEQ_CST) #elif defined(__ATOMIC_SEQ_CST)
@ -116,8 +116,8 @@ MDBX_MAYBE_UNUSED static __inline void mdbx_memory_barrier(void) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
#define HAVE_SYS_STAT_H #define HAVE_SYS_STAT_H
#define HAVE_SYS_TYPES_H #define HAVE_SYS_TYPES_H
typedef HANDLE mdbx_thread_t; typedef HANDLE osal_thread_t;
typedef unsigned mdbx_thread_key_t; typedef unsigned osal_thread_key_t;
#define MAP_FAILED NULL #define MAP_FAILED NULL
#define HIGH_DWORD(v) ((DWORD)((sizeof(v) > 4) ? ((uint64_t)(v) >> 32) : 0)) #define HIGH_DWORD(v) ((DWORD)((sizeof(v) > 4) ? ((uint64_t)(v) >> 32) : 0))
#define THREAD_CALL WINAPI #define THREAD_CALL WINAPI
@ -125,8 +125,8 @@ typedef unsigned mdbx_thread_key_t;
typedef struct { typedef struct {
HANDLE mutex; HANDLE mutex;
HANDLE event[2]; HANDLE event[2];
} mdbx_condpair_t; } osal_condpair_t;
typedef CRITICAL_SECTION mdbx_fastmutex_t; typedef CRITICAL_SECTION osal_fastmutex_t;
#if !defined(_MSC_VER) && !defined(__try) #if !defined(_MSC_VER) && !defined(__try)
/* *INDENT-OFF* */ /* *INDENT-OFF* */
@ -139,36 +139,36 @@ typedef CRITICAL_SECTION mdbx_fastmutex_t;
#if MDBX_WITHOUT_MSVC_CRT #if MDBX_WITHOUT_MSVC_CRT
#ifndef mdbx_malloc #ifndef osal_malloc
static inline void *mdbx_malloc(size_t bytes) { static inline void *osal_malloc(size_t bytes) {
return HeapAlloc(GetProcessHeap(), 0, bytes); return HeapAlloc(GetProcessHeap(), 0, bytes);
} }
#endif /* mdbx_malloc */ #endif /* osal_malloc */
#ifndef mdbx_calloc #ifndef osal_calloc
static inline void *mdbx_calloc(size_t nelem, size_t size) { static inline void *osal_calloc(size_t nelem, size_t size) {
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nelem * size); return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nelem * size);
} }
#endif /* mdbx_calloc */ #endif /* osal_calloc */
#ifndef mdbx_realloc #ifndef osal_realloc
static inline void *mdbx_realloc(void *ptr, size_t bytes) { static inline void *osal_realloc(void *ptr, size_t bytes) {
return ptr ? HeapReAlloc(GetProcessHeap(), 0, ptr, bytes) return ptr ? HeapReAlloc(GetProcessHeap(), 0, ptr, bytes)
: HeapAlloc(GetProcessHeap(), 0, bytes); : HeapAlloc(GetProcessHeap(), 0, bytes);
} }
#endif /* mdbx_realloc */ #endif /* osal_realloc */
#ifndef mdbx_free #ifndef osal_free
static inline void mdbx_free(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); } static inline void osal_free(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); }
#endif /* mdbx_free */ #endif /* osal_free */
#else /* MDBX_WITHOUT_MSVC_CRT */ #else /* MDBX_WITHOUT_MSVC_CRT */
#define mdbx_malloc malloc #define osal_malloc malloc
#define mdbx_calloc calloc #define osal_calloc calloc
#define mdbx_realloc realloc #define osal_realloc realloc
#define mdbx_free free #define osal_free free
#define mdbx_strdup _strdup #define osal_strdup _strdup
#endif /* MDBX_WITHOUT_MSVC_CRT */ #endif /* MDBX_WITHOUT_MSVC_CRT */
@ -180,26 +180,26 @@ static inline void mdbx_free(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); }
#define vsnprintf _vsnprintf /* ntdll */ #define vsnprintf _vsnprintf /* ntdll */
#endif #endif
MDBX_INTERNAL_FUNC size_t mdbx_mb2w(wchar_t *dst, size_t dst_n, const char *src, MDBX_INTERNAL_FUNC size_t osal_mb2w(wchar_t *dst, size_t dst_n, const char *src,
size_t src_n); size_t src_n);
#else /*----------------------------------------------------------------------*/ #else /*----------------------------------------------------------------------*/
typedef pthread_t mdbx_thread_t; typedef pthread_t osal_thread_t;
typedef pthread_key_t mdbx_thread_key_t; typedef pthread_key_t osal_thread_key_t;
#define INVALID_HANDLE_VALUE (-1) #define INVALID_HANDLE_VALUE (-1)
#define THREAD_CALL #define THREAD_CALL
#define THREAD_RESULT void * #define THREAD_RESULT void *
typedef struct { typedef struct {
pthread_mutex_t mutex; pthread_mutex_t mutex;
pthread_cond_t cond[2]; pthread_cond_t cond[2];
} mdbx_condpair_t; } osal_condpair_t;
typedef pthread_mutex_t mdbx_fastmutex_t; typedef pthread_mutex_t osal_fastmutex_t;
#define mdbx_malloc malloc #define osal_malloc malloc
#define mdbx_calloc calloc #define osal_calloc calloc
#define mdbx_realloc realloc #define osal_realloc realloc
#define mdbx_free free #define osal_free free
#define mdbx_strdup strdup #define osal_strdup strdup
#endif /* Platform */ #endif /* Platform */
#if __GLIBC_PREREQ(2, 12) || defined(__FreeBSD__) || defined(malloc_usable_size) #if __GLIBC_PREREQ(2, 12) || defined(__FreeBSD__) || defined(malloc_usable_size)
@ -217,7 +217,7 @@ typedef pthread_mutex_t mdbx_fastmutex_t;
* This is the basic size that the platform's memory manager uses, and is * This is the basic size that the platform's memory manager uses, and is
* fundamental to the use of memory-mapped files. */ * fundamental to the use of memory-mapped files. */
MDBX_MAYBE_UNUSED MDBX_NOTHROW_CONST_FUNCTION static __inline size_t MDBX_MAYBE_UNUSED MDBX_NOTHROW_CONST_FUNCTION static __inline size_t
mdbx_syspagesize(void) { osal_syspagesize(void) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
SYSTEM_INFO si; SYSTEM_INFO si;
GetSystemInfo(&si); GetSystemInfo(&si);
@ -233,7 +233,7 @@ typedef wchar_t pathchar_t;
typedef char pathchar_t; typedef char pathchar_t;
#endif #endif
typedef struct mdbx_mmap_param { typedef struct osal_mmap_param {
union { union {
void *address; void *address;
uint8_t *dxb; uint8_t *dxb;
@ -246,7 +246,7 @@ typedef struct mdbx_mmap_param {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
HANDLE section; /* memory-mapped section handle */ HANDLE section; /* memory-mapped section handle */
#endif #endif
} mdbx_mmap_t; } osal_mmap_t;
typedef union bin128 { typedef union bin128 {
__anonymous_struct_extension__ struct { uint64_t x, y; }; __anonymous_struct_extension__ struct { uint64_t x, y; };
@ -254,13 +254,13 @@ typedef union bin128 {
} bin128_t; } bin128_t;
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
typedef union MDBX_srwlock { typedef union osal_srwlock {
__anonymous_struct_extension__ struct { __anonymous_struct_extension__ struct {
long volatile readerCount; long volatile readerCount;
long volatile writerCount; long volatile writerCount;
}; };
RTL_SRWLOCK native; RTL_SRWLOCK native;
} MDBX_srwlock; } osal_srwlock_t;
#endif /* Windows */ #endif /* Windows */
#ifndef __cplusplus #ifndef __cplusplus
@ -270,12 +270,12 @@ typedef union MDBX_srwlock {
#if (!defined(__GLIBC__) && __GLIBC_PREREQ(2, 1)) && \ #if (!defined(__GLIBC__) && __GLIBC_PREREQ(2, 1)) && \
(defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) (defined(_GNU_SOURCE) || defined(_BSD_SOURCE))
#define mdbx_asprintf asprintf #define osal_asprintf asprintf
#define mdbx_vasprintf vasprintf #define osal_vasprintf vasprintf
#else #else
MDBX_MAYBE_UNUSED MDBX_INTERNAL_FUNC MDBX_MAYBE_UNUSED MDBX_INTERNAL_FUNC
MDBX_PRINTF_ARGS(2, 3) int mdbx_asprintf(char **strp, const char *fmt, ...); MDBX_PRINTF_ARGS(2, 3) int osal_asprintf(char **strp, const char *fmt, ...);
MDBX_INTERNAL_FUNC int mdbx_vasprintf(char **strp, const char *fmt, va_list ap); MDBX_INTERNAL_FUNC int osal_vasprintf(char **strp, const char *fmt, va_list ap);
#endif #endif
#if !defined(MADV_DODUMP) && defined(MADV_CORE) #if !defined(MADV_DODUMP) && defined(MADV_CORE)
@ -286,8 +286,8 @@ MDBX_INTERNAL_FUNC int mdbx_vasprintf(char **strp, const char *fmt, va_list ap);
#define MADV_DONTDUMP MADV_NOCORE #define MADV_DONTDUMP MADV_NOCORE
#endif /* MADV_NOCORE -> MADV_DONTDUMP */ #endif /* MADV_NOCORE -> MADV_DONTDUMP */
MDBX_MAYBE_UNUSED MDBX_INTERNAL_FUNC void mdbx_osal_jitter(bool tiny); MDBX_MAYBE_UNUSED MDBX_INTERNAL_FUNC void osal_jitter(bool tiny);
MDBX_MAYBE_UNUSED static __inline void mdbx_jitter4testing(bool tiny); MDBX_MAYBE_UNUSED static __inline void jitter4testing(bool tiny);
/* max bytes to write in one call */ /* max bytes to write in one call */
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -297,15 +297,15 @@ MDBX_MAYBE_UNUSED static __inline void mdbx_jitter4testing(bool tiny);
#endif #endif
#if defined(__linux__) || defined(__gnu_linux__) #if defined(__linux__) || defined(__gnu_linux__)
MDBX_INTERNAL_VAR uint32_t mdbx_linux_kernel_version; MDBX_INTERNAL_VAR uint32_t linux_kernel_version;
MDBX_INTERNAL_VAR bool mdbx_RunningOnWSL1 /* Windows Subsystem 1 for Linux */; MDBX_INTERNAL_VAR bool mdbx_RunningOnWSL1 /* Windows Subsystem 1 for Linux */;
#endif /* Linux */ #endif /* Linux */
#ifndef mdbx_strdup #ifndef osal_strdup
LIBMDBX_API char *mdbx_strdup(const char *str); LIBMDBX_API char *osal_strdup(const char *str);
#endif #endif
MDBX_MAYBE_UNUSED static __inline int mdbx_get_errno(void) { MDBX_MAYBE_UNUSED static __inline int osal_get_errno(void) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
DWORD rc = GetLastError(); DWORD rc = GetLastError();
#else #else
@ -314,57 +314,57 @@ MDBX_MAYBE_UNUSED static __inline int mdbx_get_errno(void) {
return rc; return rc;
} }
#ifndef mdbx_memalign_alloc #ifndef osal_memalign_alloc
MDBX_INTERNAL_FUNC int mdbx_memalign_alloc(size_t alignment, size_t bytes, MDBX_INTERNAL_FUNC int osal_memalign_alloc(size_t alignment, size_t bytes,
void **result); void **result);
#endif #endif
#ifndef mdbx_memalign_free #ifndef osal_memalign_free
MDBX_INTERNAL_FUNC void mdbx_memalign_free(void *ptr); MDBX_INTERNAL_FUNC void osal_memalign_free(void *ptr);
#endif #endif
MDBX_INTERNAL_FUNC int mdbx_condpair_init(mdbx_condpair_t *condpair); MDBX_INTERNAL_FUNC int osal_condpair_init(osal_condpair_t *condpair);
MDBX_INTERNAL_FUNC int mdbx_condpair_lock(mdbx_condpair_t *condpair); MDBX_INTERNAL_FUNC int osal_condpair_lock(osal_condpair_t *condpair);
MDBX_INTERNAL_FUNC int mdbx_condpair_unlock(mdbx_condpair_t *condpair); MDBX_INTERNAL_FUNC int osal_condpair_unlock(osal_condpair_t *condpair);
MDBX_INTERNAL_FUNC int mdbx_condpair_signal(mdbx_condpair_t *condpair, MDBX_INTERNAL_FUNC int osal_condpair_signal(osal_condpair_t *condpair,
bool part); bool part);
MDBX_INTERNAL_FUNC int mdbx_condpair_wait(mdbx_condpair_t *condpair, bool part); MDBX_INTERNAL_FUNC int osal_condpair_wait(osal_condpair_t *condpair, bool part);
MDBX_INTERNAL_FUNC int mdbx_condpair_destroy(mdbx_condpair_t *condpair); MDBX_INTERNAL_FUNC int osal_condpair_destroy(osal_condpair_t *condpair);
MDBX_INTERNAL_FUNC int mdbx_fastmutex_init(mdbx_fastmutex_t *fastmutex); MDBX_INTERNAL_FUNC int osal_fastmutex_init(osal_fastmutex_t *fastmutex);
MDBX_INTERNAL_FUNC int mdbx_fastmutex_acquire(mdbx_fastmutex_t *fastmutex); MDBX_INTERNAL_FUNC int osal_fastmutex_acquire(osal_fastmutex_t *fastmutex);
MDBX_INTERNAL_FUNC int mdbx_fastmutex_release(mdbx_fastmutex_t *fastmutex); MDBX_INTERNAL_FUNC int osal_fastmutex_release(osal_fastmutex_t *fastmutex);
MDBX_INTERNAL_FUNC int mdbx_fastmutex_destroy(mdbx_fastmutex_t *fastmutex); MDBX_INTERNAL_FUNC int osal_fastmutex_destroy(osal_fastmutex_t *fastmutex);
MDBX_INTERNAL_FUNC int mdbx_pwritev(mdbx_filehandle_t fd, struct iovec *iov, MDBX_INTERNAL_FUNC int osal_pwritev(mdbx_filehandle_t fd, struct iovec *iov,
int iovcnt, uint64_t offset, int iovcnt, uint64_t offset,
size_t expected_written); size_t expected_written);
MDBX_INTERNAL_FUNC int mdbx_pread(mdbx_filehandle_t fd, void *buf, size_t count, MDBX_INTERNAL_FUNC int osal_pread(mdbx_filehandle_t fd, void *buf, size_t count,
uint64_t offset); uint64_t offset);
MDBX_INTERNAL_FUNC int mdbx_pwrite(mdbx_filehandle_t fd, const void *buf, MDBX_INTERNAL_FUNC int osal_pwrite(mdbx_filehandle_t fd, const void *buf,
size_t count, uint64_t offset); size_t count, uint64_t offset);
MDBX_INTERNAL_FUNC int mdbx_write(mdbx_filehandle_t fd, const void *buf, MDBX_INTERNAL_FUNC int osal_write(mdbx_filehandle_t fd, const void *buf,
size_t count); size_t count);
MDBX_INTERNAL_FUNC int MDBX_INTERNAL_FUNC int
mdbx_thread_create(mdbx_thread_t *thread, osal_thread_create(osal_thread_t *thread,
THREAD_RESULT(THREAD_CALL *start_routine)(void *), THREAD_RESULT(THREAD_CALL *start_routine)(void *),
void *arg); void *arg);
MDBX_INTERNAL_FUNC int mdbx_thread_join(mdbx_thread_t thread); MDBX_INTERNAL_FUNC int osal_thread_join(osal_thread_t thread);
enum mdbx_syncmode_bits { enum osal_syncmode_bits {
MDBX_SYNC_NONE = 0, MDBX_SYNC_NONE = 0,
MDBX_SYNC_DATA = 1, MDBX_SYNC_DATA = 1,
MDBX_SYNC_SIZE = 2, MDBX_SYNC_SIZE = 2,
MDBX_SYNC_IODQ = 4 MDBX_SYNC_IODQ = 4
}; };
MDBX_INTERNAL_FUNC int mdbx_fsync(mdbx_filehandle_t fd, MDBX_INTERNAL_FUNC int osal_fsync(mdbx_filehandle_t fd,
const enum mdbx_syncmode_bits mode_bits); const enum osal_syncmode_bits mode_bits);
MDBX_INTERNAL_FUNC int mdbx_ftruncate(mdbx_filehandle_t fd, uint64_t length); MDBX_INTERNAL_FUNC int osal_ftruncate(mdbx_filehandle_t fd, uint64_t length);
MDBX_INTERNAL_FUNC int mdbx_fseek(mdbx_filehandle_t fd, uint64_t pos); MDBX_INTERNAL_FUNC int osal_fseek(mdbx_filehandle_t fd, uint64_t pos);
MDBX_INTERNAL_FUNC int mdbx_filesize(mdbx_filehandle_t fd, uint64_t *length); MDBX_INTERNAL_FUNC int osal_filesize(mdbx_filehandle_t fd, uint64_t *length);
enum mdbx_openfile_purpose { enum osal_openfile_purpose {
MDBX_OPEN_DXB_READ = 0, MDBX_OPEN_DXB_READ = 0,
MDBX_OPEN_DXB_LAZY = 1, MDBX_OPEN_DXB_LAZY = 1,
MDBX_OPEN_DXB_DSYNC = 2, MDBX_OPEN_DXB_DSYNC = 2,
@ -373,26 +373,26 @@ enum mdbx_openfile_purpose {
MDBX_OPEN_DELETE = 5 MDBX_OPEN_DELETE = 5
}; };
MDBX_INTERNAL_FUNC int mdbx_openfile(const enum mdbx_openfile_purpose purpose, MDBX_INTERNAL_FUNC int osal_openfile(const enum osal_openfile_purpose purpose,
const MDBX_env *env, const MDBX_env *env,
const pathchar_t *pathname, const pathchar_t *pathname,
mdbx_filehandle_t *fd, mdbx_filehandle_t *fd,
mdbx_mode_t unix_mode_bits); mdbx_mode_t unix_mode_bits);
MDBX_INTERNAL_FUNC int mdbx_closefile(mdbx_filehandle_t fd); MDBX_INTERNAL_FUNC int osal_closefile(mdbx_filehandle_t fd);
MDBX_INTERNAL_FUNC int mdbx_removefile(const pathchar_t *pathname); MDBX_INTERNAL_FUNC int osal_removefile(const pathchar_t *pathname);
MDBX_INTERNAL_FUNC int mdbx_removedirectory(const pathchar_t *pathname); MDBX_INTERNAL_FUNC int osal_removedirectory(const pathchar_t *pathname);
MDBX_INTERNAL_FUNC int mdbx_is_pipe(mdbx_filehandle_t fd); MDBX_INTERNAL_FUNC int osal_is_pipe(mdbx_filehandle_t fd);
MDBX_INTERNAL_FUNC int mdbx_lockfile(mdbx_filehandle_t fd, bool wait); MDBX_INTERNAL_FUNC int osal_lockfile(mdbx_filehandle_t fd, bool wait);
#define MMAP_OPTION_TRUNCATE 1 #define MMAP_OPTION_TRUNCATE 1
#define MMAP_OPTION_SEMAPHORE 2 #define MMAP_OPTION_SEMAPHORE 2
MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map, MDBX_INTERNAL_FUNC int osal_mmap(const int flags, osal_mmap_t *map,
const size_t must, const size_t limit, const size_t must, const size_t limit,
const unsigned options); const unsigned options);
MDBX_INTERNAL_FUNC int mdbx_munmap(mdbx_mmap_t *map); MDBX_INTERNAL_FUNC int osal_munmap(osal_mmap_t *map);
#define MDBX_MRESIZE_MAY_MOVE 0x00000100 #define MDBX_MRESIZE_MAY_MOVE 0x00000100
#define MDBX_MRESIZE_MAY_UNMAP 0x00000200 #define MDBX_MRESIZE_MAY_UNMAP 0x00000200
MDBX_INTERNAL_FUNC int mdbx_mresize(const int flags, mdbx_mmap_t *map, MDBX_INTERNAL_FUNC int osal_mresize(const int flags, osal_mmap_t *map,
size_t size, size_t limit); size_t size, size_t limit);
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
typedef struct { typedef struct {
@ -400,18 +400,18 @@ typedef struct {
HANDLE handles[31]; HANDLE handles[31];
} mdbx_handle_array_t; } mdbx_handle_array_t;
MDBX_INTERNAL_FUNC int MDBX_INTERNAL_FUNC int
mdbx_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array); osal_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array);
MDBX_INTERNAL_FUNC int MDBX_INTERNAL_FUNC int
mdbx_resume_threads_after_remap(mdbx_handle_array_t *array); osal_resume_threads_after_remap(mdbx_handle_array_t *array);
#endif /* Windows */ #endif /* Windows */
MDBX_INTERNAL_FUNC int mdbx_msync(mdbx_mmap_t *map, size_t offset, MDBX_INTERNAL_FUNC int osal_msync(osal_mmap_t *map, size_t offset,
size_t length, size_t length,
enum mdbx_syncmode_bits mode_bits); enum osal_syncmode_bits mode_bits);
MDBX_INTERNAL_FUNC int mdbx_check_fs_rdonly(mdbx_filehandle_t handle, MDBX_INTERNAL_FUNC int osal_check_fs_rdonly(mdbx_filehandle_t handle,
const pathchar_t *pathname, const pathchar_t *pathname,
int err); int err);
MDBX_MAYBE_UNUSED static __inline uint32_t mdbx_getpid(void) { MDBX_MAYBE_UNUSED static __inline uint32_t osal_getpid(void) {
STATIC_ASSERT(sizeof(mdbx_pid_t) <= sizeof(uint32_t)); STATIC_ASSERT(sizeof(mdbx_pid_t) <= sizeof(uint32_t));
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
return GetCurrentProcessId(); return GetCurrentProcessId();
@ -421,7 +421,7 @@ MDBX_MAYBE_UNUSED static __inline uint32_t mdbx_getpid(void) {
#endif #endif
} }
MDBX_MAYBE_UNUSED static __inline uintptr_t mdbx_thread_self(void) { MDBX_MAYBE_UNUSED static __inline uintptr_t osal_thread_self(void) {
mdbx_tid_t thunk; mdbx_tid_t thunk;
STATIC_ASSERT(sizeof(uintptr_t) >= sizeof(thunk)); STATIC_ASSERT(sizeof(uintptr_t) >= sizeof(thunk));
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -434,24 +434,23 @@ MDBX_MAYBE_UNUSED static __inline uintptr_t mdbx_thread_self(void) {
#if !defined(_WIN32) && !defined(_WIN64) #if !defined(_WIN32) && !defined(_WIN64)
#if defined(__ANDROID_API__) || defined(ANDROID) || defined(BIONIC) #if defined(__ANDROID_API__) || defined(ANDROID) || defined(BIONIC)
MDBX_INTERNAL_FUNC int mdbx_check_tid4bionic(void); MDBX_INTERNAL_FUNC int osal_check_tid4bionic(void);
#else #else
static __inline int mdbx_check_tid4bionic(void) { return 0; } static __inline int osal_check_tid4bionic(void) { return 0; }
#endif /* __ANDROID_API__ || ANDROID) || BIONIC */ #endif /* __ANDROID_API__ || ANDROID) || BIONIC */
MDBX_MAYBE_UNUSED static __inline int MDBX_MAYBE_UNUSED static __inline int
mdbx_pthread_mutex_lock(pthread_mutex_t *mutex) { osal_pthread_mutex_lock(pthread_mutex_t *mutex) {
int err = mdbx_check_tid4bionic(); int err = osal_check_tid4bionic();
return unlikely(err) ? err : pthread_mutex_lock(mutex); return unlikely(err) ? err : pthread_mutex_lock(mutex);
} }
#endif /* !Windows */ #endif /* !Windows */
MDBX_INTERNAL_FUNC uint64_t mdbx_osal_monotime(void); MDBX_INTERNAL_FUNC uint64_t osal_monotime(void);
MDBX_INTERNAL_FUNC uint64_t MDBX_INTERNAL_FUNC uint64_t osal_16dot16_to_monotime(uint32_t seconds_16dot16);
mdbx_osal_16dot16_to_monotime(uint32_t seconds_16dot16); MDBX_INTERNAL_FUNC uint32_t osal_monotime_to_16dot16(uint64_t monotime);
MDBX_INTERNAL_FUNC uint32_t mdbx_osal_monotime_to_16dot16(uint64_t monotime);
MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void); MDBX_INTERNAL_FUNC bin128_t osal_bootid(void);
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* lck stuff */ /* lck stuff */
@ -467,7 +466,7 @@ MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void);
/// MUST NOT initialize shared synchronization objects in memory-mapped /// MUST NOT initialize shared synchronization objects in memory-mapped
/// LCK-file that are already in use. /// LCK-file that are already in use.
/// \return Error code or zero on success. /// \return Error code or zero on success.
MDBX_INTERNAL_FUNC int mdbx_lck_init(MDBX_env *env, MDBX_INTERNAL_FUNC int osal_lck_init(MDBX_env *env,
MDBX_env *inprocess_neighbor, MDBX_env *inprocess_neighbor,
int global_uniqueness_flag); int global_uniqueness_flag);
@ -488,7 +487,7 @@ MDBX_INTERNAL_FUNC int mdbx_lck_init(MDBX_env *env,
/// of other instances of MDBX_env within the current process, e.g. /// of other instances of MDBX_env within the current process, e.g.
/// restore POSIX-fcntl locks after the closing of file descriptors. /// restore POSIX-fcntl locks after the closing of file descriptors.
/// \return Error code (MDBX_PANIC) or zero on success. /// \return Error code (MDBX_PANIC) or zero on success.
MDBX_INTERNAL_FUNC int mdbx_lck_destroy(MDBX_env *env, MDBX_INTERNAL_FUNC int osal_lck_destroy(MDBX_env *env,
MDBX_env *inprocess_neighbor); MDBX_env *inprocess_neighbor);
/// \brief Connects to shared interprocess locking objects and tries to acquire /// \brief Connects to shared interprocess locking objects and tries to acquire
@ -496,14 +495,14 @@ MDBX_INTERNAL_FUNC int mdbx_lck_destroy(MDBX_env *env,
/// Depending on implementation or/and platform (Windows) this function may /// Depending on implementation or/and platform (Windows) this function may
/// acquire the non-OS super-level lock (e.g. for shared synchronization /// acquire the non-OS super-level lock (e.g. for shared synchronization
/// objects initialization), which will be downgraded to OS-exclusive or /// objects initialization), which will be downgraded to OS-exclusive or
/// shared via explicit calling of mdbx_lck_downgrade(). /// shared via explicit calling of osal_lck_downgrade().
/// \return /// \return
/// MDBX_RESULT_TRUE (-1) - if an exclusive lock was acquired and thus /// MDBX_RESULT_TRUE (-1) - if an exclusive lock was acquired and thus
/// the current process is the first and only after the last use of DB. /// the current process is the first and only after the last use of DB.
/// MDBX_RESULT_FALSE (0) - if a shared lock was acquired and thus /// MDBX_RESULT_FALSE (0) - if a shared lock was acquired and thus
/// DB has already been opened and now is used by other processes. /// DB has already been opened and now is used by other processes.
/// Otherwise (not 0 and not -1) - error code. /// Otherwise (not 0 and not -1) - error code.
MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env); MDBX_INTERNAL_FUNC int osal_lck_seize(MDBX_env *env);
/// \brief Downgrades the level of initially acquired lock to /// \brief Downgrades the level of initially acquired lock to
/// operational level specified by argument. The reson for such downgrade: /// operational level specified by argument. The reson for such downgrade:
@ -516,14 +515,14 @@ MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env);
/// (env->me_flags & MDBX_EXCLUSIVE) != 0 - downgrade to exclusive /// (env->me_flags & MDBX_EXCLUSIVE) != 0 - downgrade to exclusive
/// operational lock. /// operational lock.
/// \return Error code or zero on success /// \return Error code or zero on success
MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env); MDBX_INTERNAL_FUNC int osal_lck_downgrade(MDBX_env *env);
/// \brief Locks LCK-file or/and table of readers for (de)registering. /// \brief Locks LCK-file or/and table of readers for (de)registering.
/// \return Error code or zero on success /// \return Error code or zero on success
MDBX_INTERNAL_FUNC int mdbx_rdt_lock(MDBX_env *env); MDBX_INTERNAL_FUNC int osal_rdt_lock(MDBX_env *env);
/// \brief Unlocks LCK-file or/and table of readers after (de)registering. /// \brief Unlocks LCK-file or/and table of readers after (de)registering.
MDBX_INTERNAL_FUNC void mdbx_rdt_unlock(MDBX_env *env); MDBX_INTERNAL_FUNC void osal_rdt_unlock(MDBX_env *env);
/// \brief Acquires lock for DB change (on writing transaction start) /// \brief Acquires lock for DB change (on writing transaction start)
/// Reading transactions will not be blocked. /// Reading transactions will not be blocked.
@ -538,15 +537,15 @@ LIBMDBX_API void mdbx_txn_unlock(MDBX_env *env);
/// \brief Sets alive-flag of reader presence (indicative lock) for PID of /// \brief Sets alive-flag of reader presence (indicative lock) for PID of
/// the current process. The function does no more than needed for /// the current process. The function does no more than needed for
/// the correct working of mdbx_rpid_check() in other processes. /// the correct working of osal_rpid_check() in other processes.
/// \return Error code or zero on success /// \return Error code or zero on success
MDBX_INTERNAL_FUNC int mdbx_rpid_set(MDBX_env *env); MDBX_INTERNAL_FUNC int osal_rpid_set(MDBX_env *env);
/// \brief Resets alive-flag of reader presence (indicative lock) /// \brief Resets alive-flag of reader presence (indicative lock)
/// for PID of the current process. The function does no more than needed /// for PID of the current process. The function does no more than needed
/// for the correct working of mdbx_rpid_check() in other processes. /// for the correct working of osal_rpid_check() in other processes.
/// \return Error code or zero on success /// \return Error code or zero on success
MDBX_INTERNAL_FUNC int mdbx_rpid_clear(MDBX_env *env); MDBX_INTERNAL_FUNC int osal_rpid_clear(MDBX_env *env);
/// \brief Checks for reading process status with the given pid with help of /// \brief Checks for reading process status with the given pid with help of
/// alive-flag of presence (indicative lock) or using another way. /// alive-flag of presence (indicative lock) or using another way.
@ -556,28 +555,28 @@ MDBX_INTERNAL_FUNC int mdbx_rpid_clear(MDBX_env *env);
/// MDBX_RESULT_FALSE (0) - if the reader process with the given PID is absent /// MDBX_RESULT_FALSE (0) - if the reader process with the given PID is absent
/// or not working with DB (indicative lock is not present). /// or not working with DB (indicative lock is not present).
/// Otherwise (not 0 and not -1) - error code. /// Otherwise (not 0 and not -1) - error code.
MDBX_INTERNAL_FUNC int mdbx_rpid_check(MDBX_env *env, uint32_t pid); MDBX_INTERNAL_FUNC int osal_rpid_check(MDBX_env *env, uint32_t pid);
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
#define MUSTDIE_MB2WIDE(FROM, TO) \ #define OSAL_MB2WIDE(FROM, TO) \
do { \ do { \
const char *const from_tmp = (FROM); \ const char *const from_tmp = (FROM); \
const size_t from_mblen = strlen(from_tmp); \ const size_t from_mblen = strlen(from_tmp); \
const size_t to_wlen = mdbx_mb2w(nullptr, 0, from_tmp, from_mblen); \ const size_t to_wlen = osal_mb2w(nullptr, 0, from_tmp, from_mblen); \
if (to_wlen < 1 || to_wlen > /* MAX_PATH */ INT16_MAX) \ if (to_wlen < 1 || to_wlen > /* MAX_PATH */ INT16_MAX) \
return ERROR_INVALID_NAME; \ return ERROR_INVALID_NAME; \
wchar_t *const to_tmp = _alloca((to_wlen + 1) * sizeof(wchar_t)); \ wchar_t *const to_tmp = _alloca((to_wlen + 1) * sizeof(wchar_t)); \
if (to_wlen + 1 != \ if (to_wlen + 1 != \
mdbx_mb2w(to_tmp, to_wlen + 1, from_tmp, from_mblen + 1)) \ osal_mb2w(to_tmp, to_wlen + 1, from_tmp, from_mblen + 1)) \
return ERROR_INVALID_NAME; \ return ERROR_INVALID_NAME; \
(TO) = to_tmp; \ (TO) = to_tmp; \
} while (0) } while (0)
typedef void(WINAPI *MDBX_srwlock_function)(MDBX_srwlock *); typedef void(WINAPI *osal_srwlock_t_function)(osal_srwlock_t *);
MDBX_INTERNAL_VAR MDBX_srwlock_function mdbx_srwlock_Init, MDBX_INTERNAL_VAR osal_srwlock_t_function osal_srwlock_Init,
mdbx_srwlock_AcquireShared, mdbx_srwlock_ReleaseShared, osal_srwlock_AcquireShared, osal_srwlock_ReleaseShared,
mdbx_srwlock_AcquireExclusive, mdbx_srwlock_ReleaseExclusive; osal_srwlock_AcquireExclusive, osal_srwlock_ReleaseExclusive;
#if _WIN32_WINNT < 0x0600 /* prior to Windows Vista */ #if _WIN32_WINNT < 0x0600 /* prior to Windows Vista */
typedef enum _FILE_INFO_BY_HANDLE_CLASS { typedef enum _FILE_INFO_BY_HANDLE_CLASS {

View File

@ -94,7 +94,7 @@
#define MDBX_INTERNAL_FUNC #define MDBX_INTERNAL_FUNC
#define MDBX_INTERNAL_VAR extern #define MDBX_INTERNAL_VAR extern
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */ #define xMDBX_TOOLS /* Avoid using internal eASSERT() */
#include "../mdbx.h++" #include "../mdbx.h++"
#include "../src/base.h" #include "../src/base.h"
#include "../src/osal.h" #include "../src/osal.h"

View File

@ -15,7 +15,7 @@ REGISTER_TESTCASE(copy);
void testcase_copy::copy_db(const bool with_compaction) { void testcase_copy::copy_db(const bool with_compaction) {
int err = mdbx_env_delete(copy_pathname.c_str(), MDBX_ENV_JUST_DELETE); int err = mdbx_env_delete(copy_pathname.c_str(), MDBX_ENV_JUST_DELETE);
if (err != MDBX_SUCCESS && err != MDBX_RESULT_TRUE) if (err != MDBX_SUCCESS && err != MDBX_RESULT_TRUE)
failure_perror("mdbx_removefile()", err); failure_perror("osal_removefile()", err);
err = mdbx_env_copy(db_guard.get(), copy_pathname.c_str(), err = mdbx_env_copy(db_guard.get(), copy_pathname.c_str(),
with_compaction ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS); with_compaction ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS);

View File

@ -4,7 +4,7 @@
msync(start) msync(start)
fun:msync fun:msync
... ...
fun:mdbx_sync_locked* fun:sync_locked*
} }
{ {
msync-whole-mmap-2 msync-whole-mmap-2
@ -12,7 +12,7 @@
msync(start) msync(start)
fun:msync fun:msync
... ...
fun:mdbx_env_sync_internal* fun:env_sync*
} }
{ {
msync-whole-mmap-3 msync-whole-mmap-3
@ -20,7 +20,7 @@
msync(start) msync(start)
fun:msync fun:msync
... ...
fun:mdbx_mapresize* fun:map_resize*
} }
{ {
msync-wipe-steady msync-wipe-steady
@ -28,21 +28,21 @@
msync(start) msync(start)
fun:msync fun:msync
... ...
fun:mdbx_wipe_steady* fun:wipe_steady*
} }
# memcmp() inside mdbx_iov_write() as workaround for todo4recovery://erased_by_github/libmdbx/issues/269 # memcmp() inside iov_write() as workaround for todo4recovery://erased_by_github/libmdbx/issues/269
{ {
write-page-check-bcmp write-page-check-bcmp
Memcheck:Cond Memcheck:Cond
fun:bcmp fun:bcmp
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
write-page-check-memcmp write-page-check-memcmp
Memcheck:Cond Memcheck:Cond
fun:memcmp* fun:memcmp*
fun:mdbx_iov_write* fun:iov_write*
} }
# single-page flush by pwrite() # single-page flush by pwrite()
@ -52,7 +52,7 @@
pwrite(buf) pwrite(buf)
fun:pwrite fun:pwrite
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwrite64-page-flush pwrite64-page-flush
@ -60,7 +60,7 @@
pwrite64(buf) pwrite64(buf)
fun:pwrite fun:pwrite
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
# modern Valgrind don't support the `vector[...]` pattern # modern Valgrind don't support the `vector[...]` pattern
@ -70,16 +70,16 @@
# pwritev(vector[...]) # pwritev(vector[...])
# fun:pwritev # fun:pwritev
# ... # ...
# fun:mdbx_iov_write* # fun:iov_write*
#} #}
# for((i=0;i<64;++i)); do echo -e "{\n pwritev-page-flush-$i\n Memcheck:Param\n pwritev(vector[$i])\n fun:pwritev\n ...\n fun:mdbx_iov_write*\n}"; done >> valgrind_suppress.txt # for((i=0;i<64;++i)); do echo -e "{\n pwritev-page-flush-$i\n Memcheck:Param\n pwritev(vector[$i])\n fun:pwritev\n ...\n fun:iov_write*\n}"; done >> valgrind_suppress.txt
{ {
pwritev-page-flush-0 pwritev-page-flush-0
Memcheck:Param Memcheck:Param
pwritev(vector[0]) pwritev(vector[0])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-1 pwritev-page-flush-1
@ -87,7 +87,7 @@
pwritev(vector[1]) pwritev(vector[1])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-2 pwritev-page-flush-2
@ -95,7 +95,7 @@
pwritev(vector[2]) pwritev(vector[2])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-3 pwritev-page-flush-3
@ -103,7 +103,7 @@
pwritev(vector[3]) pwritev(vector[3])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-4 pwritev-page-flush-4
@ -111,7 +111,7 @@
pwritev(vector[4]) pwritev(vector[4])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-5 pwritev-page-flush-5
@ -119,7 +119,7 @@
pwritev(vector[5]) pwritev(vector[5])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-6 pwritev-page-flush-6
@ -127,7 +127,7 @@
pwritev(vector[6]) pwritev(vector[6])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-7 pwritev-page-flush-7
@ -135,7 +135,7 @@
pwritev(vector[7]) pwritev(vector[7])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-8 pwritev-page-flush-8
@ -143,7 +143,7 @@
pwritev(vector[8]) pwritev(vector[8])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-9 pwritev-page-flush-9
@ -151,7 +151,7 @@
pwritev(vector[9]) pwritev(vector[9])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-10 pwritev-page-flush-10
@ -159,7 +159,7 @@
pwritev(vector[10]) pwritev(vector[10])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-11 pwritev-page-flush-11
@ -167,7 +167,7 @@
pwritev(vector[11]) pwritev(vector[11])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-12 pwritev-page-flush-12
@ -175,7 +175,7 @@
pwritev(vector[12]) pwritev(vector[12])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-13 pwritev-page-flush-13
@ -183,7 +183,7 @@
pwritev(vector[13]) pwritev(vector[13])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-14 pwritev-page-flush-14
@ -191,7 +191,7 @@
pwritev(vector[14]) pwritev(vector[14])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-15 pwritev-page-flush-15
@ -199,7 +199,7 @@
pwritev(vector[15]) pwritev(vector[15])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-16 pwritev-page-flush-16
@ -207,7 +207,7 @@
pwritev(vector[16]) pwritev(vector[16])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-17 pwritev-page-flush-17
@ -215,7 +215,7 @@
pwritev(vector[17]) pwritev(vector[17])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-18 pwritev-page-flush-18
@ -223,7 +223,7 @@
pwritev(vector[18]) pwritev(vector[18])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-19 pwritev-page-flush-19
@ -231,7 +231,7 @@
pwritev(vector[19]) pwritev(vector[19])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-20 pwritev-page-flush-20
@ -239,7 +239,7 @@
pwritev(vector[20]) pwritev(vector[20])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-21 pwritev-page-flush-21
@ -247,7 +247,7 @@
pwritev(vector[21]) pwritev(vector[21])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-22 pwritev-page-flush-22
@ -255,7 +255,7 @@
pwritev(vector[22]) pwritev(vector[22])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-23 pwritev-page-flush-23
@ -263,7 +263,7 @@
pwritev(vector[23]) pwritev(vector[23])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-24 pwritev-page-flush-24
@ -271,7 +271,7 @@
pwritev(vector[24]) pwritev(vector[24])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-25 pwritev-page-flush-25
@ -279,7 +279,7 @@
pwritev(vector[25]) pwritev(vector[25])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-26 pwritev-page-flush-26
@ -287,7 +287,7 @@
pwritev(vector[26]) pwritev(vector[26])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-27 pwritev-page-flush-27
@ -295,7 +295,7 @@
pwritev(vector[27]) pwritev(vector[27])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-28 pwritev-page-flush-28
@ -303,7 +303,7 @@
pwritev(vector[28]) pwritev(vector[28])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-29 pwritev-page-flush-29
@ -311,7 +311,7 @@
pwritev(vector[29]) pwritev(vector[29])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-30 pwritev-page-flush-30
@ -319,7 +319,7 @@
pwritev(vector[30]) pwritev(vector[30])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-31 pwritev-page-flush-31
@ -327,7 +327,7 @@
pwritev(vector[31]) pwritev(vector[31])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-32 pwritev-page-flush-32
@ -335,7 +335,7 @@
pwritev(vector[32]) pwritev(vector[32])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-33 pwritev-page-flush-33
@ -343,7 +343,7 @@
pwritev(vector[33]) pwritev(vector[33])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-34 pwritev-page-flush-34
@ -351,7 +351,7 @@
pwritev(vector[34]) pwritev(vector[34])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-35 pwritev-page-flush-35
@ -359,7 +359,7 @@
pwritev(vector[35]) pwritev(vector[35])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-36 pwritev-page-flush-36
@ -367,7 +367,7 @@
pwritev(vector[36]) pwritev(vector[36])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-37 pwritev-page-flush-37
@ -375,7 +375,7 @@
pwritev(vector[37]) pwritev(vector[37])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-38 pwritev-page-flush-38
@ -383,7 +383,7 @@
pwritev(vector[38]) pwritev(vector[38])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-39 pwritev-page-flush-39
@ -391,7 +391,7 @@
pwritev(vector[39]) pwritev(vector[39])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-40 pwritev-page-flush-40
@ -399,7 +399,7 @@
pwritev(vector[40]) pwritev(vector[40])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-41 pwritev-page-flush-41
@ -407,7 +407,7 @@
pwritev(vector[41]) pwritev(vector[41])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-42 pwritev-page-flush-42
@ -415,7 +415,7 @@
pwritev(vector[42]) pwritev(vector[42])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-43 pwritev-page-flush-43
@ -423,7 +423,7 @@
pwritev(vector[43]) pwritev(vector[43])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-44 pwritev-page-flush-44
@ -431,7 +431,7 @@
pwritev(vector[44]) pwritev(vector[44])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-45 pwritev-page-flush-45
@ -439,7 +439,7 @@
pwritev(vector[45]) pwritev(vector[45])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-46 pwritev-page-flush-46
@ -447,7 +447,7 @@
pwritev(vector[46]) pwritev(vector[46])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-47 pwritev-page-flush-47
@ -455,7 +455,7 @@
pwritev(vector[47]) pwritev(vector[47])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-48 pwritev-page-flush-48
@ -463,7 +463,7 @@
pwritev(vector[48]) pwritev(vector[48])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-49 pwritev-page-flush-49
@ -471,7 +471,7 @@
pwritev(vector[49]) pwritev(vector[49])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-50 pwritev-page-flush-50
@ -479,7 +479,7 @@
pwritev(vector[50]) pwritev(vector[50])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-51 pwritev-page-flush-51
@ -487,7 +487,7 @@
pwritev(vector[51]) pwritev(vector[51])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-52 pwritev-page-flush-52
@ -495,7 +495,7 @@
pwritev(vector[52]) pwritev(vector[52])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-53 pwritev-page-flush-53
@ -503,7 +503,7 @@
pwritev(vector[53]) pwritev(vector[53])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-54 pwritev-page-flush-54
@ -511,7 +511,7 @@
pwritev(vector[54]) pwritev(vector[54])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-55 pwritev-page-flush-55
@ -519,7 +519,7 @@
pwritev(vector[55]) pwritev(vector[55])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-56 pwritev-page-flush-56
@ -527,7 +527,7 @@
pwritev(vector[56]) pwritev(vector[56])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-57 pwritev-page-flush-57
@ -535,7 +535,7 @@
pwritev(vector[57]) pwritev(vector[57])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-58 pwritev-page-flush-58
@ -543,7 +543,7 @@
pwritev(vector[58]) pwritev(vector[58])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-59 pwritev-page-flush-59
@ -551,7 +551,7 @@
pwritev(vector[59]) pwritev(vector[59])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-60 pwritev-page-flush-60
@ -559,7 +559,7 @@
pwritev(vector[60]) pwritev(vector[60])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-61 pwritev-page-flush-61
@ -567,7 +567,7 @@
pwritev(vector[61]) pwritev(vector[61])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-62 pwritev-page-flush-62
@ -575,7 +575,7 @@
pwritev(vector[62]) pwritev(vector[62])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }
{ {
pwritev-page-flush-63 pwritev-page-flush-63
@ -583,5 +583,5 @@
pwritev(vector[63]) pwritev(vector[63])
fun:pwritev fun:pwritev
... ...
fun:mdbx_iov_write* fun:iov_write*
} }