2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors
|
2014-10-17 13:47:02 -04: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.
|
|
|
|
|
|
|
|
|
|
#include "client/crashpad_info.h"
|
|
|
|
|
|
2017-10-13 10:35:45 -04:00
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
2024-02-09 12:21:45 -08:00
|
|
|
|
#include "base/numerics/safe_conversions.h"
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#include "build/build_config.h"
|
2016-11-22 14:27:51 -05:00
|
|
|
|
#include "util/misc/address_sanitizer.h"
|
2017-04-28 10:08:35 -04:00
|
|
|
|
#include "util/misc/from_pointer_cast.h"
|
2014-10-17 14:24:12 -04:00
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
2014-12-16 10:22:41 -08:00
|
|
|
|
#include <mach-o/loader.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
namespace {
|
|
|
|
|
|
2017-11-15 12:43:44 -05:00
|
|
|
|
// Don’t change this when simply adding fields. Readers will size-check the
|
|
|
|
|
// structure and ignore fields they’re aware of when not present, as well as
|
|
|
|
|
// fields they’re not aware of. Only change this when introducing an
|
|
|
|
|
// incompatible layout, with the understanding that existing readers will not
|
|
|
|
|
// understand new versions.
|
2017-07-25 13:34:04 -04:00
|
|
|
|
constexpr uint32_t kCrashpadInfoVersion = 1;
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
2024-02-09 12:21:45 -08:00
|
|
|
|
// Creates a `UserDataMinidumpStreamListEntry` with the given fields, and
|
|
|
|
|
// returns a pointer to it. The caller takes ownership of the returned object.
|
|
|
|
|
crashpad::internal::UserDataMinidumpStreamListEntry* CreateListEntry(
|
|
|
|
|
uint64_t next,
|
|
|
|
|
uint32_t stream_type,
|
|
|
|
|
const void* data,
|
|
|
|
|
size_t size) {
|
|
|
|
|
auto to_be_added = new crashpad::internal::UserDataMinidumpStreamListEntry();
|
|
|
|
|
to_be_added->next = next;
|
|
|
|
|
to_be_added->stream_type = stream_type;
|
|
|
|
|
to_be_added->base_address = crashpad::FromPointerCast<uint64_t>(data);
|
|
|
|
|
to_be_added->size = base::checked_cast<uint64_t>(size);
|
|
|
|
|
return to_be_added;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
|
|
static_assert(std::is_standard_layout<CrashpadInfo>::value,
|
|
|
|
|
"CrashpadInfo must be standard layout");
|
|
|
|
|
|
2014-12-16 10:22:41 -08:00
|
|
|
|
// This structure needs to be stored somewhere that is easy to find without
|
|
|
|
|
// external information.
|
|
|
|
|
//
|
|
|
|
|
// It isn’t placed in an unnamed namespace: hopefully, this will catch attempts
|
|
|
|
|
// to place multiple copies of this structure into the same module. If that’s
|
|
|
|
|
// attempted, and the name of the symbol is the same in each translation unit,
|
|
|
|
|
// it will result in a linker error, which is better than having multiple
|
|
|
|
|
// structures show up.
|
2014-10-17 13:47:02 -04:00
|
|
|
|
//
|
|
|
|
|
// This may result in a static module initializer in debug-mode builds, but
|
|
|
|
|
// because it’s POD, no code should need to run to initialize this under
|
|
|
|
|
// release-mode optimization.
|
2018-01-10 11:23:56 -08:00
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_POSIX)
|
Partially port the crashpad_client library to Linux/Android
This defines the global (per-module) CrashpadInfo structure properly on
Linux/Android, located via the “crashpad_info” section name.
Per the ELF specification, section names with a leading dot are reserved
for the system. Reading that, I realized that the same is true of Mach-O
sections with leading underscores, so this renames the section as used
on Mach-O from __DATA,__crashpad_info to __DATA,crashpad_info.
This change is sufficient to successfully build crashpad_client as a
static library on Linux/Android, but the library is incomplete. There’s
no platform-specific database implementation, no CaptureContext() or
CRASHPAD_SIMULATE_CRASH() implementation, and most notably, no
CrashpadClient implementation.
BUG=crashpad:30
Change-Id: I29df7b0f8ee1c79bf8a19502812f59d4b1577b85
Reviewed-on: https://chromium-review.googlesource.com/406427
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-02 19:18:20 -04:00
|
|
|
|
__attribute__((
|
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_APPLE)
|
Partially port the crashpad_client library to Linux/Android
This defines the global (per-module) CrashpadInfo structure properly on
Linux/Android, located via the “crashpad_info” section name.
Per the ELF specification, section names with a leading dot are reserved
for the system. Reading that, I realized that the same is true of Mach-O
sections with leading underscores, so this renames the section as used
on Mach-O from __DATA,__crashpad_info to __DATA,crashpad_info.
This change is sufficient to successfully build crashpad_client as a
static library on Linux/Android, but the library is incomplete. There’s
no platform-specific database implementation, no CaptureContext() or
CRASHPAD_SIMULATE_CRASH() implementation, and most notably, no
CrashpadClient implementation.
BUG=crashpad:30
Change-Id: I29df7b0f8ee1c79bf8a19502812f59d4b1577b85
Reviewed-on: https://chromium-review.googlesource.com/406427
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-02 19:18:20 -04:00
|
|
|
|
// Put the structure in a well-known section name where it can be easily
|
|
|
|
|
// found without having to consult the symbol table.
|
|
|
|
|
section(SEG_DATA ",crashpad_info"),
|
2017-11-27 13:09:41 -08:00
|
|
|
|
#endif
|
2014-12-16 10:22:41 -08:00
|
|
|
|
|
2016-11-22 14:27:51 -05:00
|
|
|
|
#if defined(ADDRESS_SANITIZER)
|
Partially port the crashpad_client library to Linux/Android
This defines the global (per-module) CrashpadInfo structure properly on
Linux/Android, located via the “crashpad_info” section name.
Per the ELF specification, section names with a leading dot are reserved
for the system. Reading that, I realized that the same is true of Mach-O
sections with leading underscores, so this renames the section as used
on Mach-O from __DATA,__crashpad_info to __DATA,crashpad_info.
This change is sufficient to successfully build crashpad_client as a
static library on Linux/Android, but the library is incomplete. There’s
no platform-specific database implementation, no CaptureContext() or
CRASHPAD_SIMULATE_CRASH() implementation, and most notably, no
CrashpadClient implementation.
BUG=crashpad:30
Change-Id: I29df7b0f8ee1c79bf8a19502812f59d4b1577b85
Reviewed-on: https://chromium-review.googlesource.com/406427
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-02 19:18:20 -04:00
|
|
|
|
// AddressSanitizer would add a trailing red zone of at least 32 bytes,
|
|
|
|
|
// which would be reflected in the size of the custom section. This confuses
|
|
|
|
|
// MachOImageReader::GetCrashpadInfo(), which finds that the section’s size
|
|
|
|
|
// disagrees with the structure’s size_ field. By specifying an alignment
|
|
|
|
|
// greater than the red zone size, the red zone will be suppressed.
|
|
|
|
|
aligned(64),
|
2016-11-22 14:27:51 -05:00
|
|
|
|
#endif // defined(ADDRESS_SANITIZER)
|
Partially port the crashpad_client library to Linux/Android
This defines the global (per-module) CrashpadInfo structure properly on
Linux/Android, located via the “crashpad_info” section name.
Per the ELF specification, section names with a leading dot are reserved
for the system. Reading that, I realized that the same is true of Mach-O
sections with leading underscores, so this renames the section as used
on Mach-O from __DATA,__crashpad_info to __DATA,crashpad_info.
This change is sufficient to successfully build crashpad_client as a
static library on Linux/Android, but the library is incomplete. There’s
no platform-specific database implementation, no CaptureContext() or
CRASHPAD_SIMULATE_CRASH() implementation, and most notably, no
CrashpadClient implementation.
BUG=crashpad:30
Change-Id: I29df7b0f8ee1c79bf8a19502812f59d4b1577b85
Reviewed-on: https://chromium-review.googlesource.com/406427
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-02 19:18:20 -04:00
|
|
|
|
|
2018-02-16 09:55:34 -08:00
|
|
|
|
// There's no need to expose this as a public symbol from the symbol table.
|
|
|
|
|
// All accesses from the outside can locate the well-known section name.
|
|
|
|
|
visibility("hidden"),
|
|
|
|
|
|
Partially port the crashpad_client library to Linux/Android
This defines the global (per-module) CrashpadInfo structure properly on
Linux/Android, located via the “crashpad_info” section name.
Per the ELF specification, section names with a leading dot are reserved
for the system. Reading that, I realized that the same is true of Mach-O
sections with leading underscores, so this renames the section as used
on Mach-O from __DATA,__crashpad_info to __DATA,crashpad_info.
This change is sufficient to successfully build crashpad_client as a
static library on Linux/Android, but the library is incomplete. There’s
no platform-specific database implementation, no CaptureContext() or
CRASHPAD_SIMULATE_CRASH() implementation, and most notably, no
CrashpadClient implementation.
BUG=crashpad:30
Change-Id: I29df7b0f8ee1c79bf8a19502812f59d4b1577b85
Reviewed-on: https://chromium-review.googlesource.com/406427
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-02 19:18:20 -04:00
|
|
|
|
// The “used” attribute prevents the structure from being dead-stripped.
|
2018-01-10 11:23:56 -08:00
|
|
|
|
used))
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2014-12-16 10:22:41 -08:00
|
|
|
|
|
2015-05-01 13:48:23 -07:00
|
|
|
|
// Put the struct in a section name CPADinfo where it can be found without the
|
|
|
|
|
// symbol table.
|
|
|
|
|
#pragma section("CPADinfo", read, write)
|
Partially port the crashpad_client library to Linux/Android
This defines the global (per-module) CrashpadInfo structure properly on
Linux/Android, located via the “crashpad_info” section name.
Per the ELF specification, section names with a leading dot are reserved
for the system. Reading that, I realized that the same is true of Mach-O
sections with leading underscores, so this renames the section as used
on Mach-O from __DATA,__crashpad_info to __DATA,crashpad_info.
This change is sufficient to successfully build crashpad_client as a
static library on Linux/Android, but the library is incomplete. There’s
no platform-specific database implementation, no CaptureContext() or
CRASHPAD_SIMULATE_CRASH() implementation, and most notably, no
CrashpadClient implementation.
BUG=crashpad:30
Change-Id: I29df7b0f8ee1c79bf8a19502812f59d4b1577b85
Reviewed-on: https://chromium-review.googlesource.com/406427
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-02 19:18:20 -04:00
|
|
|
|
__declspec(allocate("CPADinfo"))
|
2014-12-16 10:22:41 -08:00
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#else // !BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_WIN)
|
Partially port the crashpad_client library to Linux/Android
This defines the global (per-module) CrashpadInfo structure properly on
Linux/Android, located via the “crashpad_info” section name.
Per the ELF specification, section names with a leading dot are reserved
for the system. Reading that, I realized that the same is true of Mach-O
sections with leading underscores, so this renames the section as used
on Mach-O from __DATA,__crashpad_info to __DATA,crashpad_info.
This change is sufficient to successfully build crashpad_client as a
static library on Linux/Android, but the library is incomplete. There’s
no platform-specific database implementation, no CaptureContext() or
CRASHPAD_SIMULATE_CRASH() implementation, and most notably, no
CrashpadClient implementation.
BUG=crashpad:30
Change-Id: I29df7b0f8ee1c79bf8a19502812f59d4b1577b85
Reviewed-on: https://chromium-review.googlesource.com/406427
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-02 19:18:20 -04:00
|
|
|
|
#error Port
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#endif // !BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_WIN)
|
Partially port the crashpad_client library to Linux/Android
This defines the global (per-module) CrashpadInfo structure properly on
Linux/Android, located via the “crashpad_info” section name.
Per the ELF specification, section names with a leading dot are reserved
for the system. Reading that, I realized that the same is true of Mach-O
sections with leading underscores, so this renames the section as used
on Mach-O from __DATA,__crashpad_info to __DATA,crashpad_info.
This change is sufficient to successfully build crashpad_client as a
static library on Linux/Android, but the library is incomplete. There’s
no platform-specific database implementation, no CaptureContext() or
CRASHPAD_SIMULATE_CRASH() implementation, and most notably, no
CrashpadClient implementation.
BUG=crashpad:30
Change-Id: I29df7b0f8ee1c79bf8a19502812f59d4b1577b85
Reviewed-on: https://chromium-review.googlesource.com/406427
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-02 19:18:20 -04:00
|
|
|
|
|
|
|
|
|
CrashpadInfo g_crashpad_info;
|
2014-12-16 10:22:41 -08:00
|
|
|
|
|
2018-02-15 10:38:36 -08:00
|
|
|
|
extern "C" int* CRASHPAD_NOTE_REFERENCE;
|
2018-01-10 11:23:56 -08:00
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
// static
|
|
|
|
|
CrashpadInfo* CrashpadInfo::GetCrashpadInfo() {
|
2022-01-19 15:00:24 -05:00
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \
|
|
|
|
|
BUILDFLAG(IS_FUCHSIA)
|
2018-02-15 10:38:36 -08:00
|
|
|
|
// This otherwise-unused reference is used so that any module that
|
|
|
|
|
// references GetCrashpadInfo() will also include the note in the
|
|
|
|
|
// .note.crashpad.info section. That note in turn contains the address of
|
|
|
|
|
// g_crashpad_info. This allows the module reader to find the CrashpadInfo
|
|
|
|
|
// structure without requiring the use of the dynamic symbol table.
|
|
|
|
|
static volatile int* pointer_to_note_section = CRASHPAD_NOTE_REFERENCE;
|
|
|
|
|
(void)pointer_to_note_section;
|
|
|
|
|
#endif
|
2014-10-17 13:47:02 -04:00
|
|
|
|
return &g_crashpad_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CrashpadInfo::CrashpadInfo()
|
|
|
|
|
: signature_(kSignature),
|
|
|
|
|
size_(sizeof(*this)),
|
|
|
|
|
version_(kCrashpadInfoVersion),
|
2016-04-21 22:19:31 -07:00
|
|
|
|
indirectly_referenced_memory_cap_(0),
|
|
|
|
|
padding_0_(0),
|
2015-03-11 17:07:11 -04:00
|
|
|
|
crashpad_handler_behavior_(TriState::kUnset),
|
|
|
|
|
system_crash_reporter_forwarding_(TriState::kUnset),
|
2016-01-14 15:12:28 -08:00
|
|
|
|
gather_indirectly_referenced_memory_(TriState::kUnset),
|
2016-04-21 22:19:31 -07:00
|
|
|
|
padding_1_(0),
|
2016-02-26 14:42:47 -08:00
|
|
|
|
extra_memory_ranges_(nullptr),
|
2016-02-29 13:28:05 -08:00
|
|
|
|
simple_annotations_(nullptr),
|
2017-10-25 16:57:44 -04:00
|
|
|
|
user_data_minidump_stream_head_(nullptr),
|
2017-11-15 12:43:44 -05:00
|
|
|
|
annotations_list_(nullptr) {}
|
2014-10-17 13:47:02 -04:00
|
|
|
|
|
2024-02-09 12:21:45 -08:00
|
|
|
|
UserDataMinidumpStreamHandle* CrashpadInfo::AddUserDataMinidumpStream(
|
|
|
|
|
uint32_t stream_type,
|
|
|
|
|
const void* data,
|
|
|
|
|
size_t size) {
|
|
|
|
|
user_data_minidump_stream_head_ = CreateListEntry(
|
|
|
|
|
crashpad::FromPointerCast<uint64_t>(user_data_minidump_stream_head_),
|
|
|
|
|
stream_type,
|
|
|
|
|
data,
|
|
|
|
|
size);
|
|
|
|
|
return user_data_minidump_stream_head_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UserDataMinidumpStreamHandle* CrashpadInfo::UpdateUserDataMinidumpStream(
|
|
|
|
|
UserDataMinidumpStreamHandle* stream_to_update,
|
|
|
|
|
uint32_t stream_type,
|
|
|
|
|
const void* data,
|
|
|
|
|
size_t size) {
|
|
|
|
|
// Create a new stream that points to the node `stream_to_update` points to.
|
|
|
|
|
const auto new_stream =
|
|
|
|
|
CreateListEntry(stream_to_update->next, stream_type, data, size);
|
|
|
|
|
|
|
|
|
|
// If `stream_to_update` is head of the list, replace the head with
|
|
|
|
|
// `new_stream`.
|
|
|
|
|
if (stream_to_update == user_data_minidump_stream_head_) {
|
|
|
|
|
user_data_minidump_stream_head_ = new_stream;
|
|
|
|
|
} else {
|
|
|
|
|
// Otherwise, find the node before `stream_to_update`, and make it point to
|
|
|
|
|
// `new_stream` instead.
|
|
|
|
|
auto current = user_data_minidump_stream_head_;
|
|
|
|
|
while (current) {
|
|
|
|
|
auto next = reinterpret_cast<internal::UserDataMinidumpStreamListEntry*>(
|
|
|
|
|
current->next);
|
|
|
|
|
if (next == stream_to_update) {
|
|
|
|
|
current->next = FromPointerCast<uint64_t>(new_stream);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
current = next;
|
|
|
|
|
}
|
|
|
|
|
CHECK(current)
|
|
|
|
|
<< "Tried to update a UserDataMinidumpStream that doesn't exist";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete stream_to_update;
|
|
|
|
|
return new_stream;
|
2016-02-29 13:28:05 -08:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
} // namespace crashpad
|