2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2018 The Crashpad Authors
|
2018-06-11 09:38:24 -07:00
|
|
|
//
|
|
|
|
// 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_SANITIZED_PROCESS_SNAPSHOT_SANITIZED_H_
|
|
|
|
#define CRASHPAD_SNAPSHOT_SANITIZED_PROCESS_SNAPSHOT_SANITIZED_H_
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "snapshot/exception_snapshot.h"
|
|
|
|
#include "snapshot/process_snapshot.h"
|
|
|
|
#include "snapshot/sanitized/module_snapshot_sanitized.h"
|
|
|
|
#include "snapshot/sanitized/thread_snapshot_sanitized.h"
|
|
|
|
#include "snapshot/thread_snapshot.h"
|
|
|
|
#include "snapshot/unloaded_module_snapshot.h"
|
|
|
|
#include "util/misc/address_types.h"
|
|
|
|
#include "util/misc/initialization_state_dcheck.h"
|
|
|
|
#include "util/misc/range_set.h"
|
2019-04-24 11:22:35 -04:00
|
|
|
#include "util/process/process_id.h"
|
2019-08-15 12:38:52 -07:00
|
|
|
#include "util/process/process_memory_sanitized.h"
|
2018-06-11 09:38:24 -07:00
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
//! \brief A ProcessSnapshot which wraps and filters sensitive information from
|
|
|
|
//! another ProcessSnapshot.
|
|
|
|
class ProcessSnapshotSanitized final : public ProcessSnapshot {
|
|
|
|
public:
|
|
|
|
ProcessSnapshotSanitized();
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
ProcessSnapshotSanitized(const ProcessSnapshotSanitized&) = delete;
|
|
|
|
ProcessSnapshotSanitized& operator=(const ProcessSnapshotSanitized&) = delete;
|
|
|
|
|
2018-06-11 09:38:24 -07:00
|
|
|
~ProcessSnapshotSanitized() override;
|
|
|
|
|
|
|
|
//! \brief Initializes this object.
|
|
|
|
//!
|
|
|
|
//! This method must be successfully called before calling any other method on
|
|
|
|
//! this object.
|
|
|
|
//!
|
|
|
|
//! \param[in] snapshot The ProcessSnapshot to sanitize.
|
2020-08-06 13:48:45 -07:00
|
|
|
//! \param[in] allowed_annotations A list of annotations names to allow to
|
2018-06-11 09:38:24 -07:00
|
|
|
//! be returned by AnnotationsSimpleMap() or from this object's module
|
|
|
|
//! snapshots. If `nullptr`, all annotations will be returned.
|
2023-09-29 15:54:13 +00:00
|
|
|
// These annotation names support pattern matching, eg: "switch-*"
|
2020-08-06 13:48:45 -07:00
|
|
|
//! \param[in] allowed_memory_ranges A list of memory ranges to allow to be
|
2020-04-27 10:54:20 -04:00
|
|
|
//! accessible via Memory(), or `nullptr` to allow all ranges.
|
2018-06-11 09:38:24 -07:00
|
|
|
//! \param[in] target_module_address An address in the target process'
|
|
|
|
//! address space within the bounds of a module to target. If the
|
|
|
|
//! crashing thread's context and stack do not contain any pointers into
|
|
|
|
//! this module's address range, this method will return `false`. If this
|
|
|
|
//! value is 0, this method will not check the context or stack for
|
|
|
|
//! references to any particular module.
|
|
|
|
//! \param[in] sanitize_stacks If `true`, the MemorySnapshots for each
|
|
|
|
//! thread's stack will be filtered using an
|
|
|
|
//! internal::StackSnapshotSanitized.
|
|
|
|
//! \return `false` if \a snapshot does not meet sanitization requirements and
|
|
|
|
//! should be filtered entirely. Otherwise `true`.
|
2019-08-27 15:25:49 -07:00
|
|
|
bool Initialize(
|
|
|
|
const ProcessSnapshot* snapshot,
|
2020-08-06 13:48:45 -07:00
|
|
|
std::unique_ptr<const std::vector<std::string>> allowed_annotations,
|
2019-08-27 15:25:49 -07:00
|
|
|
std::unique_ptr<const std::vector<std::pair<VMAddress, VMAddress>>>
|
2020-08-06 13:48:45 -07:00
|
|
|
allowed_memory_ranges,
|
2019-08-27 15:25:49 -07:00
|
|
|
VMAddress target_module_address,
|
|
|
|
bool sanitize_stacks);
|
2018-06-11 09:38:24 -07:00
|
|
|
|
|
|
|
// ProcessSnapshot:
|
|
|
|
|
2019-04-24 11:22:35 -04:00
|
|
|
crashpad::ProcessID ProcessID() const override;
|
|
|
|
crashpad::ProcessID ParentProcessID() const override;
|
2018-06-11 09:38:24 -07:00
|
|
|
void SnapshotTime(timeval* snapshot_time) const override;
|
|
|
|
void ProcessStartTime(timeval* start_time) const override;
|
|
|
|
void ProcessCPUTimes(timeval* user_time, timeval* system_time) const override;
|
|
|
|
void ReportID(UUID* report_id) const override;
|
|
|
|
void ClientID(UUID* client_id) const override;
|
|
|
|
const std::map<std::string, std::string>& AnnotationsSimpleMap()
|
|
|
|
const override;
|
|
|
|
const SystemSnapshot* System() const override;
|
|
|
|
std::vector<const ThreadSnapshot*> Threads() const override;
|
|
|
|
std::vector<const ModuleSnapshot*> Modules() const override;
|
|
|
|
std::vector<UnloadedModuleSnapshot> UnloadedModules() const override;
|
|
|
|
const ExceptionSnapshot* Exception() const override;
|
|
|
|
std::vector<const MemoryMapRegionSnapshot*> MemoryMap() const override;
|
|
|
|
std::vector<HandleSnapshot> Handles() const override;
|
|
|
|
std::vector<const MemorySnapshot*> ExtraMemory() const override;
|
2018-11-14 10:20:20 -08:00
|
|
|
const ProcessMemory* Memory() const override;
|
2018-06-11 09:38:24 -07:00
|
|
|
|
|
|
|
private:
|
2020-08-06 13:48:45 -07:00
|
|
|
// Only used when allowed_annotations_ != nullptr.
|
2018-06-11 09:38:24 -07:00
|
|
|
std::vector<std::unique_ptr<internal::ModuleSnapshotSanitized>> modules_;
|
|
|
|
|
|
|
|
// Only used when sanitize_stacks_ == true.
|
|
|
|
std::vector<std::unique_ptr<internal::ThreadSnapshotSanitized>> threads_;
|
|
|
|
|
|
|
|
RangeSet address_ranges_;
|
|
|
|
const ProcessSnapshot* snapshot_;
|
2019-08-15 12:38:52 -07:00
|
|
|
ProcessMemorySanitized process_memory_;
|
2020-08-06 13:48:45 -07:00
|
|
|
std::unique_ptr<const std::vector<std::string>> allowed_annotations_;
|
2018-06-11 09:38:24 -07:00
|
|
|
bool sanitize_stacks_;
|
|
|
|
InitializationStateDcheck initialized_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace crashpad
|
|
|
|
|
|
|
|
#endif // CRASHPAD_SNAPSHOT_SANITIZED_PROCESS_SNAPSHOT_SANITIZED_H_
|