mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-03-24 08:09:02 +00:00
TCPServer: fixed ASAN code
This commit is contained in:
parent
0463901db7
commit
2584799415
3 changed files with 18 additions and 4 deletions
|
@ -97,6 +97,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
|
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
|
||||||
|
#define P2POOL_ASAN
|
||||||
#define ASAN_POISON_MEMORY_REGION(addr, size) __asan_poison_memory_region((addr), (size))
|
#define ASAN_POISON_MEMORY_REGION(addr, size) __asan_poison_memory_region((addr), (size))
|
||||||
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) __asan_unpoison_memory_region((addr), (size))
|
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) __asan_unpoison_memory_region((addr), (size))
|
||||||
extern "C" void __asan_poison_memory_region(void const volatile* addr, size_t size);
|
extern "C" void __asan_poison_memory_region(void const volatile* addr, size_t size);
|
||||||
|
|
|
@ -597,8 +597,7 @@ void TCPServer::loop(void* data)
|
||||||
Client* c = server->m_allocateNewClient();
|
Client* c = server->m_allocateNewClient();
|
||||||
|
|
||||||
ASAN_POISON_MEMORY_REGION(wb, sizeof(WriteBuf));
|
ASAN_POISON_MEMORY_REGION(wb, sizeof(WriteBuf));
|
||||||
ASAN_POISON_MEMORY_REGION(c, c->size());
|
c->asan_poison_this();
|
||||||
ASAN_UNPOISON_MEMORY_REGION(&c->m_resetCounter, sizeof(c->m_resetCounter));
|
|
||||||
|
|
||||||
server->m_writeBuffers.emplace(capacity, wb);
|
server->m_writeBuffers.emplace(capacity, wb);
|
||||||
server->m_preallocatedClients.emplace_back(c);
|
server->m_preallocatedClients.emplace_back(c);
|
||||||
|
@ -967,8 +966,7 @@ TCPServer::Client* TCPServer::get_client()
|
||||||
|
|
||||||
void TCPServer::return_client(Client* c)
|
void TCPServer::return_client(Client* c)
|
||||||
{
|
{
|
||||||
ASAN_POISON_MEMORY_REGION(c, c->size());
|
c->asan_poison_this();
|
||||||
ASAN_UNPOISON_MEMORY_REGION(&c->m_resetCounter, sizeof(c->m_resetCounter));
|
|
||||||
m_preallocatedClients.push_back(c);
|
m_preallocatedClients.push_back(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1267,4 +1265,17 @@ void TCPServer::Client::init_addr_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TCPServer::Client::asan_poison_this() const
|
||||||
|
{
|
||||||
|
#ifdef P2POOL_ASAN
|
||||||
|
const uint8_t* begin = reinterpret_cast<const uint8_t*>(this);
|
||||||
|
const uint8_t* counter_begin = reinterpret_cast<const uint8_t*>(&m_resetCounter);
|
||||||
|
const uint8_t* counter_end = counter_begin + sizeof(m_resetCounter);
|
||||||
|
const uint8_t* end = begin + size();
|
||||||
|
|
||||||
|
ASAN_POISON_MEMORY_REGION(begin, counter_begin - begin);
|
||||||
|
ASAN_POISON_MEMORY_REGION(counter_end, end - counter_end);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace p2pool
|
} // namespace p2pool
|
||||||
|
|
|
@ -70,6 +70,8 @@ public:
|
||||||
|
|
||||||
void init_addr_string();
|
void init_addr_string();
|
||||||
|
|
||||||
|
void asan_poison_this() const;
|
||||||
|
|
||||||
char* m_readBuf;
|
char* m_readBuf;
|
||||||
uint32_t m_readBufSize;
|
uint32_t m_readBufSize;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue