From e2c17d2595346d1e6f7324d84fa61d99c8be6370 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 18 Aug 2018 18:20:38 -0700 Subject: [PATCH] ircd::db: Add some arbitrary sanity checks on port structures. --- ircd/db.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ircd/db.cc b/ircd/db.cc index eabe4d0e9..a39f4ec32 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -3190,6 +3190,13 @@ noexcept // Mutex // +static_assert +( + sizeof(rocksdb::port::Mutex) <= sizeof(pthread_mutex_t) + 1, + "link-time punning of our structure won't work if the structure is larger " + "than the one rocksdb has assumed space for." +); + rocksdb::port::Mutex::Mutex() { #ifdef RB_DEBUG_DB_PORT_ @@ -3267,6 +3274,13 @@ rocksdb::port::Mutex::AssertHeld() // RWMutex // +static_assert +( + sizeof(rocksdb::port::RWMutex) <= sizeof(pthread_rwlock_t), + "link-time punning of our structure won't work if the structure is larger " + "than the one rocksdb has assumed space for." +); + rocksdb::port::RWMutex::RWMutex() { #ifdef RB_DEBUG_DB_PORT_ @@ -3347,6 +3361,13 @@ rocksdb::port::RWMutex::WriteUnlock() // CondVar // +static_assert +( + sizeof(rocksdb::port::CondVar) <= sizeof(pthread_cond_t) + sizeof(void *), + "link-time punning of our structure won't work if the structure is larger " + "than the one rocksdb has assumed space for." +); + rocksdb::port::CondVar::CondVar(Mutex *mu) :mu{mu} {