Skip to content

[iOS] In-Proc Crash Reporter#127812

Merged
mdh1418 merged 6 commits intodotnet:mainfrom
mdh1418:inproc_crashreport_ios
May 6, 2026
Merged

[iOS] In-Proc Crash Reporter#127812
mdh1418 merged 6 commits intodotnet:mainfrom
mdh1418:inproc_crashreport_ios

Conversation

@mdh1418
Copy link
Copy Markdown
Member

@mdh1418 mdh1418 commented May 5, 2026

Extending #126916 to iOS, tvOS, and MacCatalyst.

mdh1418 and others added 2 commits May 5, 2026 11:53
Broaden the Android-only opt-in for the in-proc crash reporter to cover
the other mobile Apple platforms: iOS, tvOS, and MacCatalyst. None of
these ship with createdump, so the in-proc reporter is the only
crash-report path available and the Android integration pattern applies
directly. FEATURE_INPROC_CRASHREPORT in clrfeatures.cmake is extended
from CLR_CMAKE_TARGET_ANDROID to also cover CLR_CMAKE_TARGET_IOS,
CLR_CMAKE_TARGET_TVOS, and CLR_CMAKE_TARGET_MACCATALYST; no other build
plumbing is needed because the existing PAL callback registration and
DOTNET_EnableCrashReport / DOTNET_EnableCrashReportOnly knobs are
already platform-agnostic.

inproccrashreporter.cpp gains __APPLE__ branches for the instruction,
stack, and frame pointer accessors. Darwin's ucontext_t::uc_mcontext is
a pointer to __darwin_mcontext64, so the Apple branches dereference
through ->__ss. On arm64 the arm_thread_state64_get_pc/sp/fp(__ss)
accessor macros are used so the registers are stripped of pointer
authentication codes on arm64e (identity on arm64).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the placeholder empty strings for OSVersion and SystemModel in
the in-proc crash report with values read via sysctlbyname, matching
what createdump's CrashReportWriter::WriteSysctl does:

  OSVersion      <- kern.osproductversion  (e.g. '15.1')
  SystemModel    <- hw.model               (e.g. 'MacBookPro18,3', 'iPhone13,2')

A small WriteSysctlString helper uses a CRASHREPORT_STRING_BUFFER_SIZE
stack buffer (ample for both sysctl values) and writes an empty string
on failure so the JSON schema remains stable for downstream consumers.
sysctlbyname is async-signal-safe and avoids heap allocation, matching
the createdump behavior. SystemManufacturer stays hardcoded to 'apple'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Member

@lateralusX lateralusX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the existing CoreCLR in-proc JSON crash reporter (initially added for Android) to Apple mobile targets (iOS, tvOS, MacCatalyst) by enabling the feature in CoreCLR builds and adding Apple-specific crash report fields and register extraction.

Changes:

  • Enable FEATURE_INPROC_CRASHREPORT for iOS/tvOS/MacCatalyst builds.
  • Add Apple sysctl-backed parameters fields (OSVersion, SystemModel, SystemManufacturer) to better match createdump’s Apple payload.
  • Add Apple-specific ucontext_t register extraction for IP/SP/BP on x86_64 and arm64.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/coreclr/debug/crashreport/inproccrashreporter.cpp Adds Apple sysctl-based metadata emission and Apple-specific register extraction from ucontext_t.
src/coreclr/clrfeatures.cmake Enables the in-proc crash report feature for iOS, tvOS, and MacCatalyst targets.

Comment thread src/coreclr/debug/crashreport/inproccrashreporter.cpp Outdated
Comment thread src/coreclr/debug/crashreport/inproccrashreporter.cpp Outdated
Comment thread src/coreclr/debug/crashreport/inproccrashreporter.cpp
mdh1418 and others added 3 commits May 5, 2026 13:11
- Cache OSVersion (kern.osproductversion) and SystemModel (hw.model)
  at Initialize() time instead of querying sysctl from the signal
  handler. sysctlbyname is not on the POSIX async-signal-safe list,
  so calling it from a signal-time crash report context was unsafe.
  Matches the existing m_hostName cache-at-Initialize pattern.
- Omit OSVersion/SystemModel from the report when the cache lookup
  failed and left an empty string, mirroring createdump's
  WriteSysctl behavior.
- NUL-clamp the cached strings to bufferSize-1 to defend against
  unterminated sysctl returns.
- Add explicit <mach/mach.h> include alongside <sys/sysctl.h>; the
  mach helpers are currently pulled in transitively through
  <ucontext.h> on Darwin, but the explicit include matches
  createdump.h and the rest of the PAL conventions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Broaden the HOST_ANDROID guard around the signal-handler managed
callstack logging callback to also cover HOST_IOS, HOST_TVOS, and
HOST_MACCATALYST so that the same managed stack trace surfaced in
Android crash output is also surfaced on the other Apple POSIX
targets that opt into the in-process crash reporter.

The change covers:
- The PAL_SetLogManagedCallstackForSignalCallback registration in
  ceemain.cpp so EEPolicy::LogManagedCallstackForSignal is wired up.
- The EEPolicy::LogManagedCallstackForSignal declaration in
  eepolicy.h and its implementation in eepolicy.cpp.

The PAL signal-handler call sites (PROCLogManagedCallstackForSignal
and the underlying PAL hook) were already compiled for all
TARGET_UNIX targets, so this change just extends the managed half
of the integration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When a previously-registered signal handler is SIG_DFL, the runtime
restores the default action and re-raises so the OS produces its
standard crash artifact. On platforms that register a host callback for
PAL_SetLogManagedCallstackForSignalCallback (Android, iOS, tvOS,
MacCatalyst), invoke that callback first so the managed callstack is
written alongside PROCNotifyProcessShutdown and PROCCreateCrashDumpIfEnabled,
matching the chained-handler path's behavior. This brings parity for
Apple POSIX targets where the previous handler is typically SIG_DFL,
which previously caused signal-driven crashes (SIGABRT, SIGSEGV,
SIGBUS, SIGFPE, SIGILL) to skip managed-callstack logging.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 5, 2026 18:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/debug/crashreport/inproccrashreporter.cpp Outdated
Use arm_thread_state64_get_pc_fptr instead of arm_thread_state64_get_pc
when reading the crash thread's instruction pointer. On arm64e devices
(real hardware iOS/iPadOS/tvOS) the kernel populates ucontext_t::__pc
with the raw PAC-signed value; emitting that into the JSON crash report
yields opaque addresses with auth bits set, which are useless for
post-mortem symbolication.

The _fptr variant returns void* and, on builds with ptrauth enabled,
strips the PAC via ptrauth_strip(); on simulator and pre-arm64e builds
it reduces to the raw __pc load and is binary-equivalent. This matches
the convention already used elsewhere in the codebase for serialized
program counters: PAL machexception.cpp and context.cpp use _fptr when
populating CONTEXT.Pc, and createdump/threadinfomac.cpp uses _fptr when
serializing thread state into the minidump.

The internal-only GetInstructionPointer helper in createdump still uses
the non-_fptr variant because it is consumed only within the dumping
process and never serialized.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mdh1418
Copy link
Copy Markdown
Member Author

mdh1418 commented May 6, 2026

/ba-g "The failure is #127869"

@mdh1418 mdh1418 merged commit af80ab7 into dotnet:main May 6, 2026
107 of 109 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants