]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-bionic.git/blobdiff - linker/linker_allocator.cpp
Support gethostbyname_r_ERANGE.
[android-sdk/platform-bionic.git] / linker / linker_allocator.cpp
index 60ce1ea4735607ba35f0aab51425221b845ef71d..92220e8c4944651ace82577958e987a3460390d2 100644 (file)
@@ -18,6 +18,8 @@
 #include <sys/mman.h>
 #include <unistd.h>
 
+#include "private/bionic_prctl.h"
+
 struct LinkerAllocatorPage {
   LinkerAllocatorPage* next;
   uint8_t bytes[PAGE_SIZE-sizeof(LinkerAllocatorPage*)];
@@ -28,17 +30,12 @@ struct FreeBlockInfo {
   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();
@@ -55,8 +52,7 @@ void* LinkerBlockAllocator::alloc() {
     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;
 }
@@ -78,6 +74,8 @@ void LinkerBlockAllocator::free(void* block) {
     abort();
   }
 
+  memset(block, 0, block_size_);
+
   FreeBlockInfo* block_info = reinterpret_cast<FreeBlockInfo*>(block);
 
   block_info->next_block = free_block_list_;
@@ -101,6 +99,10 @@ void LinkerBlockAllocator::create_new_page() {
     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_;
@@ -117,8 +119,8 @@ LinkerAllocatorPage* LinkerBlockAllocator::find_page(void* block) {
   }
 
   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;
     }