blob: 1e59111e2ec805ad0a872539d349ee1f6a710917 [file] [log] [blame]
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -07001/*
Stephen Hinescc366e52012-02-21 17:22:04 -08002 * Copyright 2010-2012, The Android Open Source Project
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -07003 *
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;
Stephen Hinescc366e52012-02-21 17:22:04 -080049 OBCC_String_Ptr *mpForEachNameList;
Joseph Wenf36637f2011-07-06 18:27:12 -070050
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070051 llvm::OwningPtr<ScriptCached> mpResult;
52
53 std::map<std::string,
54 std::pair<uint32_t, unsigned char const *> > mDependencies;
55
56 bool mIsContextSlotNotAvail;
57
58 BCCSymbolLookupFn mpSymbolLookupFn;
59 void *mpSymbolLookupContext;
60
61 public:
62 MCCacheReader()
63 : mObjFile(NULL), mInfoFile(NULL), mInfoFileSize(0), mpHeader(NULL),
Joseph Wen4e199de2011-06-23 17:48:24 -070064 mpCachedDependTable(NULL), mpPragmaList(NULL),
Stephen Hinescc366e52012-02-21 17:22:04 -080065 mpVarNameList(NULL), mpFuncNameList(NULL), mpForEachNameList(NULL),
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070066 mIsContextSlotNotAvail(false) {
67 }
68
69 ~MCCacheReader();
70
71 void addDependency(OBCC_ResourceType resType,
72 std::string const &resName,
73 unsigned char const *sha1) {
74 mDependencies.insert(std::make_pair(resName,
75 std::make_pair((uint32_t)resType, sha1)));
76 }
77
78 ScriptCached *readCacheFile(FileHandle *objFile, FileHandle *infoFile, Script *s);
Joseph Wen34c600a2011-07-25 17:59:17 -070079 bool checkCacheFile(FileHandle *objFile, FileHandle *infoFile, Script *S);
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070080
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();
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070094 bool readPragmaList();
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070095 bool readObjectSlotList();
96 bool readObjFile();
97 bool readRelocationTable();
98
Joseph Wenf36637f2011-07-06 18:27:12 -070099 bool readVarNameList();
100 bool readFuncNameList();
Stephen Hinescc366e52012-02-21 17:22:04 -0800101 bool readForEachNameList();
Joseph Wenf36637f2011-07-06 18:27:12 -0700102
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -0700103 bool checkFileSize();
104 bool checkHeader();
105 bool checkMachineIntType();
106 bool checkSectionOffsetAndSize();
107 bool checkStringPool();
108 bool checkDependency();
109 bool checkContext();
110
111 bool relocate();
112
113 static void *resolveSymbolAdapter(void *context, char const *name);
114
115 };
116
117} // namespace bcc
118
119#endif // BCC_MCCACHEREADER_H