mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-30 03:44:13 +08:00
mdbx: rename internal functions, types and macros (to be closer to MithrilDB).
This commit is contained in:
parent
096d6a9bd6
commit
18e557c6e8
6521
src/core.c
6521
src/core.c
File diff suppressed because it is too large
Load Diff
196
src/internals.h
196
src/internals.h
@ -285,15 +285,15 @@ typedef union {
|
||||
#ifndef __cplusplus
|
||||
|
||||
#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))
|
||||
#else /* MDBX_HAVE_C11ATOMICS */
|
||||
#define mdbx_memory_fence(order, write) \
|
||||
#define osal_memory_fence(order, write) \
|
||||
do { \
|
||||
mdbx_compiler_barrier(); \
|
||||
osal_compiler_barrier(); \
|
||||
if (write && order > (MDBX_CPU_WRITEBACK_INCOHERENT ? mo_Relaxed \
|
||||
: mo_AcquireRelease)) \
|
||||
mdbx_memory_barrier(); \
|
||||
osal_memory_barrier(); \
|
||||
} while (0)
|
||||
#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));
|
||||
#else /* MDBX_HAVE_C11ATOMICS */
|
||||
if (order != mo_Relaxed)
|
||||
mdbx_compiler_barrier();
|
||||
osal_compiler_barrier();
|
||||
p->weak = value;
|
||||
mdbx_memory_fence(order, true);
|
||||
osal_memory_fence(order, true);
|
||||
#endif /* MDBX_HAVE_C11ATOMICS */
|
||||
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)));
|
||||
return atomic_load_explicit(MDBX_c11a_ro(uint32_t, p), mo_c11_load(order));
|
||||
#else /* MDBX_HAVE_C11ATOMICS */
|
||||
mdbx_memory_fence(order, false);
|
||||
osal_memory_fence(order, false);
|
||||
const uint32_t value = p->weak;
|
||||
if (order != mo_Relaxed)
|
||||
mdbx_compiler_barrier();
|
||||
osal_compiler_barrier();
|
||||
return value;
|
||||
#endif /* MDBX_HAVE_C11ATOMICS */
|
||||
}
|
||||
@ -584,17 +584,17 @@ typedef struct {
|
||||
wops; /* Number of explicit write operations (not a pages) to a disk */
|
||||
MDBX_atomic_uint64_t
|
||||
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;
|
||||
#endif /* MDBX_ENABLE_PGOP_STAT */
|
||||
|
||||
#if MDBX_LOCKING == MDBX_LOCKING_WIN32FILES
|
||||
#define MDBX_CLOCK_SIGN UINT32_C(0xF10C)
|
||||
typedef void mdbx_ipclock_t;
|
||||
typedef void osal_ipclock_t;
|
||||
#elif MDBX_LOCKING == MDBX_LOCKING_SYSV
|
||||
|
||||
#define MDBX_CLOCK_SIGN UINT32_C(0xF18D)
|
||||
typedef mdbx_pid_t mdbx_ipclock_t;
|
||||
typedef mdbx_pid_t osal_ipclock_t;
|
||||
#ifndef EOWNERDEAD
|
||||
#define EOWNERDEAD MDBX_RESULT_TRUE
|
||||
#endif
|
||||
@ -602,17 +602,17 @@ typedef mdbx_pid_t mdbx_ipclock_t;
|
||||
#elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \
|
||||
MDBX_LOCKING == MDBX_LOCKING_POSIX2008
|
||||
#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
|
||||
#define MDBX_CLOCK_SIGN UINT32_C(0xFC29)
|
||||
typedef sem_t mdbx_ipclock_t;
|
||||
typedef sem_t osal_ipclock_t;
|
||||
#else
|
||||
#error "FIXME"
|
||||
#endif /* MDBX_LOCKING */
|
||||
|
||||
#if MDBX_LOCKING > MDBX_LOCKING_SYSV && !defined(__cplusplus)
|
||||
MDBX_INTERNAL_FUNC int mdbx_ipclock_stub(mdbx_ipclock_t *ipc);
|
||||
MDBX_INTERNAL_FUNC int mdbx_ipclock_destroy(mdbx_ipclock_t *ipc);
|
||||
MDBX_INTERNAL_FUNC int osal_ipclock_stub(osal_ipclock_t *ipc);
|
||||
MDBX_INTERNAL_FUNC int osal_ipclock_destroy(osal_ipclock_t *ipc);
|
||||
#endif /* MDBX_LOCKING */
|
||||
|
||||
/* Reader Lock Table
|
||||
@ -729,7 +729,7 @@ typedef struct MDBX_lockinfo {
|
||||
|
||||
/* Write transaction lock. */
|
||||
#if MDBX_LOCKING > 0
|
||||
mdbx_ipclock_t mti_wlock;
|
||||
osal_ipclock_t mti_wlock;
|
||||
#endif /* MDBX_LOCKING > 0 */
|
||||
|
||||
atomic_txnid_t mti_oldest_reader;
|
||||
@ -755,7 +755,7 @@ typedef struct MDBX_lockinfo {
|
||||
|
||||
/* Readeaders registration lock. */
|
||||
#if MDBX_LOCKING > 0
|
||||
mdbx_ipclock_t mti_rlock;
|
||||
osal_ipclock_t mti_rlock;
|
||||
#endif /* MDBX_LOCKING > 0 */
|
||||
|
||||
/* 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_RW_BEGIN_FLAGS \
|
||||
(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 TXN_FLAGS \
|
||||
@ -1123,11 +1123,11 @@ struct MDBX_env {
|
||||
#define MDBX_DEPRECATED_COALESCE UINT32_C(0x2000000)
|
||||
#define ENV_INTERNAL_FLAGS (MDBX_FATAL_ERROR | MDBX_ENV_ACTIVE | MDBX_ENV_TXKEY)
|
||||
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_lazy_fd me_dxb_mmap.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
|
||||
struct MDBX_lockinfo *me_lck;
|
||||
|
||||
@ -1138,11 +1138,11 @@ struct MDBX_env {
|
||||
uint16_t me_merge_threshold,
|
||||
me_merge_threshold_gc; /* pages emptier than this are candidates for
|
||||
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 */
|
||||
MDBX_dbi me_maxdbs; /* size of the DB table */
|
||||
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 */
|
||||
void *me_pbuf; /* scratch area for DUPSORT put() */
|
||||
MDBX_txn *me_txn0; /* preallocated write transaction */
|
||||
@ -1198,7 +1198,7 @@ struct MDBX_env {
|
||||
/* --------------------------------------------------- mostly volatile part */
|
||||
|
||||
MDBX_txn *me_txn; /* current write transaction */
|
||||
mdbx_fastmutex_t me_dbi_lock;
|
||||
osal_fastmutex_t me_dbi_lock;
|
||||
#if MDBX_CACHE_METAPTR
|
||||
volatile const MDBX_meta *cache_last_meta;
|
||||
volatile const MDBX_meta *cache_steady_meta;
|
||||
@ -1211,11 +1211,11 @@ struct MDBX_env {
|
||||
MDBX_PNL me_retired_pages;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
MDBX_srwlock me_remap_guard;
|
||||
osal_srwlock_t me_remap_guard;
|
||||
/* Workaround for LockFileEx and WriteFile multithread bug */
|
||||
CRITICAL_SECTION me_windowsbug_lock;
|
||||
#else
|
||||
mdbx_fastmutex_t me_remap_guard;
|
||||
osal_fastmutex_t me_remap_guard;
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------- debugging */
|
||||
@ -1250,142 +1250,138 @@ struct MDBX_env {
|
||||
#define MDBX_RUNTIME_FLAGS_INIT \
|
||||
((MDBX_DEBUG) > 0) * MDBX_DBG_ASSERT + ((MDBX_DEBUG) > 1) * MDBX_DBG_AUDIT
|
||||
|
||||
extern uint8_t mdbx_runtime_flags;
|
||||
extern uint8_t mdbx_loglevel;
|
||||
extern MDBX_debug_func *mdbx_debug_logger;
|
||||
extern uint8_t runtime_flags;
|
||||
extern uint8_t loglevel;
|
||||
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_DBG_JITTER & mdbx_runtime_flags)
|
||||
mdbx_osal_jitter(tiny);
|
||||
if (MDBX_DBG_JITTER & runtime_flags)
|
||||
osal_jitter(tiny);
|
||||
#else
|
||||
(void)tiny;
|
||||
#endif
|
||||
}
|
||||
|
||||
MDBX_INTERNAL_FUNC void MDBX_PRINTF_ARGS(4, 5)
|
||||
mdbx_debug_log(int level, const char *function, int line, const char *fmt,
|
||||
...) MDBX_PRINTF_ARGS(4, 5);
|
||||
MDBX_INTERNAL_FUNC void mdbx_debug_log_va(int level, const char *function,
|
||||
int line, const char *fmt,
|
||||
va_list args);
|
||||
debug_log(int level, const char *function, int line, const char *fmt, ...)
|
||||
MDBX_PRINTF_ARGS(4, 5);
|
||||
MDBX_INTERNAL_FUNC void debug_log_va(int level, const char *function, int line,
|
||||
const char *fmt, va_list args);
|
||||
|
||||
#if MDBX_DEBUG
|
||||
#define mdbx_log_enabled(msg) unlikely(msg <= mdbx_loglevel)
|
||||
#define mdbx_audit_enabled() unlikely((mdbx_runtime_flags & MDBX_DBG_AUDIT))
|
||||
#define LOG_ENABLED(msg) unlikely(msg <= loglevel)
|
||||
#define AUDIT_ENABLED() unlikely((runtime_flags & MDBX_DBG_AUDIT))
|
||||
#else /* MDBX_DEBUG */
|
||||
#define mdbx_log_enabled(msg) (msg < MDBX_LOG_VERBOSE && msg <= mdbx_loglevel)
|
||||
#define mdbx_audit_enabled() (0)
|
||||
#define LOG_ENABLED(msg) (msg < MDBX_LOG_VERBOSE && msg <= loglevel)
|
||||
#define AUDIT_ENABLED() (0)
|
||||
#endif /* MDBX_DEBUG */
|
||||
|
||||
#if MDBX_FORCE_ASSERTIONS
|
||||
#define mdbx_assert_enabled() (1)
|
||||
#define ASSERT_ENABLED() (1)
|
||||
#elif MDBX_DEBUG
|
||||
#define mdbx_assert_enabled() likely((mdbx_runtime_flags & MDBX_DBG_ASSERT))
|
||||
#define ASSERT_ENABLED() likely((runtime_flags & MDBX_DBG_ASSERT))
|
||||
#else
|
||||
#define mdbx_assert_enabled() (0)
|
||||
#define ASSERT_ENABLED() (0)
|
||||
#endif /* assertions */
|
||||
|
||||
#define mdbx_debug_extra(fmt, ...) \
|
||||
#define DEBUG_EXTRA(fmt, ...) \
|
||||
do { \
|
||||
if (mdbx_log_enabled(MDBX_LOG_EXTRA)) \
|
||||
mdbx_debug_log(MDBX_LOG_EXTRA, __func__, __LINE__, fmt, __VA_ARGS__); \
|
||||
if (LOG_ENABLED(MDBX_LOG_EXTRA)) \
|
||||
debug_log(MDBX_LOG_EXTRA, __func__, __LINE__, fmt, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define mdbx_debug_extra_print(fmt, ...) \
|
||||
#define DEBUG_EXTRA_PRINT(fmt, ...) \
|
||||
do { \
|
||||
if (mdbx_log_enabled(MDBX_LOG_EXTRA)) \
|
||||
mdbx_debug_log(MDBX_LOG_EXTRA, NULL, 0, fmt, __VA_ARGS__); \
|
||||
if (LOG_ENABLED(MDBX_LOG_EXTRA)) \
|
||||
debug_log(MDBX_LOG_EXTRA, NULL, 0, fmt, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define mdbx_trace(fmt, ...) \
|
||||
#define TRACE(fmt, ...) \
|
||||
do { \
|
||||
if (mdbx_log_enabled(MDBX_LOG_TRACE)) \
|
||||
mdbx_debug_log(MDBX_LOG_TRACE, __func__, __LINE__, fmt "\n", \
|
||||
__VA_ARGS__); \
|
||||
if (LOG_ENABLED(MDBX_LOG_TRACE)) \
|
||||
debug_log(MDBX_LOG_TRACE, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define mdbx_debug(fmt, ...) \
|
||||
#define DEBUG(fmt, ...) \
|
||||
do { \
|
||||
if (mdbx_log_enabled(MDBX_LOG_DEBUG)) \
|
||||
mdbx_debug_log(MDBX_LOG_DEBUG, __func__, __LINE__, fmt "\n", \
|
||||
__VA_ARGS__); \
|
||||
if (LOG_ENABLED(MDBX_LOG_DEBUG)) \
|
||||
debug_log(MDBX_LOG_DEBUG, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define mdbx_verbose(fmt, ...) \
|
||||
#define VERBOSE(fmt, ...) \
|
||||
do { \
|
||||
if (mdbx_log_enabled(MDBX_LOG_VERBOSE)) \
|
||||
mdbx_debug_log(MDBX_LOG_VERBOSE, __func__, __LINE__, fmt "\n", \
|
||||
__VA_ARGS__); \
|
||||
if (LOG_ENABLED(MDBX_LOG_VERBOSE)) \
|
||||
debug_log(MDBX_LOG_VERBOSE, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define mdbx_notice(fmt, ...) \
|
||||
#define NOTICE(fmt, ...) \
|
||||
do { \
|
||||
if (mdbx_log_enabled(MDBX_LOG_NOTICE)) \
|
||||
mdbx_debug_log(MDBX_LOG_NOTICE, __func__, __LINE__, fmt "\n", \
|
||||
__VA_ARGS__); \
|
||||
if (LOG_ENABLED(MDBX_LOG_NOTICE)) \
|
||||
debug_log(MDBX_LOG_NOTICE, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define mdbx_warning(fmt, ...) \
|
||||
#define WARNING(fmt, ...) \
|
||||
do { \
|
||||
if (mdbx_log_enabled(MDBX_LOG_WARN)) \
|
||||
mdbx_debug_log(MDBX_LOG_WARN, __func__, __LINE__, fmt "\n", \
|
||||
__VA_ARGS__); \
|
||||
if (LOG_ENABLED(MDBX_LOG_WARN)) \
|
||||
debug_log(MDBX_LOG_WARN, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
|
||||
} 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 { \
|
||||
if (mdbx_log_enabled(MDBX_LOG_ERROR)) \
|
||||
mdbx_debug_log(MDBX_LOG_ERROR, __func__, __LINE__, fmt "\n", \
|
||||
__VA_ARGS__); \
|
||||
if (LOG_ENABLED(MDBX_LOG_ERROR)) \
|
||||
debug_log(MDBX_LOG_ERROR, __func__, __LINE__, fmt "\n", __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define mdbx_fatal(fmt, ...) \
|
||||
mdbx_debug_log(MDBX_LOG_FATAL, __func__, __LINE__, fmt "\n", __VA_ARGS__);
|
||||
#define FATAL(fmt, ...) \
|
||||
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 { \
|
||||
if (unlikely(!(expr))) \
|
||||
mdbx_assert_fail(env, msg, __func__, __LINE__); \
|
||||
} 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 */
|
||||
#define mdbx_assert(env, expr) \
|
||||
#define eASSERT(env, expr) \
|
||||
do { \
|
||||
if (mdbx_assert_enabled()) \
|
||||
mdbx_ensure(env, expr); \
|
||||
if (ASSERT_ENABLED()) \
|
||||
ENSURE(env, expr); \
|
||||
} while (0)
|
||||
|
||||
/* 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 */
|
||||
#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
|
||||
#define assert(expr) mdbx_assert(NULL, expr)
|
||||
#define assert(expr) eASSERT(NULL, expr)
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Cache coherence and mmap invalidation */
|
||||
|
||||
#if MDBX_CPU_WRITEBACK_INCOHERENT
|
||||
#define mdbx_flush_incoherent_cpu_writeback() mdbx_memory_barrier()
|
||||
#define osal_flush_incoherent_cpu_writeback() osal_memory_barrier()
|
||||
#else
|
||||
#define mdbx_flush_incoherent_cpu_writeback() mdbx_compiler_barrier()
|
||||
#define osal_flush_incoherent_cpu_writeback() osal_compiler_barrier()
|
||||
#endif /* MDBX_CPU_WRITEBACK_INCOHERENT */
|
||||
|
||||
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
|
||||
char *const begin = (char *)(-pagesize & (intptr_t)addr);
|
||||
char *const end =
|
||||
(char *)(-pagesize & (intptr_t)((char *)addr + nbytes + pagesize - 1));
|
||||
int err = msync(begin, end - begin, MS_SYNC | MS_INVALIDATE) ? errno : 0;
|
||||
mdbx_assert(nullptr, err == 0);
|
||||
eASSERT(nullptr, err == 0);
|
||||
(void)err;
|
||||
#else
|
||||
(void)pagesize;
|
||||
@ -1410,15 +1406,15 @@ mdbx_flush_incoherent_mmap(void *addr, size_t nbytes, const intptr_t pagesize) {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Internal prototypes */
|
||||
|
||||
MDBX_INTERNAL_FUNC int mdbx_cleanup_dead_readers(MDBX_env *env, int rlocked,
|
||||
int *dead);
|
||||
MDBX_INTERNAL_FUNC int mdbx_rthc_alloc(mdbx_thread_key_t *key,
|
||||
MDBX_reader *begin, MDBX_reader *end);
|
||||
MDBX_INTERNAL_FUNC void mdbx_rthc_remove(const mdbx_thread_key_t key);
|
||||
MDBX_INTERNAL_FUNC int cleanup_dead_readers(MDBX_env *env, int rlocked,
|
||||
int *dead);
|
||||
MDBX_INTERNAL_FUNC int rthc_alloc(osal_thread_key_t *key, MDBX_reader *begin,
|
||||
MDBX_reader *end);
|
||||
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 mdbx_rthc_global_dtor(void);
|
||||
MDBX_INTERNAL_FUNC void mdbx_rthc_thread_dtor(void *ptr);
|
||||
MDBX_INTERNAL_FUNC void global_ctor(void);
|
||||
MDBX_INTERNAL_FUNC void global_dtor(void);
|
||||
MDBX_INTERNAL_FUNC void thread_dtor(void *ptr);
|
||||
|
||||
#endif /* !__cplusplus */
|
||||
|
||||
@ -1648,14 +1644,14 @@ MDBX_MAYBE_UNUSED static void static_checks(void) {
|
||||
|
||||
#define MDBX_ASAN_POISON_MEMORY_REGION(addr, size) \
|
||||
do { \
|
||||
mdbx_trace("POISON_MEMORY_REGION(%p, %zu) at %u", (void *)(addr), \
|
||||
(size_t)(size), __LINE__); \
|
||||
TRACE("POISON_MEMORY_REGION(%p, %zu) at %u", (void *)(addr), \
|
||||
(size_t)(size), __LINE__); \
|
||||
ASAN_POISON_MEMORY_REGION(addr, size); \
|
||||
} while (0)
|
||||
|
||||
#define MDBX_ASAN_UNPOISON_MEMORY_REGION(addr, size) \
|
||||
do { \
|
||||
mdbx_trace("UNPOISON_MEMORY_REGION(%p, %zu) at %u", (void *)(addr), \
|
||||
(size_t)(size), __LINE__); \
|
||||
TRACE("UNPOISON_MEMORY_REGION(%p, %zu) at %u", (void *)(addr), \
|
||||
(size_t)(size), __LINE__); \
|
||||
ASAN_UNPOISON_MEMORY_REGION(addr, size); \
|
||||
} while (0)
|
||||
|
194
src/lck-posix.c
194
src/lck-posix.c
@ -28,7 +28,7 @@
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#ifndef xMDBX_ALLOY
|
||||
uint32_t mdbx_linux_kernel_version;
|
||||
uint32_t linux_kernel_version;
|
||||
bool mdbx_RunningOnWSL1;
|
||||
#endif /* xMDBX_ALLOY */
|
||||
|
||||
@ -43,7 +43,7 @@ __cold static uint8_t probe_for_WSL(const char *tag) {
|
||||
if (WSL || wsl || strcasestr(tag, "Microsoft"))
|
||||
/* Expecting no new kernel within WSL1, either it will explicitly
|
||||
* 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;
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ mdbx_global_constructor(void) {
|
||||
if (number > 0) {
|
||||
if (number > 255)
|
||||
number = 255;
|
||||
mdbx_linux_kernel_version += number << (24 - i * 8);
|
||||
linux_kernel_version += number << (24 - i * 8);
|
||||
}
|
||||
++i;
|
||||
} else {
|
||||
@ -96,13 +96,13 @@ mdbx_global_constructor(void) {
|
||||
}
|
||||
#endif /* Linux */
|
||||
|
||||
mdbx_rthc_global_init();
|
||||
global_ctor();
|
||||
}
|
||||
|
||||
MDBX_EXCLUDE_FOR_GPROF
|
||||
__cold static __attribute__((__destructor__)) void
|
||||
mdbx_global_destructor(void) {
|
||||
mdbx_rthc_global_dtor();
|
||||
global_dtor();
|
||||
#ifdef ENABLE_GPROF
|
||||
if (!&__gmon_start__)
|
||||
_mcleanup();
|
||||
@ -118,15 +118,15 @@ mdbx_global_destructor(void) {
|
||||
* размещаются совместно используемые posix-мьютексы (futex). Посредством
|
||||
* этих мьютексов (см struct MDBX_lockinfo) реализуются:
|
||||
* - Блокировка таблицы читателей для регистрации,
|
||||
* т.е. функции mdbx_rdt_lock() и mdbx_rdt_unlock().
|
||||
* т.е. функции osal_rdt_lock() и osal_rdt_unlock().
|
||||
* - Блокировка БД для пишущих транзакций,
|
||||
* т.е. функции mdbx_txn_lock() и mdbx_txn_unlock().
|
||||
*
|
||||
* Остальной функционал реализуется отдельно посредством файловых блокировок:
|
||||
* - Первоначальный захват БД в режиме 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), так как:
|
||||
* - lockf() оперирует только эксклюзивной блокировкой и требует
|
||||
@ -170,9 +170,9 @@ mdbx_global_destructor(void) {
|
||||
static int op_setlk, op_setlkw, op_getlk;
|
||||
__cold static void choice_fcntl(void) {
|
||||
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__)
|
||||
&& mdbx_linux_kernel_version >
|
||||
&& linux_kernel_version >
|
||||
0x030f0000 /* OFD locks are available since 3.15, but engages here
|
||||
only for 3.16 and later kernels (i.e. LTS) because
|
||||
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 "
|
||||
"fix build and/or NDK configuration.");
|
||||
#endif /* Android */
|
||||
mdbx_jitter4testing(true);
|
||||
jitter4testing(true);
|
||||
assert(offset >= 0 && len > 0);
|
||||
assert((uint64_t)offset < (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_len = len;
|
||||
int rc = fcntl(fd, cmd, &lock_op);
|
||||
mdbx_jitter4testing(true);
|
||||
jitter4testing(true);
|
||||
if (rc != -1) {
|
||||
if (cmd == op_getlk) {
|
||||
/* 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 (unlikely(op_setlk == 0))
|
||||
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);
|
||||
}
|
||||
|
||||
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_pid > 0);
|
||||
if (unlikely(mdbx_getpid() != env->me_pid))
|
||||
if (unlikely(osal_getpid() != env->me_pid))
|
||||
return MDBX_PANIC;
|
||||
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_pid > 0);
|
||||
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(pid > 0);
|
||||
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
|
||||
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
|
||||
return sem_init(ipc, false, 1) ? errno : 0;
|
||||
#elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \
|
||||
@ -307,7 +307,7 @@ MDBX_INTERNAL_FUNC int mdbx_ipclock_stub(mdbx_ipclock_t *ipc) {
|
||||
#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
|
||||
return sem_destroy(ipc) ? errno : 0;
|
||||
#elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \
|
||||
@ -325,7 +325,7 @@ static int check_fstat(MDBX_env *env) {
|
||||
int rc = MDBX_SUCCESS;
|
||||
if (fstat(env->me_lazy_fd, &st)) {
|
||||
rc = errno;
|
||||
mdbx_error("fstat(%s), err %d", "DXB", rc);
|
||||
ERROR("fstat(%s), err %d", "DXB", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -335,15 +335,14 @@ static int check_fstat(MDBX_env *env) {
|
||||
#else
|
||||
rc = EPERM;
|
||||
#endif
|
||||
mdbx_error("%s %s, err %d", "DXB",
|
||||
(st.st_nlink < 1) ? "file was removed" : "not a regular file",
|
||||
rc);
|
||||
ERROR("%s %s, err %d", "DXB",
|
||||
(st.st_nlink < 1) ? "file was removed" : "not a regular file", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (st.st_size < (off_t)(MDBX_MIN_PAGESIZE * NUM_METAS)) {
|
||||
mdbx_verbose("dxb-file is too short (%u), exclusive-lock needed",
|
||||
(unsigned)st.st_size);
|
||||
VERBOSE("dxb-file is too short (%u), exclusive-lock needed",
|
||||
(unsigned)st.st_size);
|
||||
rc = MDBX_RESULT_TRUE;
|
||||
}
|
||||
|
||||
@ -351,7 +350,7 @@ static int check_fstat(MDBX_env *env) {
|
||||
|
||||
if (fstat(env->me_lfd, &st)) {
|
||||
rc = errno;
|
||||
mdbx_error("fstat(%s), err %d", "LCK", rc);
|
||||
ERROR("fstat(%s), err %d", "LCK", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -361,26 +360,25 @@ static int check_fstat(MDBX_env *env) {
|
||||
#else
|
||||
rc = EPERM;
|
||||
#endif
|
||||
mdbx_error("%s %s, err %d", "LCK",
|
||||
(st.st_nlink < 1) ? "file was removed" : "not a regular file",
|
||||
rc);
|
||||
ERROR("%s %s, err %d", "LCK",
|
||||
(st.st_nlink < 1) ? "file was removed" : "not a regular file", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* 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))) {
|
||||
mdbx_verbose("lck-file is too short (%u), exclusive-lock needed",
|
||||
(unsigned)st.st_size);
|
||||
VERBOSE("lck-file is too short (%u), exclusive-lock needed",
|
||||
(unsigned)st.st_size);
|
||||
rc = MDBX_RESULT_TRUE;
|
||||
}
|
||||
|
||||
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);
|
||||
if (unlikely(mdbx_getpid() != env->me_pid))
|
||||
if (unlikely(osal_getpid() != env->me_pid))
|
||||
return MDBX_PANIC;
|
||||
#if MDBX_USE_OFDLOCKS
|
||||
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 (unlikely(mdbx_RunningOnWSL1)) {
|
||||
rc = ENOLCK /* No record locks available */;
|
||||
mdbx_error("%s, err %u",
|
||||
"WSL1 (Windows Subsystem for Linux) is mad and trouble-full, "
|
||||
"injecting failure to avoid data loss",
|
||||
rc);
|
||||
ERROR("%s, err %u",
|
||||
"WSL1 (Windows Subsystem for Linux) is mad and trouble-full, "
|
||||
"injecting failure to avoid data loss",
|
||||
rc);
|
||||
return rc;
|
||||
}
|
||||
#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,
|
||||
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, 0, OFF_T_MAX);
|
||||
if (rc != MDBX_SUCCESS) {
|
||||
mdbx_error("%s, err %u", "without-lck", rc);
|
||||
mdbx_assert(env, MDBX_IS_ERROR(rc));
|
||||
ERROR("%s, err %u", "without-lck", rc);
|
||||
eASSERT(env, MDBX_IS_ERROR(rc));
|
||||
return rc;
|
||||
}
|
||||
return MDBX_RESULT_TRUE /* Done: return with exclusive locking. */;
|
||||
@ -419,8 +417,8 @@ retry:
|
||||
if (rc == MDBX_RESULT_TRUE) {
|
||||
rc = lck_op(env->me_lfd, op_setlk, F_UNLCK, 0, 1);
|
||||
if (rc != MDBX_SUCCESS) {
|
||||
mdbx_error("%s, err %u", "unlock-before-retry", rc);
|
||||
mdbx_assert(env, MDBX_IS_ERROR(rc));
|
||||
ERROR("%s, err %u", "unlock-before-retry", rc);
|
||||
eASSERT(env, MDBX_IS_ERROR(rc));
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@ -446,23 +444,23 @@ retry:
|
||||
/* the cause may be a collision with POSIX's file-lock recovery. */
|
||||
if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY || rc == EWOULDBLOCK ||
|
||||
rc == EDEADLK)) {
|
||||
mdbx_error("%s, err %u", "dxb-exclusive", rc);
|
||||
mdbx_assert(env, MDBX_IS_ERROR(rc));
|
||||
ERROR("%s, err %u", "dxb-exclusive", rc);
|
||||
eASSERT(env, MDBX_IS_ERROR(rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Fallback to lck-shared */
|
||||
} else if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY ||
|
||||
rc == EWOULDBLOCK || rc == EDEADLK)) {
|
||||
mdbx_error("%s, err %u", "try-exclusive", rc);
|
||||
mdbx_assert(env, MDBX_IS_ERROR(rc));
|
||||
ERROR("%s, err %u", "try-exclusive", rc);
|
||||
eASSERT(env, MDBX_IS_ERROR(rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* 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.
|
||||
* - 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.
|
||||
* For distinguish these cases will use size of the lck-file later. */
|
||||
|
||||
@ -471,8 +469,8 @@ retry:
|
||||
* competing process doesn't call lck_downgrade(). */
|
||||
rc = lck_op(env->me_lfd, op_setlkw, F_RDLCK, 0, 1);
|
||||
if (rc != MDBX_SUCCESS) {
|
||||
mdbx_error("%s, err %u", "try-shared", rc);
|
||||
mdbx_assert(env, MDBX_IS_ERROR(rc));
|
||||
ERROR("%s, err %u", "try-shared", rc);
|
||||
eASSERT(env, MDBX_IS_ERROR(rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -480,7 +478,7 @@ retry:
|
||||
if (rc == MDBX_RESULT_TRUE)
|
||||
goto retry;
|
||||
if (rc != MDBX_SUCCESS) {
|
||||
mdbx_error("%s, err %u", "lck_fstat", rc);
|
||||
ERROR("%s, err %u", "lck_fstat", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -491,8 +489,8 @@ retry:
|
||||
|
||||
if (!(rc == EAGAIN || rc == EACCES || rc == EBUSY || rc == EWOULDBLOCK ||
|
||||
rc == EDEADLK)) {
|
||||
mdbx_error("%s, err %u", "try-exclusive", rc);
|
||||
mdbx_assert(env, MDBX_IS_ERROR(rc));
|
||||
ERROR("%s, err %u", "try-exclusive", rc);
|
||||
eASSERT(env, MDBX_IS_ERROR(rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -501,8 +499,8 @@ retry:
|
||||
lck_op(env->me_lazy_fd, op_setlk,
|
||||
(env->me_flags & MDBX_RDONLY) ? F_RDLCK : F_WRLCK, env->me_pid, 1);
|
||||
if (rc != MDBX_SUCCESS) {
|
||||
mdbx_error("%s, err %u", "lock-against-without-lck", rc);
|
||||
mdbx_assert(env, MDBX_IS_ERROR(rc));
|
||||
ERROR("%s, err %u", "lock-against-without-lck", rc);
|
||||
eASSERT(env, MDBX_IS_ERROR(rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -510,9 +508,9 @@ retry:
|
||||
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);
|
||||
if (unlikely(mdbx_getpid() != env->me_pid))
|
||||
if (unlikely(osal_getpid() != env->me_pid))
|
||||
return MDBX_PANIC;
|
||||
|
||||
int rc = MDBX_SUCCESS;
|
||||
@ -525,15 +523,15 @@ MDBX_INTERNAL_FUNC int mdbx_lck_downgrade(MDBX_env *env) {
|
||||
if (rc == MDBX_SUCCESS)
|
||||
rc = lck_op(env->me_lfd, op_setlk, F_RDLCK, 0, 1);
|
||||
if (unlikely(rc != 0)) {
|
||||
mdbx_error("%s, err %u", "lck", rc);
|
||||
ERROR("%s, err %u", "lck", rc);
|
||||
assert(MDBX_IS_ERROR(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) {
|
||||
if (unlikely(mdbx_getpid() != env->me_pid))
|
||||
if (unlikely(osal_getpid() != env->me_pid))
|
||||
return MDBX_PANIC;
|
||||
|
||||
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,
|
||||
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 (env->me_sysv_ipc.semid != -1)
|
||||
rc = semctl(env->me_sysv_ipc.semid, 2, IPC_RMID) ? errno : 0;
|
||||
#else
|
||||
rc = mdbx_ipclock_destroy(&lck->mti_rlock);
|
||||
rc = osal_ipclock_destroy(&lck->mti_rlock);
|
||||
if (rc == 0)
|
||||
rc = mdbx_ipclock_destroy(&lck->mti_wlock);
|
||||
rc = osal_ipclock_destroy(&lck->mti_wlock);
|
||||
#endif /* MDBX_LOCKING */
|
||||
|
||||
mdbx_assert(env, rc == 0);
|
||||
eASSERT(env, rc == 0);
|
||||
if (rc == 0) {
|
||||
const bool synced = lck->mti_unsynced_pages.weak == 0;
|
||||
mdbx_munmap(&env->me_lck_mmap);
|
||||
osal_munmap(&env->me_lck_mmap);
|
||||
if (synced)
|
||||
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
|
||||
@ -607,7 +605,7 @@ __cold MDBX_INTERNAL_FUNC int mdbx_lck_destroy(MDBX_env *env,
|
||||
/* restore file-locks */
|
||||
rc = lck_op(inprocess_neighbor->me_lfd, F_SETLKW, F_RDLCK, 0, 1);
|
||||
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,
|
||||
int global_uniqueness_flag) {
|
||||
#if MDBX_LOCKING == MDBX_LOCKING_SYSV
|
||||
@ -765,7 +763,7 @@ bailout:
|
||||
#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) {
|
||||
int rc = err;
|
||||
#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;
|
||||
}
|
||||
}
|
||||
mdbx_warning("%clock owner died, %s", (rlocked ? 'r' : 'w'),
|
||||
(rc ? "this process' env is hosed" : "recovering"));
|
||||
WARNING("%clock owner died, %s", (rlocked ? 'r' : 'w'),
|
||||
(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;
|
||||
|
||||
#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;
|
||||
|
||||
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;
|
||||
if (MDBX_IS_ERROR(rc))
|
||||
@ -826,24 +824,24 @@ __cold static int mdbx_ipclock_failed(MDBX_env *env, mdbx_ipclock_t *ipc,
|
||||
#error "FIXME"
|
||||
#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)
|
||||
env->me_flags |= MDBX_FATAL_ERROR;
|
||||
return rc;
|
||||
}
|
||||
|
||||
#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 */
|
||||
if (sizeof(pthread_mutex_t) < sizeof(pid_t) + sizeof(unsigned)) {
|
||||
pid_t tid = gettid();
|
||||
if (unlikely(tid > 0xffff)) {
|
||||
mdbx_fatal("Raise the ENOSYS(%d) error to avoid hang due "
|
||||
"the 32-bit Bionic/Android bug with tid/thread_id 0x%08x(%i) "
|
||||
"that don’t fit in 16 bits, see "
|
||||
"https://android.googlesource.com/platform/bionic/+/master/"
|
||||
"docs/32-bit-abi.md#is-too-small-for-large-pids",
|
||||
ENOSYS, tid, tid);
|
||||
FATAL("Raise the ENOSYS(%d) error to avoid hang due "
|
||||
"the 32-bit Bionic/Android bug with tid/thread_id 0x%08x(%i) "
|
||||
"that don’t fit in 16 bits, see "
|
||||
"https://android.googlesource.com/platform/bionic/+/master/"
|
||||
"docs/32-bit-abi.md#is-too-small-for-large-pids",
|
||||
ENOSYS, tid, tid);
|
||||
return ENOSYS;
|
||||
}
|
||||
}
|
||||
@ -851,11 +849,11 @@ MDBX_INTERNAL_FUNC int mdbx_check_tid4bionic(void) {
|
||||
}
|
||||
#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) {
|
||||
#if MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || \
|
||||
MDBX_LOCKING == MDBX_LOCKING_POSIX2008
|
||||
int rc = mdbx_check_tid4bionic();
|
||||
int rc = osal_check_tid4bionic();
|
||||
if (likely(rc == 0))
|
||||
rc = dont_wait ? pthread_mutex_trylock(ipc) : pthread_mutex_lock(ipc);
|
||||
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;
|
||||
}
|
||||
|
||||
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 || \
|
||||
MDBX_LOCKING == MDBX_LOCKING_POSIX2008
|
||||
int rc = pthread_mutex_unlock(ipc);
|
||||
@ -913,38 +911,38 @@ static int mdbx_ipclock_unlock(MDBX_env *env, mdbx_ipclock_t *ipc) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
MDBX_INTERNAL_FUNC int mdbx_rdt_lock(MDBX_env *env) {
|
||||
mdbx_trace("%s", ">>");
|
||||
mdbx_jitter4testing(true);
|
||||
MDBX_INTERNAL_FUNC int osal_rdt_lock(MDBX_env *env) {
|
||||
TRACE("%s", ">>");
|
||||
jitter4testing(true);
|
||||
int rc = mdbx_ipclock_lock(env, &env->me_lck->mti_rlock, false);
|
||||
mdbx_trace("<< rc %d", rc);
|
||||
TRACE("<< rc %d", rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
MDBX_INTERNAL_FUNC void mdbx_rdt_unlock(MDBX_env *env) {
|
||||
mdbx_trace("%s", ">>");
|
||||
MDBX_INTERNAL_FUNC void osal_rdt_unlock(MDBX_env *env) {
|
||||
TRACE("%s", ">>");
|
||||
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))
|
||||
mdbx_panic("%s() failed: err %d\n", __func__, rc);
|
||||
mdbx_jitter4testing(true);
|
||||
jitter4testing(true);
|
||||
}
|
||||
|
||||
int mdbx_txn_lock(MDBX_env *env, bool dont_wait) {
|
||||
mdbx_trace("%swait %s", dont_wait ? "dont-" : "", ">>");
|
||||
mdbx_jitter4testing(true);
|
||||
TRACE("%swait %s", dont_wait ? "dont-" : "", ">>");
|
||||
jitter4testing(true);
|
||||
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;
|
||||
}
|
||||
|
||||
void mdbx_txn_unlock(MDBX_env *env) {
|
||||
mdbx_trace("%s", ">>");
|
||||
TRACE("%s", ">>");
|
||||
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))
|
||||
mdbx_panic("%s() failed: err %d\n", __func__, rc);
|
||||
mdbx_jitter4testing(true);
|
||||
jitter4testing(true);
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -48,16 +48,16 @@ static
|
||||
switch (reason) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
mdbx_winnt_import();
|
||||
mdbx_rthc_global_init();
|
||||
global_ctor();
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
mdbx_rthc_global_dtor();
|
||||
global_dtor();
|
||||
break;
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
mdbx_rthc_thread_dtor(module);
|
||||
thread_dtor(module);
|
||||
break;
|
||||
}
|
||||
#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_UPPER LCK_UP_OFFSET, LCK_UP_LEN
|
||||
|
||||
MDBX_INTERNAL_FUNC int mdbx_rdt_lock(MDBX_env *env) {
|
||||
mdbx_srwlock_AcquireShared(&env->me_remap_guard);
|
||||
MDBX_INTERNAL_FUNC int osal_rdt_lock(MDBX_env *env) {
|
||||
osal_srwlock_AcquireShared(&env->me_remap_guard);
|
||||
if (env->me_lfd == INVALID_HANDLE_VALUE)
|
||||
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;
|
||||
|
||||
int rc = (int)GetLastError();
|
||||
mdbx_srwlock_ReleaseShared(&env->me_remap_guard);
|
||||
osal_srwlock_ReleaseShared(&env->me_remap_guard);
|
||||
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) {
|
||||
/* transition from S-E (locked) to S-? (used), e.g. unlock upper-part */
|
||||
if ((env->me_flags & MDBX_EXCLUSIVE) == 0 &&
|
||||
!funlock(env->me_lfd, LCK_UPPER))
|
||||
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,
|
||||
wait ? LCK_EXCLUSIVE | LCK_WAITFOR
|
||||
: LCK_EXCLUSIVE | LCK_DONTWAIT,
|
||||
@ -225,7 +225,7 @@ static int suspend_and_append(mdbx_handle_array_t **array,
|
||||
const DWORD ThreadId) {
|
||||
const unsigned limit = (*array)->limit;
|
||||
if ((*array)->count == limit) {
|
||||
void *ptr = mdbx_realloc(
|
||||
void *ptr = osal_realloc(
|
||||
(limit > ARRAY_LENGTH((*array)->handles))
|
||||
? *array
|
||||
: /* 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_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) {
|
||||
mdbx_assert(env, (env->me_flags & MDBX_NOTLS) == 0);
|
||||
osal_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) {
|
||||
eASSERT(env, (env->me_flags & MDBX_NOTLS) == 0);
|
||||
const uintptr_t CurrentTid = GetCurrentThreadId();
|
||||
int rc;
|
||||
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);
|
||||
if (rc != MDBX_SUCCESS) {
|
||||
bailout_lck:
|
||||
(void)mdbx_resume_threads_after_remap(*array);
|
||||
(void)osal_resume_threads_after_remap(*array);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@ -294,7 +294,7 @@ mdbx_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) {
|
||||
} else {
|
||||
/* Without LCK (i.e. read-only mode).
|
||||
* 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);
|
||||
if (hSnapshot == INVALID_HANDLE_VALUE)
|
||||
return (int)GetLastError();
|
||||
@ -306,7 +306,7 @@ mdbx_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) {
|
||||
rc = (int)GetLastError();
|
||||
bailout_toolhelp:
|
||||
CloseHandle(hSnapshot);
|
||||
(void)mdbx_resume_threads_after_remap(*array);
|
||||
(void)osal_resume_threads_after_remap(*array);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -331,7 +331,7 @@ mdbx_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) {
|
||||
}
|
||||
|
||||
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;
|
||||
for (unsigned i = 0; i < array->count; ++i) {
|
||||
const HANDLE hThread = array->handles[i];
|
||||
@ -370,11 +370,11 @@ mdbx_resume_threads_after_remap(mdbx_handle_array_t *array) {
|
||||
* E-S
|
||||
* 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,
|
||||
* 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.
|
||||
*
|
||||
* 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);
|
||||
|
||||
/* 1) now on ?-? (free), get ?-E (middle) */
|
||||
mdbx_jitter4testing(false);
|
||||
jitter4testing(false);
|
||||
if (!flock(lfd, LCK_EXCLUSIVE | LCK_WAITFOR, LCK_UPPER)) {
|
||||
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;
|
||||
}
|
||||
|
||||
/* 3) now on ?-E (middle), try E-E (exclusive-write) */
|
||||
mdbx_jitter4testing(false);
|
||||
jitter4testing(false);
|
||||
if (flock(lfd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_LOWER))
|
||||
return MDBX_RESULT_TRUE /* 4) got E-E (exclusive-write), done */;
|
||||
|
||||
/* 5) still on ?-E (middle) */
|
||||
rc = (int)GetLastError();
|
||||
mdbx_jitter4testing(false);
|
||||
jitter4testing(false);
|
||||
if (rc != ERROR_SHARING_VIOLATION && rc != ERROR_LOCK_VIOLATION) {
|
||||
/* 6) something went wrong, give up */
|
||||
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) */
|
||||
mdbx_jitter4testing(false);
|
||||
jitter4testing(false);
|
||||
rc = flock(lfd, LCK_SHARED | LCK_DONTWAIT, LCK_LOWER) ? MDBX_RESULT_FALSE
|
||||
: (int)GetLastError();
|
||||
|
||||
mdbx_jitter4testing(false);
|
||||
jitter4testing(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),
|
||||
* transition to S-? (used) or ?-? (free) */
|
||||
@ -474,7 +474,7 @@ static int internal_seize_lck(HANDLE lfd) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) {
|
||||
MDBX_INTERNAL_FUNC int osal_lck_seize(MDBX_env *env) {
|
||||
int rc;
|
||||
|
||||
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) {
|
||||
/* 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)) {
|
||||
rc = (int)GetLastError();
|
||||
mdbx_error("%s, err %u", "without-lck", rc);
|
||||
ERROR("%s, err %u", "without-lck", rc);
|
||||
return rc;
|
||||
}
|
||||
return MDBX_RESULT_FALSE;
|
||||
}
|
||||
|
||||
rc = internal_seize_lck(env->me_lfd);
|
||||
mdbx_jitter4testing(false);
|
||||
jitter4testing(false);
|
||||
if (rc == MDBX_RESULT_TRUE && (env->me_flags & MDBX_RDONLY) == 0) {
|
||||
/* Check that another process don't operates in without-lck mode.
|
||||
* 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. */
|
||||
if (!flock(env->me_lazy_fd, LCK_EXCLUSIVE | LCK_DONTWAIT, LCK_BODY)) {
|
||||
rc = (int)GetLastError();
|
||||
mdbx_error("%s, err %u", "lock-against-without-lck", rc);
|
||||
mdbx_jitter4testing(false);
|
||||
ERROR("%s, err %u", "lock-against-without-lck", rc);
|
||||
jitter4testing(false);
|
||||
lck_unlock(env);
|
||||
} else {
|
||||
mdbx_jitter4testing(false);
|
||||
jitter4testing(false);
|
||||
if (!funlock(env->me_lazy_fd, LCK_BODY))
|
||||
mdbx_panic("%s(%s) failed: err %u", __func__,
|
||||
"unlock-against-without-lck", (int)GetLastError());
|
||||
@ -519,7 +519,7 @@ MDBX_INTERNAL_FUNC int mdbx_lck_seize(MDBX_env *env) {
|
||||
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-?) */
|
||||
assert(env->me_lazy_fd != 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) */
|
||||
if (!flock(env->me_lfd, LCK_SHARED | LCK_DONTWAIT, LCK_LOWER)) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -557,10 +557,10 @@ MDBX_INTERNAL_FUNC int mdbx_lck_upgrade(MDBX_env *env) {
|
||||
|
||||
int rc;
|
||||
/* 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)) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -570,17 +570,17 @@ MDBX_INTERNAL_FUNC int mdbx_lck_upgrade(MDBX_env *env) {
|
||||
(int)GetLastError());
|
||||
|
||||
/* 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)) {
|
||||
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 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,
|
||||
int global_uniqueness_flag) {
|
||||
(void)env;
|
||||
@ -589,19 +589,19 @@ MDBX_INTERNAL_FUNC int mdbx_lck_init(MDBX_env *env,
|
||||
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) {
|
||||
/* LY: should unmap before releasing the locks to avoid race condition and
|
||||
* STATUS_USER_MAPPED_FILE/ERROR_USER_MAPPED_FILE */
|
||||
if (env->me_map)
|
||||
mdbx_munmap(&env->me_dxb_mmap);
|
||||
osal_munmap(&env->me_dxb_mmap);
|
||||
if (env->me_lck_mmap.lck) {
|
||||
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 &&
|
||||
mdbx_lck_upgrade(env) == MDBX_SUCCESS)
|
||||
/* 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);
|
||||
return MDBX_SUCCESS;
|
||||
@ -610,12 +610,12 @@ MDBX_INTERNAL_FUNC int mdbx_lck_destroy(MDBX_env *env,
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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;
|
||||
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;
|
||||
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_FALSE, if pid is dead (lock acquired)
|
||||
* 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;
|
||||
HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, pid);
|
||||
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
|
||||
// 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;
|
||||
}
|
||||
|
||||
static void WINAPI stub_srwlock_AcquireShared(MDBX_srwlock *srwl) {
|
||||
static void WINAPI stub_srwlock_AcquireShared(osal_srwlock_t *srwl) {
|
||||
while (true) {
|
||||
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);
|
||||
_InterlockedDecrement(&srwl->readerCount);
|
||||
}
|
||||
|
||||
static void WINAPI stub_srwlock_AcquireExclusive(MDBX_srwlock *srwl) {
|
||||
static void WINAPI stub_srwlock_AcquireExclusive(osal_srwlock_t *srwl) {
|
||||
while (true) {
|
||||
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);
|
||||
srwl->writerCount = 0;
|
||||
}
|
||||
@ -739,9 +739,9 @@ static uint64_t WINAPI stub_GetTickCount64(void) {
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef xMDBX_ALLOY
|
||||
MDBX_srwlock_function mdbx_srwlock_Init, mdbx_srwlock_AcquireShared,
|
||||
mdbx_srwlock_ReleaseShared, mdbx_srwlock_AcquireExclusive,
|
||||
mdbx_srwlock_ReleaseExclusive;
|
||||
osal_srwlock_t_function osal_srwlock_Init, osal_srwlock_AcquireShared,
|
||||
osal_srwlock_ReleaseShared, osal_srwlock_AcquireExclusive,
|
||||
osal_srwlock_ReleaseExclusive;
|
||||
|
||||
MDBX_NtExtendSection mdbx_NtExtendSection;
|
||||
MDBX_GetFileInformationByHandleEx mdbx_GetFileInformationByHandleEx;
|
||||
@ -789,24 +789,24 @@ static void mdbx_winnt_import(void) {
|
||||
GET_PROC_ADDR(hAdvapi32dll, RegGetValueA);
|
||||
#undef GET_PROC_ADDR
|
||||
|
||||
const MDBX_srwlock_function init =
|
||||
(MDBX_srwlock_function)GetProcAddress(hKernel32dll, "InitializeSRWLock");
|
||||
const osal_srwlock_t_function init = (osal_srwlock_t_function)GetProcAddress(
|
||||
hKernel32dll, "InitializeSRWLock");
|
||||
if (init != NULL) {
|
||||
mdbx_srwlock_Init = init;
|
||||
mdbx_srwlock_AcquireShared = (MDBX_srwlock_function)GetProcAddress(
|
||||
osal_srwlock_Init = init;
|
||||
osal_srwlock_AcquireShared = (osal_srwlock_t_function)GetProcAddress(
|
||||
hKernel32dll, "AcquireSRWLockShared");
|
||||
mdbx_srwlock_ReleaseShared = (MDBX_srwlock_function)GetProcAddress(
|
||||
osal_srwlock_ReleaseShared = (osal_srwlock_t_function)GetProcAddress(
|
||||
hKernel32dll, "ReleaseSRWLockShared");
|
||||
mdbx_srwlock_AcquireExclusive = (MDBX_srwlock_function)GetProcAddress(
|
||||
osal_srwlock_AcquireExclusive = (osal_srwlock_t_function)GetProcAddress(
|
||||
hKernel32dll, "AcquireSRWLockExclusive");
|
||||
mdbx_srwlock_ReleaseExclusive = (MDBX_srwlock_function)GetProcAddress(
|
||||
osal_srwlock_ReleaseExclusive = (osal_srwlock_t_function)GetProcAddress(
|
||||
hKernel32dll, "ReleaseSRWLockExclusive");
|
||||
} else {
|
||||
mdbx_srwlock_Init = stub_srwlock_Init;
|
||||
mdbx_srwlock_AcquireShared = stub_srwlock_AcquireShared;
|
||||
mdbx_srwlock_ReleaseShared = stub_srwlock_ReleaseShared;
|
||||
mdbx_srwlock_AcquireExclusive = stub_srwlock_AcquireExclusive;
|
||||
mdbx_srwlock_ReleaseExclusive = stub_srwlock_ReleaseExclusive;
|
||||
osal_srwlock_Init = stub_srwlock_Init;
|
||||
osal_srwlock_AcquireShared = stub_srwlock_AcquireShared;
|
||||
osal_srwlock_ReleaseShared = stub_srwlock_ReleaseShared;
|
||||
osal_srwlock_AcquireExclusive = stub_srwlock_AcquireExclusive;
|
||||
osal_srwlock_ReleaseExclusive = stub_srwlock_ReleaseExclusive;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#define xMDBX_TOOLS /* Avoid using internal eASSERT() */
|
||||
#include "internals.h"
|
||||
|
||||
typedef struct flagbit {
|
||||
@ -193,12 +193,12 @@ static void pagemap_cleanup(void) {
|
||||
for (size_t i = CORE_DBS + /* account pseudo-entry for meta */ 1;
|
||||
i < ARRAY_LENGTH(walk.dbi); ++i) {
|
||||
if (walk.dbi[i].name) {
|
||||
mdbx_free((void *)walk.dbi[i].name);
|
||||
osal_free((void *)walk.dbi[i].name);
|
||||
walk.dbi[i].name = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
mdbx_free(walk.pagemap);
|
||||
osal_free(walk.pagemap);
|
||||
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))
|
||||
return nullptr;
|
||||
|
||||
dbi->name = mdbx_strdup(dbi_name);
|
||||
dbi->name = osal_strdup(dbi_name);
|
||||
return last = dbi;
|
||||
}
|
||||
|
||||
@ -247,7 +247,7 @@ static void MDBX_PRINTF_ARGS(4, 5)
|
||||
break;
|
||||
|
||||
if (!p) {
|
||||
p = mdbx_calloc(1, sizeof(*p));
|
||||
p = osal_calloc(1, sizeof(*p));
|
||||
if (unlikely(!p))
|
||||
return;
|
||||
p->caption = msg;
|
||||
@ -292,7 +292,7 @@ static size_t problems_pop(struct problem *list) {
|
||||
count += problems_list->count;
|
||||
print("%s%s (%" PRIuPTR ")", i ? ", " : "", problems_list->caption,
|
||||
problems_list->count);
|
||||
mdbx_free(problems_list);
|
||||
osal_free(problems_list);
|
||||
problems_list = p;
|
||||
}
|
||||
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;
|
||||
} else if (data->iov_len - (number + 1) * sizeof(pgno_t) >=
|
||||
/* 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)
|
||||
problem_add("entry", txnid, "extra idl space",
|
||||
"%" 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);
|
||||
}
|
||||
|
||||
name = mdbx_malloc(key->iov_len + 1);
|
||||
name = osal_malloc(key->iov_len + 1);
|
||||
if (unlikely(!name))
|
||||
return MDBX_ENOMEM;
|
||||
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++;
|
||||
|
||||
rc = process_db(~0u, name, handle_userdb, false);
|
||||
mdbx_free(name);
|
||||
osal_free(name);
|
||||
if (rc != MDBX_INCOMPATIBLE)
|
||||
return rc;
|
||||
|
||||
@ -1340,7 +1340,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1504,7 +1504,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
print("Traversal b-tree by txn#%" PRIaTXN "...\n", txn->mt_txnid);
|
||||
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) {
|
||||
rc = errno ? errno : MDBX_ENOMEM;
|
||||
error("calloc() failed, error %d %s\n", rc, mdbx_strerror(rc));
|
||||
|
@ -20,7 +20,7 @@
|
||||
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#define xMDBX_TOOLS /* Avoid using internal eASSERT() */
|
||||
#include "internals.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
@ -22,7 +22,7 @@
|
||||
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#define xMDBX_TOOLS /* Avoid using internal eASSERT() */
|
||||
#include "internals.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
@ -20,7 +20,7 @@
|
||||
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#define xMDBX_TOOLS /* Avoid using internal eASSERT() */
|
||||
#include "internals.h"
|
||||
|
||||
#include <ctype.h>
|
||||
@ -403,7 +403,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (memchr(key.iov_base, '\0', key.iov_len))
|
||||
continue;
|
||||
subname = mdbx_realloc(buf4free, key.iov_len + 1);
|
||||
subname = osal_realloc(buf4free, key.iov_len + 1);
|
||||
if (!subname) {
|
||||
rc = MDBX_ENOMEM;
|
||||
break;
|
||||
|
@ -20,7 +20,7 @@
|
||||
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#define xMDBX_TOOLS /* Avoid using internal eASSERT() */
|
||||
#include "internals.h"
|
||||
|
||||
#include <ctype.h>
|
||||
@ -213,7 +213,7 @@ static int readhdr(void) {
|
||||
if (str) {
|
||||
if (*str) {
|
||||
free(subname);
|
||||
subname = mdbx_strdup(str);
|
||||
subname = osal_strdup(str);
|
||||
if (!subname) {
|
||||
if (!quiet)
|
||||
perror("strdup()");
|
||||
@ -421,7 +421,7 @@ __hot static int readline(MDBX_val *out, MDBX_val *buf) {
|
||||
|
||||
/* Is buffer too short? */
|
||||
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 (!quiet)
|
||||
fprintf(stderr,
|
||||
@ -560,7 +560,7 @@ int main(int argc, char *argv[]) {
|
||||
envflags |= MDBX_NOSUBDIR;
|
||||
break;
|
||||
case 's':
|
||||
subname = mdbx_strdup(optarg);
|
||||
subname = osal_strdup(optarg);
|
||||
break;
|
||||
case 'N':
|
||||
putflags |= MDBX_NOOVERWRITE | MDBX_NODUPDATA;
|
||||
@ -606,7 +606,7 @@ int main(int argc, char *argv[]) {
|
||||
fflush(nullptr);
|
||||
|
||||
dbuf.iov_len = 4096;
|
||||
dbuf.iov_base = mdbx_malloc(dbuf.iov_len);
|
||||
dbuf.iov_base = osal_malloc(dbuf.iov_len);
|
||||
if (!dbuf.iov_base) {
|
||||
rc = MDBX_ENOMEM;
|
||||
error("value-buffer", rc);
|
||||
|
@ -20,7 +20,7 @@
|
||||
#pragma warning(disable : 4996) /* The POSIX name is deprecated... */
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#define xMDBX_TOOLS /* Avoid using internal eASSERT() */
|
||||
#include "internals.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
@ -469,13 +469,13 @@ int main(int argc, char *argv[]) {
|
||||
MDBX_dbi subdbi;
|
||||
if (memchr(key.iov_base, '\0', key.iov_len))
|
||||
continue;
|
||||
subname = mdbx_malloc(key.iov_len + 1);
|
||||
subname = osal_malloc(key.iov_len + 1);
|
||||
memcpy(subname, key.iov_base, key.iov_len);
|
||||
subname[key.iov_len] = '\0';
|
||||
rc = mdbx_dbi_open(txn, subname, MDBX_DB_ACCEDE, &subdbi);
|
||||
if (rc == MDBX_SUCCESS)
|
||||
printf("Status of %s\n", subname);
|
||||
mdbx_free(subname);
|
||||
osal_free(subname);
|
||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||
if (rc == MDBX_INCOMPATIBLE)
|
||||
continue;
|
||||
|
207
src/osal.c
207
src/osal.c
@ -232,12 +232,12 @@ __cold void mdbx_assert_fail(const MDBX_env *env, const char *msg,
|
||||
(void)env;
|
||||
#endif /* MDBX_DEBUG */
|
||||
|
||||
if (mdbx_debug_logger)
|
||||
mdbx_debug_log(MDBX_LOG_FATAL, func, line, "assert: %s\n", msg);
|
||||
if (debug_logger)
|
||||
debug_log(MDBX_LOG_FATAL, func, line, "assert: %s\n", msg);
|
||||
else {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
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);
|
||||
if (num < 1 || !message)
|
||||
message = "<troubles with assertion-message preparation>";
|
||||
@ -261,7 +261,7 @@ __cold void mdbx_panic(const char *fmt, ...) {
|
||||
va_start(ap, fmt);
|
||||
|
||||
char *message = nullptr;
|
||||
const int num = mdbx_vasprintf(&message, fmt, ap);
|
||||
const int num = osal_vasprintf(&message, fmt, ap);
|
||||
va_end(ap);
|
||||
const char *const const_message =
|
||||
(num < 1 || !message) ? "<troubles with panic-message preparation>"
|
||||
@ -281,8 +281,8 @@ __cold void mdbx_panic(const char *fmt, ...) {
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef mdbx_vasprintf
|
||||
MDBX_INTERNAL_FUNC int mdbx_vasprintf(char **strp, const char *fmt,
|
||||
#ifndef osal_vasprintf
|
||||
MDBX_INTERNAL_FUNC int osal_vasprintf(char **strp, const char *fmt,
|
||||
va_list ap) {
|
||||
va_list ones;
|
||||
va_copy(ones, ap);
|
||||
@ -294,7 +294,7 @@ MDBX_INTERNAL_FUNC int mdbx_vasprintf(char **strp, const char *fmt,
|
||||
return needed;
|
||||
}
|
||||
|
||||
*strp = mdbx_malloc(needed + 1);
|
||||
*strp = osal_malloc(needed + 1);
|
||||
if (unlikely(*strp == nullptr)) {
|
||||
va_end(ones);
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
@ -310,25 +310,25 @@ MDBX_INTERNAL_FUNC int mdbx_vasprintf(char **strp, const char *fmt,
|
||||
|
||||
assert(actual == needed);
|
||||
if (unlikely(actual < 0)) {
|
||||
mdbx_free(*strp);
|
||||
osal_free(*strp);
|
||||
*strp = nullptr;
|
||||
}
|
||||
return actual;
|
||||
}
|
||||
#endif /* mdbx_vasprintf */
|
||||
#endif /* osal_vasprintf */
|
||||
|
||||
#ifndef mdbx_asprintf
|
||||
MDBX_INTERNAL_FUNC int mdbx_asprintf(char **strp, const char *fmt, ...) {
|
||||
#ifndef osal_asprintf
|
||||
MDBX_INTERNAL_FUNC int osal_asprintf(char **strp, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int rc = mdbx_vasprintf(strp, fmt, ap);
|
||||
int rc = osal_vasprintf(strp, fmt, ap);
|
||||
va_end(ap);
|
||||
return rc;
|
||||
}
|
||||
#endif /* mdbx_asprintf */
|
||||
#endif /* osal_asprintf */
|
||||
|
||||
#ifndef mdbx_memalign_alloc
|
||||
MDBX_INTERNAL_FUNC int mdbx_memalign_alloc(size_t alignment, size_t bytes,
|
||||
#ifndef osal_memalign_alloc
|
||||
MDBX_INTERNAL_FUNC int osal_memalign_alloc(size_t alignment, size_t bytes,
|
||||
void **result) {
|
||||
assert(is_powerof2(alignment) && alignment >= sizeof(void *));
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
@ -349,35 +349,35 @@ MDBX_INTERNAL_FUNC int mdbx_memalign_alloc(size_t alignment, size_t bytes,
|
||||
#error FIXME
|
||||
#endif
|
||||
}
|
||||
#endif /* mdbx_memalign_alloc */
|
||||
#endif /* osal_memalign_alloc */
|
||||
|
||||
#ifndef mdbx_memalign_free
|
||||
MDBX_INTERNAL_FUNC void mdbx_memalign_free(void *ptr) {
|
||||
#ifndef osal_memalign_free
|
||||
MDBX_INTERNAL_FUNC void osal_memalign_free(void *ptr) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
VirtualFree(ptr, 0, MEM_RELEASE);
|
||||
#else
|
||||
mdbx_free(ptr);
|
||||
osal_free(ptr);
|
||||
#endif
|
||||
}
|
||||
#endif /* mdbx_memalign_free */
|
||||
#endif /* osal_memalign_free */
|
||||
|
||||
#ifndef mdbx_strdup
|
||||
char *mdbx_strdup(const char *str) {
|
||||
#ifndef osal_strdup
|
||||
char *osal_strdup(const char *str) {
|
||||
if (!str)
|
||||
return NULL;
|
||||
size_t bytes = strlen(str) + 1;
|
||||
char *dup = mdbx_malloc(bytes);
|
||||
char *dup = osal_malloc(bytes);
|
||||
if (dup)
|
||||
memcpy(dup, str, bytes);
|
||||
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;
|
||||
memset(condpair, 0, sizeof(mdbx_condpair_t));
|
||||
memset(condpair, 0, sizeof(osal_condpair_t));
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
if ((condpair->mutex = CreateMutexW(NULL, FALSE, NULL)) == NULL) {
|
||||
rc = (int)GetLastError();
|
||||
@ -410,11 +410,11 @@ bailout_cond:
|
||||
(void)pthread_mutex_destroy(&condpair->mutex);
|
||||
#endif
|
||||
bailout_mutex:
|
||||
memset(condpair, 0, sizeof(mdbx_condpair_t));
|
||||
memset(condpair, 0, sizeof(osal_condpair_t));
|
||||
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)
|
||||
int rc = CloseHandle(condpair->mutex) ? MDBX_SUCCESS : (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[1])) ? err : rc;
|
||||
#endif
|
||||
memset(condpair, 0, sizeof(mdbx_condpair_t));
|
||||
memset(condpair, 0, sizeof(osal_condpair_t));
|
||||
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)
|
||||
DWORD code = WaitForSingleObject(condpair->mutex, INFINITE);
|
||||
return waitstatus2errcode(code);
|
||||
#else
|
||||
return mdbx_pthread_mutex_lock(&condpair->mutex);
|
||||
return osal_pthread_mutex_lock(&condpair->mutex);
|
||||
#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)
|
||||
return ReleaseMutex(condpair->mutex) ? MDBX_SUCCESS : (int)GetLastError();
|
||||
#else
|
||||
@ -445,7 +445,7 @@ MDBX_INTERNAL_FUNC int mdbx_condpair_unlock(mdbx_condpair_t *condpair) {
|
||||
#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) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
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
|
||||
}
|
||||
|
||||
MDBX_INTERNAL_FUNC int mdbx_condpair_wait(mdbx_condpair_t *condpair,
|
||||
MDBX_INTERNAL_FUNC int osal_condpair_wait(osal_condpair_t *condpair,
|
||||
bool part) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
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)
|
||||
InitializeCriticalSection(fastmutex);
|
||||
return MDBX_SUCCESS;
|
||||
@ -481,7 +481,7 @@ MDBX_INTERNAL_FUNC int mdbx_fastmutex_init(mdbx_fastmutex_t *fastmutex) {
|
||||
#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)
|
||||
DeleteCriticalSection(fastmutex);
|
||||
return MDBX_SUCCESS;
|
||||
@ -490,7 +490,7 @@ MDBX_INTERNAL_FUNC int mdbx_fastmutex_destroy(mdbx_fastmutex_t *fastmutex) {
|
||||
#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)
|
||||
__try {
|
||||
EnterCriticalSection(fastmutex);
|
||||
@ -503,11 +503,11 @@ MDBX_INTERNAL_FUNC int mdbx_fastmutex_acquire(mdbx_fastmutex_t *fastmutex) {
|
||||
}
|
||||
return MDBX_SUCCESS;
|
||||
#else
|
||||
return mdbx_pthread_mutex_lock(fastmutex);
|
||||
return osal_pthread_mutex_lock(fastmutex);
|
||||
#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)
|
||||
LeaveCriticalSection(fastmutex);
|
||||
return MDBX_SUCCESS;
|
||||
@ -527,7 +527,7 @@ static const DWORD WC_ERR_INVALID_CHARS =
|
||||
: 0;
|
||||
#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) {
|
||||
return MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, src,
|
||||
(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)
|
||||
return DeleteFileW(pathname) ? MDBX_SUCCESS : (int)GetLastError();
|
||||
#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); }
|
||||
#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)
|
||||
return RemoveDirectoryW(pathname) ? MDBX_SUCCESS : (int)GetLastError();
|
||||
#else
|
||||
@ -557,7 +557,7 @@ MDBX_INTERNAL_FUNC int mdbx_removedirectory(const pathchar_t *pathname) {
|
||||
#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 pathchar_t *pathname,
|
||||
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;
|
||||
static const char dev_null[] = "/dev/null";
|
||||
if (!is_valid_fd(STDIN_FILENO)) {
|
||||
mdbx_warning("STD%s_FILENO/%d is invalid, open %s for temporary stub", "IN",
|
||||
STDIN_FILENO, dev_null);
|
||||
WARNING("STD%s_FILENO/%d is invalid, open %s for temporary stub", "IN",
|
||||
STDIN_FILENO, dev_null);
|
||||
stub_fd0 = open(dev_null, O_RDONLY | O_NOCTTY);
|
||||
}
|
||||
if (!is_valid_fd(STDOUT_FILENO)) {
|
||||
mdbx_warning("STD%s_FILENO/%d is invalid, open %s for temporary stub",
|
||||
"OUT", STDOUT_FILENO, dev_null);
|
||||
WARNING("STD%s_FILENO/%d is invalid, open %s for temporary stub", "OUT",
|
||||
STDOUT_FILENO, dev_null);
|
||||
stub_fd1 = open(dev_null, O_WRONLY | O_NOCTTY);
|
||||
}
|
||||
if (!is_valid_fd(STDERR_FILENO)) {
|
||||
mdbx_warning("STD%s_FILENO/%d is invalid, open %s for temporary stub",
|
||||
"ERR", STDERR_FILENO, dev_null);
|
||||
WARNING("STD%s_FILENO/%d is invalid, open %s for temporary stub", "ERR",
|
||||
STDERR_FILENO, dev_null);
|
||||
stub_fd2 = open(dev_null, O_WRONLY | O_NOCTTY);
|
||||
}
|
||||
#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 */
|
||||
#if STDIN_FILENO == 0 && STDOUT_FILENO == 1 && STDERR_FILENO == 2
|
||||
if (*fd == STDIN_FILENO) {
|
||||
mdbx_warning("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "IN",
|
||||
STDIN_FILENO);
|
||||
WARNING("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "IN",
|
||||
STDIN_FILENO);
|
||||
assert(stub_fd0 == -1);
|
||||
*fd = dup(stub_fd0 = *fd);
|
||||
}
|
||||
if (*fd == STDOUT_FILENO) {
|
||||
mdbx_warning("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "OUT",
|
||||
STDOUT_FILENO);
|
||||
WARNING("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "OUT",
|
||||
STDOUT_FILENO);
|
||||
assert(stub_fd1 == -1);
|
||||
*fd = dup(stub_fd1 = *fd);
|
||||
}
|
||||
if (*fd == STDERR_FILENO) {
|
||||
mdbx_warning("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "ERR",
|
||||
STDERR_FILENO);
|
||||
WARNING("Got STD%s_FILENO/%d, avoid using it by dup(fd)", "ERR",
|
||||
STDERR_FILENO);
|
||||
assert(stub_fd2 == -1);
|
||||
*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)
|
||||
close(stub_fd2);
|
||||
if (*fd >= STDIN_FILENO && *fd <= STDERR_FILENO) {
|
||||
mdbx_error(
|
||||
"Rejecting the use of a FD in the range "
|
||||
"STDIN_FILENO/%d..STDERR_FILENO/%d to prevent database corruption",
|
||||
STDIN_FILENO, STDERR_FILENO);
|
||||
ERROR("Rejecting the use of a FD in the range "
|
||||
"STDIN_FILENO/%d..STDERR_FILENO/%d to prevent database corruption",
|
||||
STDIN_FILENO, STDERR_FILENO);
|
||||
close(*fd);
|
||||
return EBADF;
|
||||
}
|
||||
@ -777,7 +776,7 @@ MDBX_INTERNAL_FUNC int mdbx_openfile(const enum mdbx_openfile_purpose purpose,
|
||||
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)
|
||||
return CloseHandle(fd) ? MDBX_SUCCESS : (int)GetLastError();
|
||||
#else
|
||||
@ -786,7 +785,7 @@ MDBX_INTERNAL_FUNC int mdbx_closefile(mdbx_filehandle_t fd) {
|
||||
#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) {
|
||||
if (bytes > MAX_WRITE)
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
while (true) {
|
||||
#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) {
|
||||
while (true) {
|
||||
#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) {
|
||||
#if defined(_WIN32) || defined(_WIN64) || defined(__APPLE__) || \
|
||||
(defined(__ANDROID_API__) && __ANDROID_API__ < 24)
|
||||
size_t written = 0;
|
||||
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))
|
||||
return rc;
|
||||
written += iov[i].iov_len;
|
||||
@ -908,8 +907,8 @@ int mdbx_pwritev(mdbx_filehandle_t fd, struct iovec *iov, int iovcnt,
|
||||
#endif
|
||||
}
|
||||
|
||||
MDBX_INTERNAL_FUNC int mdbx_fsync(mdbx_filehandle_t fd,
|
||||
enum mdbx_syncmode_bits mode_bits) {
|
||||
MDBX_INTERNAL_FUNC int osal_fsync(mdbx_filehandle_t fd,
|
||||
enum osal_syncmode_bits mode_bits) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
if ((mode_bits & (MDBX_SYNC_DATA | MDBX_SYNC_IODQ)) && !FlushFileBuffers(fd))
|
||||
return (int)GetLastError();
|
||||
@ -938,7 +937,7 @@ MDBX_INTERNAL_FUNC int mdbx_fsync(mdbx_filehandle_t fd,
|
||||
break /* error */;
|
||||
#if defined(__linux__) || defined(__gnu_linux__)
|
||||
case MDBX_SYNC_SIZE:
|
||||
if (mdbx_linux_kernel_version >= 0x03060000)
|
||||
if (linux_kernel_version >= 0x03060000)
|
||||
return MDBX_SUCCESS;
|
||||
__fallthrough /* fall through */;
|
||||
#endif /* Linux */
|
||||
@ -955,7 +954,7 @@ MDBX_INTERNAL_FUNC int mdbx_fsync(mdbx_filehandle_t fd,
|
||||
#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)
|
||||
BY_HANDLE_FILE_INFORMATION info;
|
||||
if (!GetFileInformationByHandle(fd, &info))
|
||||
@ -974,7 +973,7 @@ int mdbx_filesize(mdbx_filehandle_t fd, uint64_t *length) {
|
||||
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)
|
||||
switch (GetFileType(fd)) {
|
||||
case FILE_TYPE_DISK:
|
||||
@ -1005,7 +1004,7 @@ MDBX_INTERNAL_FUNC int mdbx_is_pipe(mdbx_filehandle_t fd) {
|
||||
#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 (mdbx_SetFileInformationByHandle) {
|
||||
FILE_END_OF_FILE_INFO EndOfFileInfo;
|
||||
@ -1029,7 +1028,7 @@ MDBX_INTERNAL_FUNC int mdbx_ftruncate(mdbx_filehandle_t fd, uint64_t length) {
|
||||
#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)
|
||||
LARGE_INTEGER li;
|
||||
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_thread_create(mdbx_thread_t *thread,
|
||||
osal_thread_create(osal_thread_t *thread,
|
||||
THREAD_RESULT(THREAD_CALL *start_routine)(void *),
|
||||
void *arg) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
@ -1056,7 +1055,7 @@ mdbx_thread_create(mdbx_thread_t *thread,
|
||||
#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)
|
||||
DWORD code = WaitForSingleObject(thread, INFINITE);
|
||||
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,
|
||||
enum mdbx_syncmode_bits mode_bits) {
|
||||
enum osal_syncmode_bits mode_bits) {
|
||||
uint8_t *ptr = (uint8_t *)map->address + offset;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
if (!FlushViewOfFile(ptr, length))
|
||||
return (int)GetLastError();
|
||||
#else
|
||||
#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
|
||||
* tracks dirty pages and flushes them to storage as necessary. */
|
||||
return MDBX_SUCCESS;
|
||||
@ -1086,10 +1085,10 @@ MDBX_INTERNAL_FUNC int mdbx_msync(mdbx_mmap_t *map, size_t offset,
|
||||
return errno;
|
||||
mode_bits &= ~MDBX_SYNC_DATA;
|
||||
#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,
|
||||
int err) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
@ -1119,7 +1118,7 @@ MDBX_INTERNAL_FUNC int mdbx_check_fs_rdonly(mdbx_filehandle_t handle,
|
||||
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 (mdbx_RunningUnderWine() && !(flags & MDBX_EXCLUSIVE))
|
||||
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) {
|
||||
WCHAR *PathBuffer = mdbx_malloc(sizeof(WCHAR) * INT16_MAX);
|
||||
WCHAR *PathBuffer = osal_malloc(sizeof(WCHAR) * INT16_MAX);
|
||||
if (!PathBuffer)
|
||||
return MDBX_ENOMEM;
|
||||
|
||||
@ -1234,7 +1233,7 @@ static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) {
|
||||
}
|
||||
|
||||
bailout:
|
||||
mdbx_free(PathBuffer);
|
||||
osal_free(PathBuffer);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -1411,11 +1410,10 @@ static int check_mmap_limit(const size_t limit) {
|
||||
const int log2page = log2n_powerof2(pagesize);
|
||||
if ((limit >> (log2page + 7)) > (size_t)total_ram_pages ||
|
||||
(limit >> (log2page + 6)) > (size_t)avail_ram_pages) {
|
||||
mdbx_error(
|
||||
"%s (%zu pages) is too large for available (%zu pages) or total "
|
||||
"(%zu pages) system RAM",
|
||||
"database upper size limit", limit >> log2page, avail_ram_pages,
|
||||
total_ram_pages);
|
||||
ERROR("%s (%zu pages) is too large for available (%zu pages) or total "
|
||||
"(%zu pages) system RAM",
|
||||
"database upper size limit", limit >> log2page, avail_ram_pages,
|
||||
total_ram_pages);
|
||||
return MDBX_TOO_LARGE;
|
||||
}
|
||||
}
|
||||
@ -1423,7 +1421,7 @@ static int check_mmap_limit(const size_t limit) {
|
||||
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 unsigned options) {
|
||||
assert(size <= limit);
|
||||
@ -1435,7 +1433,7 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
||||
map->section = NULL;
|
||||
#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))
|
||||
return err;
|
||||
|
||||
@ -1444,7 +1442,7 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
||||
return err;
|
||||
|
||||
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)
|
||||
return err;
|
||||
map->filesize = size;
|
||||
@ -1452,7 +1450,7 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
||||
map->current = size;
|
||||
#endif /* !Windows */
|
||||
} else {
|
||||
err = mdbx_filesize(map->fd, &map->filesize);
|
||||
err = osal_filesize(map->fd, &map->filesize);
|
||||
if (err != MDBX_SUCCESS)
|
||||
return err;
|
||||
#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;
|
||||
}
|
||||
|
||||
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);
|
||||
/* Unpoisoning is required for ASAN to avoid false-positive diagnostic
|
||||
* 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;
|
||||
}
|
||||
|
||||
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) {
|
||||
assert(size <= limit);
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
@ -1683,12 +1681,12 @@ retry_file_and_section:
|
||||
map->address = NULL;
|
||||
}
|
||||
|
||||
err = mdbx_filesize(map->fd, &map->filesize);
|
||||
err = osal_filesize(map->fd, &map->filesize);
|
||||
if (err != MDBX_SUCCESS)
|
||||
goto bailout;
|
||||
|
||||
if ((flags & MDBX_RDONLY) == 0 && map->filesize != size) {
|
||||
err = mdbx_ftruncate(map->fd, size);
|
||||
err = osal_ftruncate(map->fd, size);
|
||||
if (err == MDBX_SUCCESS)
|
||||
map->filesize = size;
|
||||
/* ignore error, because Windows unable shrink file
|
||||
@ -1764,7 +1762,7 @@ retry_mapview:;
|
||||
#else /* Windows */
|
||||
|
||||
map->filesize = 0;
|
||||
int rc = mdbx_filesize(map->fd, &map->filesize);
|
||||
int rc = osal_filesize(map->fd, &map->filesize);
|
||||
if (rc != MDBX_SUCCESS)
|
||||
return rc;
|
||||
|
||||
@ -1774,7 +1772,7 @@ retry_mapview:;
|
||||
rc = (size > map->current) ? MDBX_UNABLE_EXTEND_MAPSIZE : MDBX_EPERM;
|
||||
} else {
|
||||
if (map->filesize != size) {
|
||||
rc = mdbx_ftruncate(map->fd, size);
|
||||
rc = osal_ftruncate(map->fd, size);
|
||||
if (rc != MDBX_SUCCESS)
|
||||
return rc;
|
||||
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 (;;) {
|
||||
#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \
|
||||
defined(__x86_64__)
|
||||
@ -2011,8 +2009,7 @@ static LARGE_INTEGER performance_frequency;
|
||||
static uint64_t ratio_16dot16_to_monotine;
|
||||
#endif
|
||||
|
||||
MDBX_INTERNAL_FUNC uint64_t
|
||||
mdbx_osal_16dot16_to_monotime(uint32_t seconds_16dot16) {
|
||||
MDBX_INTERNAL_FUNC uint64_t osal_16dot16_to_monotime(uint32_t seconds_16dot16) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
if (unlikely(performance_frequency.QuadPart == 0))
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
if (unlikely(monotime > limit)) {
|
||||
if (likely(limit != 0))
|
||||
return UINT32_MAX;
|
||||
limit = mdbx_osal_16dot16_to_monotime(UINT32_MAX - 1);
|
||||
limit = osal_16dot16_to_monotime(UINT32_MAX - 1);
|
||||
if (unlikely(monotime > limit))
|
||||
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 */;
|
||||
}
|
||||
|
||||
MDBX_INTERNAL_FUNC uint64_t mdbx_osal_monotime(void) {
|
||||
MDBX_INTERNAL_FUNC uint64_t osal_monotime(void) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
LARGE_INTEGER counter;
|
||||
counter.QuadPart = 0;
|
||||
@ -2222,7 +2219,7 @@ bootid_parse_uuid(bin128_t *s, const void *p, const size_t n) {
|
||||
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}};
|
||||
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)
|
||||
*avail_pages = -1;
|
||||
|
||||
const intptr_t pagesize = mdbx_syspagesize();
|
||||
const intptr_t pagesize = osal_syspagesize();
|
||||
if (page_size)
|
||||
*page_size = pagesize;
|
||||
if (unlikely(pagesize < MIN_PAGESIZE || !is_powerof2(pagesize)))
|
||||
|
237
src/osal.h
237
src/osal.h
@ -58,7 +58,7 @@
|
||||
#include <sys/cachectl.h>
|
||||
#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__)
|
||||
__asm__ __volatile__("" ::: "memory");
|
||||
#elif defined(_MSC_VER)
|
||||
@ -78,7 +78,7 @@ MDBX_MAYBE_UNUSED static __inline void mdbx_compiler_barrier(void) {
|
||||
#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
|
||||
atomic_thread_fence(memory_order_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)
|
||||
#define HAVE_SYS_STAT_H
|
||||
#define HAVE_SYS_TYPES_H
|
||||
typedef HANDLE mdbx_thread_t;
|
||||
typedef unsigned mdbx_thread_key_t;
|
||||
typedef HANDLE osal_thread_t;
|
||||
typedef unsigned osal_thread_key_t;
|
||||
#define MAP_FAILED NULL
|
||||
#define HIGH_DWORD(v) ((DWORD)((sizeof(v) > 4) ? ((uint64_t)(v) >> 32) : 0))
|
||||
#define THREAD_CALL WINAPI
|
||||
@ -125,8 +125,8 @@ typedef unsigned mdbx_thread_key_t;
|
||||
typedef struct {
|
||||
HANDLE mutex;
|
||||
HANDLE event[2];
|
||||
} mdbx_condpair_t;
|
||||
typedef CRITICAL_SECTION mdbx_fastmutex_t;
|
||||
} osal_condpair_t;
|
||||
typedef CRITICAL_SECTION osal_fastmutex_t;
|
||||
|
||||
#if !defined(_MSC_VER) && !defined(__try)
|
||||
/* *INDENT-OFF* */
|
||||
@ -139,36 +139,36 @@ typedef CRITICAL_SECTION mdbx_fastmutex_t;
|
||||
|
||||
#if MDBX_WITHOUT_MSVC_CRT
|
||||
|
||||
#ifndef mdbx_malloc
|
||||
static inline void *mdbx_malloc(size_t bytes) {
|
||||
#ifndef osal_malloc
|
||||
static inline void *osal_malloc(size_t bytes) {
|
||||
return HeapAlloc(GetProcessHeap(), 0, bytes);
|
||||
}
|
||||
#endif /* mdbx_malloc */
|
||||
#endif /* osal_malloc */
|
||||
|
||||
#ifndef mdbx_calloc
|
||||
static inline void *mdbx_calloc(size_t nelem, size_t size) {
|
||||
#ifndef osal_calloc
|
||||
static inline void *osal_calloc(size_t nelem, size_t size) {
|
||||
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nelem * size);
|
||||
}
|
||||
#endif /* mdbx_calloc */
|
||||
#endif /* osal_calloc */
|
||||
|
||||
#ifndef mdbx_realloc
|
||||
static inline void *mdbx_realloc(void *ptr, size_t bytes) {
|
||||
#ifndef osal_realloc
|
||||
static inline void *osal_realloc(void *ptr, size_t bytes) {
|
||||
return ptr ? HeapReAlloc(GetProcessHeap(), 0, ptr, bytes)
|
||||
: HeapAlloc(GetProcessHeap(), 0, bytes);
|
||||
}
|
||||
#endif /* mdbx_realloc */
|
||||
#endif /* osal_realloc */
|
||||
|
||||
#ifndef mdbx_free
|
||||
static inline void mdbx_free(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); }
|
||||
#endif /* mdbx_free */
|
||||
#ifndef osal_free
|
||||
static inline void osal_free(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); }
|
||||
#endif /* osal_free */
|
||||
|
||||
#else /* MDBX_WITHOUT_MSVC_CRT */
|
||||
|
||||
#define mdbx_malloc malloc
|
||||
#define mdbx_calloc calloc
|
||||
#define mdbx_realloc realloc
|
||||
#define mdbx_free free
|
||||
#define mdbx_strdup _strdup
|
||||
#define osal_malloc malloc
|
||||
#define osal_calloc calloc
|
||||
#define osal_realloc realloc
|
||||
#define osal_free free
|
||||
#define osal_strdup _strdup
|
||||
|
||||
#endif /* MDBX_WITHOUT_MSVC_CRT */
|
||||
|
||||
@ -180,26 +180,26 @@ static inline void mdbx_free(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); }
|
||||
#define vsnprintf _vsnprintf /* ntdll */
|
||||
#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);
|
||||
|
||||
#else /*----------------------------------------------------------------------*/
|
||||
|
||||
typedef pthread_t mdbx_thread_t;
|
||||
typedef pthread_key_t mdbx_thread_key_t;
|
||||
typedef pthread_t osal_thread_t;
|
||||
typedef pthread_key_t osal_thread_key_t;
|
||||
#define INVALID_HANDLE_VALUE (-1)
|
||||
#define THREAD_CALL
|
||||
#define THREAD_RESULT void *
|
||||
typedef struct {
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond[2];
|
||||
} mdbx_condpair_t;
|
||||
typedef pthread_mutex_t mdbx_fastmutex_t;
|
||||
#define mdbx_malloc malloc
|
||||
#define mdbx_calloc calloc
|
||||
#define mdbx_realloc realloc
|
||||
#define mdbx_free free
|
||||
#define mdbx_strdup strdup
|
||||
} osal_condpair_t;
|
||||
typedef pthread_mutex_t osal_fastmutex_t;
|
||||
#define osal_malloc malloc
|
||||
#define osal_calloc calloc
|
||||
#define osal_realloc realloc
|
||||
#define osal_free free
|
||||
#define osal_strdup strdup
|
||||
#endif /* Platform */
|
||||
|
||||
#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
|
||||
* fundamental to the use of memory-mapped files. */
|
||||
MDBX_MAYBE_UNUSED MDBX_NOTHROW_CONST_FUNCTION static __inline size_t
|
||||
mdbx_syspagesize(void) {
|
||||
osal_syspagesize(void) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
@ -233,7 +233,7 @@ typedef wchar_t pathchar_t;
|
||||
typedef char pathchar_t;
|
||||
#endif
|
||||
|
||||
typedef struct mdbx_mmap_param {
|
||||
typedef struct osal_mmap_param {
|
||||
union {
|
||||
void *address;
|
||||
uint8_t *dxb;
|
||||
@ -246,7 +246,7 @@ typedef struct mdbx_mmap_param {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
HANDLE section; /* memory-mapped section handle */
|
||||
#endif
|
||||
} mdbx_mmap_t;
|
||||
} osal_mmap_t;
|
||||
|
||||
typedef union bin128 {
|
||||
__anonymous_struct_extension__ struct { uint64_t x, y; };
|
||||
@ -254,13 +254,13 @@ typedef union bin128 {
|
||||
} bin128_t;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
typedef union MDBX_srwlock {
|
||||
typedef union osal_srwlock {
|
||||
__anonymous_struct_extension__ struct {
|
||||
long volatile readerCount;
|
||||
long volatile writerCount;
|
||||
};
|
||||
RTL_SRWLOCK native;
|
||||
} MDBX_srwlock;
|
||||
} osal_srwlock_t;
|
||||
#endif /* Windows */
|
||||
|
||||
#ifndef __cplusplus
|
||||
@ -270,12 +270,12 @@ typedef union MDBX_srwlock {
|
||||
|
||||
#if (!defined(__GLIBC__) && __GLIBC_PREREQ(2, 1)) && \
|
||||
(defined(_GNU_SOURCE) || defined(_BSD_SOURCE))
|
||||
#define mdbx_asprintf asprintf
|
||||
#define mdbx_vasprintf vasprintf
|
||||
#define osal_asprintf asprintf
|
||||
#define osal_vasprintf vasprintf
|
||||
#else
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL_FUNC
|
||||
MDBX_PRINTF_ARGS(2, 3) int mdbx_asprintf(char **strp, const char *fmt, ...);
|
||||
MDBX_INTERNAL_FUNC int mdbx_vasprintf(char **strp, const char *fmt, va_list ap);
|
||||
MDBX_PRINTF_ARGS(2, 3) int osal_asprintf(char **strp, const char *fmt, ...);
|
||||
MDBX_INTERNAL_FUNC int osal_vasprintf(char **strp, const char *fmt, va_list ap);
|
||||
#endif
|
||||
|
||||
#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
|
||||
#endif /* MADV_NOCORE -> MADV_DONTDUMP */
|
||||
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL_FUNC void mdbx_osal_jitter(bool tiny);
|
||||
MDBX_MAYBE_UNUSED static __inline void mdbx_jitter4testing(bool tiny);
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL_FUNC void osal_jitter(bool tiny);
|
||||
MDBX_MAYBE_UNUSED static __inline void jitter4testing(bool tiny);
|
||||
|
||||
/* max bytes to write in one call */
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
@ -297,15 +297,15 @@ MDBX_MAYBE_UNUSED static __inline void mdbx_jitter4testing(bool tiny);
|
||||
#endif
|
||||
|
||||
#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 */;
|
||||
#endif /* Linux */
|
||||
|
||||
#ifndef mdbx_strdup
|
||||
LIBMDBX_API char *mdbx_strdup(const char *str);
|
||||
#ifndef osal_strdup
|
||||
LIBMDBX_API char *osal_strdup(const char *str);
|
||||
#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)
|
||||
DWORD rc = GetLastError();
|
||||
#else
|
||||
@ -314,57 +314,57 @@ MDBX_MAYBE_UNUSED static __inline int mdbx_get_errno(void) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifndef mdbx_memalign_alloc
|
||||
MDBX_INTERNAL_FUNC int mdbx_memalign_alloc(size_t alignment, size_t bytes,
|
||||
#ifndef osal_memalign_alloc
|
||||
MDBX_INTERNAL_FUNC int osal_memalign_alloc(size_t alignment, size_t bytes,
|
||||
void **result);
|
||||
#endif
|
||||
#ifndef mdbx_memalign_free
|
||||
MDBX_INTERNAL_FUNC void mdbx_memalign_free(void *ptr);
|
||||
#ifndef osal_memalign_free
|
||||
MDBX_INTERNAL_FUNC void osal_memalign_free(void *ptr);
|
||||
#endif
|
||||
|
||||
MDBX_INTERNAL_FUNC int mdbx_condpair_init(mdbx_condpair_t *condpair);
|
||||
MDBX_INTERNAL_FUNC int mdbx_condpair_lock(mdbx_condpair_t *condpair);
|
||||
MDBX_INTERNAL_FUNC int mdbx_condpair_unlock(mdbx_condpair_t *condpair);
|
||||
MDBX_INTERNAL_FUNC int mdbx_condpair_signal(mdbx_condpair_t *condpair,
|
||||
MDBX_INTERNAL_FUNC int osal_condpair_init(osal_condpair_t *condpair);
|
||||
MDBX_INTERNAL_FUNC int osal_condpair_lock(osal_condpair_t *condpair);
|
||||
MDBX_INTERNAL_FUNC int osal_condpair_unlock(osal_condpair_t *condpair);
|
||||
MDBX_INTERNAL_FUNC int osal_condpair_signal(osal_condpair_t *condpair,
|
||||
bool part);
|
||||
MDBX_INTERNAL_FUNC int mdbx_condpair_wait(mdbx_condpair_t *condpair, bool part);
|
||||
MDBX_INTERNAL_FUNC int mdbx_condpair_destroy(mdbx_condpair_t *condpair);
|
||||
MDBX_INTERNAL_FUNC int osal_condpair_wait(osal_condpair_t *condpair, bool part);
|
||||
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 mdbx_fastmutex_acquire(mdbx_fastmutex_t *fastmutex);
|
||||
MDBX_INTERNAL_FUNC int mdbx_fastmutex_release(mdbx_fastmutex_t *fastmutex);
|
||||
MDBX_INTERNAL_FUNC int mdbx_fastmutex_destroy(mdbx_fastmutex_t *fastmutex);
|
||||
MDBX_INTERNAL_FUNC int osal_fastmutex_init(osal_fastmutex_t *fastmutex);
|
||||
MDBX_INTERNAL_FUNC int osal_fastmutex_acquire(osal_fastmutex_t *fastmutex);
|
||||
MDBX_INTERNAL_FUNC int osal_fastmutex_release(osal_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,
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
|
||||
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 *),
|
||||
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_DATA = 1,
|
||||
MDBX_SYNC_SIZE = 2,
|
||||
MDBX_SYNC_IODQ = 4
|
||||
};
|
||||
|
||||
MDBX_INTERNAL_FUNC int mdbx_fsync(mdbx_filehandle_t fd,
|
||||
const enum mdbx_syncmode_bits mode_bits);
|
||||
MDBX_INTERNAL_FUNC int mdbx_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 mdbx_filesize(mdbx_filehandle_t fd, uint64_t *length);
|
||||
MDBX_INTERNAL_FUNC int osal_fsync(mdbx_filehandle_t fd,
|
||||
const enum osal_syncmode_bits mode_bits);
|
||||
MDBX_INTERNAL_FUNC int osal_ftruncate(mdbx_filehandle_t fd, uint64_t length);
|
||||
MDBX_INTERNAL_FUNC int osal_fseek(mdbx_filehandle_t fd, uint64_t pos);
|
||||
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_LAZY = 1,
|
||||
MDBX_OPEN_DXB_DSYNC = 2,
|
||||
@ -373,26 +373,26 @@ enum mdbx_openfile_purpose {
|
||||
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 pathchar_t *pathname,
|
||||
mdbx_filehandle_t *fd,
|
||||
mdbx_mode_t unix_mode_bits);
|
||||
MDBX_INTERNAL_FUNC int mdbx_closefile(mdbx_filehandle_t fd);
|
||||
MDBX_INTERNAL_FUNC int mdbx_removefile(const pathchar_t *pathname);
|
||||
MDBX_INTERNAL_FUNC int mdbx_removedirectory(const pathchar_t *pathname);
|
||||
MDBX_INTERNAL_FUNC int mdbx_is_pipe(mdbx_filehandle_t fd);
|
||||
MDBX_INTERNAL_FUNC int mdbx_lockfile(mdbx_filehandle_t fd, bool wait);
|
||||
MDBX_INTERNAL_FUNC int osal_closefile(mdbx_filehandle_t fd);
|
||||
MDBX_INTERNAL_FUNC int osal_removefile(const pathchar_t *pathname);
|
||||
MDBX_INTERNAL_FUNC int osal_removedirectory(const pathchar_t *pathname);
|
||||
MDBX_INTERNAL_FUNC int osal_is_pipe(mdbx_filehandle_t fd);
|
||||
MDBX_INTERNAL_FUNC int osal_lockfile(mdbx_filehandle_t fd, bool wait);
|
||||
|
||||
#define MMAP_OPTION_TRUNCATE 1
|
||||
#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 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_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);
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
typedef struct {
|
||||
@ -400,18 +400,18 @@ typedef struct {
|
||||
HANDLE handles[31];
|
||||
} mdbx_handle_array_t;
|
||||
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_resume_threads_after_remap(mdbx_handle_array_t *array);
|
||||
osal_resume_threads_after_remap(mdbx_handle_array_t *array);
|
||||
#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,
|
||||
enum mdbx_syncmode_bits mode_bits);
|
||||
MDBX_INTERNAL_FUNC int mdbx_check_fs_rdonly(mdbx_filehandle_t handle,
|
||||
enum osal_syncmode_bits mode_bits);
|
||||
MDBX_INTERNAL_FUNC int osal_check_fs_rdonly(mdbx_filehandle_t handle,
|
||||
const pathchar_t *pathname,
|
||||
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));
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
return GetCurrentProcessId();
|
||||
@ -421,7 +421,7 @@ MDBX_MAYBE_UNUSED static __inline uint32_t mdbx_getpid(void) {
|
||||
#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;
|
||||
STATIC_ASSERT(sizeof(uintptr_t) >= sizeof(thunk));
|
||||
#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(__ANDROID_API__) || defined(ANDROID) || defined(BIONIC)
|
||||
MDBX_INTERNAL_FUNC int mdbx_check_tid4bionic(void);
|
||||
MDBX_INTERNAL_FUNC int osal_check_tid4bionic(void);
|
||||
#else
|
||||
static __inline int mdbx_check_tid4bionic(void) { return 0; }
|
||||
static __inline int osal_check_tid4bionic(void) { return 0; }
|
||||
#endif /* __ANDROID_API__ || ANDROID) || BIONIC */
|
||||
|
||||
MDBX_MAYBE_UNUSED static __inline int
|
||||
mdbx_pthread_mutex_lock(pthread_mutex_t *mutex) {
|
||||
int err = mdbx_check_tid4bionic();
|
||||
osal_pthread_mutex_lock(pthread_mutex_t *mutex) {
|
||||
int err = osal_check_tid4bionic();
|
||||
return unlikely(err) ? err : pthread_mutex_lock(mutex);
|
||||
}
|
||||
#endif /* !Windows */
|
||||
|
||||
MDBX_INTERNAL_FUNC uint64_t mdbx_osal_monotime(void);
|
||||
MDBX_INTERNAL_FUNC uint64_t
|
||||
mdbx_osal_16dot16_to_monotime(uint32_t seconds_16dot16);
|
||||
MDBX_INTERNAL_FUNC uint32_t mdbx_osal_monotime_to_16dot16(uint64_t monotime);
|
||||
MDBX_INTERNAL_FUNC uint64_t osal_monotime(void);
|
||||
MDBX_INTERNAL_FUNC uint64_t osal_16dot16_to_monotime(uint32_t seconds_16dot16);
|
||||
MDBX_INTERNAL_FUNC uint32_t 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 */
|
||||
|
||||
@ -467,7 +466,7 @@ MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void);
|
||||
/// MUST NOT initialize shared synchronization objects in memory-mapped
|
||||
/// LCK-file that are already in use.
|
||||
/// \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,
|
||||
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.
|
||||
/// restore POSIX-fcntl locks after the closing of file descriptors.
|
||||
/// \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);
|
||||
|
||||
/// \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
|
||||
/// acquire the non-OS super-level lock (e.g. for shared synchronization
|
||||
/// 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
|
||||
/// 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.
|
||||
/// MDBX_RESULT_FALSE (0) - if a shared lock was acquired and thus
|
||||
/// DB has already been opened and now is used by other processes.
|
||||
/// 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
|
||||
/// 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
|
||||
/// operational lock.
|
||||
/// \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.
|
||||
/// \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.
|
||||
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)
|
||||
/// 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
|
||||
/// 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
|
||||
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)
|
||||
/// 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
|
||||
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
|
||||
/// 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
|
||||
/// or not working with DB (indicative lock is not present).
|
||||
/// 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)
|
||||
|
||||
#define MUSTDIE_MB2WIDE(FROM, TO) \
|
||||
#define OSAL_MB2WIDE(FROM, TO) \
|
||||
do { \
|
||||
const char *const from_tmp = (FROM); \
|
||||
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) \
|
||||
return ERROR_INVALID_NAME; \
|
||||
wchar_t *const to_tmp = _alloca((to_wlen + 1) * sizeof(wchar_t)); \
|
||||
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; \
|
||||
(TO) = to_tmp; \
|
||||
} while (0)
|
||||
|
||||
typedef void(WINAPI *MDBX_srwlock_function)(MDBX_srwlock *);
|
||||
MDBX_INTERNAL_VAR MDBX_srwlock_function mdbx_srwlock_Init,
|
||||
mdbx_srwlock_AcquireShared, mdbx_srwlock_ReleaseShared,
|
||||
mdbx_srwlock_AcquireExclusive, mdbx_srwlock_ReleaseExclusive;
|
||||
typedef void(WINAPI *osal_srwlock_t_function)(osal_srwlock_t *);
|
||||
MDBX_INTERNAL_VAR osal_srwlock_t_function osal_srwlock_Init,
|
||||
osal_srwlock_AcquireShared, osal_srwlock_ReleaseShared,
|
||||
osal_srwlock_AcquireExclusive, osal_srwlock_ReleaseExclusive;
|
||||
|
||||
#if _WIN32_WINNT < 0x0600 /* prior to Windows Vista */
|
||||
typedef enum _FILE_INFO_BY_HANDLE_CLASS {
|
||||
|
@ -94,7 +94,7 @@
|
||||
|
||||
#define MDBX_INTERNAL_FUNC
|
||||
#define MDBX_INTERNAL_VAR extern
|
||||
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||
#define xMDBX_TOOLS /* Avoid using internal eASSERT() */
|
||||
#include "../mdbx.h++"
|
||||
#include "../src/base.h"
|
||||
#include "../src/osal.h"
|
||||
|
@ -15,7 +15,7 @@ REGISTER_TESTCASE(copy);
|
||||
void testcase_copy::copy_db(const bool with_compaction) {
|
||||
int err = mdbx_env_delete(copy_pathname.c_str(), MDBX_ENV_JUST_DELETE);
|
||||
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(),
|
||||
with_compaction ? MDBX_CP_COMPACT : MDBX_CP_DEFAULTS);
|
||||
|
@ -4,7 +4,7 @@
|
||||
msync(start)
|
||||
fun:msync
|
||||
...
|
||||
fun:mdbx_sync_locked*
|
||||
fun:sync_locked*
|
||||
}
|
||||
{
|
||||
msync-whole-mmap-2
|
||||
@ -12,7 +12,7 @@
|
||||
msync(start)
|
||||
fun:msync
|
||||
...
|
||||
fun:mdbx_env_sync_internal*
|
||||
fun:env_sync*
|
||||
}
|
||||
{
|
||||
msync-whole-mmap-3
|
||||
@ -20,7 +20,7 @@
|
||||
msync(start)
|
||||
fun:msync
|
||||
...
|
||||
fun:mdbx_mapresize*
|
||||
fun:map_resize*
|
||||
}
|
||||
{
|
||||
msync-wipe-steady
|
||||
@ -28,21 +28,21 @@
|
||||
msync(start)
|
||||
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
|
||||
Memcheck:Cond
|
||||
fun:bcmp
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
write-page-check-memcmp
|
||||
Memcheck:Cond
|
||||
fun:memcmp*
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
|
||||
# single-page flush by pwrite()
|
||||
@ -52,7 +52,7 @@
|
||||
pwrite(buf)
|
||||
fun:pwrite
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwrite64-page-flush
|
||||
@ -60,7 +60,7 @@
|
||||
pwrite64(buf)
|
||||
fun:pwrite
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
|
||||
# modern Valgrind don't support the `vector[...]` pattern
|
||||
@ -70,16 +70,16 @@
|
||||
# pwritev(vector[...])
|
||||
# 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
|
||||
Memcheck:Param
|
||||
pwritev(vector[0])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-1
|
||||
@ -87,7 +87,7 @@
|
||||
pwritev(vector[1])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-2
|
||||
@ -95,7 +95,7 @@
|
||||
pwritev(vector[2])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-3
|
||||
@ -103,7 +103,7 @@
|
||||
pwritev(vector[3])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-4
|
||||
@ -111,7 +111,7 @@
|
||||
pwritev(vector[4])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-5
|
||||
@ -119,7 +119,7 @@
|
||||
pwritev(vector[5])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-6
|
||||
@ -127,7 +127,7 @@
|
||||
pwritev(vector[6])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-7
|
||||
@ -135,7 +135,7 @@
|
||||
pwritev(vector[7])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-8
|
||||
@ -143,7 +143,7 @@
|
||||
pwritev(vector[8])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-9
|
||||
@ -151,7 +151,7 @@
|
||||
pwritev(vector[9])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-10
|
||||
@ -159,7 +159,7 @@
|
||||
pwritev(vector[10])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-11
|
||||
@ -167,7 +167,7 @@
|
||||
pwritev(vector[11])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-12
|
||||
@ -175,7 +175,7 @@
|
||||
pwritev(vector[12])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-13
|
||||
@ -183,7 +183,7 @@
|
||||
pwritev(vector[13])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-14
|
||||
@ -191,7 +191,7 @@
|
||||
pwritev(vector[14])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-15
|
||||
@ -199,7 +199,7 @@
|
||||
pwritev(vector[15])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-16
|
||||
@ -207,7 +207,7 @@
|
||||
pwritev(vector[16])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-17
|
||||
@ -215,7 +215,7 @@
|
||||
pwritev(vector[17])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-18
|
||||
@ -223,7 +223,7 @@
|
||||
pwritev(vector[18])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-19
|
||||
@ -231,7 +231,7 @@
|
||||
pwritev(vector[19])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-20
|
||||
@ -239,7 +239,7 @@
|
||||
pwritev(vector[20])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-21
|
||||
@ -247,7 +247,7 @@
|
||||
pwritev(vector[21])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-22
|
||||
@ -255,7 +255,7 @@
|
||||
pwritev(vector[22])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-23
|
||||
@ -263,7 +263,7 @@
|
||||
pwritev(vector[23])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-24
|
||||
@ -271,7 +271,7 @@
|
||||
pwritev(vector[24])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-25
|
||||
@ -279,7 +279,7 @@
|
||||
pwritev(vector[25])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-26
|
||||
@ -287,7 +287,7 @@
|
||||
pwritev(vector[26])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-27
|
||||
@ -295,7 +295,7 @@
|
||||
pwritev(vector[27])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-28
|
||||
@ -303,7 +303,7 @@
|
||||
pwritev(vector[28])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-29
|
||||
@ -311,7 +311,7 @@
|
||||
pwritev(vector[29])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-30
|
||||
@ -319,7 +319,7 @@
|
||||
pwritev(vector[30])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-31
|
||||
@ -327,7 +327,7 @@
|
||||
pwritev(vector[31])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-32
|
||||
@ -335,7 +335,7 @@
|
||||
pwritev(vector[32])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-33
|
||||
@ -343,7 +343,7 @@
|
||||
pwritev(vector[33])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-34
|
||||
@ -351,7 +351,7 @@
|
||||
pwritev(vector[34])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-35
|
||||
@ -359,7 +359,7 @@
|
||||
pwritev(vector[35])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-36
|
||||
@ -367,7 +367,7 @@
|
||||
pwritev(vector[36])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-37
|
||||
@ -375,7 +375,7 @@
|
||||
pwritev(vector[37])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-38
|
||||
@ -383,7 +383,7 @@
|
||||
pwritev(vector[38])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-39
|
||||
@ -391,7 +391,7 @@
|
||||
pwritev(vector[39])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-40
|
||||
@ -399,7 +399,7 @@
|
||||
pwritev(vector[40])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-41
|
||||
@ -407,7 +407,7 @@
|
||||
pwritev(vector[41])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-42
|
||||
@ -415,7 +415,7 @@
|
||||
pwritev(vector[42])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-43
|
||||
@ -423,7 +423,7 @@
|
||||
pwritev(vector[43])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-44
|
||||
@ -431,7 +431,7 @@
|
||||
pwritev(vector[44])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-45
|
||||
@ -439,7 +439,7 @@
|
||||
pwritev(vector[45])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-46
|
||||
@ -447,7 +447,7 @@
|
||||
pwritev(vector[46])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-47
|
||||
@ -455,7 +455,7 @@
|
||||
pwritev(vector[47])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-48
|
||||
@ -463,7 +463,7 @@
|
||||
pwritev(vector[48])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-49
|
||||
@ -471,7 +471,7 @@
|
||||
pwritev(vector[49])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-50
|
||||
@ -479,7 +479,7 @@
|
||||
pwritev(vector[50])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-51
|
||||
@ -487,7 +487,7 @@
|
||||
pwritev(vector[51])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-52
|
||||
@ -495,7 +495,7 @@
|
||||
pwritev(vector[52])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-53
|
||||
@ -503,7 +503,7 @@
|
||||
pwritev(vector[53])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-54
|
||||
@ -511,7 +511,7 @@
|
||||
pwritev(vector[54])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-55
|
||||
@ -519,7 +519,7 @@
|
||||
pwritev(vector[55])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-56
|
||||
@ -527,7 +527,7 @@
|
||||
pwritev(vector[56])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-57
|
||||
@ -535,7 +535,7 @@
|
||||
pwritev(vector[57])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-58
|
||||
@ -543,7 +543,7 @@
|
||||
pwritev(vector[58])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-59
|
||||
@ -551,7 +551,7 @@
|
||||
pwritev(vector[59])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-60
|
||||
@ -559,7 +559,7 @@
|
||||
pwritev(vector[60])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-61
|
||||
@ -567,7 +567,7 @@
|
||||
pwritev(vector[61])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-62
|
||||
@ -575,7 +575,7 @@
|
||||
pwritev(vector[62])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
{
|
||||
pwritev-page-flush-63
|
||||
@ -583,5 +583,5 @@
|
||||
pwritev(vector[63])
|
||||
fun:pwritev
|
||||
...
|
||||
fun:mdbx_iov_write*
|
||||
fun:iov_write*
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user