2395 Commits

Author SHA1 Message Date
Leonard Grey
05e3bd85eb Mac: Expect timestamp for main executable in macOS 12+ in process reader
dyld4 *does* record a timestamp for the main executable (confirmed with
a test app).

Bug: chromium:1268776
Change-Id: I13380181903be7b4886dfdf37f1aa42018a0ef55
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3833512
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
2022-08-17 19:10:43 +00:00
Leonard Grey
0c369760bd Mac: update MachOImageAnnotationsReader tests for dyld4
ASAN passes locally for me with this patch in Chromium, so re-enabling
it upstream as well.

Bug: chromium:1334418
Change-Id: I9c9b20d7c309795cb147656374bae1229be6b418
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3833503
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
2022-08-17 18:03:53 +00:00
Bruce Dawson
1876c67497 Record memory near EIP/RIP first
Checking for code-corruption is an important process in crash analysis
so it is important to record code bytes first. This was already done for
ARM and other processors so this change just moves EIP/RIP to the top of
the list.

This is important in scenarios where only a small amount of extra memory
is recorded such as in the stable channel of Chrome.

Bug: 1339513
Change-Id: I26367214ee66795c81000a0487987a130f2ea23a
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3812374
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
2022-08-09 14:56:02 +00:00
Alex Pankhurst
6c6c2ae563 [fuchsia] migrate test to CFv2
Fuchsia is undergoing a change to how programs are run and the Crashpad
tests must be migrated to the new system.

Bug: fuchsia:102371

TESTED=`fx test crashpad-test` (540 passing, 1 skipped)

Change-Id: I4daf7d160045b28b876a5f1aa93b0bd596461e0d
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3817783
Commit-Queue: Alex Pankhurst <pankhurst@google.com>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
2022-08-08 19:03:20 +00:00
Justin Cohen
7b105f83ab ios: Properly handle overflows in scoped_vm_read.
Passing -1 (or size_t max) to ScopedVMRead would succeed, because the
amount of memory to be read would overflow vm_address_t/vm_size_t and
turn into something reasonable. ScopedVMRead would return true having
only read a miniscule subset of the requested data length.

Bug: 1348341
Change-Id: I061a1d86928f211c541a6378a78ee045d489a838
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3791710
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
2022-07-29 02:33:32 +00:00
Ayush Ranjan
4e5cef683a Update documentation to use main branch name.
Some documentation uses the old default branch name `master`.
But `master` in crashpad repo is a very old branch and has been
superseded with `main`.

Change-Id: I368c829fde2d29b3f14aa14185bfc97d546bf340
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3787194
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2022-07-28 00:08:19 +00:00
Ayush Ranjan
bfc0eb5709 Close handler_sock after starting crashpad server.
handler_sock end of the socketpair is donated to the crashpad server
process which owns it. The client should not keep it open. Otherwise
if the crashpad server process crashes and the client is reading from
client_sock, the client will hang forever because the other end is still
open.

This happens when:
- /proc/sys/kernel/yama/ptrace_scope file is present.
- crashpad is invoked with missing required fields, like --database.

In this case, chrome hangs until timeout.

Change-Id: I1776432d6d9fd44dc1c24e874a15fd6d2a376003
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3786896
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Ayush Ranjan <ayushranjan@google.com>
2022-07-25 22:51:34 +00:00
Justin Cohen
1b47570f6f ios: Add buffered write to IOSIntermediateDumpWriter.
Adds a 4K buffer to the intermediate dump writer. Aside from the final
flush, only write in multiples of 4K. This saves between 30ms and 50ms
on an iPhone 12 Pro.

Change-Id: Icc4b222477bd91fd6952c7cf43b105e1f7a50adb
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3764243
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2022-07-25 12:03:48 +00:00
Alex Pankhurst
fab4801e1e [fuchsia] Fix ubsan issues
Fuchsia's undefined behavior sanitizer was detecting unaligned accesses
to 8 byte aligned data in Crashpad tests because various MINIDUMP_*
structs are packed with 4 byte alignment.

This change copies unaligned data in tests to local variable that can be
safely used to check values.

Example errors:

