exception_snapshot_linux.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2017 The Crashpad Authors. All rights reserved.
  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. #ifndef CRASHPAD_SNAPSHOT_LINUX_EXCEPTION_SNAPSHOT_LINUX_H_
  15. #define CRASHPAD_SNAPSHOT_LINUX_EXCEPTION_SNAPSHOT_LINUX_H_
  16. #include <stdint.h>
  17. #include <sys/types.h>
  18. #include <vector>
  19. #include "build/build_config.h"
  20. #include "snapshot/cpu_context.h"
  21. #include "snapshot/exception_snapshot.h"
  22. #include "snapshot/linux/process_reader_linux.h"
  23. #include "snapshot/memory_snapshot.h"
  24. #include "snapshot/memory_snapshot_generic.h"
  25. #include "util/linux/address_types.h"
  26. #include "util/misc/initialization_state_dcheck.h"
  27. namespace crashpad {
  28. namespace internal {
  29. //! \brief An ExceptionSnapshot of an signal received by a running (or crashed)
  30. //! process on a Linux system.
  31. class ExceptionSnapshotLinux final : public ExceptionSnapshot {
  32. public:
  33. ExceptionSnapshotLinux();
  34. ExceptionSnapshotLinux(const ExceptionSnapshotLinux&) = delete;
  35. ExceptionSnapshotLinux& operator=(const ExceptionSnapshotLinux&) = delete;
  36. ~ExceptionSnapshotLinux() override;
  37. //! \brief Initializes the object.
  38. //!
  39. //! \param[in] process_reader A ProcessReaderLinux for the process that
  40. //! received
  41. //! the signal.
  42. //! \param[in] siginfo_address The address in the target process' address
  43. //! space of the siginfo_t passed to the signal handler.
  44. //! \param[in] context_address The address in the target process' address
  45. //! space of the ucontext_t passed to the signal handler.
  46. //! \param[in] thread_id The thread ID of the thread that received the signal.
  47. //!
  48. //! \return `true` if the snapshot could be created, `false` otherwise with
  49. //! an appropriate message logged.
  50. bool Initialize(ProcessReaderLinux* process_reader,
  51. LinuxVMAddress siginfo_address,
  52. LinuxVMAddress context_address,
  53. pid_t thread_id,
  54. uint32_t* gather_indirectly_referenced_memory_cap);
  55. // ExceptionSnapshot:
  56. const CPUContext* Context() const override;
  57. uint64_t ThreadID() const override;
  58. uint32_t Exception() const override;
  59. uint32_t ExceptionInfo() const override;
  60. uint64_t ExceptionAddress() const override;
  61. const std::vector<uint64_t>& Codes() const override;
  62. virtual std::vector<const MemorySnapshot*> ExtraMemory() const override;
  63. private:
  64. template <typename Traits>
  65. bool ReadSiginfo(ProcessReaderLinux* reader, LinuxVMAddress siginfo_address);
  66. template <typename Traits>
  67. bool ReadContext(ProcessReaderLinux* reader, LinuxVMAddress context_address);
  68. union {
  69. #if defined(ARCH_CPU_X86_FAMILY)
  70. CPUContextX86 x86;
  71. CPUContextX86_64 x86_64;
  72. #elif defined(ARCH_CPU_ARM_FAMILY)
  73. CPUContextARM arm;
  74. CPUContextARM64 arm64;
  75. #elif defined(ARCH_CPU_MIPS_FAMILY)
  76. CPUContextMIPS mipsel;
  77. CPUContextMIPS64 mips64;
  78. #elif defined(ARCH_CPU_RISCV_FAMILY)
  79. CPUContextRISCV riscv;
  80. CPUContextRISCV64 riscv64;
  81. #endif
  82. } context_union_;
  83. CPUContext context_;
  84. std::vector<uint64_t> codes_;
  85. std::vector<std::unique_ptr<internal::MemorySnapshotGeneric>> extra_memory_;
  86. uint64_t thread_id_;
  87. uint64_t exception_address_;
  88. uint32_t signal_number_;
  89. uint32_t signal_code_;
  90. InitializationStateDcheck initialized_;
  91. };
  92. } // namespace internal
  93. } // namespace crashpad
  94. #endif // CRASHPAD_SNAPSHOT_LINUX_EXCEPTION_SNAPSHOT_LINUX_H_