2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-08-11 11:42:12 -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_MINIDUMP_MINIDUMP_MISC_INFO_WRITER_H_
|
|
|
|
|
#define CRASHPAD_MINIDUMP_MINIDUMP_MISC_INFO_WRITER_H_
|
|
|
|
|
|
2015-02-04 17:30:03 -08:00
|
|
|
|
#include <windows.h>
|
2014-08-11 11:42:12 -07:00
|
|
|
|
#include <dbghelp.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <time.h>
|
2020-09-12 09:20:14 +02:00
|
|
|
|
#include <wchar.h>
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2020-09-12 09:20:14 +02:00
|
|
|
|
#include "build/build_config.h"
|
2014-08-11 11:42:12 -07:00
|
|
|
|
#include "minidump/minidump_stream_writer.h"
|
|
|
|
|
#include "minidump/minidump_writable.h"
|
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
2014-11-05 18:15:19 -05:00
|
|
|
|
class ProcessSnapshot;
|
|
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
//! \brief Returns the string to set in MINIDUMP_MISC_INFO_4::DbgBldStr.
|
|
|
|
|
//!
|
|
|
|
|
//! dbghelp produces strings like `"dbghelp.i386,6.3.9600.16520"` and
|
|
|
|
|
//! `"dbghelp.amd64,6.3.9600.16520"`. This function mimics that format, and adds
|
|
|
|
|
//! the OS that wrote the minidump along with any relevant platform-specific
|
|
|
|
|
//! data describing the compilation environment.
|
|
|
|
|
//!
|
|
|
|
|
//! This function is an implementation detail of
|
|
|
|
|
//! MinidumpMiscInfoWriter::InitializeFromSnapshot() and is only exposed for
|
|
|
|
|
//! testing purposes.
|
|
|
|
|
std::string MinidumpMiscInfoDebugBuildString();
|
|
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
2014-08-11 11:42:12 -07:00
|
|
|
|
//! \brief The writer for a stream in the MINIDUMP_MISC_INFO family in a
|
|
|
|
|
//! minidump file.
|
|
|
|
|
//!
|
|
|
|
|
//! The actual stream written will be a MINIDUMP_MISC_INFO,
|
2017-03-01 12:59:24 -05:00
|
|
|
|
//! MINIDUMP_MISC_INFO_2, MINIDUMP_MISC_INFO_3, MINIDUMP_MISC_INFO_4, or
|
|
|
|
|
//! MINIDUMP_MISC_INFO_5 stream. Later versions of MINIDUMP_MISC_INFO are
|
|
|
|
|
//! supersets of earlier versions. The earliest version that supports all of the
|
|
|
|
|
//! information that an object of this class contains will be used.
|
2014-08-11 11:42:12 -07:00
|
|
|
|
class MinidumpMiscInfoWriter final : public internal::MinidumpStreamWriter {
|
|
|
|
|
public:
|
|
|
|
|
MinidumpMiscInfoWriter();
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
|
|
MinidumpMiscInfoWriter(const MinidumpMiscInfoWriter&) = delete;
|
|
|
|
|
MinidumpMiscInfoWriter& operator=(const MinidumpMiscInfoWriter&) = delete;
|
|
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
|
~MinidumpMiscInfoWriter() override;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
2014-11-05 18:15:19 -05:00
|
|
|
|
//! \brief Initializes MINIDUMP_MISC_INFO_N based on \a process_snapshot.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] process_snapshot The process snapshot to use as source data.
|
|
|
|
|
//!
|
|
|
|
|
//! \note Valid in #kStateMutable. No mutator methods may be called before
|
|
|
|
|
//! this method, and it is not normally necessary to call any mutator
|
|
|
|
|
//! methods after this method.
|
|
|
|
|
void InitializeFromSnapshot(const ProcessSnapshot* process_snapshot);
|
|
|
|
|
|
2014-08-11 11:42:12 -07:00
|
|
|
|
//! \brief Sets the field referenced by #MINIDUMP_MISC1_PROCESS_ID.
|
2014-11-05 18:15:19 -05:00
|
|
|
|
void SetProcessID(uint32_t process_id);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
|
|
//! \brief Sets the fields referenced by #MINIDUMP_MISC1_PROCESS_TIMES.
|
|
|
|
|
void SetProcessTimes(time_t process_create_time,
|
|
|
|
|
uint32_t process_user_time,
|
|
|
|
|
uint32_t process_kernel_time);
|
|
|
|
|
|
|
|
|
|
//! \brief Sets the fields referenced by #MINIDUMP_MISC1_PROCESSOR_POWER_INFO.
|
|
|
|
|
void SetProcessorPowerInfo(uint32_t processor_max_mhz,
|
|
|
|
|
uint32_t processor_current_mhz,
|
|
|
|
|
uint32_t processor_mhz_limit,
|
|
|
|
|
uint32_t processor_max_idle_state,
|
|
|
|
|
uint32_t processor_current_idle_state);
|
|
|
|
|
|
|
|
|
|
//! \brief Sets the field referenced by #MINIDUMP_MISC3_PROCESS_INTEGRITY.
|
|
|
|
|
void SetProcessIntegrityLevel(uint32_t process_integrity_level);
|
|
|
|
|
|
|
|
|
|
//! \brief Sets the field referenced by #MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS.
|
|
|
|
|
void SetProcessExecuteFlags(uint32_t process_execute_flags);
|
|
|
|
|
|
|
|
|
|
//! \brief Sets the field referenced by #MINIDUMP_MISC3_PROTECTED_PROCESS.
|
|
|
|
|
void SetProtectedProcess(uint32_t protected_process);
|
|
|
|
|
|
|
|
|
|
//! \brief Sets the fields referenced by #MINIDUMP_MISC3_TIMEZONE.
|
|
|
|
|
void SetTimeZone(uint32_t time_zone_id,
|
|
|
|
|
int32_t bias,
|
|
|
|
|
const std::string& standard_name,
|
|
|
|
|
const SYSTEMTIME& standard_date,
|
|
|
|
|
int32_t standard_bias,
|
|
|
|
|
const std::string& daylight_name,
|
|
|
|
|
const SYSTEMTIME& daylight_date,
|
|
|
|
|
int32_t daylight_bias);
|
|
|
|
|
|
|
|
|
|
//! \brief Sets the fields referenced by #MINIDUMP_MISC4_BUILDSTRING.
|
|
|
|
|
void SetBuildString(const std::string& build_string,
|
|
|
|
|
const std::string& debug_build_string);
|
|
|
|
|
|
2017-03-01 12:59:24 -05:00
|
|
|
|
// TODO(mark): Provide a better interface than this. Don’t force callers to
|
|
|
|
|
// build their own XSTATE_CONFIG_FEATURE_MSC_INFO structure.
|
|
|
|
|
//
|
|
|
|
|
//! \brief Sets MINIDUMP_MISC_INFO_5::XStateData.
|
|
|
|
|
void SetXStateData(const XSTATE_CONFIG_FEATURE_MSC_INFO& xstate_data);
|
|
|
|
|
|
2022-05-14 22:40:24 -07:00
|
|
|
|
//! \brief Will this write extended context information?
|
|
|
|
|
bool HasXStateData() const;
|
|
|
|
|
|
2017-03-01 12:59:24 -05:00
|
|
|
|
//! \brief Sets the field referenced by #MINIDUMP_MISC5_PROCESS_COOKIE.
|
|
|
|
|
void SetProcessCookie(uint32_t process_cookie);
|
|
|
|
|
|
2014-08-11 11:42:12 -07:00
|
|
|
|
protected:
|
|
|
|
|
// MinidumpWritable:
|
2014-10-14 11:11:57 -04:00
|
|
|
|
bool Freeze() override;
|
|
|
|
|
size_t SizeOfObject() override;
|
|
|
|
|
bool WriteObject(FileWriterInterface* file_writer) override;
|
|
|
|
|
MinidumpStreamType StreamType() const override;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
//! \brief Returns the size of the object to be written based on
|
|
|
|
|
//! MINIDUMP_MISC_INFO_N::Flags1.
|
|
|
|
|
//!
|
|
|
|
|
//! The smallest defined structure type in the MINIDUMP_MISC_INFO family that
|
|
|
|
|
//! can hold all of the data that has been populated will be used.
|
|
|
|
|
size_t CalculateSizeOfObjectFromFlags() const;
|
|
|
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_N misc_info_;
|
2017-03-01 12:59:24 -05:00
|
|
|
|
bool has_xstate_data_;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
};
|
|
|
|
|
|
2021-03-08 17:31:04 +01:00
|
|
|
|
//! \brief Conversion functions from a native UTF16 C-string to a char16_t
|
|
|
|
|
//! C-string. No-op where the native UTF16 string is std::u16string.
|
2023-11-06 18:22:47 -08:00
|
|
|
|
#if defined(WCHAR_T_IS_16_BIT) || DOXYGEN
|
2021-03-08 17:31:04 +01:00
|
|
|
|
inline const char16_t* AsU16CStr(const wchar_t* str) {
|
|
|
|
|
return reinterpret_cast<const char16_t*>(str);
|
2020-09-12 09:20:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 17:31:04 +01:00
|
|
|
|
inline char16_t* AsU16CStr(wchar_t* str) {
|
|
|
|
|
return reinterpret_cast<char16_t*>(str);
|
2020-09-12 09:20:14 +02:00
|
|
|
|
}
|
|
|
|
|
#else
|
2021-03-08 17:31:04 +01:00
|
|
|
|
inline const char16_t* AsU16CStr(const char16_t* str) {
|
2020-09-12 09:20:14 +02:00
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 17:31:04 +01:00
|
|
|
|
inline char16_t* AsU16CStr(char16_t* str) {
|
2020-09-12 09:20:14 +02:00
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-08-11 11:42:12 -07:00
|
|
|
|
} // namespace crashpad
|
|
|
|
|
|
|
|
|
|
#endif // CRASHPAD_MINIDUMP_MINIDUMP_MISC_INFO_WRITER_H_
|