'''
[../../third_party/crashpad/minidump/minidump_thread_name_list_writer_test.cc:95:3]:
runtime error: reference binding to misaligned address 0x461e104cfbd4
for type 'const RVA64' (aka 'const unsigned long'), which requires 8
byte aligment
'''

'''
'''

Change-Id: I3c0905aa9eab810c00d57f1e9e54bb8eaaff54b0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3775293
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Alex Pankhurst <pankhurst@google.com>
2022-07-20 18:24:24 +00:00
Justin Cohen
ae7d8a9ba4 ios: Use fewer vm_reads when iterating modules.
Rather than vm_reading each individual module load_command, load all of
the commands at once. This saves nearly 200ms on an iPhone 12 Pro.

Change-Id: I06f56c3ecbdf74f78759648ea62bcccd027f304c
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3764242
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2022-07-15 20:58:32 +00:00
Justin Cohen
df86075acc ios: Prevent duplicate uploads and watchdog kills with slow uploads.
On iOS, holding a lock during a slow upload can lead to watchdog kills
if the app is suspended mid-upload. Instead, if the client can obtain
the lock, the database sets a lock-time file attribute and releases the
flock. The file attribute is cleared when the upload is completed. The
lock-time attribute can be used to prevent file access from other
processes, or to discard reports that likely were terminated mid-upload.

Bug:chromium:1342051
Change-Id: Ib878f6ade8eae467ee39acb52288296759c84582
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3739019
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
2022-07-14 18:47:58 +00:00
Justin Cohen
b7db85b62d ios: vm_read module file path before calling strlen.
Adds a new IOSIntermediateDumpWriter::AddPropertyCString method which
takes an address to a cstring of unknown length and page-by-page
searches for a NUL-byte terminator.

This is necessary because currently WriteModuleInfo calls strlen
directly on the dyld and module filePath without first using vm_read.
On iOS14 this occasionally crashes, and is generally unwise. Instead,
use AddPropertyCString.

This patch also removes WriteDyldErrorStringAnnotation, as it's no
longer used going forward with iOS 15.

Bug: 1332862
Change-Id: I3801693bc39259a0127e5175dccf286a1cd97ba7
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3689516
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2022-07-14 18:47:13 +00:00
Justin Cohen
1424632592 ios: Fix testCrashWithDyldErrorString on arm64.
Fixed when running a simulator on arm64 Apple Silicon.

Change-Id: I6a6e917b4d5ff009683214794fe6a6af833be3c0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3758362
Reviewed-by: Rohit Rao <rohitrao@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2022-07-13 17:32:23 +00:00
Stephan Hartmann
7a622b2f6b GCC: fix invalid bind of packed field to uint32_t&
GCC does not allow binding a packed field to an address. Assign
to a intermediate variable instead before pushing to map.

Bug: chromium:819294
Change-Id: I806e5f99c2b19e656b91a60f72172b59c961ba5f
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3751392
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2022-07-08 18:15:29 +00:00
Alex Gough
80520bd937 Add WER runtime exception helper module for Windows
This adds a runtime exception helper (& test module) for Windows and
plumbing to allow the module to be registered by the crashpad client,
and to trigger the crashpad handler. Embedders can build their own
module to control which exceptions are passed to the handler.

See: go/chrome-windows-runtime-exception-helper for motivation.

When registered (which is the responsibility of the embedding
application), the helper is loaded by WerFault.exe when Windows
Error Reporting receives crashes that are not caught by crashpad's
normal handlers - for instance a control-flow violation when a
module is compiled with /guard:cf.

Registration:

The embedder must arrange for the full path to the helper to
be added in the appropriate Windows Error Reporting\
RuntimeExceptionHelperModules registry key.

Once an embedder's crashpad client is connected to a crashpad
handler (e.g. through SetIpcPipeName()) the embedder calls
RegisterWerModule. Internally, this registration includes handles
used to trigger the crashpad handler, an area reserved to hold an
exception and context, and structures needed by the crashpad handler.

Following a crash:

WerFault.exe handles the crash then validates and loads the helper
module. WER hands the helper module a handle to the crashing target
process and copies of the exception and context for the faulting thread.

