176 Commits

Author SHA1 Message Date
Mark Mentovai
692488a254 Un-disable WinMultiprocess-based tests in Chromium
As of
00a0654929,
crashpad_util_test is able to run in Chromium. It uses Chromium’s own
base::TestLauncher rather than gtest’s RUN_ALL_TESTS() for proper
integration with Swarming.

Launching WinMultiprocess test children out of the same test executable
via WinChildProcess is not compatible with Chromium’s parallel, shardy,
Swarmy test launcher. When running these children, the standard gtest
RUN_ALL_TESTS() launcher will now be used, even in Chromium.

Two tests disabled in Chromium are now enabled:
ExceptionHandlerServerTest.MultipleConnections and
ScopedProcessSuspend.ScopedProcessSuspend.

As part of this work, I discovered that disabled tests chosen to run via
--gtest_also_run_disabled_tests did not actually work for
WinMultiprocess-based tests, because gtest’s test launcher would refuse
to run the child side of the test, believing it was disabled. This is
fixed by always supplying --gtest_also_run_disabled_tests to
WinChildProcess children, on the basis that if the parent is managing to
run and it’s disabled, disabled tests must actually be enabled.

Bug: crashpad:205
Change-Id: Ied22f16b9329ee13b6b07fd29de704f6fe2a058e
Reviewed-on: https://chromium-review.googlesource.com/742462
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-10-27 21:42:10 +00:00
Mark Mentovai
672c872589 Upstream crashpad_util_test-in-Chromium changes
This upstreams part of
00a0654929.

The gmock_main and gtest_main test launchers detect via a
CRASHPAD_IN_CHROMIUM macro that they are building as part of Chromium,
and use Chromium’s custom test launcher rather than gtest’s
RUN_ALL_TESTS(). This enables parallelism, sharding, and integration
with Swarming.

WinMultiprocess-based tests are not compatible with this test launcher
or with the Swarming test design, and must be disabled when
CRASHPAD_IN_CHROMIUM is set. This is covered by
https://crashpad.chromium.org/bug/205.

CRASHPAD_IN_CHROMIUM is never defined during Crashpad’s own standalone
build, it’s only defined when building in Chromium.

Change-Id: I969c5d376f86ab4b3f4cc85c97d4452b53b35063
Reviewed-on: https://chromium-review.googlesource.com/740988
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-10-27 20:20:35 +00:00
Mark Mentovai
5e9ed4cb9f win: Dynamically disable WoW64 tests absent explicit 32-bit build output
Rather than having the 64-bit build assume that it lives in
out\{Debug,Release}_x64 and that it can find 32-bit build output in
out\{Debug,Release}, require the location of 32-bit build output to be
provided explicitly via the CRASHPAD_TEST_32_BIT_OUTPUT environment
variable. If this variable is not set, 64-bit tests that require 32-bit
test build output will dynamically disable themselves at runtime.

