1 |
efrain |
1 |
// Copyright 2019 Google
|
|
|
2 |
//
|
|
|
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 |
#pragma once
|
|
|
16 |
|
|
|
17 |
#include <stdbool.h>
|
|
|
18 |
#include <stdint.h>
|
|
|
19 |
|
|
|
20 |
#include "Crashlytics/Crashlytics/Helpers/FIRCLSFeatures.h"
|
|
|
21 |
#include "Crashlytics/Crashlytics/Helpers/FIRCLSThreadState.h"
|
|
|
22 |
|
|
|
23 |
// We have to pack the arrays defined in this header, so
|
|
|
24 |
// we can reason about pointer math.
|
|
|
25 |
#pragma pack(push)
|
|
|
26 |
#pragma pack(1)
|
|
|
27 |
#include <mach-o/compact_unwind_encoding.h>
|
|
|
28 |
#pragma pack(pop)
|
|
|
29 |
|
|
|
30 |
// First masks out the value, and then shifts the value by the number
|
|
|
31 |
// of zeros in the mask. __builtin_ctz returns the number of trailing zeros.
|
|
|
32 |
// Its output is undefined if the input is zero.
|
|
|
33 |
#define GET_BITS_WITH_MASK(value, mask) ((value & mask) >> (mask == 0 ? 0 : __builtin_ctz(mask)))
|
|
|
34 |
|
|
|
35 |
typedef struct {
|
|
|
36 |
const void* unwindInfo;
|
|
|
37 |
const void* ehFrame;
|
|
|
38 |
uintptr_t loadAddress;
|
|
|
39 |
|
|
|
40 |
struct unwind_info_section_header unwindHeader;
|
|
|
41 |
struct unwind_info_section_header_index_entry indexHeader;
|
|
|
42 |
uint32_t firstLevelNextFunctionOffset;
|
|
|
43 |
} FIRCLSCompactUnwindContext;
|
|
|
44 |
|
|
|
45 |
typedef struct {
|
|
|
46 |
compact_unwind_encoding_t encoding;
|
|
|
47 |
uintptr_t functionStart;
|
|
|
48 |
uintptr_t functionEnd;
|
|
|
49 |
uintptr_t lsda;
|
|
|
50 |
uintptr_t personality;
|
|
|
51 |
|
|
|
52 |
} FIRCLSCompactUnwindResult;
|
|
|
53 |
|
|
|
54 |
bool FIRCLSCompactUnwindInit(FIRCLSCompactUnwindContext* context,
|
|
|
55 |
const void* unwindInfo,
|
|
|
56 |
const void* ehFrame,
|
|
|
57 |
uintptr_t loadAddress);
|
|
|
58 |
void* FIRCLSCompactUnwindGetIndexData(FIRCLSCompactUnwindContext* context);
|
|
|
59 |
void* FIRCLSCompactUnwindGetSecondLevelData(FIRCLSCompactUnwindContext* context);
|
|
|
60 |
bool FIRCLSCompactUnwindFindFirstLevelIndex(FIRCLSCompactUnwindContext* context,
|
|
|
61 |
uintptr_t pc,
|
|
|
62 |
uint32_t* index);
|
|
|
63 |
|
|
|
64 |
bool FIRCLSCompactUnwindDwarfFrame(FIRCLSCompactUnwindContext* context,
|
|
|
65 |
uintptr_t dwarfOffset,
|
|
|
66 |
FIRCLSThreadContext* registers);
|
|
|
67 |
bool FIRCLSCompactUnwindLookupAndCompute(FIRCLSCompactUnwindContext* context,
|
|
|
68 |
FIRCLSThreadContext* registers);
|