Remove page level mprotects

Freeing block mprotects on the page which it turn
may lead to application crash if linker subsequently
tries to modify another block on the page.

Bug: 14895266
Change-Id: I8ff7f5df467d7be184242de652032b3c84e24b76
This commit is contained in:
Dmitriy Ivanov
2014-05-13 18:34:48 -07:00
parent d597d263bc
commit bc23e530c4
3 changed files with 0 additions and 44 deletions

View File

@@ -42,8 +42,6 @@ void LinkerBlockAllocator::init(size_t block_size) {
void* LinkerBlockAllocator::alloc() {
if (free_block_list_ == nullptr) {
create_new_page();
} else {
protect_page(free_block_list_, PROT_READ | PROT_WRITE);
}
FreeBlockInfo* block_info = reinterpret_cast<FreeBlockInfo*>(free_block_list_);
@@ -82,10 +80,8 @@ void LinkerBlockAllocator::free(void* block) {
FreeBlockInfo* block_info = reinterpret_cast<FreeBlockInfo*>(block);
protect_page(block_info, PROT_READ | PROT_WRITE);
block_info->next_block = free_block_list_;
block_info->num_free_blocks = 1;
protect_page(block_info, PROT_READ);
free_block_list_ = block_info;
}
@@ -98,14 +94,6 @@ void LinkerBlockAllocator::protect_all(int prot) {
}
}
void LinkerBlockAllocator::protect_page(void* block, int prot) {
LinkerAllocatorPage* page = find_page(block);
if (page == nullptr || mprotect(page, PAGE_SIZE, prot) == -1) {
abort();
}
}
void LinkerBlockAllocator::create_new_page() {
LinkerAllocatorPage* page = reinterpret_cast<LinkerAllocatorPage*>(mmap(nullptr, PAGE_SIZE,
PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0));