summaryrefslogtreecommitdiff
path: root/linker/linker_block_allocator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linker/linker_block_allocator.cpp')
-rw-r--r--linker/linker_block_allocator.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/linker/linker_block_allocator.cpp b/linker/linker_block_allocator.cpp
index d72cad3d6..fdb4c8563 100644
--- a/linker/linker_block_allocator.cpp
+++ b/linker/linker_block_allocator.cpp
@@ -55,7 +55,8 @@ LinkerBlockAllocator::LinkerBlockAllocator(size_t block_size)
: block_size_(
round_up(block_size < sizeof(FreeBlockInfo) ? sizeof(FreeBlockInfo) : block_size, 16)),
page_list_(nullptr),
- free_block_list_(nullptr)
+ free_block_list_(nullptr),
+ allocated_(0)
{}
void* LinkerBlockAllocator::alloc() {
@@ -76,6 +77,8 @@ void* LinkerBlockAllocator::alloc() {
memset(block_info, 0, block_size_);
+ ++allocated_;
+
return block_info;
}
@@ -104,6 +107,8 @@ void LinkerBlockAllocator::free(void* block) {
block_info->num_free_blocks = 1;
free_block_list_ = block_info;
+
+ --allocated_;
}
void LinkerBlockAllocator::protect_all(int prot) {
@@ -154,3 +159,18 @@ LinkerBlockAllocatorPage* LinkerBlockAllocator::find_page(void* block) {
abort();
}
+
+void LinkerBlockAllocator::purge() {
+ if (allocated_) {
+ return;
+ }
+
+ LinkerBlockAllocatorPage* page = page_list_;
+ while (page) {
+ LinkerBlockAllocatorPage* next = page->next;
+ munmap(page, kAllocateSize);
+ page = next;
+ }
+ page_list_ = nullptr;
+ free_block_list_ = nullptr;
+}