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#ifndef FP_UNWINDER_H
16#define FP_UNWINDER_H
17#include <cinttypes>
18#include "dfx_define.h"
19namespace OHOS {
20namespace HiviewDFX {
21class FpUnwinder {
22public:
23    FpUnwinder();
24    ~FpUnwinder();
25    static inline AT_ALWAYS_INLINE void GetFpPcRegs(void *regs)
26    {
27#if defined(__aarch64__)
28        asm volatile(
29        "1:\n"
30        "adr x12, 1b\n"
31        "stp x12, x29, [%[base], #0]\n"
32        : [base] "+r"(regs)
33        :
34        : "x12", "memory");
35#endif
36    }
37    static int32_t Unwind(uintptr_t* pcs, int32_t sz, int32_t skipFrameNum);
38private:
39    static int32_t UnwindFallback(uintptr_t* pcs, int32_t sz, int32_t skipFrameNum);
40    static bool ReadUintptrSafe(uintptr_t addr, uintptr_t& value);
41};
42}
43} // namespace OHOS
44#endif