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_CONTEXT_H
16800b99b8Sopenharmony_ci#define UNWIND_CONTEXT_H
17800b99b8Sopenharmony_ci
18800b99b8Sopenharmony_ci#include <memory>
19800b99b8Sopenharmony_ci#if is_ohos
20800b99b8Sopenharmony_ci#include <ucontext.h>
21800b99b8Sopenharmony_ci#endif
22800b99b8Sopenharmony_ci
23800b99b8Sopenharmony_ci#include "byte_order.h"
24800b99b8Sopenharmony_ci#include "dfx_errors.h"
25800b99b8Sopenharmony_ci#include "unwind_define.h"
26800b99b8Sopenharmony_ci#include "unwind_loc.h"
27800b99b8Sopenharmony_ci
28800b99b8Sopenharmony_cinamespace OHOS {
29800b99b8Sopenharmony_cinamespace HiviewDFX {
30800b99b8Sopenharmony_ciclass DfxMap;
31800b99b8Sopenharmony_ciclass DfxMaps;
32800b99b8Sopenharmony_ciclass DfxRegs;
33800b99b8Sopenharmony_ci
34800b99b8Sopenharmony_cistruct UnwindTableInfo {
35800b99b8Sopenharmony_ci    uintptr_t startPc = 0;
36800b99b8Sopenharmony_ci    uintptr_t endPc = 0;
37800b99b8Sopenharmony_ci    uintptr_t gp = 0; /* global-pointer in effect for this entry */
38800b99b8Sopenharmony_ci    int format = -1;
39800b99b8Sopenharmony_ci    bool isLinear = false;
40800b99b8Sopenharmony_ci    uintptr_t namePtr = 0;
41800b99b8Sopenharmony_ci    uintptr_t segbase = 0;
42800b99b8Sopenharmony_ci    uintptr_t tableLen = 0;
43800b99b8Sopenharmony_ci    uintptr_t tableData = 0;
44800b99b8Sopenharmony_ci};
45800b99b8Sopenharmony_ci
46800b99b8Sopenharmony_cistruct UnwindEntryInfo {
47800b99b8Sopenharmony_ci    uintptr_t startPc;
48800b99b8Sopenharmony_ci    uintptr_t endPc;
49800b99b8Sopenharmony_ci    uintptr_t lsda;
50800b99b8Sopenharmony_ci    uintptr_t handler;
51800b99b8Sopenharmony_ci    uintptr_t gp;
52800b99b8Sopenharmony_ci    int format = -1;
53800b99b8Sopenharmony_ci    int unwindInfoSize;
54800b99b8Sopenharmony_ci    void *unwindInfo;
55800b99b8Sopenharmony_ci};
56800b99b8Sopenharmony_ci
57800b99b8Sopenharmony_cistruct UnwindAccessors {
58800b99b8Sopenharmony_ci    int (*FindUnwindTable)(uintptr_t, UnwindTableInfo &, void *);
59800b99b8Sopenharmony_ci    int (*AccessMem)(uintptr_t, uintptr_t *, void *);
60800b99b8Sopenharmony_ci    int (*AccessReg)(int, uintptr_t *, void *);
61800b99b8Sopenharmony_ci    int (*GetMapByPc)(uintptr_t, std::shared_ptr<DfxMap> &, void *);
62800b99b8Sopenharmony_ci};
63800b99b8Sopenharmony_ci
64800b99b8Sopenharmony_cistruct UnwindContext {
65800b99b8Sopenharmony_ci    bool stackCheck = false;
66800b99b8Sopenharmony_ci    uintptr_t stackBottom = 0;
67800b99b8Sopenharmony_ci    uintptr_t stackTop = 0;
68800b99b8Sopenharmony_ci    int pid;
69800b99b8Sopenharmony_ci    std::shared_ptr<DfxRegs> regs = nullptr;
70800b99b8Sopenharmony_ci    std::shared_ptr<DfxMaps> maps = nullptr;
71800b99b8Sopenharmony_ci    std::shared_ptr<DfxMap> map = nullptr;
72800b99b8Sopenharmony_ci    struct UnwindTableInfo di;
73800b99b8Sopenharmony_ci};
74800b99b8Sopenharmony_ci} // namespace HiviewDFX
75800b99b8Sopenharmony_ci} // namespace OHOS
76800b99b8Sopenharmony_ci#endif
77