1 /* 2 * Copyright (c) 2023 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 #ifndef UNWIND_CONTEXT_H 16 #define UNWIND_CONTEXT_H 17 18 #include <memory> 19 #if is_ohos 20 #include <ucontext.h> 21 #endif 22 23 #include "byte_order.h" 24 #include "dfx_errors.h" 25 #include "unwind_define.h" 26 #include "unwind_loc.h" 27 28 namespace OHOS { 29 namespace HiviewDFX { 30 class DfxMap; 31 class DfxMaps; 32 class DfxRegs; 33 34 struct UnwindTableInfo { 35 uintptr_t startPc = 0; 36 uintptr_t endPc = 0; 37 uintptr_t gp = 0; /* global-pointer in effect for this entry */ 38 int format = -1; 39 bool isLinear = false; 40 uintptr_t namePtr = 0; 41 uintptr_t segbase = 0; 42 uintptr_t tableLen = 0; 43 uintptr_t tableData = 0; 44 }; 45 46 struct UnwindEntryInfo { 47 uintptr_t startPc; 48 uintptr_t endPc; 49 uintptr_t lsda; 50 uintptr_t handler; 51 uintptr_t gp; 52 int format = -1; 53 int unwindInfoSize; 54 void *unwindInfo; 55 }; 56 57 struct UnwindAccessors { 58 int (*FindUnwindTable)(uintptr_t, UnwindTableInfo &, void *); 59 int (*AccessMem)(uintptr_t, uintptr_t *, void *); 60 int (*AccessReg)(int, uintptr_t *, void *); 61 int (*GetMapByPc)(uintptr_t, std::shared_ptr<DfxMap> &, void *); 62 }; 63 64 struct UnwindContext { 65 bool stackCheck = false; 66 uintptr_t stackBottom = 0; 67 uintptr_t stackTop = 0; 68 int pid; 69 std::shared_ptr<DfxRegs> regs = nullptr; 70 std::shared_ptr<DfxMaps> maps = nullptr; 71 std::shared_ptr<DfxMap> map = nullptr; 72 struct UnwindTableInfo di; 73 }; 74 } // namespace HiviewDFX 75 } // namespace OHOS 76 #endif 77