1 /* 2 * Copyright (c) 2021 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 #ifndef ECMASCRIPT_STUB_MODULE_H 17 #define ECMASCRIPT_STUB_MODULE_H 18 19 #include "ecmascript/common.h" 20 #include "ecmascript/js_thread.h" 21 #include "ecmascript/mem/machine_code.h" 22 #include "libpandabase/macros.h" 23 24 namespace panda::ecmascript { 25 class PUBLIC_API StubModule { 26 public: GetStubEntry(int index)27 uint64_t GetStubEntry(int index) 28 { 29 return code_->GetDataOffsetAddress() + stubEntries_[index]; 30 } 31 void Save(const std::string &filename); 32 void Load(JSThread *thread, const std::string &filename); SetCode(MachineCode * code)33 void SetCode(MachineCode *code) 34 { 35 code_ = code; 36 } 37 SetCodePtr(uint64_t codePtr)38 void SetCodePtr(uint64_t codePtr) 39 { 40 codePtr_ = codePtr; 41 } 42 GetCodePtr()43 uint64_t GetCodePtr() 44 { 45 return codePtr_; 46 } 47 SetStubEntry(int index,uint64_t offset)48 void SetStubEntry(int index, uint64_t offset) 49 { 50 stubEntries_[index] = offset; 51 } SetHostCodeSectionAddr(uint64_t addr)52 void SetHostCodeSectionAddr(uint64_t addr) 53 { 54 hostCodeSectionAddr_ = addr; 55 } GetHostCodeSectionAddr()56 uint64_t GetHostCodeSectionAddr() const 57 { 58 return hostCodeSectionAddr_; 59 } SetDeviceCodeSectionAddr(uint64_t addr)60 void SetDeviceCodeSectionAddr(uint64_t addr) 61 { 62 devicesCodeSectionAddr_ = addr; 63 } GetDeviceCodeSectionAddr()64 uint64_t GetDeviceCodeSectionAddr() const 65 { 66 return devicesCodeSectionAddr_; 67 } GetCode()68 JSTaggedValue GetCode() 69 { 70 return JSTaggedValue(code_); 71 } SetStackMapAddr(uint64_t addr)72 void SetStackMapAddr(uint64_t addr) 73 { 74 stackMapAddr_ = addr; 75 } GetStackMapAddr()76 uint64_t GetStackMapAddr() const 77 { 78 return stackMapAddr_; 79 } SetStackMapSize(int len)80 void SetStackMapSize(int len) 81 { 82 stackMapSize_ = len; 83 } 84 GetStackMapSize()85 int GetStackMapSize() const 86 { 87 return stackMapSize_; 88 } 89 90 private: 91 std::array<uint64_t, kungfu::ALL_STUB_MAXCOUNT> stubEntries_ {-1}; 92 uint64_t hostCodeSectionAddr_ {0}; 93 uint64_t devicesCodeSectionAddr_ {0}; 94 MachineCode *code_ {nullptr}; 95 uint64_t stackMapAddr_ {0}; 96 uint64_t codePtr_{0}; 97 int stackMapSize_ {0}; 98 }; 99 } // namespace panda::ecmascript 100 #endif // ECMASCRIPT_STUB_MODULE_H 101