19 Commits

Author SHA1 Message Date
Mark Mentovai
6278690abe Update copyright boilerplate, 2022 edition (Crashpad)
sed -i '' -E -e 's/Copyright (.+) The Crashpad Authors\. All rights reserved\.$/Copyright \1 The Crashpad Authors/' $(git grep -El 'Copyright (.+) The Crashpad Authors\. All rights reserved\.$')

Bug: chromium:1098010
Change-Id: I8d6138469ddbe3d281a5d83f64cf918ec2491611
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3878262
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2022-09-06 23:54:07 +00:00
Robert Sesek
10e82d5318 mac: Make crashpad build with the 12.0 SDK
The size of dyld_all_image_infos didn't change, but the last 128 bit
of `reserved` moved out of `reserved` and got names.

On 64-bit, that's straightforward -- just move two uint64s out of the
array into fields.

On 32-bit, it's fairly awkward: It's 4 of the uintptr_t `reserved`
array, which means `UIntPtr, reserved, [4]` would have to diverge
between 32-bit and 64-bit, and also shared_cache_fs_obj_id would
straddle the `end_v14` boundary. Since macOS 12.0 doesn't support
32-bit builds, just punt on this for 32-bit. (This might possibly
mean that crashpad-on-apple-watch might not compile, but that's
a build configuration that doesn't exist.)

See comment 9 and 6 on the bug.

Bug: crashpad:375, chromium:1265179
Change-Id: I221af20c59c30a8176d5685d3f5e84aaf3de9afe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3253742
Commit-Queue: Nico Weber <thakis@chromium.org>
Auto-Submit: Nico Weber <thakis@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Message-Id: Merged from chromium 83a01b8e2cd2d4d96b0e298d012bb3a2bd93c64f
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3293642
Commit-Queue: Robert Sesek <rsesek@chromium.org>
2021-11-19 21:22:55 +00:00
Mark Mentovai
9a5a789123 mac: Fix MacOSVersionNumber for 10.12.0 < version < 10.13.4
In 5412beb63386, I asserted (via my code) that the kern.osproductversion
sysctl was introduced in 10.12.0, but this was utterly wrong. It’s not
available until 10.13.4. Compare 10.13.3
xnu-4570.41.2/bsd/kern/kern_sysctl.c to 10.13.4
xnu-4570.51.1/bsd/kern/kern_sysctl.c, look for osproductversion.

https://pbs.twimg.com/media/EU0GDTVU4AY73KC.jpg

Failures appeared starting at
https://ci.chromium.org/p/chromium/builders/ci/Mac10.12%20Tests/37499
(https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8869605548532164608/+/steps/crashpad_tests_on_Intel_GPU_on_Mac_on_Mac-10.12.6/0/stdout).

This fixes expectations to not require kern.osproductversion to exist
until 10.13.4.

VM-tested on 10.12.6, 10.13.3, 10.13.4, and 10.14.0.

Bug: crashpad:347
Test: crashpad_util_test MacUtil.MacOSVersionNumber
Change-Id: Ic58d8ca8f04394d41c691dd2d946c59497ee71d5
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2402248
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2020-09-10 13:53:29 +00:00
Mark Mentovai
bdf9471324 mac: Switch from <AvailabilityMacros.h> to <Availability.h>
The macOS 11.0 SDK, as of Xcode 12b6 12A8189n, has not updated
<AvailabilityMacros.h> with a MAC_OS_X_VERSION_11_0 or
MAC_OS_X_VERSION_10_16 constant. However, the <Availability.h> interface
has been updated to provide both __MAC_11_0 and __MAC_10_16.
<AvailabilityMacros.h>’s MAC_OS_X_VERSION_MAX_ALLOWED, which is supposed
to identify the SDK version, is broken in the 11.0 SDK in that whenever
the deployment target is set to 10.15 or earlier, the SDK will be
mis-identified through this interface as 10.15. When using the
<Availability.h> equivalent, __MAC_OS_X_VERSION_MAX_ALLOWED, the 11.0
SDK is identified as 10.16 (arguably it should be internally versioned
as 11.0, but at least this interface allows it to be detected
unambiguously.) It’s clear that the <AvailabilityMacros.h> interface
provides no meaningful support for the macOS 11.0 SDK at all, but
<Availability.h> does.

<Availability.h> was introduced in the Mac OS X 10.5 SDK, so there is no
relevant SDK version compatibility problem with this interface.

Key differences between these interfaces for the purposes used by
Crashpad:
 - <AvailabilityMacros.h> → <Availability.h>
 - MAC_OS_X_VERSION_MIN_REQUIRED (DT) → __MAC_OS_X_VERSION_MIN_REQUIRED
 - MAC_OS_X_VERSION_MAX_ALLOWED (SDK) → __MAC_OS_X_VERSION_MAX_ALLOWED
 - MAC_OS_X_VERSION_x_y → __MAC_x_y
 - <Availability.h> __MAC_OS_X_VERSION_* SDK/DT macros are only
   available when targeting macOS, while <AvailabilityMacros.h>
   MAC_OS_X_VERSION_* SDK/DT macros are available on all Apple platforms,
   which may be a source of confusion. (<Availability.h> __MAC_* macros
   do remain available on all Apple platforms.)

This change was made mostly mechanically by:

sed -i '' -Ee 's/<AvailabilityMacros.h>/<Availability.h>/g' \
    $(git grep -E -l '<AvailabilityMacros.h>' |
          grep -v AvailabilityMacros.h)

sed -i '' -Ee 's/(MAC_OS_X_VERSION_(MIN_REQUIRED|MAX_ALLOWED))/__\1/g' \
    $(git grep -E -l 'MAC_OS_X_VERSION_(MIN_REQUIRED|MAX_ALLOWED)' |
          grep -v AvailabilityMacros.h)

sed -i '' -Ee 's/(MAC_OS_X_VERSION_(10_[0-9]+))/__MAC_\2/g' \
    $(git grep -E -l 'MAC_OS_X_VERSION_(10_[0-9]+)' |
          grep -v AvailabilityMacros.h)

Bug: crashpad:347
Change-Id: Ibdcd7a6215a82f7060b7b67d98691f88454085fc
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2382421
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
2020-08-31 21:11:29 +00:00
Mark Mentovai
2fb4e9e6a4 mac: Update the process_types version of dyld_all_image_infos for 10.15
macOS 10.15 (“Catalina”) introduces a single new field to its
dyld_all_image_infos structure, and uses structure version 16.

macOS 10.13 and 10.14 were documented in <mach-o/dyld_images.h> as using
structure version 16, but they actually use version 15. They should have
used version 16, as they do use a structure expanded from macOS 10.12,
which also uses version 15. Previously, process_types was true to the
documentation, but now that this is known to be incorrect, it’s been
revised to reflect reality. Because two variants of the version 15
structure exist, run-time OS version detection is used to disambiguate.

Bug: crashpad:310
Test: crashpad_snapshot_test ProcessTypes.DyldImagesSelf (10.15 SDK)
Change-Id: Ibc82b6a73809949f4bbf416ece7aa955b627c573
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1852109
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2019-10-10 21:59:24 +00:00
Mark Mentovai
8742051c60 mac: Drop apple_cctools and getsectiondata()/getsegmentdata() wrappers
These are present on 10.7 and later, and were only provided for the
benefit of older systems that probably aren’t relevant to Crashpad any
longer.

Change-Id: If9d7222f7af05020d0ff57d5d9ed06355fa14a48
Reviewed-on: https://chromium-review.googlesource.com/827686
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-12-15 23:05:54 +00:00
Mark Mentovai
c4f6ca3c6a mac: Provide a larger thread state buffer for AVX-512 on 10.13
Crashpad doesn’t use AVX-512, but when receiving replies to exceptions
forwarded to ReportCrash, may see buffers large enough to contain
AVX-512 thread state. This can result in messages like
“UniversalExceptionRaise: (ipc/rcv) msg too large (0x10004004)”.

I386_THREAD_STATE_MAX has increased from 224 to 614 in the 10.13 SDK,
meaning that the maximum supported size for old_state and new_state in
[mach_]exception_raise_state[_identity]() has increased from 896 to
2,456 bytes. This constant defines the size of the buffer that these
MIG-generated routines will work with. By providing this definition in
compat, the buffer size is increased when building with older SDKs.

Note that on the “send” side, the size of the message given to
mach_msg() will be trimmed to include only the valid part of the state
area based on the stateCnt field, so increasing the value to 614 here
won’t result Crashpad sending messages this large. That would be a
potential interoperability concern with older OS versions.

Bug: crashpad:185, crashpad:190
Change-Id: Ia46091ae46fd6227a17f59eb4bc00914be471aa7
Reviewed-on: https://chromium-review.googlesource.com/541515
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-06-20 14:31:38 +00:00
Mark Mentovai
107fb76317 mac: Handle _dyld_get_all_image_infos() not being available on 10.13
_dyld_get_all_image_infos() was only used in test code in Crashpad.

This addresses two related problems.

When running on 10.13 or later, _dyld_get_all_image_infos() is not
available. It appears to still be implemented in dyld, but its symbol is
now private. This was always known to be an “internal” interface. When
it’s not available, fall back to obtaining the address of the process’
dyld_all_image_infos structure by calling task_info(…, TASK_DYLD_INFO,
…). Note that this is the same thing that the code being tested does,
although the tests are not rendered entirely pointless because the code
being tested consumes dyld_all_image_infos through its own
implementation of an out-of-process reader interface, while the
dyld_all_image_infos data obtained by _dyld_get_all_image_infos() is
handled strictly in-process by ordinary memory reads. This is covered by
bug 187.

When building with the 10.13 SDK, no _dyld_get_all_image_infos symbol is
available to link against. In this case, access the symbol strictly at
runtime via dlopen() if it may be available, or when expecting to only
run on 10.13 and later, don’t even bother looking for this symbol. This
is covered by part of bug 188.

Bug: crashpad:185, crashpad:187, crashpad:188
Change-Id: Ib283e070faf5d1ec35deee420213b53ec24fb1d3
Reviewed-on: https://chromium-review.googlesource.com/534633
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2017-06-14 15:08:05 +00:00
Mark Mentovai
952f787f4a doc: Standardize on “macOS” in comments
Use “macOS” as the generic unversioned name of the operating system in
comments. For version-specific references, use Mac OS X through 10.6, OS
X from 10.7 through 10.11, and macOS for 10.12.

Change-Id: I1ebee64fbf79200bc799d4a351725dd73257b54d
Reviewed-on: https://chromium-review.googlesource.com/408269
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-08 19:21:44 +00:00
Mark Mentovai
3887d99e48 mac: Handle EXC_RESOURCE RESOURCE_TYPE_IO
RESOURCE_TYPE_IO always appears to be non-fatal based on disassembly of
the function responsible for sending it in xnu 3705.0.0.1.10 (10.12dp1
16A201w).

BUG=crashpad:120,crashpad:124

Change-Id: I9dcc6673f922cbd7af910b76991825a9d9c96fe6
Reviewed-on: https://chromium-review.googlesource.com/355250
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-06-23 15:11:55 +00:00
Mark Mentovai
c281e30f93 mac: Update the dyld_all_image_infos structure for 10.12
BUG=crashpad:120

Change-Id: I7b2df5f2de13517b2586569ce267bcb0ae845101
Reviewed-on: https://chromium-review.googlesource.com/353830
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-06-20 16:14:24 +00:00
Mark Mentovai
9086d25ce8 Don’t trigger EXC_CORPSE_NOTIFY on OS X 10.11
CrashReportExceptionHandler::CatchMachException() must always set a
valid new_state. Failing to do so appears to trigger corpse generation
on OS X 10.11. This is addressed by calling ExcServerCopyState().
Previously, this was not done for exceptions forwarded to the user
ReportCrash, under the apparent mistaken assumption that ReportCrash
would do it. However, ReportCrash is given copies of out-parameters like
new_state to explicitly prevent it from influencing Crashpad’s returned
state.

ExcServerSuccessfulReturnValue() must not return MACH_RCV_PORT_DIED for
an EXC_CRASH handler on OS X 10.11. This appears to trigger corpse
generation. This is addressed by always returning KERN_SUCCESS from
EXC_CRASH handlers on OS X 10.11.

This also adds generic EXC_CORPSE_NOTIFY support throughout Crashpad.
The crashpad_handler does not listen for this exception type, but it is
now possible to work with this exception type using tools like
exception_port_tool and catch_exception_tool.

BUG=crashpad:48
TEST=Crashes handled by crashpad_handler do not result in the generation
     of reports in the root /Library/Logs/DiagnosticReports.

R=kerrnel@chromium.org, rsesek@chromium.org

Review URL: https://codereview.chromium.org/1305893010 .
2015-09-04 14:29:12 -04:00
Mark Mentovai
1baff4ff92 Accept non-fatal resource exceptions without generating crash reports.
This adds IsExceptionNonfatalResource() and its test, and uses it in
crashpad_handler. When non-fatal resource exceptions are encountered, no
crash report is generated. crashpad_handler swallows these exceptions.
Alternatively, it could allow them to be sent to the system’s host-level
resource exception handler, normally com.apple.ReportCrash.root, which
would allow them to be processed in the same way as when Crashpad is not
in use. I’m not sure which option is better. I chose to swallow them
because there doesn’t appear to be much value in letting
com.apple.ReportCrash.root and spindump look at them.

This also moves ExcCrashRecoverOriginalException() to the new file as a
sibling of IsExceptionNonfatalResource(). This provides better
organization.

BUG=crashpad:35, chromium:474163, chromium:474326
TEST=crashpad_util_test ExceptionTypes.IsExceptionNonfatalResource
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1066243002
2015-04-08 17:46:09 -04:00
Mark Mentovai
98cca0e5fc compat/mac: 10.6 SDK compatibility for pre-Xcode 4.2 10.6 SDK.
Some definitions were added to the 10.6 SDK during its lifetime, and
aren’t present in older versions of the SDK. The AVX definitions are in
this group.

Apparently, not all of Chrome’s builders use the same version of this
SDK. A try bot failure was encountered for
https://codereview.chromium.org/1011503002/ in
http://build.chromium.org/p/tryserver.chromium.mac/builders/mac_chromium_compile_dbg_ng/builds/33868/steps/compile%20%28with%20patch%29/logs/stdio.

This provides definitions in compat for when they aren’t available from
the SDK.

TEST=compile
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1001733003
2015-03-16 13:41:48 -04:00
Mark Mentovai
de0979b930 C++11: Use type aliases instead of typedefs.
This replaces all occurrences of “typedef Y X;” with “using X = Y;”.

R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/700143004
2014-11-05 14:09:01 -05:00
Mark Mentovai
5d74f120fc Convert NULL to nullptr.
This change was generated mechanically by running:

  find . \( -name \*.cc -or -name \*.mm -or -name \*.h \) \
      -and -not -path ./third_party/\* -and -not -path ./out/\* \
      -exec sed -i '' -E -e 's/(^|[^_])NULL/\1nullptr/g' {} +

Further manual fix-ups were applied to remove casts of nullptr to other
pointer types where possible, to preserve the intentional use of NULL
(as a short form of MACH_PORT_NULL) in exception_port_tool, and to fix
80-column violations.

https://groups.google.com/a/chromium.org/d/topic/chromium-dev/4mijeJHzxLg/discussion

TEST=*_test
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/656703002
2014-10-14 11:10:45 -04:00
Mark Mentovai
850ec0657d Drop 10.5 support.
TEST=util_test
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/575823002
2014-09-16 11:55:55 -04:00
Mark Mentovai
ab4978b51e 10.6 SDK compatibility.
TEST=util_test MachOImageReader.* (and all others with a 10.6 SDK build)
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/561933004
2014-09-12 12:13:27 -04:00
Mark Mentovai
dfe81014f7 Add compat to Crashpad.
compat includes headers providing definitions normally provided by the
system, in cases where the system SDK does not always provide the
correct or up-to-date definitions, and cases where code on different
platforms needs to access definitions normally only available on one
platform.

To provide definitions on a single platform, where the system SDK may
not provide the definitions correctly, use subdirectories named for the
platform, such as “mac”.

To provide definitions normally available on only one platform to
others, use subdirectories that identify that they are to be used on
platforms other than the one that originated their definitions, such as
“non_win”.

In all cases, headers should be named as they are natively in their
respective SDKs, so that it’s possible to #include them according to
their usual names.

R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/432843002
2014-07-31 13:45:51 -04:00