mirror of
https://github.com/isar/libmdbx.git
synced 2025-11-02 04:08:57 +08:00
mdbx: avoid 4-byte aligned (i.e. unaligned) access to 64-bit integers.
Historically, the page header provides 4-byte data alignment. Therefore, unfortunately, the meta page data is also aligned on a 4-byte boundary, but contains 64-bit values. This commit eliminates potentially unsafe access (SPARC, MIPS, etc) to these 64-bit values aligned on a 4-byte boundary. Thus, a build with the `-fsanitize=undefined` now passes the tests both with CLANG 11 and GCC 10. Change-Id: Ie441103e53ed96fd40507d8c0be0689e3fee69f5
This commit is contained in:
@@ -307,10 +307,10 @@ typedef struct mdbx_geo_t {
|
||||
typedef struct MDBX_meta {
|
||||
/* Stamp identifying this as an MDBX file.
|
||||
* It must be set to MDBX_MAGIC with MDBX_DATA_VERSION. */
|
||||
uint64_t mm_magic_and_version;
|
||||
uint32_t mm_magic_and_version[2];
|
||||
|
||||
/* txnid that committed this page, the first of a two-phase-update pair */
|
||||
mdbx_safe64_t mm_txnid_a;
|
||||
uint32_t mm_txnid_a[2];
|
||||
|
||||
uint16_t mm_extra_flags; /* extra DB flags, zero (nothing) for now */
|
||||
uint8_t mm_validator_id; /* ID of checksum and page validation method,
|
||||
@@ -330,17 +330,18 @@ typedef struct MDBX_meta {
|
||||
#define MDBX_DATASIGN_NONE 0u
|
||||
#define MDBX_DATASIGN_WEAK 1u
|
||||
#define SIGN_IS_STEADY(sign) ((sign) > MDBX_DATASIGN_WEAK)
|
||||
#define META_IS_STEADY(meta) SIGN_IS_STEADY((meta)->mm_datasync_sign)
|
||||
volatile uint64_t mm_datasync_sign;
|
||||
#define META_IS_STEADY(meta) \
|
||||
SIGN_IS_STEADY(unaligned_peek_u64(4, (meta)->mm_datasync_sign))
|
||||
uint32_t mm_datasync_sign[2];
|
||||
|
||||
/* txnid that committed this page, the second of a two-phase-update pair */
|
||||
mdbx_safe64_t mm_txnid_b;
|
||||
uint32_t mm_txnid_b[2];
|
||||
|
||||
/* Number of non-meta pages which were put in GC after COW. May be 0 in case
|
||||
* DB was previously handled by libmdbx without corresponding feature.
|
||||
* This value in couple with mr_snapshot_pages_retired allows fast estimation
|
||||
* of "how much reader is restraining GC recycling". */
|
||||
uint64_t mm_pages_retired;
|
||||
uint32_t mm_pages_retired[2];
|
||||
|
||||
/* The analogue /proc/sys/kernel/random/boot_id or similar to determine
|
||||
* whether the system was rebooted after the last use of the database files.
|
||||
|
||||
Reference in New Issue
Block a user