From: Dmitriy Ivanov Date: Mon, 1 Sep 2014 23:15:52 +0000 (-0700) Subject: Introduce size-based r/w allocators X-Git-Tag: android-x86-7.1-r1~757^2~707^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=0cd83ebb0e9784827d9ec0a8028a710e73a28b2b;p=android-x86%2Fbionic.git Introduce size-based r/w allocators Change-Id: I75165fc392e5380124039e6db49b0f559c8a518e --- diff --git a/linker/linker.cpp b/linker/linker.cpp index 919f8c04a..16730d663 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -627,10 +627,42 @@ done: return nullptr; } +// Each size has it's own allocator. +template +class SizeBasedAllocator { + public: + static void* alloc() { + return allocator_.alloc(); + } + + static void free(void* ptr) { + allocator_.free(ptr); + } + private: + static LinkerBlockAllocator allocator_; +}; + +template +LinkerBlockAllocator SizeBasedAllocator::allocator_(size); + +template +class TypeBasedAllocator { + public: + static T* alloc() { + return reinterpret_cast(SizeBasedAllocator::alloc()); + } + + static void free(T* ptr) { + SizeBasedAllocator::free(ptr); + } +}; + +template +using linked_list_t = LinkedList>>; + +typedef linked_list_t SoinfoLinkedList; -// Another soinfo list allocator to use in dlsym. We don't reuse -// SoinfoListAllocator because it is write-protected most of the time. static LinkerAllocator> g_soinfo_list_allocator_rw; class SoinfoListAllocatorRW { public: @@ -646,8 +678,9 @@ class SoinfoListAllocatorRW { // This is used by dlsym(3). It performs symbol lookup only within the // specified soinfo object and its dependencies in breadth first order. ElfW(Sym)* dlsym_handle_lookup(soinfo* si, soinfo** found, const char* name) { - LinkedList visit_list; - LinkedList visited; + SoinfoLinkedList visit_list; + SoinfoLinkedList visited; + visit_list.push_back(si); soinfo* current_soinfo; while ((current_soinfo = visit_list.pop_front()) != nullptr) {