• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /*
18  * Verification-time map of data section items
19  */
20 
21 #ifndef LIBDEX_DEXDATAMAP_H_
22 #define LIBDEX_DEXDATAMAP_H_
23 
24 #include "DexFile.h"
25 
26 struct DexDataMap {
27     u4 count;    /* number of items currently in the map */
28     u4 max;      /* maximum number of items that may be held */
29     u4* offsets; /* array of item offsets */
30     u2* types;   /* corresponding array of item types */
31 };
32 
33 /*
34  * Allocate and initialize a DexDataMap. Returns NULL on failure.
35  */
36 DexDataMap* dexDataMapAlloc(u4 maxCount);
37 
38 /*
39  * Free a DexDataMap.
40  */
41 void dexDataMapFree(DexDataMap* map);
42 
43 /*
44  * Add a new element to the map. The offset must be greater than the
45  * all previously added offsets.
46  */
47 void dexDataMapAdd(DexDataMap* map, u4 offset, u2 type);
48 
49 /*
50  * Get the type associated with the given offset. This returns -1 if
51  * there is no entry for the given offset.
52  */
53 int dexDataMapGet(DexDataMap* map, u4 offset);
54 
55 /*
56  * Verify that there is an entry in the map, mapping the given offset to
57  * the given type. This will return true if such an entry exists and
58  * return false as well as log an error if not.
59  */
60 bool dexDataMapVerify(DexDataMap* map, u4 offset, u2 type);
61 
62 /*
63  * Like dexDataMapVerify(), but also accept a 0 offset as valid.
64  */
dexDataMapVerify0Ok(DexDataMap * map,u4 offset,u2 type)65 DEX_INLINE bool dexDataMapVerify0Ok(DexDataMap* map, u4 offset, u2 type) {
66     if (offset == 0) {
67         return true;
68     }
69 
70     return dexDataMapVerify(map, offset, type);
71 }
72 
73 #endif  // LIBDEX_DEXDATAMAP_H_
74