239 Commits

Author SHA1 Message Date
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
Sigurdur Asgeirsson
542a91e20e Fix the race causing flaky CrashpadClient tests.
Bug: crashpad:81
Change-Id: I3cb115440638df909d1c0cdfd01c824ac0d0b073
Reviewed-on: https://chromium-review.googlesource.com/458592
Reviewed-by: Mark Mentovai <mark@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
2017-03-24 19:46:24 +00:00
Mark Mentovai
14138936b5 test: Compare ProcessInfo::Arguments() to main()’s argc/argv on POSIX
Previously on macOS, the test used an OS-specific library function to
recover the original argc and argv. On Linux/Android, it essentially
reimplemented the very code it was testing, which didn’t make for a very
good test. The new approach is to save argc and argv in main() and base
the comparison on that.

Bug: crashpad:30
Test: crashpad_util_test ProcessInfo.*, crashpad_test_test MainArguments.*
Change-Id: I578abed3b04ae10a22f79a193bbb8b6589276c97
Reviewed-on: https://chromium-review.googlesource.com/456798
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
2017-03-20 17:05:30 +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
546e64cd0b Centrally define CPUContextX86::Fsave and fsave↔︎fxsave conversions
As I was finishing d98a4de718d9, it became evident that fsave
proliferation was becoming a problem. Especially considering tests,
there was much duplicated conversion code. This ties everything up
together in a central location.

test::BytesToHexString() is a new function to ease testing of byte
arrays like x87 registers, without having to loop over each byte.

Some static_asserts are added to verify that complex structures that
need to maintain interoperability don’t grow or shrink. This is used
to check the size of the fxsave and fsave structures, as well as the
MinidumpCPUContext* structures.

BUG=crashpad:162

Change-Id: I1a1be18096ee9be250cbfb2e006adfd08eba8753
Reviewed-on: https://chromium-review.googlesource.com/444004
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-02-16 18:26:13 +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
Mark Mentovai
d1aafe78ea Port the test library and crashpad_test_test to Linux/Android
- Linux (but not Android) provides __fpurge() instead of fpurge().
 - In multiprocess_exec_test_child, use getrlimit(RLIMIT_NOFILE) instead
   of max(sysconf(_SC_OPEN_MAX), OPEN_MAX, getdtablesize()). OPEN_MAX is
   not availble on Linux (but is in Android as a bogus value), and
   getdtablesize() is not available in Android since 5.0.0 (API 21).
   sysconf(_SC_OPEN_MAX) and getdtablesize() both return
   getrlimit(RLIMIT_NOFILE) on all relevant platforms.
 - Add a Linux/Android implementation of test::Paths::Executable().
 - Respect TMPDIR for all POSIX platforms in
   ScopedTempDir::CreateTemporaryDirectory(). If TMPDIR is unset or
   empty, use /tmp, except on Android, where /tmp does not exist and
   /data/local/tmp is used instead.

Also:

 - Fix the Mac and Windows implementations of test::Paths::Executable()
   to abort on fatal error, in line with the new Linux/Android version.

BUG=crashpad:30
TEST=crashpad_test_test

Change-Id: I98a50d8579b193c813ba79794be087649e94cc06
Reviewed-on: https://chromium-review.googlesource.com/405507
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-10-31 19:30:24 +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
Mark Mentovai
89835b30f8 posix: Correctly show the expected exit status in multiprocess tests
When reason is mistaken for reason_, things can get unreasonable.

Change-Id: I3deff343fd6836eba3111ba7551174591c2bf5bc
Reviewed-on: https://chromium-review.googlesource.com/354101
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-06-20 21:08:08 +00:00
Mark Mentovai
6dbf952678 mac: Interpret the size returned by _NSGetExecutablePath() correctly
_NSGetExecutablePath() returns a buffer size including space for the
trailing NUL byte. A std::string’s length should be one less than this,
because the std::string’s length does not include the trailing NUL byte
that is guaranteed to be present.

Change-Id: I46b8a68979beda7dc5de09d0eef6f1d3d6a78ecf
Reviewed-on: https://chromium-review.googlesource.com/354100
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-06-20 21:04:05 +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
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
Mark Mentovai
7764fa1144 Remove errant double-semicolons
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1489063002 .
2015-12-01 12:56:03 -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
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
6e89d45d7d Switch googletest and googlemock to pull from the GitHub git repository
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1404033002 .
2015-11-11 11:13:37 -05: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
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
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
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
6c0d42ce9d Mach port scopers should use get() instead of type conversion operators
In https://codereview.chromium.org/1411523006, the Mach port scopers are
becoming better ScopedGenerics and are losing the type conversion
operators in the process. This is needed to adapt to that change. get()
is ugly, but being explicit about conversion isn’t a bad thing, and
these scopers will gain functionality such as Pass() as part of the
switch.

