chromium/third_party/crashpad/crashpad/snapshot/memory_snapshot.h

// Copyright 2014 The Crashpad Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CRASHPAD_SNAPSHOT_MEMORY_SNAPSHOT_H_
#define CRASHPAD_SNAPSHOT_MEMORY_SNAPSHOT_H_

#include <stdint.h>
#include <sys/types.h>

#include <memory>

#include "util/numeric/checked_range.h"

namespace crashpad {

//! \brief An abstract interface to a snapshot representing a region of memory
//!     present in a snapshot process.
class MemorySnapshot {};

//! \brief Given two memory snapshots, checks if they're overlapping or
//!     abutting, and if so, returns the result of merging the two ranges.
//!
//! This function is useful to implement
//! MemorySnapshot::MergeWithOtherSnapshot().
//!
//! \param[in] a The first range. Must have Size() > 0.
//! \param[in] b The second range. Must have Size() > 0.
//! \param[out] merged The resulting merged range. May be `nullptr` if only a
//!     characterization of the ranges is desired.
//!
//! \return `true` if the input ranges overlap or abut, with \a merged filled
//!     out, otherwise, `false` with an error logged if \a log is `true`.
bool LoggingDetermineMergedRange(const MemorySnapshot* a,
                                 const MemorySnapshot* b,
                                 CheckedRange<uint64_t, size_t>* merged);

//! \brief The same as LoggingDetermineMergedRange but with no errors logged.
//!
//! \sa LoggingDetermineMergedRange
bool DetermineMergedRange(const MemorySnapshot* a,
                          const MemorySnapshot* b,
                          CheckedRange<uint64_t, size_t>* merged);

}  // namespace crashpad

#endif  // CRASHPAD_SNAPSHOT_MEMORY_SNAPSHOT_H_