The helper then copies out the client's registration data and
duplicates handles to the crashpad handler, then fills back the various structures in the paused client that the crashpad handler will need.

The helper then signals the crashpad handler, which collects a dump then
notifies the helper that it is done.

Support:

WerRegisterExceptionHelperModule has been availble since at least
Windows 7 but WerFault would not pass on the exceptions that crashpad
could not already handle. This changed in Windows 10 20H1 (19041),
which supports HKCU and HKLM registrations, and passes in more types of
crashes. It is harmless to register the module for earlier versions
of Windows as it simply won't be loaded by WerFault.exe.

Tests:

snapshot/win/end_to_end_test.py has been refactored slightly to
group crash generation and output validation in main() by breaking
up RunTests into smaller functions.

As the module works by being loaded in WerFault.exe it is tested
in end_to_end_test.py.

Bug: crashpad:133, 866033, 865632
Change-Id: Id668bd15a510a24c79753e1bb03e9456f41a9780
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3677284
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Alex Gough <ajgo@chromium.org>
2022-07-07 17:13:24 +00:00
Justin Cohen
bac699ef47 ios: Correct xcode-hybrid setup for Xcode 14.
Changes copied verbatim from Chromium with one exception to remove
Chromium specific gn args.

This includes a mini_chromium roll to not codesign within Xcode.

Change-Id: I89b35bee08f9bc9e37f902f2b57e02acb2113ae1
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3726509
Reviewed-by: Rohit Rao <rohitrao@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2022-06-27 19:37:26 +00:00
Justin Cohen
80f383327e [win] Fix ScopedSetThreadName for Windows 7
Windows 7 doesn't support SetThreadDescription/GetThreadDescription. Add
an IsSupported to ScopedSetThreadName test to wrap unsupported calls.

Change-Id: I70d4e20b94efea03e41c5f7ed8d8e1b886192923
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3722556
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
2022-06-27 17:55:06 +00:00
Darshan Sen
1c37daa5ac Reland "posix: Replace DoubleForkAndExec() with ForkAndSpawn()"
This is a reland of 460943dd9a71dc76f68182a8ede766d5543e5341

Original change's description:
> The DoubleForkAndExec() function was taking over 622 milliseconds to run
> on macOS 11 (BigSur) on Intel i5-1038NG7. I did some debugging by adding
> some custom traces and found that the fork() syscall is the bottleneck
> here, i.e., the first fork() takes around 359 milliseconds and the
> nested fork() takes around 263 milliseconds. Replacing the nested fork()
> and exec() with posix_spawn() reduces the time consumption to 257
> milliseconds!
>
> See https://github.com/libuv/libuv/pull/3064 to know why fork() is so
> slow on macOS and why posix_spawn() is a better replacement.
>
> Another point to note is that even base::LaunchProcess() from Chromium
> calls posix_spawnp() on macOS -
> 8f8d82dea0:base/process/launch_mac.cc;l=295-296

The reland isolates the change to non-Android POSIX systems because
posix_spawn and posix_spawnp are available in Android NDK 28, but
Chromium is building with version 23.

Change-Id: If44629f5445bb0e3d0a1d3698b85f047d1cbf04f
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3721655
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2022-06-24 15:45:49 +00:00
Justin Cohen
6e946c4af8 Revert "posix: Replace DoubleForkAndExec() with ForkAndSpawn()"
This reverts commit 460943dd9a71dc76f68182a8ede766d5543e5341.

Reason for revert: This fails to compile in Chromium Android.
posix_spawn and posix_spawnp are available in Android NDK 28, but
Chromium is building with version 23.

https://ci.chromium.org/ui/p/chromium/builders/try/android_compile_dbg/1179765/overview

