Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,28 @@
// Copyright 2016 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_ADDRESS_SANITIZER_H_
#define CRASHPAD_UTIL_MISC_ADDRESS_SANITIZER_H_
#include "base/compiler_specific.h"
#include "build/build_config.h"
#if !defined(ADDRESS_SANITIZER)
#if HAS_FEATURE(address_sanitizer) || \
(defined(COMPILER_GCC) && defined(__SANITIZE_ADDRESS__))
#define ADDRESS_SANITIZER 1
#endif
#endif // !defined(ADDRESS_SANITIZER)
#endif // CRASHPAD_UTIL_MISC_ADDRESS_SANITIZER_H_
@@ -0,0 +1,69 @@
// Copyright 2017 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_ADDRESS_TYPES_H_
#define CRASHPAD_UTIL_MISC_ADDRESS_TYPES_H_
#include <stdint.h>
#include <type_traits>
#include "build/build_config.h"
#if defined(OS_MACOSX)
#include <mach/mach_types.h>
#elif defined(OS_WIN)
#include "util/win/address_types.h"
#elif defined(OS_LINUX) || defined(OS_ANDROID)
#include "util/linux/address_types.h"
#else
#error "Unhandled OS type"
#endif
namespace crashpad {
#if DOXYGEN
//! \brief Type used to represent an address in a process, potentially across
//! bitness.
using VMAddress = uint64_t;
//! \brief Type used to represent the size of a memory range (with a
//! VMAddress), potentially across bitness.
using VMSize = uint64_t;
#elif defined(OS_MACOSX)
using VMAddress = mach_vm_address_t;
using VMSize = mach_vm_size_t;
#elif defined(OS_WIN)
using VMAddress = WinVMAddress;
using VMSize = WinVMSize;
#elif defined(OS_LINUX) || defined(OS_ANDROID)
using VMAddress = LinuxVMAddress;
using VMSize = LinuxVMSize;
#endif
//! \brief Type used to represent an offset from a VMAddress, potentially
//! across bitness.
using VMOffset = std::make_signed<VMSize>::type;
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_ADDRESS_TYPES_H_
@@ -0,0 +1,27 @@
// Copyright 2016 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_ARRAYSIZE_UNSAFE_H_
#define CRASHPAD_UTIL_MISC_ARRAYSIZE_UNSAFE_H_
//! \file
//! \brief Not the safest way of computing an arrays size…
//!
//! `#%include "base/macros.h"` and use its `arraysize()` instead. This macro
//! should only be used in rare situations where `arraysize()` does not
//! function.
#define ARRAYSIZE_UNSAFE(array) (sizeof(array) / sizeof(array[0]))
#endif // CRASHPAD_UTIL_MISC_ARRAYSIZE_UNSAFE_H_
@@ -0,0 +1,34 @@
// Copyright 2017 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_AS_UNDERLYING_TYPE_H_
#define CRASHPAD_UTIL_MISC_AS_UNDERLYING_TYPE_H_
#include <type_traits>
namespace crashpad {
//! \brief Casts a value to its underlying type.
//!
//! \param[in] from The value to be casted.
//! \return \a from casted to its underlying type.
template <typename From>
constexpr typename std::underlying_type<From>::type AsUnderlyingType(
From from) {
return static_cast<typename std::underlying_type<From>::type>(from);
}
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_AS_UNDERLYING_TYPE_H_
+52
View File
@@ -0,0 +1,52 @@
// Copyright 2014 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_CLOCK_H_
#define CRASHPAD_UTIL_MISC_CLOCK_H_
#include <stdint.h>
#include "build/build_config.h"
namespace crashpad {
//! \brief Returns the value of the systems monotonic clock.
//!
//! The monotonic clock is a tick counter whose epoch is unspecified. It is a
//! monotonically-increasing clock that cannot be set, and never jumps backwards
//! on a running system. The monotonic clock may stop while the system is
//! sleeping, and it may be reset when the system starts up. This clock is
//! suitable for computing durations of events. Subject to the underlying
//! clocks resolution, successive calls to this function will result in a
//! series of increasing values.
//!
//! \return The value of the systems monotonic clock, in nanoseconds.
uint64_t ClockMonotonicNanoseconds();
#if !defined(OS_WIN) // Not implemented on Windows yet.
//! \brief Sleeps for the specified duration.
//!
//! \param[in] nanoseconds The number of nanoseconds to sleep. The actual sleep
//! may be slightly longer due to latencies and timer resolution.
//!
//! This function is resilient against the underlying `nanosleep()` system call
//! being interrupted by a signal.
void SleepNanoseconds(uint64_t nanoseconds);
#endif
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_CLOCK_H_
@@ -0,0 +1,95 @@
// Copyright 2017 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_FROM_POINTER_CAST_H_
#define CRASHPAD_UTIL_MISC_FROM_POINTER_CAST_H_
#include <stdint.h>
#include <cstddef>
#include <type_traits>
#include "base/numerics/safe_conversions.h"
namespace crashpad {
#if DOXYGEN
//! \brief Casts from a pointer type to an integer.
//!
//! Compared to `reinterpret_cast<>()`, FromPointerCast<>() defines whether a
//! pointer type is sign-extended or zero-extended. Casts to signed integral
//! types are sign-extended. Casts to unsigned integral types are zero-extended.
//!
//! Use FromPointerCast<>() instead of `reinterpret_cast<>()` when casting a
//! pointer to an integral type that may not be the same width as a pointer.
//! There is no need to prefer FromPointerCast<>() when casting to an integral
//! type thats definitely the same width as a pointer, such as `uintptr_t` and
//! `intptr_t`.
template <typename To, typename From>
FromPointerCast(From from) {
return reinterpret_cast<To>(from);
}
#else // DOXYGEN
// Cast std::nullptr_t to any type.
//
// In C++14, the nullptr_t check could use std::is_null_pointer<From>::value
// instead of the is_same<remove_cv<From>::type, nullptr_t>::type construct.
template <typename To, typename From>
typename std::enable_if<
std::is_same<typename std::remove_cv<From>::type, std::nullptr_t>::value,
To>::type
FromPointerCast(From) {
return To();
}
// Cast a pointer to any other pointer type.
template <typename To, typename From>
typename std::enable_if<std::is_pointer<From>::value &&
std::is_pointer<To>::value,
To>::type
FromPointerCast(From from) {
return reinterpret_cast<To>(from);
}
// Cast a pointer to an integral type. Sign-extend when casting to a signed
// type, zero-extend when casting to an unsigned type.
template <typename To, typename From>
typename std::enable_if<std::is_pointer<From>::value &&
std::is_integral<To>::value,
To>::type
FromPointerCast(From from) {
const auto intermediate =
reinterpret_cast<typename std::conditional<std::is_signed<To>::value,
intptr_t,
uintptr_t>::type>(from);
if (sizeof(To) >= sizeof(From)) {
// If the destination integral type is at least as wide as the source
// pointer type, use static_cast<>() and just return it.
return static_cast<To>(intermediate);
}
// If the destination integral type is narrower than the source pointer type,
// use checked_cast<>().
return base::checked_cast<To>(intermediate);
}
#endif // DOXYGEN
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_FROM_POINTER_CAST_H_
@@ -0,0 +1,44 @@
// Copyright 2015 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_IMPLICIT_CAST_H_
#define CRASHPAD_UTIL_MISC_IMPLICIT_CAST_H_
namespace crashpad {
// Use implicit_cast as a safe version of static_cast or const_cast
// for upcasting in the type hierarchy (i.e. casting a pointer to Foo
// to a pointer to SuperclassOfFoo or casting a pointer to Foo to
// a const pointer to Foo).
// When you use implicit_cast, the compiler checks that the cast is safe.
// Such explicit implicit_casts are necessary in surprisingly many
// situations where C++ demands an exact type match instead of an
// argument type convertible to a target type.
//
// The From type can be inferred, so the preferred syntax for using
// implicit_cast is the same as for static_cast etc.:
//
// implicit_cast<ToType>(expr)
//
// implicit_cast would have been part of the C++ standard library,
// but the proposal was submitted too late. It will probably make
// its way into the language in the future.
template<typename To, typename From>
inline To implicit_cast(From const &f) {
return f;
}
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_IMPLICIT_CAST_H_
@@ -0,0 +1,100 @@
// Copyright 2014 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_INITIALIZATION_INITIALIZATION_STATE_H_
#define CRASHPAD_UTIL_MISC_INITIALIZATION_INITIALIZATION_STATE_H_
#include <stdint.h>
#include "base/macros.h"
namespace crashpad {
//! \brief Tracks whether data are initialized.
//!
//! Objects of this type track whether the data theyre guarding are
//! initialized. The three possible states are uninitialized (the initial
//! state), initializing, and valid. As the guarded data are initialized, an
//! InitializationState object will normally transition through these three
//! states. A fourth state corresponds to the destruction of objects of this
//! type, making it less likely that a use-after-free of an InitializationState
//! object will appear in the valid state.
//!
//! If the only purpose for tracking the initialization state of guarded data is
//! to DCHECK when the object is in an unexpected state, use
//! InitializationStateDcheck instead.
class InitializationState {
public:
//! \brief The objects state.
enum State : uint8_t {
//! \brief The object has not yet been initialized.
kStateUninitialized = 0,
//! \brief The object is being initialized.
//!
//! This state protects against attempted reinitializaton of
//! partially-initialized objects whose initial initialization attempt
//! failed. This state is to be used while objects are initializing, but are
//! not yet fully initialized.
kStateInvalid,
//! \brief The object has been initialized.
kStateValid,
//! \brief The object has been destroyed.
kStateDestroyed,
};
InitializationState() : state_(kStateUninitialized) {}
~InitializationState() { state_ = kStateDestroyed; }
//! \brief Returns `true` if the objects state is #kStateUninitialized and it
//! is safe to begin initializing it.
bool is_uninitialized() const { return state_ == kStateUninitialized; }
//! \brief Sets the objects state to #kStateInvalid, marking initialization
//! as being in process.
void set_invalid() { state_ = kStateInvalid; }
//! \brief Sets the objects state to #kStateValid, marking it initialized.
void set_valid() { state_ = kStateValid; }
//! \brief Returns `true` if the the objects state is #kStateValid and it has
//! been fully initialized and may be used.
bool is_valid() const { return state_ == kStateValid; }
protected:
//! \brief Returns the objects state.
//!
//! Consumers of this class should use an is_state_*() method instead.
State state() const { return state_; }
//! \brief Sets the objects state.
//!
//! Consumers of this class should use a set_state_*() method instead.
void set_state(State state) { state_ = state; }
private:
// state_ is volatile to ensure that itll be set by the destructor when it
// runs. Otherwise, optimizations might prevent it from ever being set to
// kStateDestroyed, limiting this class ability to catch use-after-free
// errors.
volatile State state_;
DISALLOW_COPY_AND_ASSIGN(InitializationState);
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_INITIALIZATION_INITIALIZATION_STATE_H_
@@ -0,0 +1,188 @@
// Copyright 2014 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_INITIALIZATION_INITIALIZATION_STATE_DCHECK_H_
#define CRASHPAD_UTIL_MISC_INITIALIZATION_INITIALIZATION_STATE_DCHECK_H_
//! \file
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "util/misc/initialization_state.h"
namespace crashpad {
#if DCHECK_IS_ON() || DOXYGEN
//! \brief Tracks whether data are initialized, triggering a DCHECK assertion
//! on an invalid data access.
//!
//! Put an InitializationStateDcheck member into a class to help DCHECK that
//! its in the right states at the right times. This is useful for classes with
//! Initialize() methods. The chief advantage of InitializationStateDcheck over
//! having a member variable to track state is that when the only use of the
//! variable is to DCHECK, it wastes space (in memory and executable code) in
//! non-DCHECK builds unless the code is also peppered with ugly `#%ifdef`s.
//!
//! This implementation concentrates the ugly `#%ifdef`s in one location.
//!
//! Usage:
//!
//! \code
//! class Class {
//! public:
//! Class() : initialized_() {}
//!
//! void Initialize() {
//! INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
//! // Perform initialization.
//! INITIALIZATION_STATE_SET_VALID(initialized_);
//! }
//!
//! void DoSomething() {
//! INITIALIZATION_STATE_DCHECK_VALID(initialized_);
//! // Do something.
//! }
//!
//! private:
//! InitializationStateDcheck initialized_;
//! };
//! \endcode
class InitializationStateDcheck : public InitializationState {
public:
InitializationStateDcheck() : InitializationState() {}
//! \brief Returns the objects state.
//!
//! Consumers of this class should not call this method. Use the
//! INITIALIZATION_STATE_SET_INITIALIZING(), INITIALIZATION_STATE_SET_VALID(),
//! and INITIALIZATION_STATE_DCHECK_VALID() macros instead.
//
// The superclass state() accessor is protected, but it needs to be exposed
// to consumers of this class for the macros below to work properly. The
// macros prefer access to the unerlying state value over a simple boolean
// because with access to the state value, DCHECK_EQ can be used, which, when
// tripped, prints both the expected and observed values. This can aid
// troubleshooting.
State state() const { return InitializationState::state(); }
//! \brief Marks an uninitialized object as initializing.
//!
//! If the object is in the #kStateUninitialized state, changes its state to
//! #kStateInvalid (initializing) and returns the previous
//! (#kStateUninitialized) state. Otherwise, returns the objects current
//! state.
//!
//! Consumers of this class should not call this method. Use the
//! INITIALIZATION_STATE_SET_INITIALIZING() macro instead.
State SetInitializing();
//! \brief Marks an initializing object as valid.
//!
//! If the object is in the #kStateInvalid (initializing) state, changes its
//! state to #kStateValid and returns the previous (#kStateInvalid) state.
//! Otherwise, returns the objects current state.
//!
//! Consumers of this class should not call this method. Use the
//! INITIALIZATION_STATE_SET_VALID() macro instead.
State SetValid();
private:
DISALLOW_COPY_AND_ASSIGN(InitializationStateDcheck);
};
// Using macros enables the non-DCHECK no-op implementation below to be more
// compact and less intrusive. These are macros instead of methods that call
// DCHECK to enable the DCHECK failure message to point to the correct file and
// line number, and to allow additional messages to be streamed on failure with
// the << operator.
//! \brief Checks that a crashpad::InitializationStateDcheck object is in the
//! crashpad::InitializationState::kStateUninitialized state, and changes
//! its state to initializing
//! (crashpad::InitializationState::kStateInvalid).
//!
//! If the object is not in the correct state, a DCHECK assertion is triggered
//! and the objects state remains unchanged.
//!
//! \param[in] initialization_state_dcheck A crashpad::InitializationStateDcheck
//! object.
//!
//! \sa crashpad::InitializationStateDcheck
#define INITIALIZATION_STATE_SET_INITIALIZING(initialization_state_dcheck) \
DCHECK_EQ((initialization_state_dcheck).SetInitializing(), \
(initialization_state_dcheck).kStateUninitialized)
//! \brief Checks that a crashpad::InitializationStateDcheck object is in the
//! initializing (crashpad::InitializationState::kStateInvalid) state, and
//! changes its state to crashpad::InitializationState::kStateValid.
//!
//! If the object is not in the correct state, a DCHECK assertion is triggered
//! and the objects state remains unchanged.
//!
//! \param[in] initialization_state_dcheck A crashpad::InitializationStateDcheck
//! object.
//!
//! \sa crashpad::InitializationStateDcheck
#define INITIALIZATION_STATE_SET_VALID(initialization_state_dcheck) \
DCHECK_EQ((initialization_state_dcheck).SetValid(), \
(initialization_state_dcheck).kStateInvalid)
//! \brief Checks that a crashpad::InitializationStateDcheck object is in the
//! crashpad::InitializationState::kStateValid state.
//!
//! If the object is not in the correct state, a DCHECK assertion is triggered.
//!
//! \param[in] initialization_state_dcheck A crashpad::InitializationStateDcheck
//! object.
//!
//! \sa crashpad::InitializationStateDcheck
#define INITIALIZATION_STATE_DCHECK_VALID(initialization_state_dcheck) \
DCHECK_EQ((initialization_state_dcheck).state(), \
(initialization_state_dcheck).kStateValid)
#else
#if defined(COMPILER_MSVC)
// bool[0] (below) is not accepted by MSVC.
struct InitializationStateDcheck {
};
#else
// Since this is to be used as a DCHECK (for debugging), it should be
// non-intrusive in non-DCHECK (non-debug, release) builds. An empty struct
// would still have a nonzero size (rationale:
// http://www.stroustrup.com/bs_faq2.html#sizeof-empty). Zero-length arrays are
// technically invalid according to the standard, but clang and g++ accept them
// without complaint even with warnings turned up. They take up no space at all,
// and they can be “initialized” with the same () syntax used to initialize
// objects of the DCHECK_IS_ON() InitializationStateDcheck class above.
using InitializationStateDcheck = bool[0];
#endif // COMPILER_MSVC
// Avoid triggering warnings by repurposing these macros when DCHECKs are
// disabled.
#define INITIALIZATION_STATE_SET_INITIALIZING(initialization_state_dcheck) \
ALLOW_UNUSED_LOCAL(initialization_state_dcheck)
#define INITIALIZATION_STATE_SET_VALID(initialization_state_dcheck) \
ALLOW_UNUSED_LOCAL(initialization_state_dcheck)
#define INITIALIZATION_STATE_DCHECK_VALID(initialization_state_dcheck) \
ALLOW_UNUSED_LOCAL(initialization_state_dcheck)
#endif
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_INITIALIZATION_INITIALIZATION_STATE_DCHECK_H_
+44
View File
@@ -0,0 +1,44 @@
// Copyright 2017 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_LEXING_H_
#define CRASHPAD_UTIL_MISC_LEXING_H_
namespace crashpad {
//! \brief Match a pattern at the start of a char string.
//!
//! \param[in,out] input A pointer to the char string to match against. \a input
//! is advanced past the matched pattern if it is found.
//! \param[in] pattern The pattern to match at the start of \a input.
//! \return `true` if the pattern is matched exactly and \a input is advanced,
//! otherwise `false`.
bool AdvancePastPrefix(const char** input, const char* pattern);
//! \brief Convert a prefix of a char string to a numeric value.
//!
//! Valid values are positive or negative decimal numbers, matching the regular
//! expression "-?\d+", and within the limits of T.
//!
//! \param[in,out] input A pointer to the char string to match against. \a input
//! is advanced past the number if one is found.
//! \param[out] value The converted number, if one is found.
//! \return `true` if a number is found at the start of \a input and \a input is
//! advanced, otherwise `false`.
template <typename T>
bool AdvancePastNumber(const char** input, T* value);
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_LEXING_H
+185
View File
@@ -0,0 +1,185 @@
// Copyright 2016 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_METRICS_H_
#define CRASHPAD_UTIL_MISC_METRICS_H_
#include <inttypes.h>
#include "base/macros.h"
#include "util/file/file_io.h"
namespace crashpad {
//! \brief Container class to hold shared UMA metrics integration points.
//!
//! Each static function in this class will call a `UMA_*` from
//! `base/metrics/histogram_macros.h`. When building Crashpad standalone,
//! (against mini_chromium), these macros do nothing. When built against
//! Chromium's base, they allow integration with its metrics system.
class Metrics {
public:
//! \brief Values for CrashReportPending().
//!
//! \note These are used as metrics enumeration values, so new values should
//! always be added at the end, before PendingReportReason::kMaxValue.
enum class PendingReportReason : int32_t {
//! \brief A report was newly created and is ready for upload.
kNewlyCreated = 0,
//! \brief The user manually requested the report be uploaded.
kUserInitiated = 1,
//! \brief The number of values in this enumeration; not a valid value.
kMaxValue
};
//! \brief Reports when a crash upload has entered the pending state.
static void CrashReportPending(PendingReportReason reason);
//! \brief Reports the size of a crash report file in bytes. Should be called
//! when a new report is written to disk.
static void CrashReportSize(FileHandle file);
//! \brief Reports on a crash upload attempt, and if it succeeded.
static void CrashUploadAttempted(bool successful);
//! \brief Values for CrashUploadSkipped().
//!
//! \note These are used as metrics enumeration values, so new values should
//! always be added at the end, before CrashSkippedReason::kMaxValue.
enum class CrashSkippedReason : int32_t {
//! \brief Crash uploading is disabled.
kUploadsDisabled = 0,
//! \brief There was another upload too recently, so this one was throttled.
kUploadThrottled = 1,
//! \brief The report had an unexpected timestamp.
kUnexpectedTime = 2,
//! \brief The database reported an error, likely due to a filesystem
//! problem.
kDatabaseError = 3,
//! \brief The upload of the crash failed during communication with the
//! server.
kUploadFailed = 4,
//! \brief The upload of the crash failed during communication with the
//! server.
kUserRefused = 5,
//! \brief The number of values in this enumeration; not a valid value.
kMaxValue
};
//! \brief Reports when a report is moved to the completed state in the
//! database, without the report being uploadad.
static void CrashUploadSkipped(CrashSkippedReason reason);
//! \brief The result of capturing an exception.
//!
//! \note These are used as metrics enumeration values, so new values should
//! always be added at the end, before CaptureResult::kMaxValue.
enum class CaptureResult : int32_t {
//! \brief The exception capture succeeded normally.
kSuccess = 0,
//! \brief Unexpected exception behavior.
//!
//! This value is only used on macOS.
kUnexpectedExceptionBehavior = 1,
//! \brief Failed due to attempt to suspend self.
//!
//! This value is only used on macOS.
kFailedDueToSuspendSelf = 2,
//! \brief The process snapshot could not be captured.
kSnapshotFailed = 3,
//! \brief The exception could not be initialized.
kExceptionInitializationFailed = 4,
//! \brief The attempt to prepare a new crash report in the crash database
//! failed.
kPrepareNewCrashReportFailed = 5,
//! \brief Writing the minidump to disk failed.
kMinidumpWriteFailed = 6,
//! \brief There was a database error in attempt to complete the report.
kFinishedWritingCrashReportFailed = 7,
//! \brief The number of values in this enumeration; not a valid value.
kMaxValue
};
//! \brief Reports on the outcome of capturing a report in the exception
//! handler. Should be called on all capture completion paths.
static void ExceptionCaptureResult(CaptureResult result);
//! \brief The exception code for an exception was retrieved.
//!
//! These values are OS-specific, and correspond to
//! MINIDUMP_EXCEPTION::ExceptionCode.
static void ExceptionCode(uint32_t exception_code);
//! \brief The exception handler server started capturing an exception.
static void ExceptionEncountered();
//! \brief An important event in a handler process lifetime.
//!
//! \note These are used as metrics enumeration values, so new values should
//! always be added at the end, before LifetimeMilestone::kMaxValue.
enum class LifetimeMilestone : int32_t {
//! \brief The handler process started.
kStarted = 0,
//! \brief The handler process exited normally and cleanly.
kExitedNormally,
//! \brief The handler process exited early, but was successful in
//! performing some non-default action on user request.
kExitedEarly,
//! \brief The handler process exited with a failure code.
kFailed,
//! \brief The handler process was forcibly terminated.
kTerminated,
//! \brief The handler process crashed.
kCrashed,
//! \brief The number of values in this enumeration; not a valid value.
kMaxValue
};
//! \brief Records a handler start/exit/crash event.
static void HandlerLifetimeMilestone(LifetimeMilestone milestone);
//! \brief The handler process crashed with the given exception code.
//!
//! This is currently only reported on Windows.
static void HandlerCrashed(uint32_t exception_code);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Metrics);
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_METRICS_H_
+40
View File
@@ -0,0 +1,40 @@
// Copyright 2017 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_PATHS_H_
#define CRASHPAD_UTIL_PATHS_H_
#include "base/files/file_path.h"
#include "base/macros.h"
namespace crashpad {
//! \brief Functions to obtain paths.
class Paths {
public:
//! \brief Obtains the pathname of the currently-running executable.
//!
//! \param[out] path The pathname of the currently-running executable.
//!
//! \return `true` on success. `false` on failure, with a message logged.
//!
//! \note In test code, use test::TestPaths::Executable() instead.
static bool Executable(base::FilePath* path);
DISALLOW_IMPLICIT_CONSTRUCTORS(Paths);
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_TEST_PATHS_H_
@@ -0,0 +1,133 @@
// Copyright 2015 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_PDB_STRUCTURES_H_
#define CRASHPAD_UTIL_MISC_PDB_STRUCTURES_H_
#include <stdint.h>
#include "util/misc/uuid.h"
namespace crashpad {
//! \brief A CodeView record linking to a `.pdb` 2.0 file.
//!
//! This format provides an indirect link to debugging data by referencing an
//! external `.pdb` file by its name, timestamp, and age. This structure may be
//! pointed to by MINIDUMP_MODULE::CvRecord. It has been superseded by
//! CodeViewRecordPDB70.
//!
//! For more information about this structure and format, see <a
//! href="http://www.debuginfo.com/articles/debuginfomatch.html#pdbfiles">Matching
//! Debug Information</a>, PDB Files, and <a
//! href="http://undocumented.rawol.com/sbs-w2k-1-windows-2000-debugging-support.pdf#page=63">Undocumented
//! Windows 2000 Secrets</a>, Windows 2000 Debugging Support/Microsoft Symbol
//! File Internals/CodeView Subsections.
//!
//! \sa IMAGE_DEBUG_MISC
struct CodeViewRecordPDB20 {
//! \brief The magic number identifying this structure version, stored in
//! #signature.
//!
//! In a hex dump, this will appear as “NB10” when produced by a little-endian
//! machine.
static const uint32_t kSignature = '01BN';
//! \brief The magic number identifying this structure version, the value of
//! #kSignature.
uint32_t signature;
//! \brief The offset to CodeView data.
//!
//! In this structure, this field always has the value `0` because no CodeView
//! data is present, there is only a link to CodeView data stored in an
//! external file.
uint32_t offset;
//! \brief The time that the `.pdb` file was created, in `time_t` format, the
//! number of seconds since the POSIX epoch.
uint32_t timestamp;
//! \brief The revision of the `.pdb` file.
//!
//! A `.pdb` files age indicates incremental changes to it. When a `.pdb`
//! file is created, it has age `1`, and subsequent updates increase this
//! value.
uint32_t age;
//! \brief The path or file name of the `.pdb` file associated with the
//! module.
//!
//! This is a NUL-terminated string. On Windows, it will be encoded in the
//! code page of the system that linked the module. On other operating
//! systems, UTF-8 may be used.
uint8_t pdb_name[1];
};
//! \brief A CodeView record linking to a `.pdb` 7.0 file.
//!
//! This format provides an indirect link to debugging data by referencing an
//! external `.pdb` file by its name, %UUID, and age. This structure may be
//! pointed to by MINIDUMP_MODULE::CvRecord.
//!
//! For more information about this structure and format, see <a
//! href="http://www.debuginfo.com/articles/debuginfomatch.html#pdbfiles">Matching
//! Debug Information</a>, PDB Files.
//!
//! \sa CodeViewRecordPDB20
//! \sa IMAGE_DEBUG_MISC
struct CodeViewRecordPDB70 {
// UUID has a constructor, which makes it non-POD, which makes this structure
// non-POD. In order for the default constructor to zero-initialize other
// members, an explicit constructor must be provided.
CodeViewRecordPDB70()
: signature(),
uuid(),
age(),
pdb_name() {
}
//! \brief The magic number identifying this structure version, stored in
//! #signature.
//!
//! In a hex dump, this will appear as “RSDS” when produced by a little-endian
//! machine.
static const uint32_t kSignature = 'SDSR';
//! \brief The magic number identifying this structure version, the value of
//! #kSignature.
uint32_t signature;
//! \brief The `.pdb` files unique identifier.
UUID uuid;
//! \brief The revision of the `.pdb` file.
//!
//! A `.pdb` files age indicates incremental changes to it. When a `.pdb`
//! file is created, it has age `1`, and subsequent updates increase this
//! value.
uint32_t age;
//! \brief The path or file name of the `.pdb` file associated with the
//! module.
//!
//! This is a NUL-terminated string. On Windows, it will be encoded in the
//! code page of the system that linked the module. On other operating
//! systems, UTF-8 may be used.
uint8_t pdb_name[1];
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_PDB_STRUCTURES_H_
@@ -0,0 +1,31 @@
// Copyright 2015 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_RANDOM_STRING_H_
#define CRASHPAD_UTIL_MISC_RANDOM_STRING_H_
#include <string>
namespace crashpad {
//! \brief Returns a random string.
//!
//! The string consists of 16 uppercase characters chosen at random. The
//! returned string has over 75 bits of randomness (26<sup>16</sup> &gt;
//! 2<sup>75</sup>).
std::string RandomString();
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_RANDOM_STRING_H_
@@ -0,0 +1,48 @@
// Copyright 2017 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_REINTERPRET_BYTES_H_
#define CRASHPAD_UTIL_MISC_REINTERPRET_BYTES_H_
#include <stddef.h>
namespace crashpad {
namespace internal {
bool ReinterpretBytesImpl(const char* from,
size_t from_size,
char* to,
size_t to_size);
} // namespace internal
//! \brief Copies the bytes of \a from to \a to.
//!
//! This function is similar to `bit_cast`, except that it can operate on
//! differently sized types.
//!
//! \return `true` if the copy is possible without information loss, otherwise
//! `false` with a message logged.
template <typename From, typename To>
bool ReinterpretBytes(const From& from, To* to) {
return internal::ReinterpretBytesImpl(reinterpret_cast<const char*>(&from),
sizeof(From),
reinterpret_cast<char*>(to),
sizeof(To));
}
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_REINTERPRET_BYTES_H_
@@ -0,0 +1,54 @@
// Copyright 2014 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_SCOPED_FORBID_RETURN_H_
#define CRASHPAD_UTIL_MISC_SCOPED_FORBID_RETURN_H_
#include "base/macros.h"
namespace crashpad {
//! \brief Asserts that a scope must not be exited while unsafe.
//!
//! An object of this class has two states: armed and disarmed. A disarmed
//! object is a harmless no-op. An armed object will abort execution upon
//! destruction. Newly-constructed objects are armed by default.
//!
//! These objects may be used to assert that a scope not be exited while it is
//! unsafe to do so. If it ever becomes safe to leave such a scope, an object
//! can be disarmed.
class ScopedForbidReturn {
public:
ScopedForbidReturn() : armed_(true) {}
~ScopedForbidReturn();
//! \brief Arms the object so that it will abort execution when destroyed.
//!
//! The most recent call to Arm() or Disarm() sets the state of the object.
void Arm() { armed_ = true; }
//! \brief Arms the object so that it will abort execution when destroyed.
//!
//! The most recent call to Arm() or Disarm() sets the state of the object.
void Disarm() { armed_ = false; }
private:
bool armed_;
DISALLOW_COPY_AND_ASSIGN(ScopedForbidReturn);
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_SCOPED_FORBID_RETURN_H_
@@ -0,0 +1,132 @@
// Copyright 2014 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_SYMBOLIC_CONSTANTS_COMMON_H_
#define CRASHPAD_UTIL_MISC_SYMBOLIC_CONSTANTS_COMMON_H_
//! \file
//!
//! \anchor symbolic_constant_terminology
//! Symbolic constant terminology
//! =============================
//! <dl>
//! <dt>Family</dt>
//! <dd>A group of related symbolic constants. Typically, within a single
//! family, one function will be used to transform a numeric value to a
//! string equivalent, and another will perform the inverse operation.
//! Families include POSIX signals and Mach exception masks.</dd>
//! <dt>Full name</dt>
//! <dd>The normal symbolic name used for a constant. For example, in the
//! family of POSIX signals, the strings `"SIGHUP"` and `"SIGSEGV"` are
//! full names.</dd>
//! <dt>Short name</dt>
//! <dd>An abbreviated form of symbolic name used for a constant. Short names
//! vary between families, but are commonly constructed by removing a
//! common prefix from full names. For example, in the family of POSIX
//! signals, the prefix is `SIG`, and short names include `"HUP"` and
//! `"SEGV"`.</dd>
//! <dt>Numeric string</dt>
//! <dd>A string that does not contain a full or short name, but contains a
//! numeric value that can be interpreted as a symbolic constant. For
//! example, in the family of POSIX signals, `SIGKILL` generally has value
//! `9`, so the numeric string `"9"` would be interpreted equivalently to
//! `"SIGKILL"`.</dd>
//! </dl>
namespace crashpad {
//! \brief Options for various `*ToString` functions in `symbolic_constants_*`
//! files.
//!
//! \sa \ref symbolic_constant_terminology "Symbolic constant terminology"
enum SymbolicConstantToStringOptionBits {
//! \brief Return the full name for a given constant.
//!
//! \attention API consumers should provide this value when desired, but
//! should provide only one of kUseFullName and ::kUseShortName. Because
//! kUseFullName is valueless, implementers should check for the absence
//! of ::kUseShortName instead.
kUseFullName = 0 << 0,
//! \brief Return the short name for a given constant.
kUseShortName = 1 << 0,
//! \brief If no symbolic name is known for a given constant, return an empty
//! string.
//!
//! \attention API consumers should provide this value when desired, but
//! should provide only one of kUnknownIsEmpty and ::kUnknownIsNumeric.
//! Because kUnknownIsEmpty is valueless, implementers should check for
//! the absence of ::kUnknownIsNumeric instead.
kUnknownIsEmpty = 0 << 1,
//! \brief If no symbolic name is known for a given constant, return a numeric
//! string.
//!
//! The numeric format used will vary by family, but will be appropriate to
//! the family. Families whose values are typically constructed as bitfields
//! will generally use a hexadecimal format, and other families will generally
//! use a signed or unsigned decimal format.
kUnknownIsNumeric = 1 << 1,
//! \brief Use `|` to combine values in a bitfield.
//!
//! For families whose values may be constructed as bitfields, allow
//! conversion to strings containing multiple individual components treated as
//! being combined by a bitwise “or” operation. An example family of constants
//! that behaves this way is the suite of Mach exception masks. For constants
//! that are not constructed as bitfields, or constants that are only
//! partially constructed as bitfields, this option has no effect.
kUseOr = 1 << 2,
};
//! \brief A bitfield containing values of #SymbolicConstantToStringOptionBits.
using SymbolicConstantToStringOptions = unsigned int;
//! \brief Options for various `StringTo*` functions in `symbolic_constants_*`
//! files.
//!
//! Not every `StringTo*` function will implement each of these options. See
//! function-specific documentation for details.
//!
//! \sa \ref symbolic_constant_terminology "Symbolic constant terminology"
enum StringToSymbolicConstantOptionBits {
//! \brief Allow conversion from a string containing a symbolic constant by
//! its full name.
kAllowFullName = 1 << 0,
//! \brief Allow conversion from a string containing a symbolic constant by
//! its short name.
kAllowShortName = 1 << 1,
//! \brief Allow conversion from a numeric string.
kAllowNumber = 1 << 2,
//! \brief Allow `|` to combine values in a bitfield.
//!
//! For families whose values may be constructed as bitfields, allow
//! conversion of strings containing multiple individual components treated as
//! being combined by a bitwise “or” operation. An example family of constants
//! that behaves this way is the suite of Mach exception masks. For constants
//! that are not constructed as bitfields, or constants that are only
//! partially constructed as bitfields, this option has no effect.
kAllowOr = 1 << 3,
};
//! \brief A bitfield containing values of #StringToSymbolicConstantOptionBits.
using StringToSymbolicConstantOptions = unsigned int;
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_SYMBOLIC_CONSTANTS_COMMON_H_
+74
View File
@@ -0,0 +1,74 @@
// Copyright 2015 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_TIME_H_
#define CRASHPAD_UTIL_MISC_TIME_H_
#include <stdint.h>
#include <sys/time.h>
#include <time.h>
#include "build/build_config.h"
#if defined(OS_WIN)
#include <windows.h>
#endif
namespace crashpad {
constexpr uint64_t kNanosecondsPerSecond = static_cast<uint64_t>(1E9);
//! \brief Add `timespec` \a ts1 and \a ts2 and return the result in \a result.
void AddTimespec(const timespec& ts1, const timespec& ts2, timespec* result);
//! \brief Subtract `timespec` \a ts2 from \a ts1 and return the result in \a
//! result.
void SubtractTimespec(const timespec& ts1,
const timespec& ts2,
timespec* result);
//! \brief Convert the timespec \a ts to a timeval \a tv.
//! \return `true` if the assignment is possible without truncation.
bool TimespecToTimeval(const timespec& ts, timeval* tv);
//! \brief Convert the timeval \a tv to a timespec \a ts.
void TimevalToTimespec(const timeval& tv, timespec* ts);
#if defined(OS_WIN) || DOXYGEN
//! \brief Convert a `timespec` to a Windows `FILETIME`, converting from POSIX
//! epoch to Windows epoch.
FILETIME TimespecToFiletimeEpoch(const timespec& ts);
//! \brief Convert a Windows `FILETIME` to `timespec`, converting from Windows
//! epoch to POSIX epoch.
timespec FiletimeToTimespecEpoch(const FILETIME& filetime);
//! \brief Convert Windows `FILETIME` to `timeval`, converting from Windows
//! epoch to POSIX epoch.
timeval FiletimeToTimevalEpoch(const FILETIME& filetime);
//! \brief Convert Windows `FILETIME` to `timeval`, treating the values as
//! an interval of elapsed time.
timeval FiletimeToTimevalInterval(const FILETIME& filetime);
//! \brief Similar to POSIX `gettimeofday()`, gets the current system time in
//! UTC.
void GetTimeOfDay(timeval* tv);
#endif // OS_WIN
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_TIME_H_
@@ -0,0 +1,41 @@
// Copyright 2015 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_TRI_STATE_H_
#define CRASHPAD_UTIL_MISC_TRI_STATE_H_
#include <stdint.h>
namespace crashpad {
//! \brief A tri-state value that can be unset, on, or off.
enum class TriState : uint8_t {
//! \brief The value has not explicitly been set.
//!
//! To allow a zero-initialized value to have this behavior, this must have
//! the value `0`.
kUnset = 0,
//! \brief The value has explicitly been set to on, or a behavior has
//! explicitly been enabled.
kEnabled,
//! \brief The value has explicitly been set to off, or a behavior has
//! explicitly been disabled.
kDisabled,
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_TRI_STATE_H_
+101
View File
@@ -0,0 +1,101 @@
// Copyright 2014 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_UUID_H_
#define CRASHPAD_UTIL_MISC_UUID_H_
#include <stdint.h>
#include <string>
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include <rpc.h>
#endif
namespace crashpad {
//! \brief A universally unique identifier (%UUID).
//!
//! An alternate term for %UUID is “globally unique identifier” (GUID), used
//! primarily by Microsoft.
//!
//! A %UUID is a unique 128-bit number specified by RFC 4122.
//!
//! This is a POD structure.
struct UUID {
bool operator==(const UUID& that) const;
bool operator!=(const UUID& that) const { return !operator==(that); }
//! \brief Initializes the %UUID to zero.
void InitializeToZero();
//! \brief Initializes the %UUID from a sequence of bytes.
//!
//! \a bytes is taken as a %UUID laid out in big-endian format in memory. On
//! little-endian machines, appropriate byte-swapping will be performed to
//! initialize an objects data members.
//!
//! \param[in] bytes A buffer of exactly 16 bytes that will be assigned to the
//! %UUID.
void InitializeFromBytes(const uint8_t* bytes);
//! \brief Initializes the %UUID from a RFC 4122 §3 formatted string.
//!
//! \param[in] string A string of the form
//! `"00112233-4455-6677-8899-aabbccddeeff"`.
//!
//! \return `true` if the string was formatted correctly and the object has
//! been initialized with the data. `false` if the string could not be
//! parsed, with the object state untouched.
bool InitializeFromString(const base::StringPiece& string);
//! \brief Initializes the %UUID using a standard system facility to generate
//! the value.
//!
//! \return `true` if the %UUID was initialized correctly, `false` otherwise
//! with a message logged.
bool InitializeWithNew();
#if defined(OS_WIN) || DOXYGEN
//! \brief Initializes the %UUID from a system `UUID` or `GUID` structure.
//!
//! \param[in] system_uuid A system `UUID` or `GUID` structure.
void InitializeFromSystemUUID(const ::UUID* system_uuid);
#endif // OS_WIN
//! \brief Formats the %UUID per RFC 4122 §3.
//!
//! \return A string of the form `"00112233-4455-6677-8899-aabbccddeeff"`.
std::string ToString() const;
#if defined(OS_WIN) || DOXYGEN
//! \brief The same as ToString, but returned as a string16.
base::string16 ToString16() const;
#endif // OS_WIN
// These fields are laid out according to RFC 4122 §4.1.2.
uint32_t data_1;
uint16_t data_2;
uint16_t data_3;
uint8_t data_4[2];
uint8_t data_5[6];
};
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_UUID_H_
+42
View File
@@ -0,0 +1,42 @@
// Copyright 2017 The Crashpad Authors. All rights reserved.
//
// 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_UTIL_MISC_ZLIB_H_
#define CRASHPAD_UTIL_MISC_ZLIB_H_
#include <string>
namespace crashpad {
//! \brief Obtain a \a window_bits parameter to pass to `deflateInit2()` or
//! `inflateInit2()` that specifies a `gzip` wrapper instead of the default
//! zlib wrapper.
//!
//! \param[in] window_bits A \a window_bits value that only specifies the base-2
//! logarithm of the deflate sliding window size.
//!
//! \return \a window_bits adjusted to specify a `gzip` wrapper, to be passed to
//! `deflateInit2()` or `inflateInit2()`.
int ZlibWindowBitsWithGzipWrapper(int window_bits);
//! \brief Formats a string for an error received from the zlib library.
//!
//! \param[in] zr A zlib result code, such as `Z_STREAM_ERROR`.
//!
//! \return A formatted string.
std::string ZlibErrorString(int zr);
} // namespace crashpad
#endif // CRASHPAD_UTIL_MISC_ZLIB_H_