blob: 7e43dc9344055fbe230a5e6302c53eae4d4dfda6 [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
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
Carl Shapiro375fb112011-06-14 20:31:24 -070021#ifndef LIBDEX_DEXDATAMAP_H_
22#define LIBDEX_DEXDATAMAP_H_
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080023
24#include "DexFile.h"
25
Carl Shapirobfc97992011-04-27 14:16:08 -070026struct DexDataMap {
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080027 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 */
Carl Shapirobfc97992011-04-27 14:16:08 -070031};
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080032
33/*
34 * Allocate and initialize a DexDataMap. Returns NULL on failure.
35 */
36DexDataMap* dexDataMapAlloc(u4 maxCount);
37
38/*
39 * Free a DexDataMap.
40 */
41void 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 */
47void 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 */
53int 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 */
60bool dexDataMapVerify(DexDataMap* map, u4 offset, u2 type);
61
62/*
63 * Like dexDataMapVerify(), but also accept a 0 offset as valid.
64 */
65DEX_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
Carl Shapiro375fb112011-06-14 20:31:24 -070073#endif // LIBDEX_DEXDATAMAP_H_