Add ASAN poisoning to the arena
This commit is contained in:
parent
2f59b0ba12
commit
426d3d7029
2 changed files with 16 additions and 4 deletions
|
@ -1,6 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <sanitizer/asan_interface.h>
|
||||
|
||||
#include <concepts>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#include "error.hpp"
|
||||
|
@ -81,15 +84,24 @@ class GcRootList {
|
|||
class ArenaHeap {
|
||||
public:
|
||||
ArenaHeap(uint8_t* buf, uint64_t bufsize)
|
||||
: buf(buf), bufsize(bufsize), boundary(0) {}
|
||||
: buf(buf), bufsize(bufsize), boundary(0) {
|
||||
memset(buf, 0, bufsize);
|
||||
ASAN_POISON_MEMORY_REGION(buf, bufsize);
|
||||
}
|
||||
|
||||
Result<void*> alloc(uint64_t size) {
|
||||
// Always align to 64 bits
|
||||
if (size % 8 != 0) size += 8 - size % 8;
|
||||
|
||||
if (boundary + size >= bufsize) return ErrorCode::OutOfMemory;
|
||||
// padding for guard value
|
||||
uint64_t boundary_size = 8;
|
||||
|
||||
if (boundary + size + boundary_size >= bufsize)
|
||||
return ErrorCode::OutOfMemory;
|
||||
void* res = buf + boundary;
|
||||
boundary += size;
|
||||
ASAN_UNPOISON_MEMORY_REGION(res, size);
|
||||
boundary += boundary_size;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -139,7 +151,7 @@ class StaticArenaHeap : public ArenaHeap {
|
|||
|
||||
private:
|
||||
static const uint64_t heapsize = size - sizeof(ArenaHeap);
|
||||
uint8_t _buf[heapsize]{0};
|
||||
uint8_t _buf[heapsize];
|
||||
};
|
||||
|
||||
template <uint64_t size>
|
||||
|
|
|
@ -30,7 +30,7 @@ int main() {
|
|||
std::cout << "root count: " << arena.root_count() << "\n";
|
||||
*/
|
||||
|
||||
auto s = DIEIF(String::create(arena, "(1 2 3 \"foo\")"));
|
||||
auto s = DIEIF(String::create(arena, "(1 2 3 \"foo\" (xyz))"));
|
||||
auto reader = Reader(arena, s);
|
||||
|
||||
auto r = DIEIF(reader.read_one());
|
||||
|
|
Loading…
Reference in a new issue