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 ECMASCRIPT_PLATFORM_AOT_RUNTIME_INFO_H
17#define ECMASCRIPT_PLATFORM_AOT_RUNTIME_INFO_H
18
19#include <signal.h>
20#include <string>
21
22#include "ecmascript/compiler/aot_compiler_preprocessor.h"
23#include "ecmascript/dfx/stackinfo/js_stackinfo.h"
24#include "ecmascript/ohos/ohos_pkg_args.h"
25#include "ecmascript/ecma_vm.h"
26#include "llvm/BinaryFormat/ELF.h"
27
28namespace panda::ecmascript {
29#ifdef JIT_ESCAPE_ENABLE
30void GetSignalHandler(int signal, siginfo_t *info, void *context);
31void SignalReg(int signo);
32#endif
33void SignalAllReg();
34
35using AotCompilerPreprocessor = kungfu::AotCompilerPreprocessor;
36class AotCrashInfo {
37constexpr static const char *const AOT_ESCAPE_DISABLE = "ark.aot.escape.disable";
38constexpr static int AOT_CRASH_COUNT = 1;
39constexpr static int OTHERS_CRASH_COUNT = 3;
40constexpr static int JIT_CRASH_COUNT = 1;
41constexpr static int JS_CRASH_COUNT = 3;
42constexpr static int OPT_CODE_CRASH_THRESHOLD = 1;
43public:
44    explicit AotCrashInfo() = default;
45    virtual ~AotCrashInfo() = default;
46
47    static AotCrashInfo &GetInstance()
48    {
49        static AotCrashInfo singleAotCrashInfo;
50        return singleAotCrashInfo;
51    }
52
53    bool IsAotEscapedOrNotInEnableList(EcmaVM *vm, const std::string &bundleName) const;
54    void SetOptionPGOProfiler(JSRuntimeOptions *options, const std::string &bundleName) const;
55    bool PUBLIC_API IsAotEscapedOrCompiledOnce(AotCompilerPreprocessor &cPreprocessor, int32_t &ret) const;
56    static bool PUBLIC_API IsAotEscaped(const std::string &pgoRealPath = "");
57    static bool IsJitEscape();
58    static bool GetAotEscapeDisable();
59    static std::string GetSandBoxPath();
60    static int GetAotCrashCount();
61    static int GetJitCrashCount();
62    static int GetJsCrashCount();
63    static int GetOthersCrashCount();
64};
65} // namespace panda::ecmascript
66#endif  // ECMASCRIPT_PLATFORM_AOT_RUNTIME_INFO_H
67