This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
mirrored from https://android.googlesource.com/platform/dalvik.git
-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathLinearAlloc.h
120 lines (103 loc) · 3.55 KB
/
LinearAlloc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Simple linear memory allocator.
*/
#ifndef _DALVIK_LINEARALLOC
#define _DALVIK_LINEARALLOC
/*
* If this is set, we create additional data structures and make many
* additional mprotect() calls.
*/
#define ENFORCE_READ_ONLY false
/*
* Linear allocation state. We could tuck this into the start of the
* allocated region, but that would prevent us from sharing the rest of
* that first page.
*/
typedef struct LinearAllocHdr {
int curOffset; /* offset where next data goes */
pthread_mutex_t lock; /* controls updates to this struct */
char* mapAddr; /* start of mmap()ed region */
int mapLength; /* length of region */
int firstOffset; /* for chasing through */
short* writeRefCount; /* for ENFORCE_READ_ONLY */
} LinearAllocHdr;
/*
* Create a new alloc region.
*/
LinearAllocHdr* dvmLinearAllocCreate(Object* classLoader);
/*
* Destroy a region.
*/
void dvmLinearAllocDestroy(Object* classLoader);
/*
* Allocate a chunk of memory. The memory will be zeroed out.
*
* For ENFORCE_READ_ONLY, call dvmLinearReadOnly on the result.
*/
void* dvmLinearAlloc(Object* classLoader, size_t size);
/*
* Reallocate a chunk. The original storage is not released, but may be
* erased to aid debugging.
*
* For ENFORCE_READ_ONLY, call dvmLinearReadOnly on the result. Also, the
* caller should probably mark the "mem" argument read-only before calling.
*/
void* dvmLinearRealloc(Object* classLoader, void* mem, size_t newSize);
/* don't call these directly */
void dvmLinearSetReadOnly(Object* classLoader, void* mem);
void dvmLinearSetReadWrite(Object* classLoader, void* mem);
/*
* Mark a chunk of memory from Alloc or Realloc as read-only. This must
* be done after all changes to the block of memory have been made. This
* actually operates on a page granularity.
*/
INLINE void dvmLinearReadOnly(Object* classLoader, void* mem)
{
if (ENFORCE_READ_ONLY && mem != NULL)
dvmLinearSetReadOnly(classLoader, mem);
}
/*
* Make a chunk of memory writable again.
*/
INLINE void dvmLinearReadWrite(Object* classLoader, void* mem)
{
if (ENFORCE_READ_ONLY && mem != NULL)
dvmLinearSetReadWrite(classLoader, mem);
}
/*
* Free a chunk. Does not increase available storage, but the freed area
* may be erased to aid debugging.
*/
void dvmLinearFree(Object* classLoader, void* mem);
/*
* Helper function; allocates new storage and copies "str" into it.
*
* For ENFORCE_READ_ONLY, do *not* call dvmLinearReadOnly on the result.
* This is done automatically.
*/
char* dvmLinearStrdup(Object* classLoader, const char* str);
/*
* Dump the contents of a linear alloc area.
*/
void dvmLinearAllocDump(Object* classLoader);
/*
* Determine if [start, start+length) is contained in the in-use area of
* a single LinearAlloc. The full set of linear allocators is scanned.
*/
bool dvmLinearAllocContains(const void* start, size_t length);
#endif /*_DALVIK_LINEARALLOC*/