1 /*
2 * Copyright (c) 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 OHOS_ABILITY_RUNTIME_CJ_ENVSETUP_H
17 #define OHOS_ABILITY_RUNTIME_CJ_ENVSETUP_H
18 
19 #include <string>
20 
21 namespace OHOS {
22 struct CJErrorObject {
23     const char* name;
24     const char* message;
25     const char* stack;
26 };
27 
28 struct CJUncaughtExceptionInfo {
29     const char* hapPath;
30     std::function<void(const char* summary, const CJErrorObject errorObj)> uncaughtTask;
31 };
32 
33 enum SanitizerKind {
34     NONE,
35     ASAN,
36     TSAN,
37     HWASAN,
38 };
39 
40 struct CJEnvMethods {
41     void (*initCJAppNS)(const std::string& path) = nullptr;
42     void (*initCJSDKNS)(const std::string& path) = nullptr;
43     void (*initCJSysNS)(const std::string& path) = nullptr;
44     void (*initCJChipSDKNS)(const std::string& path) = nullptr;
45     bool (*startRuntime)() = nullptr;
46     bool (*startUIScheduler)() = nullptr;
47     void* (*loadCJModule)(const char* dllName) = nullptr;
48     void* (*loadLibrary)(uint32_t kind, const char* dllName) = nullptr;
49     void* (*getSymbol)(void* handle, const char* symbol) = nullptr;
50     void* (*loadCJLibrary)(const char* dllName) = nullptr;
51     bool (*startDebugger)() = nullptr;
52     void (*registerCJUncaughtExceptionHandler)(const CJUncaughtExceptionInfo& uncaughtExceptionInfo) = nullptr;
53     void (*setSanitizerKindRuntimeVersion)(SanitizerKind kind) = nullptr;
54 };
55 
56 class CJEnv {
57 public:
58     static CJEnvMethods* LoadInstance();
59 };
60 
61 }
62 
63 #endif // OHOS_ABILITY_RUNTIME_CJ_ENVSETUP_H
64