1 /* 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 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 OBCC_DependencyTable *mpCachedDependTable; 44 OBCC_PragmaList *mpPragmaList; 45 OBCC_FuncTable *mpFuncTable; 46 47 OBCC_String_Ptr *mpVarNameList; 48 OBCC_String_Ptr *mpFuncNameList; 49 50 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), 63 mpCachedDependTable(NULL), mpPragmaList(NULL), 64 mpVarNameList(NULL), mpFuncNameList(NULL), 65 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 bool checkCacheFile(FileHandle *objFile, FileHandle *infoFile, Script *S); 79 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(); 93 bool readPragmaList(); 94 bool readObjectSlotList(); 95 bool readObjFile(); 96 bool readRelocationTable(); 97 98 bool readVarNameList(); 99 bool readFuncNameList(); 100 101 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 118