index 60ce1ea4735607ba35f0aab51425221b845ef71d..92220e8c4944651ace82577958e987a3460390d2 100644 (file)
#include <sys/mman.h>
#include <unistd.h>
+#include "private/bionic_prctl.h"
+
struct LinkerAllocatorPage {
LinkerAllocatorPage* next;
uint8_t bytes[PAGE_SIZE-sizeof(LinkerAllocatorPage*)];
size_t num_free_blocks;
};
-LinkerBlockAllocator::LinkerBlockAllocator()
- : block_size_(0),
+LinkerBlockAllocator::LinkerBlockAllocator(size_t block_size)
+ : block_size_(block_size < sizeof(FreeBlockInfo) ? sizeof(FreeBlockInfo) : block_size),
page_list_(nullptr),
free_block_list_(nullptr)
{}
-void LinkerBlockAllocator::init(size_t block_size) {
- block_size_ = block_size < sizeof(FreeBlockInfo) ? sizeof(FreeBlockInfo) : block_size;
-}
-
-
void* LinkerBlockAllocator::alloc() {
if (free_block_list_ == nullptr) {
create_new_page();
free_block_list_ = block_info->next_block;
}
- block_info->next_block = nullptr;
- block_info->num_free_blocks = 0;
+ memset(block_info, 0, block_size_);
return block_info;
}
abort();
}
+ memset(block, 0, block_size_);
+
FreeBlockInfo* block_info = reinterpret_cast<FreeBlockInfo*>(block);
block_info->next_block = free_block_list_;
abort(); // oom
}
+ prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, page, PAGE_SIZE, "linker_alloc");
+
+ memset(page, 0, PAGE_SIZE);
+
FreeBlockInfo* first_block = reinterpret_cast<FreeBlockInfo*>(page->bytes);
first_block->next_block = free_block_list_;
first_block->num_free_blocks = (PAGE_SIZE - sizeof(LinkerAllocatorPage*))/block_size_;
}
LinkerAllocatorPage* page = page_list_;
- const uint8_t* page_ptr = reinterpret_cast<const uint8_t*>(page);
while (page != nullptr) {
+ const uint8_t* page_ptr = reinterpret_cast<const uint8_t*>(page);
if (block >= (page_ptr + sizeof(page->next)) && block < (page_ptr + PAGE_SIZE)) {
return page;
}