mirror of
https://github.com/isar/libmdbx.git
synced 2025-08-25 09:44:27 +08:00
mdbx: portability fixes for SunOS/Solaris/OpenIndiana.
Change-Id: I0442367e798903598d706c65b536a127ca982fce
This commit is contained in:
@@ -3479,8 +3479,8 @@ static int __cold mdbx_set_readahead(MDBX_env *env, const size_t offset,
|
||||
if (unlikely(madvise(env->me_map + offset, length, MADV_WILLNEED) != 0))
|
||||
return errno;
|
||||
#elif defined(POSIX_MADV_WILLNEED)
|
||||
rc = posix_madvise(env->me_map + offset, length, POSIX_MADV_WILLNEED);
|
||||
if (unlikely(rc != 0))
|
||||
int err = posix_madvise(env->me_map + offset, length, POSIX_MADV_WILLNEED);
|
||||
if (unlikely(err != 0))
|
||||
return errno;
|
||||
#elif defined(_WIN32) || defined(_WIN64)
|
||||
if (mdbx_PrefetchVirtualMemory) {
|
||||
@@ -6329,7 +6329,7 @@ static int mdbx_page_flush(MDBX_txn *txn, const unsigned keep) {
|
||||
}
|
||||
iov_off = pgno2bytes(env, dp->mp_pgno);
|
||||
}
|
||||
iov[iov_items].iov_base = dp;
|
||||
iov[iov_items].iov_base = (void *)dp;
|
||||
iov[iov_items].iov_len = size;
|
||||
iov_items += 1;
|
||||
iov_bytes += size;
|
||||
@@ -7428,7 +7428,8 @@ static void __cold mdbx_setup_pagesize(MDBX_env *env, const size_t pagesize) {
|
||||
STATIC_ASSERT(mdbx_nodemax(MIN_PAGESIZE) > 42);
|
||||
STATIC_ASSERT(mdbx_nodemax(MAX_PAGESIZE) < UINT16_MAX);
|
||||
const intptr_t nodemax = mdbx_nodemax(pagesize);
|
||||
mdbx_ensure(env, nodemax > 42 && nodemax < UINT16_MAX && nodemax % 2 == 0);
|
||||
mdbx_ensure(env,
|
||||
nodemax > 42 && nodemax < (int)UINT16_MAX && nodemax % 2 == 0);
|
||||
env->me_nodemax = (unsigned)nodemax;
|
||||
|
||||
STATIC_ASSERT(mdbx_maxkey(MIN_PAGESIZE) > 42);
|
||||
@@ -8076,9 +8077,9 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
|
||||
env->me_dxb_mmap.current - used_aligned2os_bytes,
|
||||
MADV_DONTNEED);
|
||||
#elif defined(POSIX_MADV_DONTNEED)
|
||||
(void)madvise(env->me_map + used_aligned2os_bytes,
|
||||
env->me_dxb_mmap.current - used_aligned2os_bytes,
|
||||
POSIX_MADV_DONTNEED);
|
||||
(void)posix_madvise(env->me_map + used_aligned2os_bytes,
|
||||
env->me_dxb_mmap.current - used_aligned2os_bytes,
|
||||
POSIX_MADV_DONTNEED);
|
||||
#elif defined(POSIX_FADV_DONTNEED)
|
||||
(void)posix_fadvise(env->me_fd, used_aligned2os_bytes,
|
||||
env->me_dxb_mmap.current - used_aligned2os_bytes,
|
||||
@@ -8094,8 +8095,8 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
|
||||
const bool readahead = (env->me_flags & MDBX_NORDAHEAD) == 0 &&
|
||||
mdbx_is_readahead_reasonable(env->me_dxb_mmap.current,
|
||||
0) == MDBX_RESULT_TRUE;
|
||||
err = mdbx_set_readahead(env, 0, env->me_dxb_mmap.current, readahead);
|
||||
if (err != MDBX_SUCCESS)
|
||||
err = mdbx_set_readahead(env, 0, used_bytes, readahead);
|
||||
if (err != MDBX_SUCCESS && lck_rc == /* lck exclusive */ MDBX_RESULT_TRUE)
|
||||
return err;
|
||||
|
||||
mdbx_assert(env, used_bytes >= pgno2bytes(env, NUM_METAS) &&
|
||||
@@ -13025,7 +13026,7 @@ static int mdbx_page_split(MDBX_cursor *mc, const MDBX_val *newkey,
|
||||
rp->mp_lower += sizeof(indx_t);
|
||||
mdbx_cassert(mc, rp->mp_upper >= ksize - sizeof(indx_t));
|
||||
rp->mp_upper -= (indx_t)(ksize - sizeof(indx_t));
|
||||
mdbx_cassert(mc, x <= UINT16_MAX);
|
||||
mdbx_cassert(mc, x <= (int)UINT16_MAX);
|
||||
mc->mc_ki[mc->mc_top] = (indx_t)x;
|
||||
}
|
||||
} else {
|
||||
|
@@ -233,7 +233,8 @@
|
||||
|
||||
#ifndef MDBX_USE_OFDLOCKS
|
||||
#if defined(F_OFD_SETLK) && defined(F_OFD_SETLKW) && defined(F_OFD_GETLK) && \
|
||||
!defined(MDBX_SAFE4QEMU)
|
||||
!defined(MDBX_SAFE4QEMU) && \
|
||||
!defined(__sun) /* OFD-lock are broken on Solaris */
|
||||
#define MDBX_USE_OFDLOCKS 1
|
||||
#else
|
||||
#define MDBX_USE_OFDLOCKS 0
|
||||
|
@@ -179,6 +179,11 @@ __extern_C void __assert_rtn(const char *function, const char *file, int line,
|
||||
|
||||
#define __assert_fail(assertion, file, line, function) \
|
||||
__assert_rtn(function, file, line, assertion)
|
||||
#elif defined(__sun) || defined(__SVR4) || defined(__svr4__)
|
||||
__extern_C void __assert_c99(const char *assection, const char *file, int line,
|
||||
const char *function) __noreturn;
|
||||
#define __assert_fail(assertion, file, line, function) \
|
||||
__assert_c99(assertion, file, line, function)
|
||||
#elif defined(__OpenBSD__)
|
||||
__extern_C __dead void __assert2(const char *file, int line,
|
||||
const char *function,
|
||||
@@ -1070,24 +1075,27 @@ static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) {
|
||||
const unsigned type = 0;
|
||||
const char *const name = statvfs_info.f_fstypename;
|
||||
const size_t name_len = VFS_NAMELEN;
|
||||
#elif defined(_AIX) || defined(__OS400__) || defined(FSTYPSZ) || \
|
||||
defined(_FSTYPSZ)
|
||||
#elif defined(_AIX) || defined(__OS400__)
|
||||
const char *const name = statvfs_info.f_basetype;
|
||||
const size_t name_len = sizeof(statvfs_info.f_basetype);
|
||||
struct stat st;
|
||||
if (fstat(handle, &st))
|
||||
return errno;
|
||||
const unsigned type = st.st_vfstype;
|
||||
if ((st.st_flag & FS_REMOTE) != 0 && !(flags & MDBX_EXCLUSIVE))
|
||||
return MDBX_EREMOTE;
|
||||
#elif defined(FSTYPSZ) || defined(_FSTYPSZ)
|
||||
const unsigned type = 0;
|
||||
const char *const name = statfs_info.f_basetype;
|
||||
const size_t name_len = sizeof(statfs_info.f_basetype);
|
||||
const char *const name = statvfs_info.f_basetype;
|
||||
const size_t name_len = sizeof(statvfs_info.f_basetype);
|
||||
#elif defined(__sun) || defined(__SVR4) || defined(__svr4__) || \
|
||||
defined(ST_FSTYPSZ) || defined(_ST_FSTYPSZ)
|
||||
const unsigned type = 0;
|
||||
#if defined(_ST_FSTYPSZ) || defined(_ST_FSTYPSZ)
|
||||
struct stat stat_info;
|
||||
if (fstat(handle, &stat_info))
|
||||
struct stat st;
|
||||
if (fstat(handle, &st))
|
||||
return errno;
|
||||
const char *const name = stat_info.st_fstype;
|
||||
const char *const name = st.st_fstype;
|
||||
const size_t name_len = strlen(name);
|
||||
#else
|
||||
const char *const name = "";
|
||||
const size_t name_len = 0;
|
||||
#endif
|
||||
#else
|
||||
struct statfs statfs_info;
|
||||
if (fstatfs(handle, &statfs_info))
|
||||
@@ -1135,10 +1143,10 @@ static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) {
|
||||
#endif /* ST/MNT_LOCAL */
|
||||
|
||||
#ifdef ST_EXPORTED
|
||||
if (st_flags & ST_EXPORTED)
|
||||
if ((st_flags & ST_EXPORTED) != 0 && !(flags & MDBX_RDONLY))
|
||||
return MDBX_EREMOTE;
|
||||
#elif defined(MNT_EXPORTED)
|
||||
if (mnt_flags & MNT_EXPORTED)
|
||||
if ((mnt_flags & MNT_EXPORTED) != 0 && !(flags & MDBX_RDONLY))
|
||||
return MDBX_EREMOTE;
|
||||
#endif /* ST/MNT_EXPORTED */
|
||||
|
||||
@@ -1190,7 +1198,7 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
||||
map->current = size;
|
||||
#endif
|
||||
} else {
|
||||
uint64_t filesize;
|
||||
uint64_t filesize = 0;
|
||||
err = mdbx_filesize(map->fd, &filesize);
|
||||
if (err != MDBX_SUCCESS)
|
||||
return err;
|
||||
@@ -1451,7 +1459,7 @@ retry_mapview:;
|
||||
map->limit = ViewSize;
|
||||
#else
|
||||
|
||||
uint64_t filesize;
|
||||
uint64_t filesize = 0;
|
||||
int rc = mdbx_filesize(map->fd, &filesize);
|
||||
if (rc != MDBX_SUCCESS)
|
||||
return rc;
|
||||
@@ -1749,7 +1757,7 @@ static __cold __maybe_unused bool bootid_parse_uuid(bin128_t *s, const void *p,
|
||||
|
||||
__cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
|
||||
bin128_t bin = {{0, 0}};
|
||||
bool got_machineid = false, got_bootime = false, got_bootseq = false;
|
||||
bool got_machineid = false, got_boottime = false, got_bootseq = false;
|
||||
|
||||
#if defined(__linux__) || defined(__gnu_linux__)
|
||||
{
|
||||
@@ -1790,7 +1798,7 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
|
||||
len = sizeof(boottime);
|
||||
if (!sysctlbyname("kern.boottime", &boottime, &len, nullptr, 0) &&
|
||||
len == sizeof(boottime) && boottime.tv_sec)
|
||||
got_bootime = true;
|
||||
got_boottime = true;
|
||||
}
|
||||
#endif /* Apple/Darwin */
|
||||
|
||||
@@ -1878,7 +1886,7 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
|
||||
&len) == ERROR_SUCCESS &&
|
||||
len >= sizeof(buf.BaseTime) && buf.BaseTime) {
|
||||
bootid_collect(&bin, &buf.BaseTime, len);
|
||||
got_bootime = true;
|
||||
got_boottime = true;
|
||||
}
|
||||
|
||||
/* BootTime from SYSTEM_TIMEOFDAY_INFORMATION */
|
||||
@@ -1891,14 +1899,14 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
|
||||
buf.SysTimeOfDayInfoHacked.BootTime.QuadPart) {
|
||||
bootid_collect(&bin, &buf.SysTimeOfDayInfoHacked.BootTime,
|
||||
sizeof(buf.SysTimeOfDayInfoHacked.BootTime));
|
||||
got_bootime = true;
|
||||
got_boottime = true;
|
||||
}
|
||||
|
||||
if (!got_bootime) {
|
||||
if (!got_boottime) {
|
||||
uint64_t boottime = windows_bootime();
|
||||
if (boottime) {
|
||||
bootid_collect(&bin, &boottime, sizeof(boottime));
|
||||
got_bootime = true;
|
||||
got_boottime = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1962,7 +1970,7 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
#if defined(CTL_KERN) && defined(KERN_BOOTTIME)
|
||||
if (!got_bootime) {
|
||||
if (!got_boottime) {
|
||||
static const int mib[] = {CTL_KERN, KERN_BOOTTIME};
|
||||
struct timeval boottime;
|
||||
size_t len = sizeof(boottime);
|
||||
@@ -1974,13 +1982,13 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
|
||||
ARRAY_LENGTH(mib), &boottime, &len, NULL, 0) == 0 &&
|
||||
len == sizeof(boottime) && boottime.tv_sec) {
|
||||
bootid_collect(&bin, &boottime, len);
|
||||
got_bootime = true;
|
||||
got_boottime = true;
|
||||
}
|
||||
}
|
||||
#endif /* CTL_KERN && KERN_BOOTTIME */
|
||||
|
||||
#if defined(__sun) || defined(__SVR4) || defined(__svr4__)
|
||||
if (!got_bootime) {
|
||||
if (!got_boottime) {
|
||||
kstat_ctl_t *kc = kstat_open();
|
||||
if (kc) {
|
||||
kstat_t *kp = kstat_lookup(kc, "unix", 0, "system_misc");
|
||||
@@ -2005,13 +2013,13 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
|
||||
#endif /* SunOS / Solaris */
|
||||
|
||||
#if _XOPEN_SOURCE_EXTENDED && defined(BOOT_TIME)
|
||||
if (!got_bootime) {
|
||||
if (!got_boottime) {
|
||||
setutxent();
|
||||
const struct utmpx id = {.ut_type = BOOT_TIME};
|
||||
const struct utmpx *entry = getutxid(&id);
|
||||
if (entry) {
|
||||
bootid_collect(&bin, entry, sizeof(*entry));
|
||||
got_bootime = true;
|
||||
got_boottime = true;
|
||||
while (unlikely((entry = getutxid(&id)) != nullptr)) {
|
||||
/* have multiple reboot records, assuming we can distinguish next
|
||||
* bootsession even if RTC is wrong or absent */
|
||||
@@ -2024,7 +2032,7 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
|
||||
#endif /* _XOPEN_SOURCE_EXTENDED && BOOT_TIME */
|
||||
|
||||
if (!got_bootseq) {
|
||||
if (!got_bootime || !MDBX_TRUST_RTC)
|
||||
if (!got_boottime || !MDBX_TRUST_RTC)
|
||||
goto lack;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
@@ -38,6 +38,8 @@
|
||||
!defined(MDBX_TOOLS)
|
||||
#define _NO_CRT_STDIO_INLINE
|
||||
#endif
|
||||
#elif !defined(_POSIX_C_SOURCE)
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#endif /* Windows */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@@ -87,13 +89,6 @@
|
||||
#include <sys/vmmeter.h>
|
||||
#else
|
||||
#include <malloc.h>
|
||||
#ifndef _POSIX_C_SOURCE
|
||||
#ifdef _POSIX_SOURCE
|
||||
#define _POSIX_C_SOURCE 1
|
||||
#else
|
||||
#define _POSIX_C_SOURCE 0
|
||||
#endif
|
||||
#endif
|
||||
#endif /* !xBSD */
|
||||
|
||||
#if defined(__FreeBSD__) || __has_include(<malloc_np.h>)
|
||||
|
Reference in New Issue
Block a user