Original change's description:
> posix: Replace DoubleForkAndExec() with ForkAndSpawn()
>
> The DoubleForkAndExec() function was taking over 622 milliseconds to run
> on macOS 11 (BigSur) on Intel i5-1038NG7. I did some debugging by adding
> some custom traces and found that the fork() syscall is the bottleneck
> here, i.e., the first fork() takes around 359 milliseconds and the
> nested fork() takes around 263 milliseconds. Replacing the nested fork()
> and exec() with posix_spawn() reduces the time consumption to 257
> milliseconds!
>
> See https://github.com/libuv/libuv/pull/3064 to know why fork() is so
> slow on macOS and why posix_spawn() is a better replacement.
>
> Another point to note is that even base::LaunchProcess() from Chromium
> calls posix_spawnp() on macOS -
> 8f8d82dea0:base/process/launch_mac.cc;l=295-296
>
> Change-Id: I25c6ee9629a1ae5d0c32b361b56a1ce0b4b0fd26
> Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3641386
> Reviewed-by: Mark Mentovai <mark@chromium.org>
> Commit-Queue: Mark Mentovai <mark@chromium.org>

Change-Id: I7f6161bc4734c50308438cdde1e193023ee9bfb8
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3719439
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2022-06-23 12:08:23 +00:00
Justin Cohen
23cefd0417 Fix Chromium compile.
Fixes error: invalid operands to binary expression ('std::ostream'
(aka 'basic_ostream<char>') and 'const char[19]') << "pthread_setname_np";

in test/scoped_set_thread_name_posix.cc

Change-Id: I77eeeee9c828d563aaa15331733001e522a04642
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3714964
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2022-06-23 03:28:39 +00:00
Justin Cohen
21546d8514 Use call_once in lazy settings load.
This fixes a test case that accesses settings for the first time in
multiple threads simultaneously.

Fixed: crashpad:417
Change-Id: I6539682f171563f8ff5a1203fdd550ab92afc276
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3711807
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2022-06-22 17:22:19 +00:00
Nico Weber
7c30a508eb Build actual crashpad .asm files in win/cross builds
Now that we have llvm-ml, we no longer need the workaround for this.

This upstreams
https://chromium-review.googlesource.com/c/chromium/src/+/3708412

Bug: chromium:762167
Change-Id: Iadc8ba9753bb7dd079415ee744f3b176b7e2f629
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3707748
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2022-06-17 13:48:37 +00:00
Darshan Sen
460943dd9a posix: Replace DoubleForkAndExec() with ForkAndSpawn()
The DoubleForkAndExec() function was taking over 622 milliseconds to run
on macOS 11 (BigSur) on Intel i5-1038NG7. I did some debugging by adding
some custom traces and found that the fork() syscall is the bottleneck
here, i.e., the first fork() takes around 359 milliseconds and the
nested fork() takes around 263 milliseconds. Replacing the nested fork()
and exec() with posix_spawn() reduces the time consumption to 257
milliseconds!

See https://github.com/libuv/libuv/pull/3064 to know why fork() is so
slow on macOS and why posix_spawn() is a better replacement.

Another point to note is that even base::LaunchProcess() from Chromium
calls posix_spawnp() on macOS -
8f8d82dea0:base/process/launch_mac.cc;l=295-296

Change-Id: I25c6ee9629a1ae5d0c32b361b56a1ce0b4b0fd26
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3641386
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2022-06-16 13:42:26 +00:00
Mark Mentovai
07ef17371d Add buildtools/clang_format/script to DEPS
clang-format doesn’t work after week’s buildtools update to 0a14d52dad27
without separately checking out buildtools/clang_format/script.

Change-Id: I8330aacb85d1ba96318e5f2cd4563b6d32615963
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3707851
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Justin Cohen <justincohen@chromium.org>
2022-06-15 14:54:13 +00:00
Mark Mentovai
3ae34b169b [test] Fix test build failures in Chromium
Importing Crashpad into Chromium revealed a few build failures:

1) The MSVC compiler needed assistance constructing SleepingThreads

2) scoped_set_thread_name_posix.cc did not build on Android, where
   BUILDFLAG(IS_LINUX) is not defined and __ANDROID_API__ must be
   set to 24 or higher to use pthread_getname_np()

This fixes the build failures, which I tested with a Chromium CQ
dry-run:

https://crrev.com/c/3703491

