blob: d9e4027c7340452a7822d0623f2cc4b9e4efdfba [file] [log] [blame]
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -07001/*
2 * Copyright 2010, 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#ifndef BCC_MCCACHEREADER_H
18#define BCC_MCCACHEREADER_H
19
20#include "ScriptCached.h"
21
22#include <llvm/ADT/OwningPtr.h>
23
24#include <map>
25#include <string>
26#include <utility>
27
28#include <stddef.h>
29#include <stdint.h>
30
31struct MCO_Header;
32
33namespace bcc {
34 class FileHandle;
35 class Script;
36
37 class MCCacheReader {
38 private:
39 FileHandle *mObjFile, *mInfoFile;
40 off_t mInfoFileSize;
41
42 MCO_Header *mpHeader;
43 OBCC_DependencyTable *mpCachedDependTable;
44 OBCC_PragmaList *mpPragmaList;
45 OBCC_FuncTable *mpFuncTable;
46
Joseph Wenf36637f2011-07-06 18:27:12 -070047 OBCC_String_Ptr *mpVarNameList;
48 OBCC_String_Ptr *mpFuncNameList;
49
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070050 llvm::OwningPtr<ScriptCached> mpResult;
51
52 std::map<std::string,
53 std::pair<uint32_t, unsigned char const *> > mDependencies;
54
55 bool mIsContextSlotNotAvail;
56
57 BCCSymbolLookupFn mpSymbolLookupFn;
58 void *mpSymbolLookupContext;
59
60 public:
61 MCCacheReader()
62 : mObjFile(NULL), mInfoFile(NULL), mInfoFileSize(0), mpHeader(NULL),
Joseph Wen4e199de2011-06-23 17:48:24 -070063 mpCachedDependTable(NULL), mpPragmaList(NULL),
Joseph Wenf36637f2011-07-06 18:27:12 -070064 mpVarNameList(NULL), mpFuncNameList(NULL),
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070065 mIsContextSlotNotAvail(false) {
66 }
67
68 ~MCCacheReader();
69
70 void addDependency(OBCC_ResourceType resType,
71 std::string const &resName,
72 unsigned char const *sha1) {
73 mDependencies.insert(std::make_pair(resName,
74 std::make_pair((uint32_t)resType, sha1)));
75 }
76
77 ScriptCached *readCacheFile(FileHandle *objFile, FileHandle *infoFile, Script *s);
78
79 bool isContextSlotNotAvail() const {
80 return mIsContextSlotNotAvail;
81 }
82
83 void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) {
84 mpSymbolLookupFn = pFn;
85 mpSymbolLookupContext = pContext;
86 }
87
88 private:
89 bool readHeader();
90 bool readStringPool();
91 bool readDependencyTable();
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070092 bool readPragmaList();
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070093 bool readObjectSlotList();
94 bool readObjFile();
95 bool readRelocationTable();
96
Joseph Wenf36637f2011-07-06 18:27:12 -070097 bool readVarNameList();
98 bool readFuncNameList();
99
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -0700100 bool checkFileSize();
101 bool checkHeader();
102 bool checkMachineIntType();
103 bool checkSectionOffsetAndSize();
104 bool checkStringPool();
105 bool checkDependency();
106 bool checkContext();
107
108 bool relocate();
109
110 static void *resolveSymbolAdapter(void *context, char const *name);
111
112 };
113
114} // namespace bcc
115
116#endif // BCC_MCCACHEREADER_H