memory_snapshot.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2014 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_MEMORY_SNAPSHOT_H_
  15. #define CRASHPAD_SNAPSHOT_MEMORY_SNAPSHOT_H_
  16. #include <stdint.h>
  17. #include <sys/types.h>
  18. namespace crashpad {
  19. //! \brief An abstract interface to a snapshot representing a region of memory
  20. //! present in a snapshot process.
  21. class MemorySnapshot {
  22. public:
  23. //! \brief An interface that MemorySnapshot clients must implement in order to
  24. //! receive memory snapshot data.
  25. //!
  26. //! This callback-based model frees MemorySnapshot implementations from having
  27. //! to deal with memory region ownership problems. When a memory snapshot’s
  28. //! data is read, it will be passed to a delegate method.
  29. class Delegate {
  30. public:
  31. virtual ~Delegate() {}
  32. //! \brief Called by MemorySnapshot::Read() to provide data requested by a
  33. //! call to that method.
  34. //!
  35. //! \param[in] data A pointer to the data that was read. The callee does not
  36. //! take ownership of this data. This data is only valid for the
  37. //! duration of the call to this method. This parameter may be `nullptr`
  38. //! if \a size is `0`.
  39. //! \param[in] size The size of the data that was read.
  40. //!
  41. //! \return `true` on success, `false` on failure. MemoryDelegate::Read()
  42. //! will use this as its own return value.
  43. virtual bool MemorySnapshotDelegateRead(void* data, size_t size) = 0;
  44. };
  45. virtual ~MemorySnapshot() {}
  46. //! \brief The base address of the memory snapshot in the snapshot process’
  47. //! address space.
  48. virtual uint64_t Address() const = 0;
  49. //! \brief The size of the memory snapshot.
  50. virtual size_t Size() const = 0;
  51. //! \brief Calls Delegate::MemorySnapshotDelegateRead(), providing it with
  52. //! the memory snapshot’s data.
  53. //!
  54. //! Implementations do not necessarily read the memory snapshot data prior to
  55. //! this method being called. Memory snapshot data may be loaded lazily and
  56. //! may be discarded after being passed to the delegate. This provides clean
  57. //! memory management without burdening a snapshot implementation with the
  58. //! requirement that it track all memory region data simultaneously.
  59. //!
  60. //! \return `false` on failure, otherwise, the return value of
  61. //! Delegate::MemorySnapshotDelegateRead(), which should be `true` on
  62. //! success and `false` on failure.
  63. virtual bool Read(Delegate* delegate) const = 0;
  64. };
  65. } // namespace crashpad
  66. #endif // CRASHPAD_SNAPSHOT_MEMORY_SNAPSHOT_H_