blob: 972f0c835c0645d15c68c8e495fdebca509eed8e [file] [log] [blame]
Stephen Hines4a68b1c2012-05-03 12:28:14 -07001/*
2 * Copyright 2010-2012, 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 Script;
35 class InputFile;
36
37 class MCCacheReader {
38 private:
39 InputFile *mObjFile, *mInfoFile;
40 off_t mInfoFileSize;
41
42 MCO_Header *mpHeader;
43 MCO_DependencyTable *mpCachedDependTable;
44 MCO_PragmaList *mpPragmaList;
45 MCO_FuncTable *mpFuncTable;
46
47 MCO_String_Ptr *mpVarNameList;
48 MCO_String_Ptr *mpFuncNameList;
49 MCO_String_Ptr *mpForEachNameList;
50
51 llvm::OwningPtr<ScriptCached> mpResult;
52
Stephen Hines0f6b1d32012-05-03 12:29:33 -070053 std::map<std::string,
54 std::pair<uint32_t, unsigned char const *> > mDependencies;
Stephen Hines4a68b1c2012-05-03 12:28:14 -070055
56 bool mIsContextSlotNotAvail;
57
58 BCCSymbolLookupFn mpSymbolLookupFn;
59 void *mpSymbolLookupContext;
60
61 public:
62 MCCacheReader()
63 : mObjFile(NULL), mInfoFile(NULL), mInfoFileSize(0), mpHeader(NULL),
64 mpCachedDependTable(NULL), mpPragmaList(NULL),
65 mpVarNameList(NULL), mpFuncNameList(NULL), mpForEachNameList(NULL),
66 mIsContextSlotNotAvail(false) {
67 }
68
69 ~MCCacheReader();
70
Stephen Hines0f6b1d32012-05-03 12:29:33 -070071 void addDependency(MCO_ResourceType resType,
72 std::string const &resName,
Stephen Hines4a68b1c2012-05-03 12:28:14 -070073 unsigned char const *sha1) {
Stephen Hines0f6b1d32012-05-03 12:29:33 -070074 mDependencies.insert(std::make_pair(resName,
75 std::make_pair((uint32_t)resType, sha1)));
Stephen Hines4a68b1c2012-05-03 12:28:14 -070076 }
77
78 ScriptCached *readCacheFile(InputFile &objFile, InputFile &infoFile, Script *s);
79 bool checkCacheFile(InputFile &objFile, InputFile &infoFile, Script *S);
80
81 bool isContextSlotNotAvail() const {
82 return mIsContextSlotNotAvail;
83 }
84
85 void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) {
86 mpSymbolLookupFn = pFn;
87 mpSymbolLookupContext = pContext;
88 }
89
90 private:
91 bool readHeader();
92 bool readStringPool();
93 bool readDependencyTable();
94 bool readPragmaList();
95 bool readObjectSlotList();
96 bool readObjFile();
97 bool readRelocationTable();
98
99 bool readVarNameList();
100 bool readFuncNameList();
101 bool readForEachNameList();
102
103 bool checkFileSize();
104 bool checkHeader();
105 bool checkMachineIntType();
106 bool checkSectionOffsetAndSize();
107 bool checkStringPool();
108 bool checkDependency();
109 bool checkContext();
110
111 bool relocate();
Stephen Hines5fb14742012-05-03 12:29:50 -0700112
113 static void *resolveSymbolAdapter(void *context, char const *name);
114
Stephen Hines4a68b1c2012-05-03 12:28:14 -0700115 };
116
117} // namespace bcc
118
119#endif // BCC_MCCACHEREADER_H