In order for this to work, a new DISABLED_TEST() macro is added to
support dynamically disabled tests. gtest does not have its own
first-class support for this
(https://groups.google.com/d/topic/googletestframework/Nwh3u7YFuN4,
https://github.com/google/googletest/issues/490) so this local solution
is used instead.

For tests via Crashpad’s own build\run_tests.py, which is how Crashpad’s
own buildbots and trybots invoke tests, CRASHPAD_TEST_32_BIT_OUTPUT is
set to a locaton compatible with the paths expected for the GYP-based
build. No test coverage is lost on Crashpad’s own buildbots and trybots.

For Crashpad tests in Chromium’s buildbots and trybots, this environment
variable will not be set, causing these tests to be dynamically
disabled.

Bug: crashpad:203, chromium:743139, chromium:777924
Change-Id: I3c0de2bf4f835e13ed5a4adda5760d6fed508126
Reviewed-on: https://chromium-review.googlesource.com/739795
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-10-26 18:31:57 +00:00
Nico Weber
9bc5989125 crashpad_util_test warning fixes for clang-cl, 64-bit edition.
This upstreams https://chromium-review.googlesource.com/c/chromium/src/+/738402

Bug: chromium:777924
Change-Id: Ib3c8f4f77631da45a2911029e8925c1afad1c244
Reviewed-on: https://chromium-review.googlesource.com/738553
Commit-Queue: Nico Weber <thakis@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
2017-10-25 20:53:51 +00:00
Nico Weber
2f48159011 Make crashpad_util_test build without warnings with clang-cl on Windows.
This upstreams https://chromium-review.googlesource.com/c/chromium/src/+/735820/

Bug: chromium:777924
Change-Id: I9fe76b839442d73a6c2836ccfe6cbe41acd67fad
Reviewed-on: https://chromium-review.googlesource.com/738394
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
2017-10-25 19:02:47 +00:00
Mark Mentovai
6d5bd1d04d win: Go back to using ml.exe for SafeTerminateProcess()
This reverts 55133d332b6c and adds a broken dummy SafeTerminateProcess()
for cross builds instead. It’s similar to 2f4516f93838, which was for
CaptureContext().

This upstreams
af5f31ed61
(slightly modified).

The dummy implementation in the “broken” file affords no protection
against third-party code patching TerminateProcess() badly. The “broken”
file is not used by Crashpad anywhere at all, and is only used by
Crashpad in Chromium during a cross build targeting Windows without the
benefit of Microsoft’s ml.exe assembler. Strictly speaking, this file
does not need to be checked in to the Crashpad repository, but since
Chromium needs it to unblock its not-production-ready cross build for
Windows, it’s being landed here to avoid Chromium’s copy of Crashpad
appearing as modified or “dirty” relative to this upstream copy.

Bug: chromium:762167, chromium:777924
Change-Id: Iba68c0cab142fbe9541ea254a9a856b8263e4c70
Reviewed-on: https://chromium-review.googlesource.com/735078
Reviewed-by: Mark Mentovai <mark@chromium.org>
2017-10-24 19:07:38 +00:00
Mark Mentovai
2f4516f938 win: Provide broken CHECK()ing dummy CaptureContext() for cross builds
This upstreams
fc1ac734b0
(slightly modified).

This dummy implementation is not used by Crashpad anywhere at all, and
is only used by Crashpad in Chromium during a cross build targeting
Windows without the benefit of Microsoft’s ml.exe/ml64.exe assembler.
Strictly speaking, this file does not need to be checked in to the
Crashpad repository, but since Chromium needs it to unblock its
not-production-ready cross build for Windows, it’s being landed here to
avoid Chromium’s copy of Crashpad appearing as modified or “dirty”
relative to this upstream copy. (Even though this file is really dirty.)

Bug: chromium:762167
Change-Id: Ibfdc316c1f5fe81d4b3a1d86f4032adccac467e5
Reviewed-on: https://chromium-review.googlesource.com/734102
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2017-10-23 19:56:35 +00:00
Mark Mentovai
55133d332b win: Use inline asm instead of ml.exe for SafeTerminateProcess()
This upstreams
912c9907d5
(slightly modified).

Bug: chromium:762167
Change-Id: I69c605f693da8691d32222b5617f62637c1c2dcd
Reviewed-on: https://chromium-review.googlesource.com/734100
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2017-10-23 19:14:05 +00:00
Joshua Peraza
474c7331a6 Add DirectoryReader to iterate over files in a directory
This change also adds functions to create directories, remove files and
directories, and check for the existence of files and directories.

Change-Id: I62b78219ae2b277d6976d2d90ec86fcabd0ef073
Reviewed-on: https://chromium-review.googlesource.com/696132
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
2017-10-16 19:56:54 +00:00
Nikhil Marathe
dabe8477da win: Fix TEB.TlsSlots offset
The Crashpad representation of the TEB struct had an incorrect PVOID
reserved of len 397. This should be 402 once we calculate that the other
members occupy 40/80 (32 vs 64) bytes.

Wine has a well documented copy
4df0162caf/include/winternl.h (L309)
that shows the offsets TlsSlots should be at. This patch makes that
change. TlsSlots is now at offset 3600 on 32-bit and offset 5248 on
64-bit.

Change-Id: I4ea4c44b1e49d3ea02d433f386f164703a373dab
Reviewed-on: https://chromium-review.googlesource.com/717040
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2017-10-13 19:03:07 +00:00
Mark Mentovai
a327c86a52 C++14 is required, don’t pretend to support pre-C++11 or pre-MSVS 2015
Change-Id: Ide835421599480acc63e8e88ce2217433c0d376e
Reviewed-on: https://chromium-review.googlesource.com/719036
Reviewed-by: Leonard Mosescu <mosescu@chromium.org>
2017-10-13 15:49:59 +00:00
Mark Mentovai
4c4e67952c win: 10.0.16299.0 SDK compatibility
This corresponds to Windows 10 version 1709 (Fall Creators Update,
“Redstone 3”).

While compiling util/win/nt_internals.cc:

…\crashpad\crashpad\util\win\nt_internals.cc(22): error C2371: 'CLIENT_ID': redefinition; different basic types
c:\program files (x86)\windows kits\10\include\10.0.16299.0\um\winternl.h(83): note: see declaration of 'CLIENT_ID'

The CLIENT_ID structure, which should have been part of the SDK to begin
with, has been added. Provide a compatible definition in <winternl.h>.

Bug: chromium:773476
Change-Id: Iafc77f8cffd06d1194fc909bad587f1ffd1687a2
Reviewed-on: https://chromium-review.googlesource.com/711415
Reviewed-by: Leonard Mosescu <mosescu@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2017-10-11 22:39:00 +00:00
Mark Mentovai
31df2acb12 win: Fix messages in ProcessInfo::LoggingRangeIsFullyReadable()
|ranges| is a coalesced list of committed and accessible memory ranges
trimmed to reflect only those that overlap |range|. |range| is only
fully unreadable if |ranges| is empty. If |ranges| contains more than
one element, it indicates that |range| is sparse (since |ranges| is
coalesced, there must be a “hole”). This should be treated as partially
unreadable, the same as when |ranges[0]| doesn’t begin or end where
|range| does.

Test: self_destroying_test_program.exe (via end_to_end_test.py)
Change-Id: I55fc2b201089113f2b07395e352704b99d212801
Reviewed-on: https://chromium-review.googlesource.com/702535
Reviewed-by: Leonard Mosescu <mosescu@chromium.org>
2017-10-05 20:55:32 +00:00
Mark Mentovai
e5896de993 win: Fix process_structs.h definition of RTL_USER_PROCESS_PARAMETERS
In the 64-bit version of the structure, padding is needed between
ShowWindowFlags and WindowTitle.

The CurrentDirectores (yes, that’s how it’s spelled) members would have
been interpreted incorrectly because STRING was defined incorrectly. The
length fields are USHORT, not DWORD. In the 64-bit version of the
structure, a padding member ensured that the structure was at least the
correct size. In the 32-bit version of the structure, this caused the
structure size to be inflated, so all but the first CurrentDirectores
element and any struct member that followed would appear at incorrect
offsets, and the overall struct size being read was larger than
appropriate.

This resolves crashpad_handler logging (usually) three errors while
handling a 64-bit process crash, such as:

[pid:tid:yyyymmdd,hhmmss.mmm:ERROR process_info.cc:632] range at
0x780f24de00000000, size 0x275 fully unreadable
[pid:tid:yyyymmdd,hhmmss.mmm:ERROR process_info.cc:632] range at
0x780f24fe00000000, size 0x275 fully unreadable
[pid:tid:yyyymmdd,hhmmss.mmm:ERROR process_info.cc:632] range at 0x0,
size 0x275 fully unreadable

Bug: crashpad:198
Test: end_to_end_test.py
Change-Id: I1655101de01cf46b4b50eda45a11f8d0f3bca8b3
Reviewed-on: https://chromium-review.googlesource.com/701736
Reviewed-by: Leonard Mosescu <mosescu@chromium.org>
2017-10-05 20:49:08 +00:00
Mark Mentovai
90054edf62 win: De-flake hanging_program.exe
hanging_program.exe is used by crash_other_program.exe, which is in turn
used by end_to_end_test.py. It hangs by loading loader_lock_dll.dll,
which squats in its entry point function while the loader lock is held.

hanging_program.exe needs to do some work in its Thread1() before the
loader lock is taken (a SetThreadPriority() call), and needs to do some
work in its main thread once the loader lock is held (it needs to signal
crash_other_program.exe that it’s successfully wedged itself).
Previously, proper synchronization was not provided. A 1-second Sleep()
was used to wait for the loader lock to be taken. Thread1() pre-work was
only achieved before the loader lock was taken by sheer luck. Things
didn’t always work out so nicely.

This uses an event handle to provide synchronization. An environment
variable is used to pass the handle to loader_lock_dll.dll, because
there aren’t many better options available. This eliminates both flake
and the unnecessary 1-second delay in hanging_program.exe, and since
this program runs twice during end_to_end_test.py, it improves that
test’s runtime by 2 seconds.

Bug: crashpad:197
Test: end_to_end_test.py
Change-Id: Ib9883215ef96bed7571464cc68e09b6ab6310ae6
Reviewed-on: https://chromium-review.googlesource.com/700076
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Leonard Mosescu <mosescu@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-10-04 19:58:56 +00:00
Mark Mentovai
c6adcc2482 win: Make CrashpadClient::DumpAndCrashTargetProcess() less chatty
CrashpadClient::DumpAndCrashTargetProcess() suspends the target process
and injects a thread to raise an exception. The injected thread is not
suspended, and may proceed to the point that the system recognizes the
process as terminating by the time the overall process suspension is
lifted. Previously, if this happened, an extraneous error was logged for
the attempt to resume a terminating process.

This introduces “termination tolerance” to ScopedProcessSuspend, which
allows an object to be configured to ignore this error and not log any
messages when this condition is expected.

This resolves log messages such as this one, produced frequently during
calls to CrashpadClient::DumpAndCrashTargetProcess() (including in
end_to_end_test.py):

> [pid:tid:yyyymmdd,hhmmss.mmm:ERROR scoped_process_suspend.cc:39]
> NtResumeProcess: An attempt was made to access an exiting process.
> (0xc000010a)

0xc000010a = STATUS_PROCESS_IS_TERMINATING

Test: end_to_end_test.py
Change-Id: Iab4c50fb21adce5502080ad25a6f734ec566d65c
Reviewed-on: https://chromium-review.googlesource.com/700715
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-10-04 19:04:47 +00:00
Xi Cheng
01110c0a3b win: Fix %u, %d, %x/DWORD printf mismatches
To enable clang-cl's printf format string mismatch checking, a few
mismatch errors need to be fixed where DWORD (unsigned long) is printed
with %u, %d or %x (an 'l' is needed).

Change-Id: I2cbfafe823a186bfe3a555aec3a7ca03e85466f8
Reviewed-on: https://chromium-review.googlesource.com/598651
Commit-Queue: Xi Cheng <chengx@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
2017-08-02 22:04:13 +00:00
Mark Mentovai
8f0636288a Use constexpr at namespace scope
This is essentially based on a search for “^const .*=”.

Change-Id: I9332c1f0cf7c891ba1ae373dc537f700f9a1d956
Reviewed-on: https://chromium-review.googlesource.com/585452
Reviewed-by: Leonard Mosescu <mosescu@chromium.org>
2017-07-29 01:06:52 +00:00
Mark Mentovai
6dac7ecdf5 Use constexpr at function scope
This is essentially based on a search for “^ *const [^*&]*=[^(]*$”

Change-Id: Id571119d0b9a64c6f387eccd51cea7c9eb530e13
Reviewed-on: https://chromium-review.googlesource.com/585555
Reviewed-by: Leonard Mosescu <mosescu@chromium.org>
2017-07-29 00:50:40 +00:00
Mark Mentovai
281be63d00 Standardize on static constexpr for arrays when possible
This uses “static” at function scope to avoid making local copies, even
in cases where the compiler can’t see that the local copy is
unnecessary. “constexpr” adds additional safety in that it prevents
global state from being initialized from any runtime dependencies, which
would be undesirable.

At namespace scope, “constexpr” is also used where appropriate.

For the most part, this was a mechanical transformation for things
matching '(^| )const [^=]*\['.

Similar transformations could be applied to non-arrays in some cases,
but there’s limited practical impact in most non-array cases relative to
arrays, there are far more use sites, and much more manual intervention
would be required.

Change-Id: I3513b739ee8b0be026f8285475cddc5f9cc81152
Reviewed-on: https://chromium-review.googlesource.com/583997
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Leonard Mosescu <mosescu@chromium.org>
2017-07-25 17:40:51 +00:00
Mark Mentovai
15103742e0 Use FromPointerCast<>() in many places where it makes sense
I opted to leave casts to types that were definitely the same size
alone. reinterpret_cast<uintptr_t>(pointer) and
reinterpret_cast<intptr_t>(pointer) should always be safe, for example.
Casts to other integral types have been replaced with
FromPointerCast<>(), which does zero-extension or sign-extension based
on the target type.

To make it possible to use FromPointerCast<>() with some use sites that
were already using checked_cast<>(), FromPointerCast<>() now uses
check_cast<>() when converting to a narrower type.

Test: crashpad_util_test FromPointerCast*, others
Change-Id: I4a71b4aa2d87f545c75524290a702f5f3138d675
Reviewed-on: https://chromium-review.googlesource.com/489701
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-05-01 15:54:00 +00:00
Mark Mentovai
74fddc3fed win: Wrap test::ChildLauncher::Start() in ASSERT_NO_FATAL_FAILURE()
Test: crashpad_snapshot_test, crashpad_util_test, end_to_end_test
Change-Id: I09581521678fe3b083c409f308eeab2e583b3c9f
Reviewed-on: https://chromium-review.googlesource.com/481245
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-19 17:47:23 +00:00
Mark Mentovai
e04194afd9 win: Wrap TerminateProcess() to accept cdecl patches on x86
TerminateProcess(), like most of the Windows API, is declared WINAPI,
which is __stdcall on 32-bit x86. That means that the callee,
TerminateProcess() itself, is responsible for cleaning up parameters on
the stack on return. In https://crashpad.chromium.org/bug/179, crashes
in ExceptionHandlerServer::OnNonCrashDumpEvent() were observed in ways
that make it evident that TerminateProcess() has been patched with a
__cdecl routine. The crucial difference between __stdcall and __cdecl is
that the caller is responsible for stack parameter cleanup in __cdecl.
The mismatch means that nobody cleans parameters from the stack, and the
stack pointer has an unexpected value, which in the case of the Crashpad
handler crash, results in TerminateProcess()’s second argument
erroneously being used as the lock address in the call to
ReleaseSRWLockExclusive() or LeaveCriticalSection().

As a workaround, on 32-bit x86, call through SafeTerminateProcess(), a
custom assembly routine that’s compatible with either __stdcall or
__cdecl implementations of TerminateProcess() by not trusting the value
of the stack pointer on return from that function. Instead, the stack
pointer is restored directly from the frame pointer.

Bug: crashpad:179
Test: crashpad_util_test SafeTerminateProcess.*, others
Change-Id: If9508f4eb7631020ea69ddbbe4a22eb335cdb325
Reviewed-on: https://chromium-review.googlesource.com/481180
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-19 17:45:32 +00:00
Mark Mentovai
79425e4d97 win: Free an old buffer before attempting to allocate a resized one
When GetProcessInformation() obtains SystemProcessInformation, it
resizes its buffer as directed by NtQuerySystemInformation(). Nothing of
value resides in the old buffer if a resize is attempted, so it can be
freed before attempting to allocate a resized one.

This may help crashes like go/crash/f385e94c80000000, which experience
out-of-memory while attempting to allocate a resized buffer. It also may
not help, because the required buffer size may just be too large to fit
in memory. See https://crashpad.chromium.org/bug/143#c19.

Change-Id: I63b9b8c1efda22d2fdbf05ef2b74975b92556bbd
Reviewed-on: https://chromium-review.googlesource.com/473792
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-11 21:49:46 +00:00
Mark Mentovai
4b450c8137 test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.

This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.

EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.

References:

https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
77d6b17338
https://github.com/google/googletest/pull/713

Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 12:34:24 +00:00
Mark Mentovai
4688351623 “Promote” test::Paths::Executable() to Paths::Executable()
This supports the “double handler” or “double handler with low
probability” models from https://crashpad.chromium.org/bug/143.

For crashpad_handler to be become its own client, it needs access to its
own executable path to pass to CrashpadClient::StartHandler(). This was
formerly available in the test-only test::Paths::Executable(). Bring
that function’s implementation to the non-test Paths::Executable() in
util/misc, and rename test::Paths to test::TestPaths to avoid future
confusion.

test::TestPaths must still be used to access TestDataRoot(), which does
not make any sense to non-test code.

test::TestPaths::Executable() is retained for use by tests, which most
likely prefer the fatal semantics of that function. Paths::Executable()
is not fatal because for the purposes of implementing the double
handler, a failure to locate the executable path (which may happen on
some systems in deeply-nested directory hierarchies) shouldn’t cause the
initial crashpad_handler to abort, even if it does prevent a second
crashpad_handler from being started.

Bug: crashpad:143
Test: crashpad_util_test Paths.*, crashpad_test_test TestPaths.*
Change-Id: I9f75bf61839ce51e33c9f7c0d7031cebead6a156
Reviewed-on: https://chromium-review.googlesource.com/466346
Reviewed-by: Scott Graham <scottmg@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2017-04-03 18:58:01 +00:00
Mark Mentovai
270490ff79 win: Be more careful about child process exit codes
Checking child process’ exit codes would have helped catch bug
crashpad:160 sooner. Instead, we had a flaky hang that was difficult to
reproduce locally.

Bug: crashpad:160
Test: crashpad_snapshot_test ExceptionSnapshotWinTest.ChildCrash*:ProcessSnapshotTest.CrashpadInfoChild*:SimulateCrash.ChildDumpWithoutCrashing*, crashpad_util_test ProcessInfo.OtherProcess
Change-Id: I73bd2be1437d05f0501a146dcb9efbe3b8e0f8b7
Reviewed-on: https://chromium-review.googlesource.com/459039
Reviewed-by: Scott Graham <scottmg@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2017-03-24 20:12:31 +00:00
Mark Mentovai
013d5e14a3 #include <stddef.h> where offsetof() is used
Bug: crashpad:30
Change-Id: If23ca9ea3141d3d34dc494aa29a1bd1dc8f83130
Reviewed-on: https://chromium-review.googlesource.com/458079
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-03-23 02:15:32 +00:00
Mark Mentovai
00b6442752 Make file_io reads more rational and predictable
ReadFile() attempted to continue reading after a short read. In most
cases, this is fine. However, ReadFile() would keep trying to fill a
partially-filled buffer until experiencing a 0-length read(), signaling
end-of-file. For certain weird file descriptors like terminal input, EOF
is an ephemeral condition, and attempting to read beyond EOF doesn’t
actually return 0 (EOF) provided that they remain open, it will block
waiting for more input. Consequently, ReadFile() and anything based on
ReadFile() had an undocumented and quirky interface, which was that any
short read that it returned (not an underlying short read) actually
indicated EOF.

This facet of ReadFile() was unexpected, so it’s being removed. The new
behavior is that ReadFile() will return an underlying short read. The
behavior of FileReaderInterface::Read() is updated in accordance with
this change.

Upon experiencing a short read, the caller can determine the best
action. Most callers were already prepared for this behavior. Outside of
util/file, only crashpad_database_util properly implemented EOF
detection according to previous semantics, and adapting it to new
semantics is trivial.

Callers who require an exact-length read can use the new
ReadFileExactly(), or the newly renamed LoggingReadFileExactly() or
CheckedReadFileExactly(). These functions will retry following a short
read. The renamed functions were previously called LoggingReadFile() and
CheckedReadFile(), but those names implied that they were simply
wrapping ReadFile(), which is not the case. They wrapped ReadFile() and
further, insisted on a full read. Since ReadFile()’s semantics are now
changing but these functions’ are not, they’re now even more distinct
from ReadFile(), and must be renamed to avoid confusion.

Test: *
Change-Id: I06b77e0d6ad8719bd2eb67dab93a8740542dd908
Reviewed-on: https://chromium-review.googlesource.com/456676
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-03-16 20:07:43 +00:00
Mark Mentovai
f34ed66b93 metrics: Record handler lifetime milestone events
It could be useful to put our existing Crashpad.HandlerCrashed metrics
into context by getting a sense of handler starts, clean exits, and
other types of exits.

BUG=crashpad:100

Change-Id: I8982075158ea6d210eb2ddad678302e339a42192
Reviewed-on: https://chromium-review.googlesource.com/444124
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-02-22 18:48:12 +00:00
Sigurdur Asgeirsson
6af23a933a Use best-effort allocation in ProcessInfo::BuildHandleVector.
BUG=crashpad:158

Change-Id: If8666140a7fc5315eeb791d0998226de89a22cc3
Reviewed-on: https://chromium-review.googlesource.com/438791
Reviewed-by: Mark Mentovai <mark@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-02-08 20:20:46 +00:00
Scott Graham
0567536f86 win: Attempt to fix unloaded modules list by using RtlGetUnloadEventTraceEx
I haven't been able to reproduce this locally, but we see errors in
crash dumps where the unloaded module list consists of a number of
modules with invalid names and implausible addresses. My assumption is
that RTL_UNLOAD_EVENT_TRACE isn't correct for some OS levels. Instead of
trying to finesse and test that, use RtlGetUnloadEventTraceEx() instead
of RtlGetUnloadEventTrace(), which returns an element size. (This
function is Vista+ which is why it wasn't used the first time around.)

R=mark@chromium.org
BUG=chromium:620175

Change-Id: I4d7080a03623276f9c1c038d6e7329af70e4a64c
Reviewed-on: https://chromium-review.googlesource.com/421564
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-12-16 20:32:25 +00:00
Scott Graham
32981a3ee9 win: Fix clang warning in SECURITY_DESCRIPTOR construction
c:\src\cr\src\third_party\crashpad\crashpad\util\win\registration_protocol_win.cc(193,23):  error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces]
                      SECURITY_MANDATORY_LABEL_AUTHORITY,
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c:\src\depot_tools\win_toolchain\vs_files\d5dc33b15d1b2c086f2f6632e2fd15882f80dbd3\win_sdk\Include\10.0.10586.0\um\winnt.h(9068,54):  note: expanded from macro 'SECURITY_MANDATORY_LABEL_AUTHORITY'
                                                     ^~~~~~~~~~~~
1 error generated.

R=mark@chromium.org
BUG=chromium:656800

Change-Id: I1121a42ca98d8a7432e247d4b44a9ad1214d4b39
Reviewed-on: https://chromium-review.googlesource.com/418010
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-12-08 18:12:04 +00:00
Scott Graham
f94dd14c45 win: fix SECURITY_DESCRIPTOR builder on vs2013
After https://chromium.googlesource.com/crashpad/crashpad/+/5b83e587.

R=mark@chromium.org
BUG=chromium:655788,chromium:656800

Change-Id: Ic33b9daedc340bfce3cc4ddde4eb4c93f68e7ad0
Reviewed-on: https://chromium-review.googlesource.com/417412
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-12-07 21:51:57 +00:00
Scott Graham
5b83e58771 win: Remove use of rpcrt4 and advapi32 from some util code
ConvertStringSecurityDescriptorToSecurityDescriptor() is used when
creating the initial connection pipe. Because this is done from inside
DllMain(), we cannot use advapi32 (where this function is). Instead,
save the binary representation of the self-relative SECURITY_DESCRIPTOR.
It is conceivable that this could change, but unlikely as this is the
same blob that would be stored on a file in NTFS.

Another potential approach would be to not make the pipe available to
all integrity levels here, and instead modify the Chromium sandbox code
to allow a specific pipe name prefix that would have to correspond with
the pipe name that Crashpad creates.

Similarly, UuidCreate() (used when initializing the database) is in a
DLL that can't be loaded early, so use the Linux/Android implementation
on Windows too.

R=mark@chromium.org
BUG=chromium:655788,chromium:656800

Change-Id: I434f8e96fc275fc30d0a31208b025bfc08595ff9
Reviewed-on: https://chromium-review.googlesource.com/417223
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-12-07 20:03:45 +00:00
Mark Mentovai
57b2210ed7 GCC fix: Make UUID POD
This eliminates all constructors, but nearly all points of use were
using the default constructor to initialize a UUID member variable as in
uuid_(). This syntax will still produce a zeroed-out UUID.

While compiling, for example, minidump_rva_list_writer.cc:

In file included from ../../minidump/minidump_rva_list_writer.h:25:0,
                 from ../../minidump/minidump_rva_list_writer.cc:15:
../../minidump/minidump_extensions.h:412:8: error: ignoring packed attribute because of unpacked non-POD field ‘crashpad::UUID crashpad::MinidumpCrashpadInfo::report_id’ [-Werror]
   UUID report_id;
        ^~~~~~~~~
../../minidump/minidump_extensions.h:424:8: error: ignoring packed attribute because of unpacked non-POD field ‘crashpad::UUID crashpad::MinidumpCrashpadInfo::client_id’ [-Werror]
   UUID client_id;
        ^~~~~~~~~

Tested with:
 - GCC 4.9 from NDK r13 targeting arm with SDK 16
 - GCC 4.9 from NDK r13 targeting arm64 with SDK 21
 - GCC 6.2 targeting x86_64

BUG=crashpad:30

Change-Id: Iec6b1557441b69d75246f2f75c59c4158fb7ca29
Reviewed-on: https://chromium-review.googlesource.com/409641
Reviewed-by: Scott Graham <scottmg@chromium.org>
2016-11-11 17:37:14 +00:00
Mark Mentovai
acabe35928 doc: Fix all Doxygen warnings, cleaning up some generated documentation
This makes Doxygen’s output more actionable by setting QUIET = YES to
suppress verbose progress spew, and WARN_IF_UNDOCUMENTED = NO to prevent
warnings for undocumented classes and members from being generated. The
latter is too noisy, producing 721 warnings in the current codebase.

The remaining warnings produced by Doxygen were useful and actionable.
They fell into two categories: abuses of Doxygen’s markup syntax, and
missing (or misspelled) parameter documentation. In a small number of
cases, pass-through parameters had intentionally been left undocumented.
In these cases, they are now given blank \param descriptions. This is
not optimal, but there doesn’t appear to be any other way to tell
Doxygen to allow a single parameter to be undocumented.

Some tricky Doxygen errors were resolved by asking it to not enter
directiores that we do not provide documentation in (such as the
“on-platform” compat directories, compat/mac and compat/win, as well as
compat/non_cxx11_lib) while allowing it to enter the
“off-platform” directories that we do document (compat/non_mac and
compat/non_win).

A Doxygen run (doc/support/generate_doxygen.sh) now produces no output
at all. It would produce warnings if any were triggered.

Not directly related, but still relevant to documentation,
doc/support/generate.sh is updated to remove temporary removals of
now-extinct files and directories. doc/appengine/README is updated so
that a consistent path to “goapp” is used throughout the file.

Change-Id: I300730c04de4d3340551ea3086ca70cc5ff862d1
Reviewed-on: https://chromium-review.googlesource.com/408812
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-08 19:24:05 +00:00
Scott Graham
c4cdec3d72 Handle non-crashing cases for server failure to start
Follow up #4!

R=mark@chromium.org
BUG=chromium:567850,chromium:656800
TEST=tests added to crashpad_client_test

Change-Id: I2a53f2168988e620ce240750c6c2d544ba95c8b4
Reviewed-on: https://chromium-review.googlesource.com/406741
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-11-03 16:38:22 +00:00
Scott Graham
76ef9b5c2b win: Address failure-to-start-handler case for async startup
Second follow up to https://chromium-review.googlesource.com/c/400015/

The ideal would be that if we fail to start the handler, then we don't
end up passing through our unhandled exception filter at all.

In the case of the non-initial client (i.e. renderers) we can do this by
not setting our UnhandledExceptionFilter until after we know we've
connected successfully (because those connections are synchronous from
its point of view). We also change WaitForNamedPipe in the connection
message to block forever, so as long as the precreated pipe exists,
they'll wait to connect. After the initial client has passed the server
side of that pipe to the handler, the handler has the only handle to it.
So, if the handler has disappeared for whatever reason, pipe-connecting
clients will fail with FILE_NOT_FOUND, and will not stick around in the
connection loop. This means non-initial clients do not need additional
logic to avoid getting stuck in our UnhandledExceptionFilter.

For the initial client, it would be ideal to avoid passing through our
UEF too, but none of the 3 options are great:
1. Block until we find out if we started, and then install the filter.
   We don't want to do that, because we don't want to wait.
2. Restore the old filter if it turns out we failed to start. We can't
   do that because Chrome disables ::SetUnhandledExceptionFilter()
   immediately after StartHandler/SetHandlerIPCPipe returns.
3. Don't install our filter until we've successfully started. We don't
   want to do that because we'd miss early crashes, negating the benefit
   of deferred startup.

So, we do need to pass through our UnhandledExceptionFilter. I don't
want more Win32 API calls during the vulnerable filter function. So, at
any point during async startup where there's a failure, set a global
atomic that allows the filter function to abort without trying to signal
a handler that's known to not exist.

One further improvement we might want to look at is unexpected
termination of the handler (as opposed to a failure to start) which
would still result in a useless Sleep(60s). This isn't new behaviour,
but now we have a clear thing to do if we detect the handler is gone.

(Also a missing DWORD/size_t cast for the _x64 bots.)

R=mark@chromium.org
BUG=chromium:567850,chromium:656800

Change-Id: I5be831ca39bd8b2e5c962b9647c8bd469e2be878
Reviewed-on: https://chromium-review.googlesource.com/400985
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-11-02 21:39:52 +00:00
Scott Graham
cc0b7deef2 Get VS2013 compilation working again for Crashpad
Follow up #1 to https://chromium-review.googlesource.com/c/400015/,
still pending further discussion on details of registration.

R=mark@chromium.org
BUG=chromium:567850,chromium:656800

Change-Id: Idfee3a3241d7cfe418fbf9e40f17f35e5dbefac9
Reviewed-on: https://chromium-review.googlesource.com/401182
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-10-22 00:05:02 +00:00
Scott Graham
2d87606bb5 win: Start crashpad_handler by inheriting connection data to it
Previously, StartHandler() launched the handler process, then connected
over a pipe to register for crash handling. Instead, the initial client
can create and inherit handles to the handler and pass those handle
values and other data (addresses, etc.) on the command line.

This should improve startup time as there's no need to synchronize with
the process at startup, and allows avoiding a call to CreateProcess()
directly in StartHandler(), which is important for registration for
crash reporting from DllMain().

Incidentally adds new utility functions for string/number conversion and
string splitting.

Note: API change; UseHandler() is removed for all platforms.

BUG=chromium:567850,chromium:656800

Change-Id: I1602724183cb107f805f109674c53e95841b24fd
Reviewed-on: https://chromium-review.googlesource.com/400015
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-10-21 20:35:58 +00:00
Scott Graham
a16a7fd4ef win: Make DumpAndCrash() always terminate, and tidy up special codes
Upstreaming with tidying up of
https://codereview.chromium.org/2377693002/.

R=mark@chromium.org
BUG=chromium:634418

Change-Id: Ie8b3b673c8d2a06c5cc918a034688aa9396cfbf4
Reviewed-on: https://chromium-review.googlesource.com/390436
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-09-29 04:44:20 +00:00
Scott Graham
d9c7247870 win: Make GetReadableRangesOfMemoryMap() less slow in Debug
d:\src\crashpad\crashpad>git checkout origin/master
Note: checking out 'origin/master'.
...
HEAD is now at f497e54... win: Fix indirectly gathered memory cap

[f497e54...]d:\src\crashpad\crashpad>ninja -C out\Debug
ninja: Entering directory `out\Debug'
[0->23/23 ~0] STAMP obj\All.actions_depends.stamp

[f497e54...]d:\src\crashpad\crashpad>tim out\Debug\crashpad_snapshot_test --gtest_filter=ProcessSnapshotTest.CrashpadInfoChild
Running main() from gtest_main.cc
Note: Google Test filter = ProcessSnapshotTest.CrashpadInfoChild
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from ProcessSnapshotTest
[ RUN      ] ProcessSnapshotTest.CrashpadInfoChild
[       OK ] ProcessSnapshotTest.CrashpadInfoChild (147879 ms)
[----------] 1 test from ProcessSnapshotTest (147880 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (147884 ms total)
[  PASSED  ] 1 test.

real: 2m27.907s
qpc: 147914874us

[f497e54...]d:\src\crashpad\crashpad>git checkout slow-debug
Previous HEAD position was f497e54... win: Fix indirectly gathered memory cap
Switched to branch 'slow-debug'
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

[slow-debug]d:\src\crashpad\crashpad>ninja -C out\Debug
ninja: Entering directory `out\Debug'
[0->23/23 ~0] STAMP obj\All.actions_depends.stamp

[slow-debug]d:\src\crashpad\crashpad>tim out\Debug\crashpad_snapshot_test --gtest_filter=ProcessSnapshotTest.CrashpadInfoChild
Running main() from gtest_main.cc
Note: Google Test filter = ProcessSnapshotTest.CrashpadInfoChild
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from ProcessSnapshotTest
[ RUN      ] ProcessSnapshotTest.CrashpadInfoChild
[       OK ] ProcessSnapshotTest.CrashpadInfoChild (4414 ms)
[----------] 1 test from ProcessSnapshotTest (4416 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (4420 ms total)
[  PASSED  ] 1 test.

real: 0m4.453s
qpc: 4454559us

R=mark@chromium.org
BUG=crashpad:114

Change-Id: I9f18fe54a2711a483ced86ece0b261cdfffc6192
Reviewed-on: https://chromium-review.googlesource.com/346490
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-05-20 17:23:10 +00:00
Scott Graham
6c39959a97 win: Only resume process if successfully suspended
R=mark@chromium.org
BUG=crashpad:110

Change-Id: I9c8ad6e1dfc53fdf93ed6316b0efa55a880b77f9
Reviewed-on: https://chromium-review.googlesource.com/345668
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-05-18 23:45:59 +00:00
Scott Graham
a02ba24006 Convert from scoped_ptr to std::unique_ptr
Follows https://codereview.chromium.org/1911823002/ but fixes includes
that were messed up there.

Change-Id: Ic4bad7d095ee6f5a1c9f8ca2d11ac9e67d55a626
Reviewed-on: https://chromium-review.googlesource.com/340497
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-04-25 19:16:26 +00:00
Scott Graham
6a6a0c27ed win: Support dumping another process by causing it to crash
Adds a new client API which allows causing an exception in another
process. This is accomplished by injecting a thread that calls
RaiseException(). A special exception code is used that indicates to the
handler that the exception arguments contain a thread id and exception
code, which are in turn used to fabricate an exception record. This is
so that the API can allow the client to "blame" a particular thread in
the target process.

The target process must also be a registered Crashpad client, as the
normal exception mechanism is used to handle the exception.

The injection of a thread is used instead of DebugBreakProcess() which
does not cause the UnhandledExceptionFilter() to be executed.
NtCreateThreadEx() is used in lieu of CreateRemoteThread() as it allows
passing of a flag which avoids calling DllMain()s. This is necessary to
allow thread creation to succeed even when the target process is
deadlocked on the loader lock.

BUG=crashpad:103

Change-Id: I797007bd2b1e3416afe3f37a6566c0cdb259b106
Reviewed-on: https://chromium-review.googlesource.com/339263
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-04-22 17:27:58 +00:00
Taiju Tsuiki
12536e06e5 Replace base/template_util.h stuff with C++11 type_traits
BUG=chromium:554293

Change-Id: I5fe06bcba261dd770f1882519b541f870f4a1e62
Reviewed-on: https://chromium-review.googlesource.com/331150
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-04-01 15:29:16 +00:00
Scott Graham
badfacccee win: Add support for capturing unloaded modules
R=mark@chromium.org
BUG=crashpad:89

Change-Id: Ib6a67147e538811168d68f14a457fdceab30c02e
Reviewed-on: https://chromium-review.googlesource.com/327231
Reviewed-by: Mark Mentovai <mark@chromium.org>
2016-02-18 00:55:38 +00:00
Patrick Monette
4794225f22 Adding an API to read module annotations in snapshot.gyp
Kasko needs a way to read crash keys from out of process. This API
reuses the functionality of PEImageAnnotationsReader.

Change-Id: I2f3bbc358212e6f50235183e9dbb4e5a2cf989cf

This is a reupload of https://codereview.chromium.org/1586433003/ but
for gerrit.

Change-Id: I2f3bbc358212e6f50235183e9dbb4e5a2cf989cf
Reviewed-on: https://chromium-review.googlesource.com/322550
Reviewed-by: Scott Graham <scottmg@chromium.org>
Tested-by: Scott Graham <scottmg@chromium.org>
Reviewed-by: Scott Graham <scottmg@google.com>
2016-01-18 20:35:42 +00:00
Mark Mentovai
6d2d31d2d1 Use base/macros.h instead of base/basictypes.h
This was done in Chromium’s local copy of Crashpad in 562827afb599. This
change is similar to that one, except more care was taken to avoid
including headers from a .cc or _test.cc when already included by the
associated .h. Rather than using <stddef.h> for size_t, Crashpad has
always used <sys/types.h>, so that’s used here as well.

This updates mini_chromium to 8a2363f486e3a0dc562a68884832d06d28d38dcc,
which removes base/basictypes.h.

e128dcf10122 Remove base/move.h; use std::move() instead of Pass()
8a2363f486e3 Move basictypes.h to macros.h

R=avi@chromium.org

Review URL: https://codereview.chromium.org/1566713002 .
2016-01-06 12:22:50 -05:00
Mark Mentovai
583d1dc3ef Provide std::move() in compat instead of using crashpad::move()
This more-natural spelling doesn’t require Crashpad developers to have
to remember anything special when writing code in Crashpad. It’s easier
to grep for and it’s easier to remove the “compat” part when pre-C++11
libraries are no longer relevant.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1513573005 .
2015-12-09 17:36:32 -05:00
Scott Graham
b9e732d318 win: Fix a few sign mismatch warnings in crashpad.
BUG=chromium:567877
R=mark@chromium.org, scottmg@chromium.org

Review URL: https://codereview.chromium.org/1503403003 .
2015-12-08 14:21:29 -08:00
Mark Mentovai
f55d18ade6 Add AlignedVector and use it for vector<MEMORY_BASIC_INFORMATION64>
MEMORY_BASIC_INFORMATION64 specifies an alignment of 16, but the
standard allocator used by containers doesn't honor this. Although 16
is the default alignment size used on Windows for x86_64, it's not for
32-bit x86. clang assumed that the alignment of the structure was as
declared, and used an SSE load sequence that required this alignment.

AlignedAllocator is a replacement for std::allocator that allows the
alignment to be specified. AlignedVector is an std::vector<> that uses
AlignedAllocator instead of std::allocator.

BUG=chromium:564691
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1498133002 .
2015-12-08 15:38:17 -05:00
Scott Graham
894a06070e win: Fix some warnings reported by /analyze
Reported by brucedawson@chromium.org.

R=mark@chromium.org
BUG=chromium:427616

Review URL: https://codereview.chromium.org/1489293004 .
2015-12-02 13:52:03 -08:00
Mark Mentovai
5be8ce4ea0 Get module versions and types from in-memory images
Don't call GetFileVersionInfo(), which calls LoadLibrary() to be able to
access the module's resources. Loading modules from the crashy process
into the handler process can cause trouble. The Crashpad handler
definitely doesn't want to run arbitrary modules' module initializer
code.

Since the VS_FIXEDFILEINFO needed is already in memory in the remote
process' address space, just access it from there.

BUG=crashpad:78
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1475023004 .
2015-12-01 17:06:37 -05:00
Dana Jansens
6bebb10829 Replace use of .Pass() with crashpad::move().
Since C++11 library support isn't available everywhere crashpad is
compiled, add our own move() method in the crashpad namespace to replace
std::move() for now. Replace uses of .Pass() with this method.

R=mark@chromium.org, scottmg@chromium.org
BUG=chromium:557422

Review URL: https://codereview.chromium.org/1483073004 .
2015-11-30 14:20:54 -08:00
Mark Mentovai
116e1087f0 win: Don't warn when no VERSIONINFO resource is present in a module
Modules will work without a VERSIONINFO resource. This happens in some
of Crashpad's tests.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1467993003 .
2015-11-23 16:17:50 -05:00
Scott Graham
74e69ed555 win: Avoid some more clang complaints
R=mark@chromium.org
BUG=chromium:82385

Review URL: https://codereview.chromium.org/1463633002 .
2015-11-19 15:09:59 -08:00
Scott Graham
0a717f0d27 win: class VM_COUNTERS -> struct
The fields aren't accessed anyway, but clang warns that they're
completely inaccessible. Also, matches all the other definitions in this
file.

R=mark@chromium.org

Review URL: https://codereview.chromium.org/1462203002 .
2015-11-19 14:26:36 -08:00
Mark Mentovai
4f09b58d1f Add RandomString() and its test, and use it everywhere it makes sense
This unifies several things that used a 16-character random string, and
a few other users of random identifiers where it also made sense to use
a 16-character random string.

TEST=crashpad_util_test RandomString.RandomString
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1451793002 .
2015-11-16 13:39:01 -05:00
Mark Mentovai
7413569ea6 win: Explain the CreateFile() client-side pipe-opening loop
The bug and linked code review has more of the history, but we’ve been
tempted to remove the loop outright a couple of times already before
realizing that it serves an important purpose. Hopefully this comment
will protect our future selves from going on the same fool’s errand.

BUG=crashpad:75
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1427643010 .
2015-11-10 16:43:13 -05:00
Mark Mentovai
81ece89d6a Make ScopedGeneric uses slightly more consistent
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1426533008 .
2015-11-09 15:33:36 -05:00
Scott Graham
ff274507dc win: Only retry in UseHandler() loop on ERROR_PIPE_BUSY
This is better because now end_to_end_test.py fails immediately with

[1180:9020:20151106,145204.830:ERROR registration_protocol_win.cc:39] CreateFile: The system cannot find the file specified.  (0x2)

R=mark@chromium.org
BUG=crashpad:75

Review URL: https://codereview.chromium.org/1409693011 .
2015-11-06 15:54:48 -08:00
Mark Mentovai
b666bcbe98 win: Use signed int as the integer representation of HANDLEs
HandleToInt() and IntToHandle() use int, a signed type, for the 32-bit
integer representation of HANDLE values. For opaque values, an unsigned
type would normally be used, but in this case, signed was chosen for
sign extension to work correctly. INVALID_HANDLE_VALUE is defined as
((HANDLE)(LONG_PTR)-1), and this needs to round-trip through the chosen
integer representation back to the same HANDLE value. Sign extension is
also recommended by
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384203.

As suggested in
https://codereview.chromium.org/1422503015/diff/1/util/win/handle.cc#newcode24

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1422023010 .
2015-11-06 15:03:13 -05:00
Scott Graham
e75e8c800f win: Lower integrity level of connection pipe
This is necessary to be able to connect to crashpad_handler from a
Chrome renderer.

R=jschuh@chromium.org, mark@chromium.org
BUG=chromium:546288

Review URL: https://codereview.chromium.org/1405093013 .
2015-11-06 10:43:39 -08:00
Mark Mentovai
82ffeaa0f0 win: crashpad_util_test ProcessInfo.Handles doesn't work with CONOUT$
In 2eeaa3ac549a, I added a check to make sure that the expected CONOUT$
handle was found. Its omission seemed to be unintentional. The tests
passed for me on Windows 10, but failed on the bots. I can reproduce
the failures locally on Windows 7.

Doing the inheritance test with a file other than CONOUT$ fixes the
immediate problem, but we should find out why this CONOUT$ handle isn't
showing up in the handles list on Windows 7, fix it, and add back a
test.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1428753009 .
2015-11-05 15:08:28 -05:00
Mark Mentovai
2eeaa3ac54 win: Add HandleToInt() and IntToHandle()
This consolidates all of the twisted casts and comments that discuss how
HANDLEs are really only 32 bits wide even in 64-bit processes on 64-bit
operating systems into a single location.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1422503015 .
2015-11-05 14:00:26 -05:00
Mark Mentovai
3e988865ad win: crashpad_handler should create its own pipe name in ephemeral mode
Allowing the client to create its own pipe name string caused a race
between client and server. Instead, in this mode, the server now creates
the pipe name along with a pipe, and returns it to its client via a
--handshake-handle. This guarantees that by the time the client gets the
pipe name, the server has already created it.

Ephemeral mode is now implied by --handshake-handle. The --persistent
option is gone. --persistent mode is enabled when using --pipe-name.

BUG=crashpad:69
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1432563003 .
2015-11-03 19:26:18 -05:00
Mark Mentovai
7f939285de win: Rename CrashpadClient::SetHandler() to SetHandlerIPCPipe()
In https://codereview.chromium.org/1414533006/, I'm adding a few
Mac-specific SetHandler() variants, so it makes sense to name each
SetHandler() variant for what it does.

I'm also making it take a wstring argument, which seems like a more
natural fit for what it does. There should be fewer string conversions
this way.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1406993008 .
2015-11-02 17:00:06 -05:00
Mark Mentovai
740c668e87 win: Implement CrashpadClient::StartHandler()
BUG=crashpad:69
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1428803006 .
2015-11-02 13:59:36 -05:00
Scott Graham
4860f64923 win: Handle binary with embedded CodeView debug record
I considered writing the CodeView records to the minidump, but I didn't
find a ton of docs and debugging is only lightly supported (e.g.
http://www.debuginfo.com/articles/gendebuginfo.html#debuggersandformats
and it doesn't attempt to load at all on more recent Visual Studios).

As we won't be generating symbols in this format, and we don't expect to
have symbols for any weird modules that get injected into us in the
wild, it seems like we don't lose anything by just ignoring them.

R=mark@chromium.org
BUG=crashpad:47

Review URL: https://codereview.chromium.org/1430773003 .
2015-10-31 11:45:39 -07:00
Mark Mentovai
cd0e25f1ba Update all URLs to point to https://crashpad.chromium.org/
All other links to code.google.com and googlecode.com are fixed to point
to their proper new homes as well.

R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1414243005 .
2015-10-29 18:31:20 -04:00
Mark Mentovai
06ad194571 win: Construct ExceptionHandlerServer() with its pipe argument (again)
This re-lands 9d03d54d0ba1, which was partially un-done by an apparent
bad rebase leading up to fc7d8b3a27e1.

Review URL: https://codereview.chromium.org/1424213005 .
2015-10-29 18:19:37 -04:00
Mark Mentovai
fc7d8b3a27 mac: Make crashpad_handler get its receive right from its client
Previously, crashpad_handler made its own receive right, and transferred
a corresponding send right to its client. There are two advantages to
making the receive right in the client:

 - It is possible to monitor the receive right for a port-destroyed
   notificaiton in the client, allowing the handler to be restarted if
   it dies.
 - For the future run-from-launchd mode (bug crashpad:25), the handler
   will obtain its receive right from the bootstrap server instead of
   making its own. Having the handler get its receive right from
   different sources allows more code to be shared than if it were to
   sometimes get a receive right and sometimes make a receive right and
   transfer a send right.

This includes a restructuring in crashpad_client_mac.cc that will make
it easier to give it an option to restart crashpad_handler if it dies.
The handler starting logic should all behave the same as before.

BUG=crashpad:68
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1409073013 .
2015-10-29 18:09:03 -04:00
Mark Mentovai
9d03d54d0b win: Construct ExceptionHandlerServer() with its pipe argument
This allows better code sharing in crashpad_handler’s main(). It doesn’t
look like much of an improvement now, but a separate change will cause
the Mac ExceptionHandlerServer() to be constructed with an argument. It
will be beneficial for Mac and Windows to be able to share the Run()
call.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1402333004 .
2015-10-29 15:12:23 -04:00
Scott Graham
03d8be4a15 win: Fix NTSTATUS_LOG for no-function arg version of COMPACT_GOOGLE_LOG_EX_
R=mark@chromium.org
BUG=crashpad:1, chromium:546288

Review URL: https://codereview.chromium.org/1426493002 .
2015-10-23 14:32:17 -07:00
Scott Graham
4b780ba040 Tidy up to enable C4800 on Windows
Fixes two incorrect usages of ssize_t/off_t being implicitly converted
to bool. As such, I think it's worth the cost of the additional !! on
BOOL returning Win32 functions.

R=mark@chromium.org

Review URL: https://codereview.chromium.org/1408123006 .
2015-10-22 14:32:13 -07:00
Scott Graham
90ef7475cd win: Validate readability of memory ranges added to minidump
R=mark@chromium.org
BUG=crashpad:59

Review URL: https://codereview.chromium.org/1412243005 .
2015-10-21 16:07:03 -07:00
Mark Mentovai
d075a9eb2e win: Add and use GET_FUNCTION() and GET_FUNCTION_REQUIRED()
These wrap the GetProcAddress(LoadLibrary(), …) idiom into macros that
are much less wordy.

TEST=crashpad_util_test GetFunction.GetFunction and all others
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1405323003 .
2015-10-19 14:32:07 -04:00
Mark Mentovai
1818dbbb08 win: Fix crashpad_util_test ProcessInfo.Handles
This new test from 7de04b02f85d was failing on Windows 10. I started by
adding the hint, which produced “CreateFileMapping: Access is denied.
(0x5)”. Switching the “Global\” to “Local\” fixes the test for me.

TEST=crashpad_util_test ProcessInfo.Handles
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1407993003 .
2015-10-19 13:40:50 -04:00
Scott Graham
4600643a78 Some plumbing for the beginning of getting handles into snapshot/minidump
Follows https://codereview.chromium.org/1400413002/.

R=mark@chromium.org
BUG=crashpad:21, crashpad:46, crashpad:52

Review URL: https://codereview.chromium.org/1407643004 .
2015-10-16 15:58:40 -07:00
Scott Graham
7de04b02f8 win: Add Handles() to ProcessInfo
To eventually be used to fill out MINIDUMP_HANDLE_DESCRIPTOR.

R=mark@chromium.org
BUG=crashpad:21, crashpad:46, crashpad:52

Review URL: https://codereview.chromium.org/1400413002 .
2015-10-16 15:31:32 -07:00
Scott Graham
d1e49bd221 Fix CRITICAL_SECTION test
I thought I had confirmed that this still allocated and ignored the flag
on older OSs, but I must have not had the PLOG active yet? I'm not sure
what I did. (I might try to blame VMware as it has an annoying habit of
caching old binaries when you use it's "Shared Folders" feature to point
at the dev machine's build dir.)

I confirmed that it does work on Win8 and Win10 but doesn't on Win XP
and Win 7.

R=mark@chromium.org
BUG=crashpad:52

Review URL: https://codereview.chromium.org/1405243002 .
2015-10-16 14:55:14 -07:00
Scott Graham
4893a9b76d win: Capture some CRITICAL_SECTION debugging data
Capture the memory for the loader lock (can be inspected by !cs), as
well as all locks that were created with .DebugInfo which can be viewed
with !locks.

e.g.

0:000> !cs ntdll!LdrpLoaderLock
-----------------------------------------
Critical section   = 0x778d6410 (ntdll!LdrpLoaderLock+0x0)
DebugInfo          = 0x778d6b6c
NOT LOCKED
LockSemaphore      = 0x0
SpinCount          = 0x04000000

0:000> !locks -v

CritSec ntdll!RtlpProcessHeapsListLock+0 at 778d7620
LockCount          NOT LOCKED
RecursionCount     0
OwningThread       0
EntryCount         0
ContentionCount    0

CritSec +7a0248 at 007a0248
LockCount          NOT LOCKED
RecursionCount     0
OwningThread       0
EntryCount         0
ContentionCount    0

CritSec crashy_program!g_critical_section_with_debug_info+0 at 01342c48
LockCount          NOT LOCKED
RecursionCount     0
OwningThread       0
EntryCount         0
ContentionCount    0

CritSec crashy_program!crashpad::`anonymous namespace'::g_test_critical_section+0 at 01342be0
WaiterWoken        No
LockCount          0
RecursionCount     1
OwningThread       34b8
EntryCount         0
ContentionCount    0
*** Locked

Scanned 4 critical sections

R=mark@chromium.org
BUG=crashpad:52

Review URL: https://codereview.chromium.org/1392093003 .
2015-10-15 13:18:08 -07:00
Scott Graham
d3bdb23ffe Use MEMORY_BASIC_INFORMATION64 rather than a custom MemoryInfo
We already use all the shared constants for page protection and type,
so rather than making various incompatible structures, just use
the MEMORY_BASIC_INFORMATION64 one directly, so that it can be directly
used.

R=mark@chromium.org
BUG=crashpad:20, crashpad:46

Review URL: https://codereview.chromium.org/1375313005 .
2015-10-07 12:23:08 -07:00
Scott Graham
ccd5ec6404 MEM_RESERVE regions are not accessible by ReadProcessMemory()
Sadly this code did not survive a collision with the real world. In
probing for the environment block there's a MEM_COMMIT region followed
directly by a MEM_RESERVE region (past the end of the environment
block).

Update region checker to correctly treat MEM_RESERVE as inaccessible.

R=mark@chromium.org
BUG=crashpad:20, crashpad:46, crashpad:59

Review URL: https://codereview.chromium.org/1370063005 .
2015-10-01 15:28:40 -07:00
Scott Graham
ecf3b37863 win: Save contents of TEBs allowing !teb and !gle to work in windbg
crashy_program's log looks something like this now:

0:000> .ecxr
eax=00000007 ebx=7f24e000 ecx=7f24d000 edx=00000000 esi=00497ec8 edi=00d39ca0
eip=00cf5d12 esp=001ffcd8 ebp=001ffcdc iopl=0         nv up ei ng nz ac po cy
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010293
crashy_program+0x5d12:
00cf5d12 ??              ???
0:000> !teb
TEB at 7f24d000
    ExceptionList:        001ff548
    StackBase:            00200000
    StackLimit:           001fd000
    SubSystemTib:         00000000
    FiberData:            00001e00
    ArbitraryUserPointer: 00000000
    Self:                 7f24d000
    EnvironmentPointer:   00000000
    ClientId:             00003658 . 00004630
    RpcHandle:            00000000
    Tls Storage:          7f24d02c
    PEB Address:          7f24e000
    LastErrorValue:       2
    LastStatusValue:      c000000f
    Count Owned Locks:    0
    HardErrorMode:        0
0:000> !gle
LastErrorValue: (Win32) 0x2 (2) - The system cannot find the file specified.
LastStatusValue: (NTSTATUS) 0xc000000f - {File Not Found}  The file %hs does not exist.

R=mark@chromium.org
BUG=crashpad:46

Review URL: https://codereview.chromium.org/1364803004 .
2015-10-01 14:04:49 -07:00
Scott Graham
4df538f283 win: Add memory map range intersection helper
To be used for improved version of ReadMemory() that is memory-map
aware, in particular for reading the environment block in
https://codereview.chromium.org/1360863006/.

R=mark@chromium.org
BUG=crashpad:20, crashpad:46

Review URL: https://codereview.chromium.org/1372183002 .
2015-10-01 11:47:32 -07:00
Scott Graham
9d9302bb02 win: fix VirtualQueryEx on < win10
On Win10, VirtualQueryEx supports querying the x64 part of WOW64
processes. However, on lower OSs it errors past 2/3G. There's no direct
way to retrieve to maximum memory address for processes other than
yourself, but fortunately, VirtualQueryEx sets a distinct error code
when `lpAddress` exceeds the maximum accessible address, so we can just
terminate successfully in that case.

R=mark@chromium.org
BUG=crashpad:20, crashpad:46

Review URL: https://codereview.chromium.org/1376353002 .
2015-09-30 17:20:23 -07:00
Mark Mentovai
c8592b847b win: Add and use a custom CaptureContext() implementation
RtlCaptureContext() is buggy and limited.

BUG=crashpad:53
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1377963002 .
2015-09-30 14:10:08 -04:00
Scott Graham
56c8359b27 win: Gather memory information
Not yet written as MINIDUMP_MEMORY_INFO_LIST to minidump.

R=mark@chromium.org
BUG=crashpad:20, crashpad:46

Review URL: https://codereview.chromium.org/1369833002 .
2015-09-25 21:11:04 -07:00
Scott Graham
475ac81cce win: Implement CRASHPAD_SIMULATE_CRASH()
Windows requires the connection to the handler to do anything, so it
can't really be implemented or tested without CrashpadClient and the
connection machinery.

R=mark@chromium.org
BUG=crashpad:53

Review URL: https://codereview.chromium.org/1356383002 .
2015-09-25 13:45:32 -07:00
Scott Graham
0758dbde9a win: Save contents of PEB to minidump to start making !peb work
This makes the basics of !peb work in windbg, however, pointed-to things
are not yet retrieved. For full functionality, a variety of pointers in
the PEB also needs to be walked and captured.

e.g.

Previously:

0:000> .ecxr
eax=00000007 ebx=7e383000 ecx=c3f9a943 edx=00000000 esi=006d62d0 edi=003c9280
eip=00384828 esp=005bf634 ebp=005bf638 iopl=0         nv up ei pl zr na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010246
crashy_program!crashpad::`anonymous namespace'::SomeCrashyFunction+0x28:
00384828 c7002a000000    mov     dword ptr [eax],2Ah  ds:002b:00000007=????????
0:000> !peb
PEB at 7e383000
error 1 InitTypeRead( nt!_PEB at 7e383000)...

Now:

0:000> .ecxr
eax=00000007 ebx=7f958000 ecx=02102f4d edx=00000000 esi=00e162d0 edi=01389280
eip=01344828 esp=00c2fb64 ebp=00c2fb68 iopl=0         nv up ei pl zr na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010246
crashy_program!crashpad::`anonymous namespace'::SomeCrashyFunction+0x28:
01344828 c7002a000000    mov     dword ptr [eax],2Ah  ds:002b:00000007=????????
0:000> !peb
PEB at 7f958000
    InheritedAddressSpace:    No
    ReadImageFileExecOptions: No
    BeingDebugged:            No
    ImageBaseAddress:         01340000
    Ldr                       77ec8b40
    *** unable to read Ldr table at 77ec8b40
    SubSystemData:     00000000
    ProcessHeap:       00e10000
    ProcessParameters: 00e114e0
    CurrentDirectory:  '< Name not readable >'
    WindowTitle:  '< Name not readable >'
    ImageFile:    '< Name not readable >'
    CommandLine:  '< Name not readable >'
    DllPath:      '< Name not readable >'
    Environment:  00000000
       Unable to read Environment string.

R=mark@chromium.org
BUG=crashpad:46

Review URL: https://codereview.chromium.org/1364053002 .
2015-09-25 10:31:02 -07:00
Scott Graham
5165c48b3a Use argument escaping function in util/win/process_info_test.cc
R=mark@chromium.org

Review URL: https://codereview.chromium.org/1356753004 .
2015-09-22 09:20:23 -07:00
Scott Graham
6082aed2f2 win: Get Crashpad compiling under VS2015
R=mark@chromium.org
BUG=crashpad:1, chromium:440500

Review URL: https://codereview.chromium.org/1357833002 .
2015-09-21 10:51:15 -07:00
Scott Graham
4a34a3dd89 win: Make reading NT_IMAGE_HEADERS work cross-bitness
Factor out some test launching code used in cross-bitness tests.

R=mark@chromium.org
BUG=crashpad:50

Review URL: https://codereview.chromium.org/1352323002 .
2015-09-20 11:16:31 -07:00
Scott Graham
bf556829d9 win: support x64 reading x86 (wow64)
Removes the bitness-specific targets in favour of pulling binaries from
the other build directory. This is to avoid the added complexity of
duplicating all the targets for the x86 in x64 build.

Overall, mostly templatizing more functions to support the
wow64-flavoured structures. The only additional functionality required
is reading the x86 TEB that's chained from the x64 TEB when running
as WOW64.

The crashing child test was switched to a manual CreateProcess because
it needs to launch a binary other than itself.

R=mark@chromium.org
BUG=crashpad:50

Review URL: https://codereview.chromium.org/1349313003 .
2015-09-18 16:06:05 -07:00
Scott Graham
8ce88d8953 win x86: Grab bag of restructuring to get tests working on x86-on-x86
A few function implementations that were missing, various switches
for functions/functionality that didn't exist on XP, and far too long
figuring out what exactly was wrong with SYSTEM_PROCESS_INFORMATION
on x86 (the "alignment_for_x86" fields).

R=mark@chromium.org
BUG=crashpad:1, crashpad:50, chromium:531663

Review URL: https://codereview.chromium.org/1336823002 .
2015-09-16 12:42:20 -07:00
Scott Graham
bc55c7916e win: Add (currently unused) NTSTATUS_LOG
Split out of https://codereview.chromium.org/1336823002/, I'll go and
adapt various places to use it as I need to touch them.

R=mark@chromium.org
BUG=crashpad:1, crashpad:50

Review URL: https://codereview.chromium.org/1343873003 .
2015-09-15 09:22:29 -07:00
Scott Graham
6c23e37ee9 win: Fix ProcessInfo test when running on x86 host OS
R=mark@chromium.org
BUG=crashpad:50

Review URL: https://codereview.chromium.org/1339813002 .
2015-09-14 11:07:59 -07:00