Shih-wei Liao | 5e3e0ce | 2011-06-17 13:59:46 -0700 | [diff] [blame^] | 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 | llvm::OwningPtr<ScriptCached> mpResult; |
| 48 | |
| 49 | std::map<std::string, |
| 50 | std::pair<uint32_t, unsigned char const *> > mDependencies; |
| 51 | |
| 52 | bool mIsContextSlotNotAvail; |
| 53 | |
| 54 | BCCSymbolLookupFn mpSymbolLookupFn; |
| 55 | void *mpSymbolLookupContext; |
| 56 | |
| 57 | public: |
| 58 | MCCacheReader() |
| 59 | : mObjFile(NULL), mInfoFile(NULL), mInfoFileSize(0), mpHeader(NULL), |
| 60 | mpCachedDependTable(NULL), mpPragmaList(NULL), mpFuncTable(NULL), |
| 61 | mIsContextSlotNotAvail(false) { |
| 62 | } |
| 63 | |
| 64 | ~MCCacheReader(); |
| 65 | |
| 66 | void addDependency(OBCC_ResourceType resType, |
| 67 | std::string const &resName, |
| 68 | unsigned char const *sha1) { |
| 69 | mDependencies.insert(std::make_pair(resName, |
| 70 | std::make_pair((uint32_t)resType, sha1))); |
| 71 | } |
| 72 | |
| 73 | ScriptCached *readCacheFile(FileHandle *objFile, FileHandle *infoFile, Script *s); |
| 74 | |
| 75 | bool isContextSlotNotAvail() const { |
| 76 | return mIsContextSlotNotAvail; |
| 77 | } |
| 78 | |
| 79 | void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) { |
| 80 | mpSymbolLookupFn = pFn; |
| 81 | mpSymbolLookupContext = pContext; |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | bool readHeader(); |
| 86 | bool readStringPool(); |
| 87 | bool readDependencyTable(); |
| 88 | bool readExportVarList(); |
| 89 | bool readExportFuncList(); |
| 90 | bool readPragmaList(); |
| 91 | bool readFuncTable(); |
| 92 | bool readObjectSlotList(); |
| 93 | bool readObjFile(); |
| 94 | bool readRelocationTable(); |
| 95 | |
| 96 | bool checkFileSize(); |
| 97 | bool checkHeader(); |
| 98 | bool checkMachineIntType(); |
| 99 | bool checkSectionOffsetAndSize(); |
| 100 | bool checkStringPool(); |
| 101 | bool checkDependency(); |
| 102 | bool checkContext(); |
| 103 | |
| 104 | bool relocate(); |
| 105 | |
| 106 | static void *resolveSymbolAdapter(void *context, char const *name); |
| 107 | |
| 108 | }; |
| 109 | |
| 110 | } // namespace bcc |
| 111 | |
| 112 | #endif // BCC_MCCACHEREADER_H |