• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "ecmascript/compiler/aot_file/aot_file_info.h"
17 
18 namespace panda::ecmascript {
Destroy()19 void AOTFileInfo::Destroy()
20 {
21     entryNum_ = 0;
22     moduleNum_ = 0;
23     totalCodeSize_ = 0;
24     entries_.clear();
25     des_.clear();
26     ExecutedMemoryAllocator::DestroyBuf(stubsMem_);
27 }
28 
CalCallSiteInfo(uintptr_t retAddr,std::tuple<uint64_t,uint8_t *,int,CalleeRegAndOffsetVec> & ret) const29 bool AOTFileInfo::CalCallSiteInfo(uintptr_t retAddr,
30                                   std::tuple<uint64_t, uint8_t *, int, CalleeRegAndOffsetVec> &ret) const
31 {
32     uint64_t textStart = 0;
33     uint8_t *stackmapAddr = nullptr;
34     int delta = 0;
35     const auto &des = GetCodeUnits();
36     const auto &funcEntryDes = GetStubs();
37 
38     auto cmp = [](const AOTFileInfo::FuncEntryDes &a, const AOTFileInfo::FuncEntryDes &b) {
39         return a.codeAddr_ < b.codeAddr_;
40     };
41     size_t len = des.size();
42     for (size_t i = 0; i < len; i++) {
43         auto d = des[i];
44         uint64_t addr = d.GetSecAddr(ElfSecName::TEXT);
45         uint32_t size = d.GetSecSize(ElfSecName::TEXT);
46         if (retAddr < addr || retAddr >= addr + size) {
47             continue;
48         }
49         stackmapAddr = d.GetArkStackMapRawPtr();
50         ASSERT(stackmapAddr != nullptr);
51         textStart = addr;
52         auto startIndex = d.GetStartIndex();
53         auto funcCount = d.GetFuncCount();
54         auto s = funcEntryDes.begin() + startIndex;
55         auto t = funcEntryDes.begin() + startIndex + funcCount;
56         AOTFileInfo::FuncEntryDes target;
57         target.codeAddr_ = retAddr - 1;  // -1: for pc
58         auto it = std::upper_bound(s, t, target, cmp);
59         --it;
60         ASSERT(it != t);
61         ASSERT((it->codeAddr_ <= target.codeAddr_) && (target.codeAddr_ < it->codeAddr_ + it->funcSize_));
62         delta = it->fpDeltaPrevFrameSp_;
63         CalleeRegAndOffsetVec calleeRegInfo;
64         for (uint32_t j = 0; j < it->calleeRegisterNum_; j++) {
65             DwarfRegType reg = static_cast<DwarfRegType>(it->CalleeReg2Offset_[2 * j]);
66             OffsetType offset = static_cast<OffsetType>(it->CalleeReg2Offset_[2 * j + 1]);
67             DwarfRegAndOffsetType regAndOffset = std::make_pair(reg, offset);
68             calleeRegInfo.emplace_back(regAndOffset);
69         }
70         ret = std::make_tuple(textStart, stackmapAddr, delta, calleeRegInfo);
71         return true;
72     }
73     return false;
74 }
75 }  // namespace panda::ecmascript
76