Change-Id: Ibde7cacaa45d384272890ea9b1ee2d707048ab03
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3703446
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
2022-06-15 00:49:56 +00:00
Ben Hamilton
02bdf8f9d7 [snapshot] Add missing #include in process_reader_win_test.cc
The Chromium presubmits flagged a missing #include in
process_reader_win_test.cc.  This adds the missing #include.

Change-Id: I68aed4328f976bba547a0cb7a9ea833fdf71873b
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3703312
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2022-06-14 20:01:06 +00:00
Alex Pankhurst
f19ef3c607 [fuchsia] Fix uninitialized fields
Fuchsia's Crashpad roller was broken due to uninitialized fields in
structs.

Bug: fxbug.dev/101498
Change-Id: I1283afea9c5ac4eddb432590f9a5ec5cb1856a7c
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3704517
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Alex Pankhurst <pankhurst@google.com>
2022-06-14 19:07:22 +00:00
Clemens Backes
2bf08e6223 Detect blocked signal installation by sanitizers
Sanitizers can prevent the installation of signal handlers, but
sigaction would still return 0 (for success). Detect this by checking
the installed signal handler via a second call to sigaction.

R=mark@chromium.org

Bug: chromium:1328749
Change-Id: I62a5777379ec5c6b1ca2d5a62e7cd3fb8ed1437b
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3702302
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
2022-06-14 14:25:29 +00:00
Ben Hamilton
ed8cfeb2cd [snapshot] Add support for thread names
This CL adds a new method ThreadSnapshot::ThreadName(), implements
it in each snapshot implementation, and adds tests for iOS, macOS,
Linux, Windows, and Fuchsia.

Bug: crashpad:327
Change-Id: I35031975223854c19d977e057dd026a40d33fd41
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3671776
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Ben Hamilton <benhamilton@google.com>
Reviewed-by: Ben Hamilton <benhamilton@google.com>
2022-06-13 20:58:37 +00:00
Mark Mentovai
0a14d52dad Update buildtools (gn and clang-format)
This updates buildtools to 8b16338d17cd. gn has migrated out of
buildtools and into its own cipd package, so gn is pulled at
2ecd43a10266 (current). This provides a mac-x86_64 or mac-arm64 gn as
appropriate for the host CPU architecture. The buildtools update also
brings distinct clang-format executables for mac-x86_64 and mac-arm64 as
appropriate.

Change-Id: I4162b093cfe8d5a2ba66ba62f6462813ea489dbd
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3700190
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Justin Cohen <justincohen@chromium.org>
2022-06-10 15:34:13 +00:00
Justin Cohen
816c5572b8 Lazy load settings in CrashReportDatabase.
Before this patch, settings.dat is read from and written to during
database initialization. This happens within Crashpad for iOS, and
within Chrome during startup here:
https://source.chromium.org/chromium/chromium/src/+/main:components/crash/core/app/crashpad.cc;l=209
These are blocking calls on the main thread.

CrashReportDatabaseMac::Initialize will still fail if the various
directory create/ensure calls fail.

Change-Id: Ic665884d1f41caa853aba9b29b6fb2c14b2cda15
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3674639
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2022-06-09 13:41:43 +00:00
Ben Hamilton
339b125241 [minidump] Fix unaligned pointer in thread name list
https://crrev.com/c/3671775/ introduced a warning (and thus, a
compilation failure) on 32-bit ARM when taking the address of the RVA64
field MINIDUMP_THREAD_NAME::RvaOfThreadName:

minidump/minidump_thread_name_list_writer.cc:57:23: error: taking address of packed member 'RvaOfThreadName' of class or structure 'MINIDUMP_THREAD_NAME' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member]
  name_->RegisterRVA(&thread_name_.RvaOfThreadName);
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Indeed, MINIDUMP_THREAD_NAME's RvaOfThreadName field is not aligned,
so the technique used in MinidumpWritable::Register*() of passing in a
rawptr to an arbitrary struct field which is later dereferenced cannot
be used for this field.

This CL replaces the use of MinidumpWritable::Register*() with
overriding MinidumpThreadNameWriter::WillWriteAtOffsetImpl() to
directly calculate and assign thread_name_.RvaOfThreadName.

