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
/
DvmDex.h
161 lines (138 loc) · 4.68 KB
/
DvmDex.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* 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.
*/
/*
* The VM wraps some additional data structures around the DexFile. These
* are defined here.
*/
#ifndef DALVIK_DVMDEX_H_
#define DALVIK_DVMDEX_H_
#include "libdex/DexFile.h"
/* extern */
struct ClassObject;
struct HashTable;
struct InstField;
struct Method;
struct StringObject;
/*
* Some additional VM data structures that are associated with the DEX file.
*/
struct DvmDex {
/* pointer to the DexFile we're associated with */
DexFile* pDexFile;
/* clone of pDexFile->pHeader (it's used frequently enough) */
const DexHeader* pHeader;
/* interned strings; parallel to "stringIds" */
struct StringObject** pResStrings;
/* resolved classes; parallel to "typeIds" */
struct ClassObject** pResClasses;
/* resolved methods; parallel to "methodIds" */
struct Method** pResMethods;
/* resolved instance fields; parallel to "fieldIds" */
/* (this holds both InstField and StaticField) */
struct Field** pResFields;
/* interface method lookup cache */
struct AtomicCache* pInterfaceCache;
/* shared memory region with file contents */
bool isMappedReadOnly;
MemMapping memMap;
/* lock ensuring mutual exclusion during updates */
pthread_mutex_t modLock;
};
/*
* Given a file descriptor for an open "optimized" DEX file, map it into
* memory and parse the contents.
*
* On success, returns 0 and sets "*ppDvmDex" to a newly-allocated DvmDex.
* On failure, returns a meaningful error code [currently just -1].
*/
int dvmDexFileOpenFromFd(int fd, DvmDex** ppDvmDex);
/*
* Open a partial DEX file. Only useful as part of the optimization process.
*/
int dvmDexFileOpenPartial(const void* addr, int len, DvmDex** ppDvmDex);
/*
* Free a DvmDex structure, along with any associated structures.
*/
void dvmDexFileFree(DvmDex* pDvmDex);
/*
* Change the 1- or 2-byte value at the specified address to a new value. If
* the location already has the new value, do nothing.
*
* This does not make any synchronization guarantees. The caller must
* ensure exclusivity vs. other callers.
*
* For the 2-byte call, the pointer should have 16-bit alignment.
*
* Returns "true" on success.
*/
bool dvmDexChangeDex1(DvmDex* pDvmDex, u1* addr, u1 newVal);
bool dvmDexChangeDex2(DvmDex* pDvmDex, u2* addr, u2 newVal);
/*
* Return the requested item if it has been resolved, or NULL if it hasn't.
*/
INLINE struct StringObject* dvmDexGetResolvedString(const DvmDex* pDvmDex,
u4 stringIdx)
{
assert(stringIdx < pDvmDex->pHeader->stringIdsSize);
return pDvmDex->pResStrings[stringIdx];
}
INLINE struct ClassObject* dvmDexGetResolvedClass(const DvmDex* pDvmDex,
u4 classIdx)
{
assert(classIdx < pDvmDex->pHeader->typeIdsSize);
return pDvmDex->pResClasses[classIdx];
}
INLINE struct Method* dvmDexGetResolvedMethod(const DvmDex* pDvmDex,
u4 methodIdx)
{
assert(methodIdx < pDvmDex->pHeader->methodIdsSize);
return pDvmDex->pResMethods[methodIdx];
}
INLINE struct Field* dvmDexGetResolvedField(const DvmDex* pDvmDex,
u4 fieldIdx)
{
assert(fieldIdx < pDvmDex->pHeader->fieldIdsSize);
return pDvmDex->pResFields[fieldIdx];
}
/*
* Update the resolved item table. Resolution always produces the same
* result, so we're not worried about atomicity here.
*/
INLINE void dvmDexSetResolvedString(DvmDex* pDvmDex, u4 stringIdx,
struct StringObject* str)
{
assert(stringIdx < pDvmDex->pHeader->stringIdsSize);
pDvmDex->pResStrings[stringIdx] = str;
}
INLINE void dvmDexSetResolvedClass(DvmDex* pDvmDex, u4 classIdx,
struct ClassObject* clazz)
{
assert(classIdx < pDvmDex->pHeader->typeIdsSize);
pDvmDex->pResClasses[classIdx] = clazz;
}
INLINE void dvmDexSetResolvedMethod(DvmDex* pDvmDex, u4 methodIdx,
struct Method* method)
{
assert(methodIdx < pDvmDex->pHeader->methodIdsSize);
pDvmDex->pResMethods[methodIdx] = method;
}
INLINE void dvmDexSetResolvedField(DvmDex* pDvmDex, u4 fieldIdx,
struct Field* field)
{
assert(fieldIdx < pDvmDex->pHeader->fieldIdsSize);
pDvmDex->pResFields[fieldIdx] = field;
}
#endif // DALVIK_DVMDEX_H_