1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef ECMASCRIPT_COMPILER_AOT_FILE_STUB_FILE_INFO_H 16 #define ECMASCRIPT_COMPILER_AOT_FILE_STUB_FILE_INFO_H 17 18 #include "ecmascript/compiler/aot_file/aot_file_info.h" 19 20 namespace panda::ecmascript { 21 class PUBLIC_API StubFileInfo : public AOTFileInfo { 22 public: 23 StubFileInfo() = default; 24 ~StubFileInfo() override = default; 25 void Save(const std::string &filename, Triple triple); 26 AddModuleDes(ModuleSectionDes & moduleDes)27 void AddModuleDes(ModuleSectionDes &moduleDes) 28 { 29 des_.emplace_back(moduleDes); 30 for (auto &s : moduleDes.GetSectionsInfo()) { 31 auto sec = ElfSection(s.first); 32 if (sec.isSequentialAOTSec()) { 33 accumulateTotalSize(s.second.second); 34 } 35 } 36 accumulateTotalSize(moduleDes.GetArkStackMapSize()); 37 } 38 GetAsmStubAddr()39 uint64_t GetAsmStubAddr() const 40 { 41 return reinterpret_cast<uint64_t>(asmStubAddr_); 42 } 43 GetAsmStubSize()44 uint32_t GetAsmStubSize() const 45 { 46 return static_cast<uint32_t>(asmStubSize_); 47 } 48 SetAsmStubAddr(void * addr)49 void SetAsmStubAddr(void *addr) 50 { 51 asmStubAddr_ = addr; 52 } 53 SetAsmStubAddr(uintptr_t addr)54 void SetAsmStubAddr(uintptr_t addr) 55 { 56 asmStubAddr_ = reinterpret_cast<void *>(addr); 57 } 58 SetAsmStubSize(size_t size)59 void SetAsmStubSize(size_t size) 60 { 61 asmStubSize_ = size; 62 } 63 FillAsmStubTempHolder(uint8_t * buffer,size_t bufferSize)64 void FillAsmStubTempHolder(uint8_t *buffer, size_t bufferSize) 65 { 66 asmStubTempHolder_.resize(bufferSize); 67 if (memcpy_s(asmStubTempHolder_.data(), bufferSize, buffer, bufferSize) != EOK) { 68 LOG_FULL(FATAL) << "memcpy_s failed"; 69 return; 70 } 71 SetAsmStubAddr(asmStubTempHolder_.data()); 72 SetAsmStubSize(bufferSize); 73 } 74 75 void Dump() const DUMP_API_ATTR; 76 77 private: 78 static constexpr uint32_t ASMSTUB_MODULE_NUM = 3; 79 80 bool MmapLoad(); 81 bool Load(); 82 const std::vector<ElfSecName> &GetDumpSectionNames(); 83 void *asmStubAddr_ {nullptr}; 84 size_t asmStubSize_ {0}; 85 std::vector<int> asmStubTempHolder_ {}; 86 87 friend class AnFileDataManager; 88 }; 89 } // namespace panda::ecmascript 90 #endif // ECMASCRIPT_COMPILER_AOT_FILE_STUB_FILE_INFO_H 91