Change-Id: I71e751a5b5e896b5e7277879bdbdff6e9eefe023
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3693846
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Ben Hamilton <benhamilton@google.com>
Reviewed-by: Ben Hamilton <benhamilton@google.com>
2022-06-08 18:52:32 +00:00
Justin Cohen
0662aeb83e Fix usage of sprintf.
sprintf is marked as deprecated with Xcode 14.

Bug: 1331345
Change-Id: I600372d270272348d6c114112e9d7d71e75bc091
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3688301
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2022-06-07 04:02:13 +00:00
Ben Hamilton
6d0d1a4be6 [minidump] Add support for THREAD_NAME_LIST stream
The minidump stream type MINIDUMP_THREAD_NAME_LIST represents
thread names as a list in the form [(thread_id, thread name), ...].

This introduces a new MinidumpThreadNameListWriter class which
allows OS-specific snapshot writers to write thread names using
this new stream type.

Bug: crashpad:327
Change-Id: Ief45df5dbbf44c0e1254786bfbe6720112ceef38
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3671775
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Ben Hamilton <benhamilton@google.com>
2022-06-06 19:39:09 +00:00
Ben Hamilton
91cec09d93 [minidump] Extend minidump string writer support for RVA64 strings
To support MINIDUMP_THREAD_NAME_LIST (which uses 64-bit RVAs for the
thread name MINIDUMP_STRING), this adds minidump string writing and
reading support for the new 64-bit RVA64 and
MINIDUMP_LOCATION_DESCRIPTOR64 types.

Bug: crashpad:327
Change-Id: Iffefffef358517dfc6deac02051dff9dbb8eb214
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3673779
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Ben Hamilton <benhamilton@google.com>
2022-06-02 18:46:16 +00:00
Alex Pankhurst
fc0b157a8e [fuchsia] Fix build errors on Fuchsia
Fuchsia's Crashpad roller was failing due to 'std::size' not being found
and struct fields not being initialized (detected by
-Wmissing-field-initializers)

- Fix 'std::size' issue by using a std::array instead of a plain C array
- Fix missing initializers with default values

Bug: fxbug.dev/101498
Change-Id: I75fa54d5c1730772b1af1be31c64b0cc58886a90
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3687239
Commit-Queue: Alex Pankhurst <pankhurst@google.com>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
2022-06-02 17:55:15 +00:00
Ben Hamilton
a903f7541f [minidump] Add support for RVA64 / MINIDUMP_LOCATION_DESCRIPTOR64
Newer minidump stream types, like MINIDUMP_THREAD_NAME_LIST, use
64-bit RVAs (which have 64-bit location descriptors) instead of 32-bit
RVAs and location descriptors.

This adds support to MinidumpWritable for the new 64-bit RVA64 and
MINIDUMP_LOCATION_DESCRIPTOR64 types.

Bug: crashpad:327
Change-Id: Icd67bca600756a68ef9ba7d5a429f935eebf726f
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3673776
Commit-Queue: Ben Hamilton <benhamilton@google.com>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
2022-06-01 19:13:07 +00:00
Ben Hamilton
b1ffe93562 [ios] Fix two shutdown races
There were two shutdown races in the iOS Crashpad client:

1) MachMessageServer::Run can return either MACH_RCV_PORT_CHANGED *or*
   MACH_RCV_INVALID_NAME based on the timing of when the port is
   closed, for example:
   c21f7bab5c/Sources/CwlPreconditionTesting/CwlCatchBadInstruction.swift (L131)
2) The iOS crashpad::CrashHandler thread could read from its member
   variable mach_handler_running_ while another thread wrote to it

Change-Id: I696ece8575d9b88cbd0593e7c479bd4c7f863f45
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3651395
Reviewed-by: Justin Cohen <justincohen@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
2022-05-24 18:15:58 +00:00
Peter Kasting
5f2a706f71 Blind attempt to fix compile failure in latest roll.
Bug: none
Change-Id: Iea44283cf4df029b595e87bb42b57422e310e7a4
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3659054
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
2022-05-23 04:44:26 +00:00
Peter Kasting
13a1e171eb C++20 build fixes.
* ATOMIC_FLAG_INIT is deprecated.
* Compound ops on volatiles are deprecated.

