General purpose memory allocator for linker.

Add basic general purpose memory allocator to
 linker in order to enable usage of other libraries
 like libziparchive.

Change-Id: I4a680ebb36ed5ba67c61249f81dba9f567808434
This commit is contained in:
Dmitriy Ivanov
2015-03-10 17:48:27 -07:00
parent 11a06c73f6
commit 19656ce537
8 changed files with 745 additions and 20 deletions

View File

@@ -14,8 +14,8 @@
* limitations under the License.
*/
#ifndef __LINKER_ALLOCATOR_H
#define __LINKER_ALLOCATOR_H
#ifndef __LINKER_BLOCK_ALLOCATOR_H
#define __LINKER_BLOCK_ALLOCATOR_H
#include <stdlib.h>
#include <limits.h>
@@ -24,11 +24,11 @@
struct LinkerBlockAllocatorPage;
/*
* This class is a non-template version of the LinkerAllocator
* This class is a non-template version of the LinkerTypeAllocator
* It keeps code inside .cpp file by keeping the interface
* template-free.
*
* Please use LinkerAllocator<type> where possible (everywhere).
* Please use LinkerTypeAllocator<type> where possible (everywhere).
*/
class LinkerBlockAllocator {
public:
@@ -50,11 +50,21 @@ class LinkerBlockAllocator {
};
/*
* We can't use malloc(3) in the dynamic linker.
*
* A simple allocator for the dynamic linker. An allocator allocates instances
* of a single fixed-size type. Allocations are backed by page-sized private
* anonymous mmaps.
*
* The differences between this allocator and LinkerMemoryAllocator are:
* 1. This allocator manages space more efficiently. LinkerMemoryAllocator
* operates in power-of-two sized blocks up to 1k, when this implementation
* splits the page to aligned size of structure; For example for structures
* with size 513 this allocator will use 516 (520 for lp64) bytes of data
* where generalized implementation is going to use 1024 sized blocks.
*
* 2. This allocator does not munmap allocated memory, where LinkerMemoryAllocator does.
*
* 3. This allocator provides mprotect services to the user, where LinkerMemoryAllocator
* always treats it's memory as READ|WRITE.
*/
template<typename T>
class LinkerTypeAllocator {
@@ -68,4 +78,4 @@ class LinkerTypeAllocator {
DISALLOW_COPY_AND_ASSIGN(LinkerTypeAllocator);
};
#endif // __LINKER_ALLOCATOR_H
#endif // __LINKER_BLOCK_ALLOCATOR_H