/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ECMASCRIPT_COMPILER_AOT_FILE_STUB_FILE_INFO_H #define ECMASCRIPT_COMPILER_AOT_FILE_STUB_FILE_INFO_H #include "ecmascript/compiler/aot_file/aot_file_info.h" namespace panda::ecmascript { class PUBLIC_API StubFileInfo : public AOTFileInfo { public: StubFileInfo() = default; ~StubFileInfo() override = default; void Save(const std::string &filename, Triple triple); void AddModuleDes(ModuleSectionDes &moduleDes) { des_.emplace_back(moduleDes); for (auto &s : moduleDes.GetSectionsInfo()) { auto sec = ElfSection(s.first); if (sec.isSequentialAOTSec()) { accumulateTotalSize(s.second.second); } } accumulateTotalSize(moduleDes.GetArkStackMapSize()); } uint64_t GetAsmStubAddr() const { return reinterpret_cast(asmStubAddr_); } uint32_t GetAsmStubSize() const { return static_cast(asmStubSize_); } void SetAsmStubAddr(void *addr) { asmStubAddr_ = addr; } void SetAsmStubAddr(uintptr_t addr) { asmStubAddr_ = reinterpret_cast(addr); } void SetAsmStubSize(size_t size) { asmStubSize_ = size; } void FillAsmStubTempHolder(uint8_t *buffer, size_t bufferSize) { asmStubTempHolder_.resize(bufferSize); if (memcpy_s(asmStubTempHolder_.data(), bufferSize, buffer, bufferSize) != EOK) { LOG_FULL(FATAL) << "memcpy_s failed"; return; } SetAsmStubAddr(asmStubTempHolder_.data()); SetAsmStubSize(bufferSize); } void Dump() const DUMP_API_ATTR; private: static constexpr uint32_t ASMSTUB_MODULE_NUM = 3; bool MmapLoad(); bool Load(); const std::vector &GetDumpSectionNames(); void *asmStubAddr_ {nullptr}; size_t asmStubSize_ {0}; std::vector asmStubTempHolder_ {}; friend class AnFileDataManager; }; } // namespace panda::ecmascript #endif // ECMASCRIPT_COMPILER_AOT_FILE_STUB_FILE_INFO_H