mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-20 05:08:21 +08:00
mdbx: more for compatibility (musl).
One more for https://github.com/ReOpen/ReOpenLDAP/issues/123
This commit is contained in:
parent
4507c1c6bb
commit
bb205df001
2
Makefile
2
Makefile
@ -43,7 +43,7 @@ MANPAGES := mdb_stat.1 mdb_copy.1 mdb_dump.1 mdb_load.1
|
||||
TESTS := mtest0 mtest1 mtest2 mtest3 mtest4 mtest5 mtest6 wbench \
|
||||
yota_test1 yota_test2
|
||||
|
||||
SRC_LMDB := mdb.c midl.c lmdb.h midl.h reopen.h barriers.h
|
||||
SRC_LMDB := mdb.c midl.c lmdb.h midl.h defs.h barriers.h
|
||||
SRC_MDBX := $(SRC_LMDB) mdbx.c mdbx.h
|
||||
|
||||
.PHONY: mdbx lmdb all install clean check tests coverage
|
||||
|
336
defs.h
Normal file
336
defs.h
Normal file
@ -0,0 +1,336 @@
|
||||
/*
|
||||
* Copyright 2015-2017 Leonid Yuriev <leo@yuriev.ru>
|
||||
* and other libmdbx authors: please see AUTHORS file.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted only as authorized by the OpenLDAP
|
||||
* Public License.
|
||||
*
|
||||
* A copy of this license is available in the file LICENSE in the
|
||||
* top-level directory of the distribution or, alternatively, at
|
||||
* <http://www.OpenLDAP.org/license.html>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __GNUC_PREREQ
|
||||
# if defined(__GNUC__) && defined(__GNUC_MINOR__)
|
||||
# define __GNUC_PREREQ(maj, min) \
|
||||
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
|
||||
# else
|
||||
# define __GNUC_PREREQ(maj, min) (0)
|
||||
# endif
|
||||
#endif /* __GNUC_PREREQ */
|
||||
|
||||
#ifndef __CLANG_PREREQ
|
||||
# ifdef __clang__
|
||||
# define __CLANG_PREREQ(maj,min) \
|
||||
((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
|
||||
# else
|
||||
# define __CLANG_PREREQ(maj,min) (0)
|
||||
# endif
|
||||
#endif /* __CLANG_PREREQ */
|
||||
|
||||
#ifndef __GLIBC_PREREQ
|
||||
# if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
|
||||
# define __GLIBC_PREREQ(maj, min) \
|
||||
((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))
|
||||
# else
|
||||
# define __GLIBC_PREREQ(maj, min) (0)
|
||||
# endif
|
||||
#endif /* __GLIBC_PREREQ */
|
||||
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(x) (0)
|
||||
#endif
|
||||
|
||||
#ifndef __has_feature
|
||||
# define __has_feature(x) (0)
|
||||
#endif
|
||||
|
||||
#ifndef __has_extension
|
||||
# define __has_extension(x) (0)
|
||||
#endif
|
||||
|
||||
#ifndef __has_builtin
|
||||
# define __has_builtin(x) (0)
|
||||
#endif
|
||||
|
||||
#if __has_feature(thread_sanitizer)
|
||||
# define __SANITIZE_THREAD__ 1
|
||||
#endif
|
||||
|
||||
#if __has_feature(address_sanitizer)
|
||||
# define __SANITIZE_ADDRESS__ 1
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __extern_C
|
||||
# ifdef __cplusplus
|
||||
# define __extern_C extern "C"
|
||||
# else
|
||||
# define __extern_C
|
||||
# endif
|
||||
#endif /* __extern_C */
|
||||
|
||||
#ifndef __cplusplus
|
||||
# ifndef bool
|
||||
# define bool _Bool
|
||||
# endif
|
||||
# ifndef true
|
||||
# define true (1)
|
||||
# endif
|
||||
# ifndef false
|
||||
# define false (0)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(nullptr) && !defined(__cplusplus) || (__cplusplus < 201103L && !defined(_MSC_VER))
|
||||
# define nullptr NULL
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#if !defined(__thread) && (defined(_MSC_VER) || defined(__DMC__))
|
||||
# define __thread __declspec(thread)
|
||||
#endif /* __thread */
|
||||
|
||||
#ifndef __alwaysinline
|
||||
# if defined(__GNUC__) || __has_attribute(always_inline)
|
||||
# define __alwaysinline __inline __attribute__((always_inline))
|
||||
# elif defined(_MSC_VER)
|
||||
# define __alwaysinline __forceinline
|
||||
# else
|
||||
# define __alwaysinline
|
||||
# endif
|
||||
#endif /* __alwaysinline */
|
||||
|
||||
#ifndef __noinline
|
||||
# if defined(__GNUC__) || __has_attribute(noinline)
|
||||
# define __noinline __attribute__((noinline))
|
||||
# elif defined(_MSC_VER)
|
||||
# define __noinline __declspec(noinline)
|
||||
# elif defined(__SUNPRO_C) || defined(__sun) || defined(sun)
|
||||
# define __noinline inline
|
||||
# elif !defined(__INTEL_COMPILER)
|
||||
# define __noinline /* FIXME ? */
|
||||
# endif
|
||||
#endif /* __noinline */
|
||||
|
||||
#ifndef __must_check_result
|
||||
# if defined(__GNUC__) || __has_attribute(warn_unused_result)
|
||||
# define __must_check_result __attribute__((warn_unused_result))
|
||||
# else
|
||||
# define __must_check_result
|
||||
# endif
|
||||
#endif /* __must_check_result */
|
||||
|
||||
#ifndef __deprecated
|
||||
# if defined(__GNUC__) || __has_attribute(deprecated)
|
||||
# define __deprecated __attribute__((deprecated))
|
||||
# elif defined(_MSC_VER)
|
||||
# define __deprecated __declspec(deprecated)
|
||||
# else
|
||||
# define __deprecated
|
||||
# endif
|
||||
#endif /* __deprecated */
|
||||
|
||||
#ifndef __packed
|
||||
# if defined(__GNUC__) || __has_attribute(packed)
|
||||
# define __packed __attribute__((packed))
|
||||
# else
|
||||
# define __packed
|
||||
# endif
|
||||
#endif /* __packed */
|
||||
|
||||
#ifndef __aligned
|
||||
# if defined(__GNUC__) || __has_attribute(aligned)
|
||||
# define __aligned(N) __attribute__((aligned(N)))
|
||||
# elif defined(_MSC_VER)
|
||||
# define __aligned(N) __declspec(align(N))
|
||||
# else
|
||||
# define __aligned(N)
|
||||
# endif
|
||||
#endif /* __aligned */
|
||||
|
||||
#ifndef __noreturn
|
||||
# if defined(__GNUC__) || __has_attribute(noreturn)
|
||||
# define __noreturn __attribute__((noreturn))
|
||||
# elif defined(_MSC_VER)
|
||||
# define __noreturn __declspec(noreturn)
|
||||
# else
|
||||
# define __noreturn
|
||||
# endif
|
||||
#endif /* __noreturn */
|
||||
|
||||
#ifndef __nothrow
|
||||
# if defined(__GNUC__) || __has_attribute(nothrow)
|
||||
# define __nothrow __attribute__((nothrow))
|
||||
# elif defined(_MSC_VER) && defined(__cplusplus)
|
||||
# define __nothrow __declspec(nothrow)
|
||||
# else
|
||||
# define __nothrow
|
||||
# endif
|
||||
#endif /* __nothrow */
|
||||
|
||||
#ifndef __pure_function
|
||||
/* Many functions have no effects except the return value and their
|
||||
* return value depends only on the parameters and/or global variables.
|
||||
* Such a function can be subject to common subexpression elimination
|
||||
* and loop optimization just as an arithmetic operator would be.
|
||||
* These functions should be declared with the attribute pure. */
|
||||
# if defined(__GNUC__) || __has_attribute(pure)
|
||||
# define __pure_function __attribute__((pure))
|
||||
# else
|
||||
# define __pure_function
|
||||
# endif
|
||||
#endif /* __pure_function */
|
||||
|
||||
#ifndef __const_function
|
||||
/* Many functions do not examine any values except their arguments,
|
||||
* and have no effects except the return value. Basically this is just
|
||||
* slightly more strict class than the PURE attribute, since function
|
||||
* is not allowed to read global memory.
|
||||
*
|
||||
* Note that a function that has pointer arguments and examines the
|
||||
* data pointed to must not be declared const. Likewise, a function
|
||||
* that calls a non-const function usually must not be const.
|
||||
* It does not make sense for a const function to return void. */
|
||||
# if defined(__GNUC__) || __has_attribute(const)
|
||||
# define __const_function __attribute__((const))
|
||||
# else
|
||||
# define __const_function
|
||||
# endif
|
||||
#endif /* __const_function */
|
||||
|
||||
#ifndef __dll_hidden
|
||||
# if defined(__GNUC__) || __has_attribute(visibility)
|
||||
# define __hidden __attribute__((visibility("hidden")))
|
||||
# else
|
||||
# define __hidden
|
||||
# endif
|
||||
#endif /* __dll_hidden */
|
||||
|
||||
#ifndef __optimize
|
||||
# if defined(__OPTIMIZE__)
|
||||
# if defined(__clang__) && !__has_attribute(optimize)
|
||||
# define __optimize(ops)
|
||||
# elif defined(__GNUC__) || __has_attribute(optimize)
|
||||
# define __optimize(ops) __attribute__((optimize(ops)))
|
||||
# else
|
||||
# define __optimize(ops)
|
||||
# endif
|
||||
# else
|
||||
# define __optimize(ops)
|
||||
# endif
|
||||
#endif /* __optimize */
|
||||
|
||||
#ifndef __hot
|
||||
# if defined(__OPTIMIZE__)
|
||||
# if defined(__clang__) && !__has_attribute(hot)
|
||||
/* just put frequently used functions in separate section */
|
||||
# define __hot __attribute__((section("text.hot"))) __optimize("O3")
|
||||
# elif defined(__GNUC__) || __has_attribute(hot)
|
||||
# define __hot __attribute__((hot)) __optimize("O3")
|
||||
# else
|
||||
# define __hot __optimize("O3")
|
||||
# endif
|
||||
# else
|
||||
# define __hot
|
||||
# endif
|
||||
#endif /* __hot */
|
||||
|
||||
#ifndef __cold
|
||||
# if defined(__OPTIMIZE__)
|
||||
# if defined(__clang__) && !__has_attribute(cold)
|
||||
/* just put infrequently used functions in separate section */
|
||||
# define __cold __attribute__((section("text.unlikely"))) __optimize("Os")
|
||||
# elif defined(__GNUC__) || __has_attribute(cold)
|
||||
# define __cold __attribute__((cold)) __optimize("Os")
|
||||
# else
|
||||
# define __cold __optimize("Os")
|
||||
# endif
|
||||
# else
|
||||
# define __cold
|
||||
# endif
|
||||
#endif /* __cold */
|
||||
|
||||
#ifndef __flatten
|
||||
# if defined(__OPTIMIZE__) && (defined(__GNUC__) || __has_attribute(flatten))
|
||||
# define __flatten __attribute__((flatten))
|
||||
# else
|
||||
# define __flatten
|
||||
# endif
|
||||
#endif /* __flatten */
|
||||
|
||||
#ifndef likely
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# define likely(cond) __builtin_expect(!!(cond), 1)
|
||||
# else
|
||||
# define likely(x) (x)
|
||||
# endif
|
||||
#endif /* likely */
|
||||
|
||||
#ifndef unlikely
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# define unlikely(cond) __builtin_expect(!!(cond), 0)
|
||||
# else
|
||||
# define unlikely(x) (x)
|
||||
# endif
|
||||
#endif /* unlikely */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
/* Wrapper around __func__, which is a C99 feature */
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
||||
# define mdbx_func_ __func__
|
||||
#elif (defined(__GNUC__) && __GNUC__ >= 2) || defined(__clang__) || defined(_MSC_VER)
|
||||
# define mdbx_func_ __FUNCTION__
|
||||
#else
|
||||
# define mdbx_func_ "<mdbx_unknown>"
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#if defined(HAVE_VALGRIND) || defined(USE_VALGRIND)
|
||||
/* Get debugging help from Valgrind */
|
||||
# include <valgrind/memcheck.h>
|
||||
# ifndef VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE
|
||||
/* LY: available since Valgrind 3.10 */
|
||||
# define VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
||||
# define VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
||||
# endif
|
||||
#else
|
||||
# define VALGRIND_CREATE_MEMPOOL(h,r,z)
|
||||
# define VALGRIND_DESTROY_MEMPOOL(h)
|
||||
# define VALGRIND_MEMPOOL_TRIM(h,a,s)
|
||||
# define VALGRIND_MEMPOOL_ALLOC(h,a,s)
|
||||
# define VALGRIND_MEMPOOL_FREE(h,a)
|
||||
# define VALGRIND_MEMPOOL_CHANGE(h,a,b,s)
|
||||
# define VALGRIND_MAKE_MEM_NOACCESS(a,s)
|
||||
# define VALGRIND_MAKE_MEM_DEFINED(a,s)
|
||||
# define VALGRIND_MAKE_MEM_UNDEFINED(a,s)
|
||||
# define VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
||||
# define VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
||||
# define VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,s) (0)
|
||||
# define VALGRIND_CHECK_MEM_IS_DEFINED(a,s) (0)
|
||||
#endif /* ! USE_VALGRIND */
|
||||
|
||||
#ifdef __SANITIZE_THREAD__
|
||||
# define ATTRIBUTE_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread, noinline))
|
||||
#else
|
||||
# define ATTRIBUTE_NO_SANITIZE_THREAD
|
||||
#endif
|
||||
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
# include <sanitizer/asan_interface.h>
|
||||
# define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address, noinline))
|
||||
#else
|
||||
# define ASAN_POISON_MEMORY_REGION(addr, size) \
|
||||
((void)(addr), (void)(size))
|
||||
# define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
|
||||
((void)(addr), (void)(size))
|
||||
# define ATTRIBUTE_NO_SANITIZE_ADDRESS
|
||||
#endif /* __SANITIZE_ADDRESS__ */
|
64
mdb.c
64
mdb.c
@ -47,12 +47,15 @@
|
||||
/* LY: Please do not ask us for Windows support, just never!
|
||||
* But you can make a fork for Windows, or become maintainer for FreeBSD... */
|
||||
#ifndef __gnu_linux__
|
||||
# warning "ReOpenMDBX supports only GNU Linux"
|
||||
# warning "This version of ReOpenMDBX supports only GNU Linux"
|
||||
#endif
|
||||
|
||||
#include <features.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include "./lmdb.h"
|
||||
#include "./defs.h"
|
||||
|
||||
#if !defined(__GNUC__) || !__GNUC_PREREQ(4,2)
|
||||
#if !__GNUC_PREREQ(4,2)
|
||||
/* LY: Actualy ReOpenMDBX was not tested with compilers
|
||||
* older than GCC 4.4 (from RHEL6).
|
||||
* But you could remove this #error and try to continue at your own risk.
|
||||
@ -61,7 +64,7 @@
|
||||
# warning "ReOpenMDBX required at least GCC 4.2 compatible C/C++ compiler."
|
||||
#endif
|
||||
|
||||
#if !defined(__GNU_LIBRARY__) || !__GLIBC_PREREQ(2,12)
|
||||
#if !__GLIBC_PREREQ(2,12)
|
||||
/* LY: Actualy ReOpenMDBX was not tested with something
|
||||
* older than glibc 2.12 (from RHEL6).
|
||||
* But you could remove this #error and try to continue at your own risk.
|
||||
@ -74,7 +77,6 @@
|
||||
# undef NDEBUG
|
||||
#endif
|
||||
|
||||
#include "./reopen.h"
|
||||
#include "./barriers.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -88,8 +90,6 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -98,15 +98,40 @@
|
||||
#include <malloc.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#if !(defined(BYTE_ORDER) || defined(__BYTE_ORDER))
|
||||
# include <netinet/in.h>
|
||||
# include <resolv.h> /* defines BYTE_ORDER on HPUX and Solaris */
|
||||
#endif
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef __GLIBC__
|
||||
# include <assert.h>
|
||||
#elif defined(NDEBUG)
|
||||
# define assert(expr) ((void)0)
|
||||
#else
|
||||
# define assert(expr) \
|
||||
do { \
|
||||
if (unlikely(!(expr))) \
|
||||
__assert_fail(#expr, __FILE__, __LINE__, mdbx_func_); \
|
||||
} while(0)
|
||||
#endif /* __GLIBC__ */
|
||||
|
||||
/* Prototype should match libc runtime. ISO POSIX (2003) & LSB 3.1 */
|
||||
__extern_C void __assert_fail(
|
||||
const char* assertion,
|
||||
const char* file,
|
||||
unsigned line,
|
||||
const char* function) __nothrow __noreturn;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _POSIX_SYNCHRONIZED_IO
|
||||
# define fdatasync fsync
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#if !(defined(BYTE_ORDER) || defined(__BYTE_ORDER))
|
||||
# include <netinet/in.h>
|
||||
# include <resolv.h> /* defines BYTE_ORDER on HPUX and Solaris */
|
||||
#endif
|
||||
|
||||
#ifndef BYTE_ORDER
|
||||
# if (defined(_LITTLE_ENDIAN) || defined(_BIG_ENDIAN)) && !(defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN))
|
||||
/* Solaris just defines one or the other */
|
||||
@ -133,7 +158,16 @@
|
||||
# define MISALIGNED_OK 1
|
||||
#endif
|
||||
|
||||
#include "./lmdb.h"
|
||||
#ifndef CACHELINE_SIZE
|
||||
# if defined(__ia64__) || defined(__ia64) || defined(_M_IA64)
|
||||
# define CACHELINE_SIZE 128
|
||||
# else
|
||||
# define CACHELINE_SIZE 64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "./midl.h"
|
||||
|
||||
#if ! MDBX_MODE_ENABLED
|
||||
@ -190,9 +224,9 @@
|
||||
*/
|
||||
#ifndef MDB_USE_ROBUST
|
||||
/* Howard Chu: Android currently lacks Robust Mutex support */
|
||||
# if defined(EOWNERDEAD) && !defined(ANDROID) \
|
||||
# if defined(EOWNERDEAD) \
|
||||
/* LY: glibc before 2.10 has a troubles with Robust Mutex too. */ \
|
||||
&& __GLIBC_PREREQ(2,10)
|
||||
&& ((__GLIBC_PREREQ(2,10) && !defined(ANDROID)) || defined(PTHREAD_MUTEX_ROBUST))
|
||||
# define MDB_USE_ROBUST 1
|
||||
# else
|
||||
# define MDB_USE_ROBUST 0
|
||||
@ -10698,6 +10732,8 @@ mdb_mutex_failed(MDB_env *env, pthread_mutex_t *mutex, int rc)
|
||||
pthread_mutex_unlock(mutex);
|
||||
}
|
||||
}
|
||||
#else
|
||||
(void) mutex;
|
||||
#endif /* MDB_USE_ROBUST */
|
||||
if (unlikely(rc)) {
|
||||
mdb_debug("lock mutex failed, %s", mdb_strerror(rc));
|
||||
|
237
reopen.h
237
reopen.h
@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2017 Leonid Yuriev <leo@yuriev.ru>.
|
||||
* Copyright 2015,2016 Peter-Service R&D LLC.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted only as authorized by the OpenLDAP
|
||||
* Public License.
|
||||
*
|
||||
* A copy of this license is available in the file LICENSE in the
|
||||
* top-level directory of the distribution or, alternatively, at
|
||||
* <http://www.OpenLDAP.org/license.html>.
|
||||
*/
|
||||
|
||||
#ifndef _REOPEN_H
|
||||
#define _REOPEN_H
|
||||
|
||||
#ifndef __CLANG_PREREQ
|
||||
# ifdef __clang__
|
||||
# define __CLANG_PREREQ(maj,min) \
|
||||
((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
|
||||
# else
|
||||
# define __CLANG_PREREQ(maj,min) (0)
|
||||
# endif
|
||||
#endif /* __CLANG_PREREQ */
|
||||
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(x) (0)
|
||||
#endif
|
||||
|
||||
#if !defined(__thread) && (defined(_MSC_VER) || defined(__DMC__))
|
||||
# define __thread __declspec(thread)
|
||||
#endif
|
||||
|
||||
#ifndef __forceinline
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# define __forceinline __inline __attribute__((always_inline))
|
||||
# elif ! defined(_MSC_VER)
|
||||
# define __forceinline
|
||||
# endif
|
||||
#endif /* __forceinline */
|
||||
|
||||
#ifndef __noinline
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# define __noinline __attribute__((noinline))
|
||||
# elif defined(_MSC_VER)
|
||||
# define __noinline __declspec(noinline)
|
||||
# endif
|
||||
#endif /* __noinline */
|
||||
|
||||
#ifndef __must_check_result
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# define __must_check_result __attribute__((warn_unused_result))
|
||||
# else
|
||||
# define __must_check_result
|
||||
# endif
|
||||
#endif /* __must_check_result */
|
||||
|
||||
#ifndef __hot
|
||||
# if defined(__OPTIMIZE__) && (defined(__GNUC__) && !defined(__clang__))
|
||||
# define __hot __attribute__((hot, optimize("O3")))
|
||||
# elif defined(__GNUC__)
|
||||
/* cland case, just put frequently used functions in separate section */
|
||||
# define __hot __attribute__((section("text.hot")))
|
||||
# else
|
||||
# define __hot
|
||||
# endif
|
||||
#endif /* __hot */
|
||||
|
||||
#ifndef __cold
|
||||
# if defined(__OPTIMIZE__) && (defined(__GNUC__) && !defined(__clang__))
|
||||
# define __cold __attribute__((cold, optimize("Os")))
|
||||
# elif defined(__GNUC__)
|
||||
/* cland case, just put infrequently used functions in separate section */
|
||||
# define __cold __attribute__((section("text.unlikely")))
|
||||
# else
|
||||
# define __cold
|
||||
# endif
|
||||
#endif /* __cold */
|
||||
|
||||
#ifndef __flatten
|
||||
# if defined(__OPTIMIZE__) && (defined(__GNUC__) || defined(__clang__))
|
||||
# define __flatten __attribute__((flatten))
|
||||
# else
|
||||
# define __flatten
|
||||
# endif
|
||||
#endif /* __flatten */
|
||||
|
||||
#ifndef __aligned
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# define __aligned(N) __attribute__((aligned(N)))
|
||||
# elif defined(__MSC_VER)
|
||||
# define __aligned(N) __declspec(align(N))
|
||||
# else
|
||||
# define __aligned(N)
|
||||
# endif
|
||||
#endif /* __align */
|
||||
|
||||
#ifndef __noreturn
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# define __noreturn __attribute__((noreturn))
|
||||
# elif defined(__MSC_VER)
|
||||
# define __noreturn __declspec(noreturn)
|
||||
# else
|
||||
# define __noreturn
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __nothrow
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# define __nothrow __attribute__((nothrow))
|
||||
# elif defined(__MSC_VER)
|
||||
# define __nothrow __declspec(nothrow)
|
||||
# else
|
||||
# define __nothrow
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CACHELINE_SIZE
|
||||
# if defined(__ia64__) || defined(__ia64) || defined(_M_IA64)
|
||||
# define CACHELINE_SIZE 128
|
||||
# else
|
||||
# define CACHELINE_SIZE 64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __cache_aligned
|
||||
# define __cache_aligned __aligned(CACHELINE_SIZE)
|
||||
#endif
|
||||
|
||||
#ifndef likely
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# ifdef __cplusplus
|
||||
/* LY: workaround for "pretty" boost */
|
||||
static __inline __attribute__((always_inline))
|
||||
bool likely(bool cond) { return __builtin_expect(cond, 1); }
|
||||
# else
|
||||
# define likely(cond) __builtin_expect(!!(cond), 1)
|
||||
# endif
|
||||
# else
|
||||
# define likely(x) (x)
|
||||
# endif
|
||||
#endif /* likely */
|
||||
|
||||
#ifndef unlikely
|
||||
# if defined(__GNUC__) || defined(__clang__)
|
||||
# ifdef __cplusplus
|
||||
/* LY: workaround for "pretty" boost */
|
||||
static __inline __attribute__((always_inline))
|
||||
bool unlikely(bool cond) { return __builtin_expect(cond, 0); }
|
||||
# else
|
||||
# define unlikely(cond) __builtin_expect(!!(cond), 0)
|
||||
# endif
|
||||
# else
|
||||
# define unlikely(x) (x)
|
||||
# endif
|
||||
#endif /* unlikely */
|
||||
|
||||
#ifndef __extern_C
|
||||
# ifdef __cplusplus
|
||||
# define __extern_C extern "C"
|
||||
# else
|
||||
# define __extern_C
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __noop
|
||||
# define __noop() do {} while (0)
|
||||
#endif
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/* Prototype should match libc runtime. ISO POSIX (2003) & LSB 3.1 */
|
||||
__extern_C void __assert_fail(
|
||||
const char* assertion,
|
||||
const char* file,
|
||||
unsigned line,
|
||||
const char* function) __nothrow __noreturn;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#if defined(HAVE_VALGRIND) || defined(USE_VALGRIND)
|
||||
/* Get debugging help from Valgrind */
|
||||
# include <valgrind/memcheck.h>
|
||||
# ifndef VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE
|
||||
/* LY: available since Valgrind 3.10 */
|
||||
# define VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
||||
# define VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
||||
# endif
|
||||
#else
|
||||
# define VALGRIND_CREATE_MEMPOOL(h,r,z)
|
||||
# define VALGRIND_DESTROY_MEMPOOL(h)
|
||||
# define VALGRIND_MEMPOOL_TRIM(h,a,s)
|
||||
# define VALGRIND_MEMPOOL_ALLOC(h,a,s)
|
||||
# define VALGRIND_MEMPOOL_FREE(h,a)
|
||||
# define VALGRIND_MEMPOOL_CHANGE(h,a,b,s)
|
||||
# define VALGRIND_MAKE_MEM_NOACCESS(a,s)
|
||||
# define VALGRIND_MAKE_MEM_DEFINED(a,s)
|
||||
# define VALGRIND_MAKE_MEM_UNDEFINED(a,s)
|
||||
# define VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
||||
# define VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(a,s)
|
||||
# define VALGRIND_CHECK_MEM_IS_ADDRESSABLE(a,s) (0)
|
||||
# define VALGRIND_CHECK_MEM_IS_DEFINED(a,s) (0)
|
||||
#endif /* ! USE_VALGRIND */
|
||||
|
||||
#if defined(__has_feature)
|
||||
# if __has_feature(thread_sanitizer)
|
||||
# define __SANITIZE_THREAD__ 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __SANITIZE_THREAD__
|
||||
# define ATTRIBUTE_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread, noinline))
|
||||
#else
|
||||
# define ATTRIBUTE_NO_SANITIZE_THREAD
|
||||
#endif
|
||||
|
||||
#if defined(__has_feature)
|
||||
# if __has_feature(address_sanitizer)
|
||||
# define __SANITIZE_ADDRESS__ 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
# include <sanitizer/asan_interface.h>
|
||||
# define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address, noinline))
|
||||
#else
|
||||
# define ASAN_POISON_MEMORY_REGION(addr, size) \
|
||||
((void)(addr), (void)(size))
|
||||
# define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
|
||||
((void)(addr), (void)(size))
|
||||
# define ATTRIBUTE_NO_SANITIZE_ADDRESS
|
||||
#endif /* __SANITIZE_ADDRESS__ */
|
||||
|
||||
#endif /* _REOPEN_H */
|
Loading…
x
Reference in New Issue
Block a user