• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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_stub_csigns.h"
21 #include "ecmascript/compiler/baseline/baseline_stub_csigns.h"
22 #include "ecmascript/compiler/builtins/builtins_call_signature.h"
23 #include "ecmascript/compiler/rt_call_signature.h"
24 
25 namespace panda::ecmascript {
26 struct BCStubEntries {
27     static constexpr size_t EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT =
28         kungfu::BytecodeStubCSigns::NUM_OF_ALL_NORMAL_STUBS;
29     // The number of bytecodes.
30     static constexpr size_t BC_HANDLER_COUNT = kungfu::BytecodeStubCSigns::LAST_VALID_OPCODE + 1;
31     static constexpr size_t COUNT = kungfu::BytecodeStubCSigns::NUM_OF_STUBS;
32     static_assert(EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT <= COUNT);
33     Address stubEntries_[COUNT] = {0};
34 
35     static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
36     static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
37 
SetBCStubEntries38     void Set(size_t index, Address addr)
39     {
40         ASSERT(index < COUNT);
41         stubEntries_[index] = addr;
42     }
43 
GetAddrBCStubEntries44     Address* GetAddr()
45     {
46         return reinterpret_cast<Address*>(stubEntries_);
47     }
48 
GetBCStubEntries49     Address Get(size_t index) const
50     {
51         ASSERT(index < COUNT);
52         return stubEntries_[index];
53     }
54 };
55 STATIC_ASSERT_EQ_ARCH(sizeof(BCStubEntries), BCStubEntries::SizeArch32, BCStubEntries::SizeArch64);
56 
57 struct RTStubEntries {
58     static constexpr size_t COUNT = kungfu::RuntimeStubCSigns::NUM_OF_STUBS;
59     Address stubEntries_[COUNT];
60 
61     static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
62     static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
63 
SetRTStubEntries64     void Set(size_t index, Address addr)
65     {
66         ASSERT(index < COUNT);
67         stubEntries_[index] = addr;
68     }
69 
GetRTStubEntries70     Address Get(size_t index) const
71     {
72         ASSERT(index < COUNT);
73         return stubEntries_[index];
74     }
75 };
76 STATIC_ASSERT_EQ_ARCH(sizeof(RTStubEntries), RTStubEntries::SizeArch32, RTStubEntries::SizeArch64);
77 
78 struct COStubEntries {
79     static constexpr size_t COUNT = kungfu::CommonStubCSigns::NUM_OF_STUBS;
80     Address stubEntries_[COUNT];
81 
82     static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
83     static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
84 
SetCOStubEntries85     void Set(size_t index, Address addr)
86     {
87         ASSERT(index < COUNT);
88         stubEntries_[index] = addr;
89     }
90 
GetCOStubEntries91     Address Get(size_t index) const
92     {
93         ASSERT(index < COUNT);
94         return stubEntries_[index];
95     }
96 };
97 
98 struct BCDebuggerStubEntries {
99     static constexpr size_t EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT =
100         kungfu::BytecodeStubCSigns::NUM_OF_ALL_NORMAL_STUBS;
101     static constexpr size_t COUNT = kungfu::BytecodeStubCSigns::LAST_VALID_OPCODE + 1;
102     Address stubEntries_[COUNT];
103 
104     static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
105     static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
106 
SetBCDebuggerStubEntries107     void Set(size_t index, Address addr)
108     {
109         ASSERT(index < COUNT);
110         stubEntries_[index] = addr;
111     }
112 
GetBCDebuggerStubEntries113     Address Get(size_t index) const
114     {
115         ASSERT(index < COUNT);
116         return stubEntries_[index];
117     }
118 
SetNonexistentBCHandlerStubEntriesBCDebuggerStubEntries119     void SetNonexistentBCHandlerStubEntries(Address addr)
120     {
121         for (size_t i = EXISTING_BC_HANDLER_STUB_ENTRIES_COUNT; i < COUNT; i++) {
122             if (stubEntries_[i] == 0) {
123                 stubEntries_[i] = addr;
124             }
125         }
126     }
127 };
128 
129 struct BuiltinStubEntries {
130     static constexpr size_t COUNT = kungfu::BuiltinsStubCSigns::NUM_OF_BUILTINS_STUBS;
131     Address stubEntries_[COUNT];
132 
133     static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
134     static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
135 
SetBuiltinStubEntries136     void Set(size_t index, Address addr)
137     {
138         ASSERT(index < COUNT);
139         stubEntries_[index] = addr;
140     }
141 
GetBuiltinStubEntries142     Address Get(size_t index) const
143     {
144         ASSERT(index < COUNT);
145         return stubEntries_[index];
146     }
147 };
148 
149 struct BaselineStubEntries {
150     static constexpr size_t COUNT = kungfu::BaselineStubCSigns::NUM_OF_STUBS;
151     Address stubEntries_[COUNT];
152 
153     static constexpr size_t SizeArch32 = sizeof(uint32_t) * COUNT;
154     static constexpr size_t SizeArch64 = sizeof(uint64_t) * COUNT;
155 
SetBaselineStubEntries156     void Set(size_t index, Address addr)
157     {
158         ASSERT(index < COUNT);
159         stubEntries_[index] = addr;
160     }
161 
GetBaselineStubEntries162     Address Get(size_t index) const
163     {
164         ASSERT(index < COUNT);
165         return stubEntries_[index];
166     }
167 };
168 
169 STATIC_ASSERT_EQ_ARCH(sizeof(COStubEntries), COStubEntries::SizeArch32, COStubEntries::SizeArch64);
170 } // namespace panda::ecmascript
171 
172 #endif // ECMASCRIPT_JS_THREAD_STUB_ENTRIES_H
173