Bug: chromium:1284275
Change-Id: I2235662c00e4be8c5eba2aaf565663faf8d9576a
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3658639
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
2022-05-22 01:13:35 +00:00
Mark Mentovai
c5094b99a4 minidump: Size the annotation list writer iovec more carefully
https://chromium-review.googlesource.com/c/crashpad/crashpad/+/731309/6#message-19ebbbfb10fa499bb00989728b19756982641326

Change-Id: I274eb62bdc9b0039196dc01902eb8654154a8c1a
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3654638
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2022-05-20 17:37:04 +00:00
Ben Hamilton
55de7bb48e [Crashpad/Annotations] Increase maximum annotation name length to 256
Crashpad annotation names are currently limited to 64 bytes.

Breakpad supports up to 256 bytes, so for compatibility with existing
clients, this increases the maximum annotation name size from 64 to
256 and adds new tests to confirm the maximum name and value sizes.

Change-Id: Ib7954bea96046b6b7e18ed9743fe2a15dd3dabac
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3655975
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Reviewed-by: Justin Cohen <justincohen@chromium.org>
2022-05-19 21:23:53 +00:00
Ben Hamilton
2071abaeb4 [ios] Fix FD leak in IOSIntermediateDumpWriter
IOSIntermediateDumpWriter::Close() is intended to close the FD opened
by the in-process handler.

Currently, InProcessHandler::ScopedLockedWriter::~ScopedLockedWriter() does invoke IOSIntermediateDumpWriter::Close().

However, InProcessHandler::Initialize() invokes the utility CreateWriterWithPath() which directly creates an IOSIntermediateDumpWriter. It neither uses ScopedLockedWriter nor invokes Close().

This fixes the issue by:

1) Making IOSIntermediateDumpWriter::~IOSIntermediateDumpWriter() DCHECK() that it's closed
2) Calling IOSIntermediateDumpWriter::Close() from InProcessHandler::~InProcessHandler() and from test files

Change-Id: Ibfede0a3d2aeac948c7ff3d56445e13d1a4028b5
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3648710
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: Justin Cohen <justincohen@chromium.org>
2022-05-18 19:25:09 +00:00
Alex Gough
1fa6eb27f6 Fix compile for arm64
Some xstate flags are not available in arm64 as it does not have
xstate so we should omit the InitializeXState method on the
`target_cpu = arm64` configuration.

Bug: 1250098
Change-Id: I5c92d6efbe90587bdebef87d4a6ce4e9b25afa4d
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3653575
Commit-Queue: Alex Gough <ajgo@chromium.org>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
2022-05-18 17:16:59 +00:00
Alex Gough
d8567ffc53 Capture shadow stack region if available
Where shadow stacks are available, capture the entire shadow stack page
unconditionally.

Bug: 1250098
Change-Id: I5e2273c19b5f2d571195ff1252396df7dd70566a
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3493684
Commit-Queue: Alex Gough <ajgo@chromium.org>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
2022-05-17 03:59:48 +00:00
Alex Gough
9ef737a26d Captures shadow stack registers for x64 Windows contexts
Windows extended contexts must be allocated by InitializeContext2 and
may not be aligned. This means we cannot simply store a struct in
our thread snapshot object, but must instead store enough memory
and alias our struct onto this backing memory.

Note that shadow stack pointers are not yet recorded for the initial
exception - this cannot be determined using LocateXStateFeature in
the capturing process and will be added in a future CL by plumbing
through client messages when a crashed process requests a dump.

See crash/32bd2c53a252705c for an example dump with this baked into
chrome, that has passed through breakpad without breaking it. Local
testing shows this creates valid dumps when built into Chrome, but
that the referenced memory limits may need to be increased to allow
for ssp referenced memory to be included.

See "MANAGING STATE USING THE XSAVE FEATURE SET" Chapter 13 in the
Intel SDM[0]. Many of the offsets and sizes of the extended features
are provided by cpu specific values. We can access these in Windows
using the SDK, and transfer these to the saved extended context
which in turn is understandable by windbg.

