• 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 #ifndef ECMASCRIPT_JS_THREAD_STUB_ENTRIES_H
17 #define ECMASCRIPT_JS_THREAD_STUB_ENTRIES_H
18 
19 #include "ecmascript/compiler/bc_call_signature.h"
20 #include "ecmascript/compiler/common_stubs.h"
21 
22 namespace panda::ecmascript {
23 struct BCStubEntries {
24     static constexpr size_t EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT =
25         kungfu::BytecodeStubCSigns::NUM_OF_ALL_NORMAL_STUBS;
26     // The number of bytecodes.
27     static constexpr size_t BC_HANDLER_COUNT = kungfu::BytecodeStubCSigns::LAST_VALID_OPCODE + 1;
28     static constexpr size_t COUNT = kungfu::BytecodeStubCSigns::NUM_OF_STUBS;
29     static_assert(EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT <= COUNT);
30     Address stubEntries_[COUNT] = {0};
31 
32     static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
33     static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
34 
SetBCStubEntries35     void Set(size_t index, Address addr)
36     {
37         ASSERT(index < COUNT);
38         stubEntries_[index] = addr;
39     }
40 
GetAddrBCStubEntries41     Address* GetAddr()
42     {
43         return reinterpret_cast<Address*>(stubEntries_);
44     }
45 
GetBCStubEntries46     Address Get(size_t index) const
47     {
48         ASSERT(index < COUNT);
49         return stubEntries_[index];
50     }
51 };
52 STATIC_ASSERT_EQ_ARCH(sizeof(BCStubEntries), BCStubEntries::SizeArch32, BCStubEntries::SizeArch64);
53 
54 struct RTStubEntries {
55     static constexpr size_t COUNT = kungfu::RuntimeStubCSigns::NUM_OF_STUBS;
56     Address stubEntries_[COUNT];
57 
58     static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
59     static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
60 
SetRTStubEntries61     void Set(size_t index, Address addr)
62     {
63         ASSERT(index < COUNT);
64         stubEntries_[index] = addr;
65     }
66 
GetRTStubEntries67     Address Get(size_t index) const
68     {
69         ASSERT(index < COUNT);
70         return stubEntries_[index];
71     }
72 };
73 STATIC_ASSERT_EQ_ARCH(sizeof(RTStubEntries), RTStubEntries::SizeArch32, RTStubEntries::SizeArch64);
74 
75 struct COStubEntries {
76     static constexpr size_t COUNT = kungfu::CommonStubCSigns::NUM_OF_STUBS;
77     Address stubEntries_[COUNT];
78 
79     static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
80     static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
81 
SetCOStubEntries82     void Set(size_t index, Address addr)
83     {
84         ASSERT(index < COUNT);
85         stubEntries_[index] = addr;
86     }
87 
GetCOStubEntries88     Address Get(size_t index) const
89     {
90         ASSERT(index < COUNT);
91         return stubEntries_[index];
92     }
93 };
94 
95 struct BCDebuggerStubEntries {
96     static constexpr size_t EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT =
97         kungfu::BytecodeStubCSigns::NUM_OF_ALL_NORMAL_STUBS;
98     static constexpr size_t COUNT = kungfu::BytecodeStubCSigns::LAST_VALID_OPCODE + 1;
99     Address stubEntries_[COUNT];
100 
101     static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
102     static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
103 
SetBCDebuggerStubEntries104     void Set(size_t index, Address addr)
105     {
106         ASSERT(index < COUNT);
107         stubEntries_[index] = addr;
108     }
109 
GetBCDebuggerStubEntries110     Address Get(size_t index) const
111     {
112         ASSERT(index < COUNT);
113         return stubEntries_[index];
114     }
115 
SetNonexistentBCHandlerStubEntriesBCDebuggerStubEntries116     void SetNonexistentBCHandlerStubEntries(Address addr)
117     {
118         for (size_t i = EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT; i < COUNT; i++) {
119             if (stubEntries_[i] == 0) {
120                 stubEntries_[i] = addr;
121             }
122         }
123     }
124 };
125 
126 struct BuiltinStubEntries {
127     static constexpr size_t COUNT = kungfu::BuiltinsStubCSigns::NUM_OF_BUILTINS_STUBS;
128     Address stubEntries_[COUNT];
129 
130     static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
131     static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
132 
SetBuiltinStubEntries133     void Set(size_t index, Address addr)
134     {
135         ASSERT(index < COUNT);
136         stubEntries_[index] = addr;
137     }
138 
GetBuiltinStubEntries139     Address Get(size_t index) const
140     {
141         ASSERT(index < COUNT);
142         return stubEntries_[index];
143     }
144 };
145 STATIC_ASSERT_EQ_ARCH(sizeof(COStubEntries), COStubEntries::SizeArch32, COStubEntries::SizeArch64);
146 } // namespace panda::ecmascript
147 
148 #endif // ECMASCRIPT_JS_THREAD_STUB_ENTRIES_H
149