As a bonus, some would-be uses of get() to check for valid port rights
are becoming a more descriptive is_valid().

R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1405273002 .
2015-10-20 11:03:25 -04:00
Mark Mentovai
2d8a0498ab Add FileWriteMode::kCreateOrFail
BUG=crashpad:63
TEST=crashpad_util_test FileIO.OpenFileForWrite
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1390023002 .
2015-10-07 08:20:55 -04:00
Mark Mentovai
bb13efbda7 Add and use scoped-right-returning wrappers for Mach bootstrap routines
This wraps bootstrap_check_in() in BootstrapCheckIn(), and
bootstrap_look_up() in BootstrapLookUp(). The wrappers make it more
difficult to accidentally leak a returned right. They’re easier to use,
encapsulating common error checking and logging, simplifying all call
sites.

TEST=crashpad_util_test MachExtensions.BootstrapCheckInAndLookUp
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1383283003 .
2015-10-05 17:07:15 -04:00
Scott Graham
bd9bc07625 win: Make reading CrashpadInfo work across bitness
R=mark@chromium.org
BUG=crashpad:50

Review URL: https://codereview.chromium.org/1355503005 .
2015-09-22 10:37:11 -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
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
0b022d72a2 Include implicit_cast.h at all users of it.
The implicit_cast in base will be no more, make sure we have a reference
to the crashpad version at all callsites.

BUG=529769, 472900, crashpad:51
R=mark@chromium.org, scottmg@chromium.org

Review URL: https://codereview.chromium.org/1344683002 .
2015-09-14 14:51:05 -07:00
Scott Graham
754cc3609c win x86: a few trivial compile fixes when GYP_DEFINES=target_arch=ia32
(CL to add x86 bots to waterfall in progress too.)

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

Review URL: https://codereview.chromium.org/1325173002 .
2015-09-02 18:35:19 -07:00
Erik Wright
263582c2d0 Refactor multiprocess test code to allow multiple child processes to be launched.
BUG=
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1164453003 .
2015-07-31 12:31:58 -04:00
Jackie Quinn
797adb3206 Roll DEPS for mini_chromium for updates to base/posix/safe_strerror
Also updates includes and usage of safe_strerror.

BUG=499322
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1181043002.

Patch from Jackie Quinn <jyquinn@chromium.org>.
2015-06-11 20:25:49 -04:00
Scott Graham
1d33a8b0b6 win: fix uncaught multiprocess child test failures
R=erikwright@chromium.org

Review URL: https://codereview.chromium.org/1164683005
2015-06-01 12:17:10 -07:00
Scott Graham
ac709baa2e win: add a child ProcessReader test
Now that we have a multiprocess test harness, add a test for
ProcessReaderWin for reading from a child.

Parent test code wasn't closing handles properly; fix that.

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

Review URL: https://codereview.chromium.org/1160843006
2015-06-01 10:07:51 -07:00
Scott Graham
58df54fffb win: Retrieve "simple map" annotations from modules
Follows https://codereview.chromium.org/1126273003/.

R=rsesek@chromium.org, cpu@chromium.org
TBR=mark@chromium.org
BUG=crashpad:1

Review URL: https://codereview.chromium.org/1138923004
2015-05-28 14:41:32 -07:00
Scott Graham
44727e9c79 win: Add WinMultiprocess for multiprocess Windows tests
As a prerequisite for https://codereview.chromium.org/1138923004/.

R=cpu@chromium.org, rsesek@chromium.org
TBR=mark@chromium.org
BUG=crashpad:1

Review URL: https://codereview.chromium.org/1151953002
2015-05-28 09:04:17 -07:00
Erik Wright
f357afc43e Move thread from test/ to util/thread/.
BUG=
R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/1134943003
2015-05-13 14:05:57 -04:00
Mark Mentovai
809ea8158d test: Move util/test to its own top-level directory, test.
After 9e79ea1da719, it no longer makes sense for crashpad_util_test_lib
to “hide” in util/util_test.gyp. All of util/test is moved to its own
top-level directory, test, which all other test code is allowed to
depend on. test, too, is allowed to depend on all other non-test code.

In a future change, when crashpad_util_test_lib gains a dependency on
crashpad_client, it won’t look so weird for something in util (even
though it’s in util/test) to depend on something in client, because the
thing that needs to depend on client will live in test, not util.

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

Review URL: https://codereview.chromium.org/1051533002
2015-03-31 17:44:14 -04:00