blob: 7fcbe4167eabcc4168e62b25aff9c5fdb9210fba [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);
Joseph Wen34c600a2011-07-25 17:59:17 -070078 bool checkCacheFile(FileHandle *objFile, FileHandle *infoFile, Script *S);
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070079
80 bool isContextSlotNotAvail() const {
81 return mIsContextSlotNotAvail;
82 }
83
84 void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) {
85 mpSymbolLookupFn = pFn;
86 mpSymbolLookupContext = pContext;
87 }
88
89 private:
90 bool readHeader();
91 bool readStringPool();
92 bool readDependencyTable();
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070093 bool readPragmaList();
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -070094 bool readObjectSlotList();
95 bool readObjFile();
96 bool readRelocationTable();
97
Joseph Wenf36637f2011-07-06 18:27:12 -070098 bool readVarNameList();
99 bool readFuncNameList();
100
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -0700101 bool checkFileSize();
102 bool checkHeader();
103 bool checkMachineIntType();
104 bool checkSectionOffsetAndSize();
105 bool checkStringPool();
106 bool checkDependency();
107 bool checkContext();
108
109 bool relocate();
110
111 static void *resolveSymbolAdapter(void *context, char const *name);
112
113 };
114
115} // namespace bcc
116
117#endif // BCC_MCCACHEREADER_H