• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024-2025 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 PANDA_PLUGINS_ETS_RUNTIME_TYPES_ETS_RUNTIME_LINKER_H
17 #define PANDA_PLUGINS_ETS_RUNTIME_TYPES_ETS_RUNTIME_LINKER_H
18 
19 #include <cstdint>
20 #include "include/object_header.h"
21 #include "plugins/ets/runtime/types/ets_object.h"
22 #include "plugins/ets/runtime/types/ets_primitives.h"
23 
24 namespace ark {
25 class ClassLinkerContext;
26 }  // namespace ark
27 
28 namespace ark::ets {
29 
30 namespace test {
31 class EtsRuntimeLinkerTest;
32 }  // namespace test
33 
34 class EtsRuntimeLinker : public EtsObject {
35 public:
36     EtsRuntimeLinker() = delete;
37     ~EtsRuntimeLinker() = delete;
38 
39     NO_COPY_SEMANTIC(EtsRuntimeLinker);
40     NO_MOVE_SEMANTIC(EtsRuntimeLinker);
41 
FromEtsObject(EtsObject * obj)42     static EtsRuntimeLinker *FromEtsObject(EtsObject *obj)
43     {
44         return reinterpret_cast<EtsRuntimeLinker *>(obj);
45     }
46 
FromCoreType(ObjectHeader * obj)47     static EtsRuntimeLinker *FromCoreType(ObjectHeader *obj)
48     {
49         return reinterpret_cast<EtsRuntimeLinker *>(obj);
50     }
51 
AsObject()52     EtsObject *AsObject()
53     {
54         return this;
55     }
56 
GetClassLinkerContext()57     ClassLinkerContext *GetClassLinkerContext()
58     {
59         return reinterpret_cast<ClassLinkerContext *>(classLinkerCtxPtr_);
60     }
61 
FindLoadedClass(const uint8_t * descriptor)62     EtsClass *FindLoadedClass(const uint8_t *descriptor)
63     {
64         auto *ctx = GetClassLinkerContext();
65         ASSERT(ctx != nullptr);
66         auto *klass = ctx->FindClass(descriptor);
67         return klass != nullptr ? EtsClass::FromRuntimeClass(klass) : nullptr;
68     }
69 
SetClassLinkerContext(ClassLinkerContext * ctx)70     void SetClassLinkerContext(ClassLinkerContext *ctx)
71     {
72         ASSERT(ctx != nullptr);
73         classLinkerCtxPtr_ = reinterpret_cast<EtsLong>(ctx);
74     }
75 
76 private:
77     // ets.RuntimeLinker fields BEGIN
78     EtsLong classLinkerCtxPtr_;
79     // ets.RuntimeLinker fields END
80 
81     friend class test::EtsRuntimeLinkerTest;
82 };
83 
84 }  // namespace ark::ets
85 
86 #endif  // PANDA_PLUGINS_ETS_RUNTIME_TYPES_ETS_RUNTIME_LINKER_H
87