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_CACHEREADER_H 18 #define BCC_CACHEREADER_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 OBCC_Header; 32 33 namespace bcc { 34 class FileHandle; 35 class Script; 36 37 class CacheReader { 38 private: 39 FileHandle *mObjFile; 40 FileHandle *mInfoFile; 41 off_t mInfoFileSize; 42 43 OBCC_Header *mpHeader; 44 OBCC_DependencyTable *mpCachedDependTable; 45 OBCC_PragmaList *mpPragmaList; 46 OBCC_FuncTable *mpFuncTable; 47 48 llvm::OwningPtr<ScriptCached> mpResult; 49 50 std::map<std::string, 51 std::pair<uint32_t, unsigned char const *> > mDependencies; 52 53 bool mIsContextSlotNotAvail; 54 55 public: 56 CacheReader() 57 : mObjFile(NULL), mInfoFile(NULL), mInfoFileSize(0), mpHeader(NULL), 58 mpCachedDependTable(NULL), mpPragmaList(NULL), mpFuncTable(NULL), 59 mIsContextSlotNotAvail(false) { 60 } 61 62 ~CacheReader(); 63 64 void addDependency(OBCC_ResourceType resType, 65 std::string const &resName, 66 unsigned char const *sha1) { 67 mDependencies.insert(std::make_pair(resName, 68 std::make_pair((uint32_t)resType, sha1))); 69 } 70 71 ScriptCached *readCacheFile(FileHandle *objFile, 72 FileHandle *infoFile, 73 Script *s); 74 75 bool isContextSlotNotAvail() const { 76 return mIsContextSlotNotAvail; 77 } 78 79 private: 80 bool readHeader(); 81 bool readStringPool(); 82 bool readDependencyTable(); 83 bool readExportVarList(); 84 bool readExportFuncList(); 85 bool readPragmaList(); 86 bool readFuncTable(); 87 bool readObjectSlotList(); 88 bool readContext(); 89 bool readRelocationTable(); 90 91 bool checkFileSize(); 92 bool checkHeader(); 93 bool checkMachineIntType(); 94 bool checkSectionOffsetAndSize(); 95 bool checkStringPool(); 96 bool checkDependency(); 97 bool checkContext(); 98 99 bool relocate(); 100 }; 101 102 } // namespace bcc 103 104 #endif // BCC_CACHEREADER_H 105