• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 #include <log/log.h>
23 #include <unwindstack/Memory.h>
24 
25 #include "gwp_asan/common.h"
26 #include "types.h"
27 #include "utility.h"
28 
29 class Cause;
30 class Tombstone;
31 
32 class GwpAsanCrashData {
33  public:
34   GwpAsanCrashData() = delete;
35   ~GwpAsanCrashData() = default;
36 
37   // Construct the crash data object. Takes a handle to the object that can
38   // supply the memory of the dead process, and pointers to the GWP-ASan state
39   // and metadata regions within that process. Also takes the thread information
40   // of the crashed process. If the process didn't crash via SEGV, GWP-ASan may
41   // still be responsible, as it terminates when it detects an internal error
42   // (double free, invalid free). In these cases, we will retrieve the fault
43   // address from the GWP-ASan allocator's state.
44   GwpAsanCrashData(unwindstack::Memory* process_memory, const ProcessInfo& process_info,
45                    const ThreadInfo& thread_info);
46 
47   // Is GWP-ASan responsible for this crash.
48   bool CrashIsMine() const;
49 
50   // Returns the fault address. The fault address may be the same as provided
51   // during construction, or it may have been retrieved from GWP-ASan's internal
52   // allocator crash state.
53   uintptr_t GetFaultAddress() const;
54 
55   void AddCauseProtos(Tombstone* tombstone, unwindstack::Unwinder* unwinder) const;
56 
57  protected:
58   // Is GWP-ASan responsible for this crash.
59   bool is_gwp_asan_responsible_ = false;
60 
61   // Thread ID of the crash.
62   size_t thread_id_;
63 
64   // The type of error that GWP-ASan caused (and the stringified version),
65   // Undefined if GWP-ASan isn't responsible for the crash.
66   gwp_asan::Error error_;
67   const char* error_string_;
68 
69   // Pointer to the crash address. Holds the internal crash address if it
70   // exists, otherwise the address provided at construction.
71   uintptr_t crash_address_ = 0u;
72 
73   // Pointer to the metadata for the responsible allocation, nullptr if it
74   // doesn't exist.
75   const gwp_asan::AllocationMetadata* responsible_allocation_ = nullptr;
76 
77   // Internal state.
78   gwp_asan::AllocatorState state_;
79   std::unique_ptr<const gwp_asan::AllocationMetadata> metadata_;
80 };
81