mirror of
https://github.com/monero-project/monero.git
synced 2024-11-18 00:37:43 +00:00
ARMv7: fix unaligned accesses
And cleanup some key comparators
This commit is contained in:
parent
5a07cefe7b
commit
7db89ed2ee
1 changed files with 15 additions and 20 deletions
|
@ -38,6 +38,10 @@
|
|||
#include "crypto/crypto.h"
|
||||
#include "profile_tools.h"
|
||||
|
||||
#if defined(__i386) || defined(__x86_64)
|
||||
#define MISALIGNED_OK 1
|
||||
#endif
|
||||
|
||||
using epee::string_tools::pod_to_hex;
|
||||
|
||||
// Increase when the DB changes in a non backward compatible way, and there
|
||||
|
@ -143,22 +147,11 @@ private:
|
|||
std::unique_ptr<char[]> data;
|
||||
};
|
||||
|
||||
auto compare_uint64 = [](const MDB_val *a, const MDB_val *b)
|
||||
{
|
||||
const uint64_t va = *(const uint64_t*)a->mv_data;
|
||||
const uint64_t vb = *(const uint64_t*)b->mv_data;
|
||||
if (va < vb) return -1;
|
||||
else if (va == vb) return 0;
|
||||
else return 1;
|
||||
};
|
||||
|
||||
auto compare_uint8 = [](const MDB_val *a, const MDB_val *b)
|
||||
int compare_uint8(const MDB_val *a, const MDB_val *b)
|
||||
{
|
||||
const uint8_t va = *(const uint8_t*)a->mv_data;
|
||||
const uint8_t vb = *(const uint8_t*)b->mv_data;
|
||||
if (va < vb) return -1;
|
||||
else if (va == vb) return 0;
|
||||
else return 1;
|
||||
return va - vb;
|
||||
};
|
||||
|
||||
int compare_hash32(const MDB_val *a, const MDB_val *b)
|
||||
|
@ -1099,29 +1092,26 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
|
|||
lmdb_db_open(txn, LMDB_TXS, MDB_CREATE, m_txs, "Failed to open db handle for m_txs");
|
||||
lmdb_db_open(txn, LMDB_TX_UNLOCKS, MDB_CREATE, m_tx_unlocks, "Failed to open db handle for m_tx_unlocks");
|
||||
lmdb_db_open(txn, LMDB_TX_HEIGHTS, MDB_CREATE, m_tx_heights, "Failed to open db handle for m_tx_heights");
|
||||
lmdb_db_open(txn, LMDB_TX_OUTPUTS, MDB_DUPSORT | MDB_CREATE, m_tx_outputs, "Failed to open db handle for m_tx_outputs");
|
||||
lmdb_db_open(txn, LMDB_TX_OUTPUTS, MDB_DUPSORT | MDB_INTEGERDUP | MDB_CREATE, m_tx_outputs, "Failed to open db handle for m_tx_outputs");
|
||||
|
||||
lmdb_db_open(txn, LMDB_OUTPUT_TXS, MDB_INTEGERKEY | MDB_CREATE, m_output_txs, "Failed to open db handle for m_output_txs");
|
||||
lmdb_db_open(txn, LMDB_OUTPUT_INDICES, MDB_INTEGERKEY | MDB_CREATE, m_output_indices, "Failed to open db handle for m_output_indices");
|
||||
lmdb_db_open(txn, LMDB_OUTPUT_AMOUNTS, MDB_INTEGERKEY | MDB_DUPSORT | MDB_DUPFIXED | MDB_CREATE, m_output_amounts, "Failed to open db handle for m_output_amounts");
|
||||
lmdb_db_open(txn, LMDB_OUTPUT_AMOUNTS, MDB_INTEGERKEY | MDB_INTEGERDUP| MDB_DUPSORT | MDB_DUPFIXED | MDB_CREATE, m_output_amounts, "Failed to open db handle for m_output_amounts");
|
||||
lmdb_db_open(txn, LMDB_OUTPUT_KEYS, MDB_INTEGERKEY | MDB_CREATE, m_output_keys, "Failed to open db handle for m_output_keys");
|
||||
|
||||
lmdb_db_open(txn, LMDB_SPENT_KEYS, MDB_CREATE, m_spent_keys, "Failed to open db handle for m_spent_keys");
|
||||
|
||||
lmdb_db_open(txn, LMDB_HF_STARTING_HEIGHTS, MDB_CREATE, m_hf_starting_heights, "Failed to open db handle for m_hf_starting_heights");
|
||||
lmdb_db_open(txn, LMDB_HF_VERSIONS, MDB_CREATE, m_hf_versions, "Failed to open db handle for m_hf_versions");
|
||||
lmdb_db_open(txn, LMDB_HF_VERSIONS, MDB_INTEGERKEY| MDB_CREATE, m_hf_versions, "Failed to open db handle for m_hf_versions");
|
||||
|
||||
lmdb_db_open(txn, LMDB_PROPERTIES, MDB_CREATE, m_properties, "Failed to open db handle for m_properties");
|
||||
|
||||
mdb_set_dupsort(txn, m_output_amounts, compare_uint64);
|
||||
mdb_set_dupsort(txn, m_tx_outputs, compare_uint64);
|
||||
mdb_set_compare(txn, m_spent_keys, compare_hash32);
|
||||
mdb_set_compare(txn, m_block_heights, compare_hash32);
|
||||
mdb_set_compare(txn, m_txs, compare_hash32);
|
||||
mdb_set_compare(txn, m_tx_unlocks, compare_hash32);
|
||||
mdb_set_compare(txn, m_tx_heights, compare_hash32);
|
||||
mdb_set_compare(txn, m_hf_starting_heights, compare_uint8);
|
||||
mdb_set_compare(txn, m_hf_versions, compare_uint64);
|
||||
mdb_set_compare(txn, m_properties, compare_string);
|
||||
|
||||
// get and keep current height
|
||||
|
@ -2789,7 +2779,12 @@ uint64_t BlockchainLMDB::get_hard_fork_starting_height(uint8_t version) const
|
|||
if (result)
|
||||
throw0(DB_ERROR("Error attempting to retrieve a hard fork starting height from the db"));
|
||||
|
||||
uint64_t ret = *(const uint64_t*)val_ret.mv_data;
|
||||
uint64_t ret;
|
||||
#ifdef MISALIGNED_OK
|
||||
ret = *(const uint64_t*)val_ret.mv_data;
|
||||
#else
|
||||
memcpy(&ret, val_ret.mv_data, sizeof(uint64_t));
|
||||
#endif
|
||||
TXN_POSTFIX_RDONLY();
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue