ircd::db::port: Improve punned object size matching; in-bounds initialization.

This commit is contained in:
Jason Volk 2023-03-05 17:49:15 -08:00
parent 198049615b
commit d5c2ff0e99
2 changed files with 37 additions and 6 deletions

View File

@ -24,7 +24,13 @@ static_assert
rocksdb::port::Mutex::Mutex()
noexcept
{
memset(this, 0x0, sizeof(pthread_mutex_t));
static_assert
(
sizeof(mu_) >= sizeof(mu),
"Mutex is not fully initialized."
);
memset(&mu_, 0x0, sizeof(mu_));
if constexpr(RB_DEBUG_DB_PORT > 1)
{
@ -125,7 +131,13 @@ static_assert
rocksdb::port::RWMutex::RWMutex()
noexcept
{
memset(this, 0x0, sizeof(pthread_rwlock_t));
static_assert
(
sizeof(mu_) >= sizeof(mu),
"RWMutex is not fully initialized."
);
memset(&mu_, 0x0, sizeof(mu_));
if constexpr(RB_DEBUG_DB_PORT > 1)
{
@ -252,7 +264,13 @@ static_assert
rocksdb::port::CondVar::CondVar(Mutex *mu)
noexcept
{
memset(this, 0x0, sizeof(pthread_cond_t) + sizeof(Mutex *));
static_assert
(
sizeof(cv_) >= sizeof(cv),
"CondVar is not fully initialized."
);
memset(&cv_, 0x0, sizeof(cv_));
this->mu = mu;
if constexpr(RB_DEBUG_DB_PORT > 1)

View File

@ -41,7 +41,11 @@ class rocksdb::port::Mutex
{
friend class CondVar;
ctx::mutex mu;
union
{
ctx::mutex mu;
pthread_mutex_t mu_;
};
public:
void Lock() noexcept;
@ -57,8 +61,13 @@ class rocksdb::port::Mutex
class rocksdb::port::CondVar
{
union
{
ctx::condition_variable cv;
pthread_cond_t cv_;
};
Mutex *mu;
ctx::condition_variable cv;
public:
void Wait() noexcept;
@ -72,7 +81,11 @@ class rocksdb::port::CondVar
class rocksdb::port::RWMutex
{
ctx::shared_mutex mu;
union
{
ctx::shared_mutex mu;
pthread_rwlock_t mu_;
};
public:
void ReadLock() noexcept;