• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
31 struct MCO_Header;
32 
33 namespace 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     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 
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:
MCCacheReader()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 
addDependency(MCO_ResourceType resType,std::string const & resName,unsigned char const * sha1)71     void addDependency(MCO_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);
79     bool checkCacheFile(FileHandle *objFile, FileHandle *infoFile, Script *S);
80 
isContextSlotNotAvail()81     bool isContextSlotNotAvail() const {
82       return mIsContextSlotNotAvail;
83     }
84 
registerSymbolCallback(BCCSymbolLookupFn pFn,void * pContext)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();
112 
113     static void *resolveSymbolAdapter(void *context, char const *name);
114 
115   };
116 
117 } // namespace bcc
118 
119 #endif // BCC_MCCACHEREADER_H
120