1800b99b8Sopenharmony_ci/*
2800b99b8Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3800b99b8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4800b99b8Sopenharmony_ci * you may not use this file except in compliance with the License.
5800b99b8Sopenharmony_ci * You may obtain a copy of the License at
6800b99b8Sopenharmony_ci *
7800b99b8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8800b99b8Sopenharmony_ci *
9800b99b8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10800b99b8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11800b99b8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12800b99b8Sopenharmony_ci * See the License for the specific language governing permissions and
13800b99b8Sopenharmony_ci * limitations under the License.
14800b99b8Sopenharmony_ci */
15800b99b8Sopenharmony_ci#ifndef UNWIND_DEFINE_H
16800b99b8Sopenharmony_ci#define UNWIND_DEFINE_H
17800b99b8Sopenharmony_ci
18800b99b8Sopenharmony_ci#include <cinttypes>
19800b99b8Sopenharmony_ci#include <string>
20800b99b8Sopenharmony_ci#include <unistd.h>
21800b99b8Sopenharmony_ci#if defined(__arm__)
22800b99b8Sopenharmony_ci#include "unwind_arm_define.h"
23800b99b8Sopenharmony_ci#elif defined(__aarch64__)
24800b99b8Sopenharmony_ci#include "unwind_arm64_define.h"
25800b99b8Sopenharmony_ci#elif defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64
26800b99b8Sopenharmony_ci#include "unwind_riscv64_define.h"
27800b99b8Sopenharmony_ci#elif defined(__x86_64__)
28800b99b8Sopenharmony_ci#include "unwind_x86_64_define.h"
29800b99b8Sopenharmony_ci#else
30800b99b8Sopenharmony_ci#error "Unsupported architecture"
31800b99b8Sopenharmony_ci#endif
32800b99b8Sopenharmony_ci
33800b99b8Sopenharmony_cinamespace OHOS {
34800b99b8Sopenharmony_cinamespace HiviewDFX {
35800b99b8Sopenharmony_ci#define FP_MINI_REGS_SIZE 4
36800b99b8Sopenharmony_ci#define QUT_MINI_REGS_SIZE 7
37800b99b8Sopenharmony_ci
38800b99b8Sopenharmony_ci#define ARM_EXIDX_TABLE_SIZE 8
39800b99b8Sopenharmony_ci
40800b99b8Sopenharmony_cistatic const int FRAME_MAX_SIZE = 64;
41800b99b8Sopenharmony_ci
42800b99b8Sopenharmony_ci/**
43800b99b8Sopenharmony_ci * @brief chip architecture
44800b99b8Sopenharmony_ci */
45800b99b8Sopenharmony_cienum ArchType : uint8_t {
46800b99b8Sopenharmony_ci    ARCH_UNKNOWN = 0,
47800b99b8Sopenharmony_ci    ARCH_ARM,
48800b99b8Sopenharmony_ci    ARCH_ARM64,
49800b99b8Sopenharmony_ci    ARCH_RISCV64,
50800b99b8Sopenharmony_ci    ARCH_X86,
51800b99b8Sopenharmony_ci    ARCH_X86_64,
52800b99b8Sopenharmony_ci};
53800b99b8Sopenharmony_ci
54800b99b8Sopenharmony_cienum UnwindType : int8_t {
55800b99b8Sopenharmony_ci    UNWIND_TYPE_CUSTOMIZE_LOCAL = -3,
56800b99b8Sopenharmony_ci    UNWIND_TYPE_CUSTOMIZE = -2,
57800b99b8Sopenharmony_ci    UNWIND_TYPE_LOCAL = -1,
58800b99b8Sopenharmony_ci    UNWIND_TYPE_REMOTE,
59800b99b8Sopenharmony_ci};
60800b99b8Sopenharmony_ci
61800b99b8Sopenharmony_cienum UnwindDynInfoFormatType {
62800b99b8Sopenharmony_ci    UNW_INFO_FORMAT_TABLE,              /* unw_dyn_table_t */
63800b99b8Sopenharmony_ci    UNW_INFO_FORMAT_REMOTE_TABLE,       /* unw_dyn_remote_table_t */
64800b99b8Sopenharmony_ci    UNW_INFO_FORMAT_ARM_EXIDX,          /* ARM specific unwind info */
65800b99b8Sopenharmony_ci};
66800b99b8Sopenharmony_ci
67800b99b8Sopenharmony_ci/**
68800b99b8Sopenharmony_ci * @brief Unwind regs type
69800b99b8Sopenharmony_ci */
70800b99b8Sopenharmony_cienum UnwindRegsType {
71800b99b8Sopenharmony_ci    /** Dwarf */
72800b99b8Sopenharmony_ci    REGS_TYPE_DWARF = 0,
73800b99b8Sopenharmony_ci    /** Qut */
74800b99b8Sopenharmony_ci    REGS_TYPE_QUT,
75800b99b8Sopenharmony_ci};
76800b99b8Sopenharmony_ci
77800b99b8Sopenharmony_ci/**
78800b99b8Sopenharmony_ci * @brief Unwind mode
79800b99b8Sopenharmony_ci */
80800b99b8Sopenharmony_cienum UnwindMode {
81800b99b8Sopenharmony_ci    /** Dwarf unwind */
82800b99b8Sopenharmony_ci    DWARF_UNWIND = 0,
83800b99b8Sopenharmony_ci    /** Frame pointer unwind */
84800b99b8Sopenharmony_ci    FRAMEPOINTER_UNWIND,
85800b99b8Sopenharmony_ci    /** Quick unwind table */
86800b99b8Sopenharmony_ci    MINIMAL_UNWIND,
87800b99b8Sopenharmony_ci    /** Mix unwind table */
88800b99b8Sopenharmony_ci    MIX_UNWIND,
89800b99b8Sopenharmony_ci};
90800b99b8Sopenharmony_ci
91800b99b8Sopenharmony_ci/**
92800b99b8Sopenharmony_ci * @brief Unwind cache mode
93800b99b8Sopenharmony_ci */
94800b99b8Sopenharmony_cienum UnwindCachingPolicy : uint8_t {
95800b99b8Sopenharmony_ci    /** unwind no cache */
96800b99b8Sopenharmony_ci    UNWIND_CACHE_NONE = 0,
97800b99b8Sopenharmony_ci    /** unwind global cache */
98800b99b8Sopenharmony_ci    UNWIND_CACHE_GLOBAL,
99800b99b8Sopenharmony_ci    /** unwind per-thread cache */
100800b99b8Sopenharmony_ci    UNWIND_CACHE_PER_THREAD,
101800b99b8Sopenharmony_ci};
102800b99b8Sopenharmony_ci} // namespace HiviewDFX
103800b99b8Sopenharmony_ci} // namespace OHOS
104800b99b8Sopenharmony_ci#endif
105