Further information is available from AMD Ch. 18 "Shadow Stacks"[1].

    [0] https://software.intel.com/content/www/us/en/develop/download/intel-64-and-ia-32-architectures-sdm-combined-volumes-1-2a-2b-2c-2d-3a-3b-3c-3d-and-4.html.
    [1] https://www.amd.com/system/files/TechDocs/24593.pdf

Bug: 1250098
Change-Id: I4b13bcb023e9d5fba257044abfd7e251d66a9329
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3300992
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Alex Gough <ajgo@chromium.org>
2022-05-17 03:39:16 +00:00
Alex Gough
9e0051aba6 Write compacted xsave contexts in minidumps
Adds new structures and offsets for minidump extended contexts. This
information will be captured from threads in a later CL so this CL
does not yet write different dumps, except in testing.

Minidump format for extended compacted contexts has been determined by
experiment. Offsets for where to write various parts of the context
are hardcoded to 0x550 as this matches values seen in Windows. Offsets
for misc_info_5 match those seen in working minidumps that can be opened
in windbg. Our hope is that while these could change in future, CPU
and OS vendors are unlikely to change them.

See doc[0] for a discussion of these fields and offsets in the minidump.

See "MANAGING STATE USING THE XSAVE FEATURE SET" Chapter 13 in the
Intel SDM[1]. Many of the offsets and sizes of the extended features
are provided by cpu specific values. We can access these in Windows
using the SDK, and transfer these to the saved extended context
which in turn is understandable by windbg.

Further information is available from AMD Ch. 18 "Shadow Stacks"[2].

    [0] https://docs.google.com/document/d/1Dn8n97r5B7kxYouvujNnPIYd_7QeVHpahSRmB92Qn6g/edit#heading=h.hivqj2jg39y
    [1] https://software.intel.com/content/www/us/en/develop/download/intel-64-and-ia-32-architectures-sdm-combined-volumes-1-2a-2b-2c-2d-3a-3b-3c-3d-and-4.html.
    [2] https://www.amd.com/system/files/TechDocs/24593.pdf

Bug: 1250098
Change-Id: Ia9041acc379c6d38329ee99737a2a0a77f7a1ee0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3536964
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Alex Gough <ajgo@chromium.org>
2022-05-17 01:45:56 +00:00
Alex Gough
25222891c7 Add fields for shadow stack registers to x64 snapshot
This will be used in a later CL to shuttle shadow stack information
from capture to minidumps. For now these fields are zeroed and have
no effect on any platform.

The x64 snapshot context we use no longer directly maps to the early
CONTEXT structure used by Windows (the prelude still matches). This
may cause confusion if people use the size of a snapshot context when
they meant to use sizeof(CONTEXT).

Bug: 1250098
Change-Id: Idac7d888b9e606ceb250c4027e0e7f29f4c0a55f
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3536963
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Alex Gough <ajgo@chromium.org>
2022-05-17 01:12:26 +00:00
Alex Gough
a5b7e504c6 Thread snapshots on Windows can have varying size
In a future CL we will make use of InitializeContext2 which can produce
contexts of varying sizes - this makes the existing use of a union for
wow/x64 contexts no longer feasible.

The context union in process_reader_win is replaced with a (moveable,
copyable) helper struct which currently only knows how to allocate
the replaced WOW or CONTEXT sized unions.

As this field is no longer a member of the Thread struct it cannot
be passed into other functions as a reference, so instead a pointer
is used in these functions.

Bug: 1250098
Change-Id: Ied3fe971c0073bbdafc071217e1bb0f72350bb4e
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3538668
Commit-Queue: Alex Gough <ajgo@chromium.org>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
2022-05-17 00:40:26 +00:00
Justin Cohen
4581a355b1 ios: Limit depth of intermediate dump parser.
Limit the parser stack to 10 to prevent malformed intermediate dumps
from causing a stack overflow.

Bug: 1321382
Change-Id: I880e80de585b0fb18f0c383102b9227d6ffbfa76
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3637719
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
2022-05-11 16:24:00 +00:00