Skip to content

SOS: read macOS arm64 thread metadata from a valid address - #5953

Open
max-charlamb wants to merge 3 commits into
dotnet:mainfrom
max-charlamb:max-charlamb/macos-arm64-special-thread-info
Open

SOS: read macOS arm64 thread metadata from a valid address#5953
max-charlamb wants to merge 3 commits into
dotnet:mainfrom
max-charlamb:max-charlamb/macos-arm64-special-thread-info

Conversation

@max-charlamb

@max-charlamb max-charlamb commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

  • read macOS arm64 createdump thread metadata from the new 47-bit-valid address
  • fall back to the legacy address for compatibility with existing createdump output
  • use the selected address for all subsequent thread-info entries

Motivation

Apple Silicon LLDB rejects the legacy 0x7fffffff00000000 synthetic segment and assigns sequential thread IDs beginning at zero. SOS cannot then correlate LLDB threads with runtime OS thread IDs or retrieve the selected thread context.

Coordinated writer change: dotnet/runtime#131962

Related precedent

This follows @steveisok's coordinated Apple Silicon fix for SpecialDiagInfoAddress:

Testing

Draft pending coordinated macOS arm64 validation with the runtime writer change.

max-charlamb and others added 2 commits August 6, 2026 14:39
Probe the new Apple Silicon createdump thread-info address and retain the
legacy address fallback for compatibility with existing dumps.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7805386d-16fd-4306-bcc9-54d4ea7b65cf
Read Apple Silicon createdump thread metadata from
0x00007ffffff00000 while retaining the legacy-address fallback.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7805386d-16fd-4306-bcc9-54d4ea7b65cf
@max-charlamb
max-charlamb marked this pull request as ready for review August 6, 2026 19:42
@max-charlamb
max-charlamb requested a review from a team as a code owner August 6, 2026 19:42
Copilot AI review requested due to automatic review settings August 6, 2026 19:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Updates SOS’s macOS arm64 thread-metadata reader to probe a new 47-bit-valid synthetic address (to satisfy LLDB) while retaining a fallback to the legacy address for older createdump outputs.

Changes:

  • Read SpecialThreadInfoHeader from a new macOS arm64-safe address, with fallback to the legacy address.
  • Carry forward the selected base address for subsequent SpecialThreadInfoEntry reads.
  • Introduce a dedicated SpecialThreadInfoLegacyAddress constant and document the rationale.

Reviewed changes

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

File Description
src/SOS/lldbplugin/services.cpp Adds fallback probing logic and uses the chosen base address for the thread-info table walk.
src/SOS/inc/specialthreadinfo.h Defines a new 47-bit-valid address for Apple Silicon and a legacy fallback constant.
Suppressed comments (1)

src/SOS/lldbplugin/services.cpp:2773

  • The signature validation is currently only used to decide whether to fall back; if the fallback read succeeds but returns unexpected data (or if legacy == primary), the function can proceed without ever validating header.signature. Add a post-read validation step (after the potential fallback) that returns early if header.signature does not match SPECIAL_THREADINFO_SIGNATURE.
    size_t read = process.ReadMemory(threadInfoAddress, &header, sizeof(SpecialThreadInfoHeader), error);
    if ((error.Fail() || read != sizeof(header) ||
         strncmp(header.signature, SPECIAL_THREADINFO_SIGNATURE, sizeof(SPECIAL_THREADINFO_SIGNATURE)) != 0)
        && SpecialThreadInfoAddress != SpecialThreadInfoLegacyAddress)
    {
        // Fall back to the legacy address for dumps produced by older createdump binaries.
        error.Clear();
        threadInfoAddress = SpecialThreadInfoLegacyAddress;
        read = process.ReadMemory(threadInfoAddress, &header, sizeof(SpecialThreadInfoHeader), error);
    }
    if (error.Fail() || read != sizeof(header))
    {
        return;
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/SOS/lldbplugin/services.cpp
Comment on lines +20 to +24
const uint64_t SpecialThreadInfoAddress = 0x00007ffffff00000;
const uint64_t SpecialThreadInfoLegacyAddress = 0x7fffffff00000000;
#else
const uint64_t SpecialThreadInfoAddress = 0x7fffffff00000000;
const uint64_t SpecialThreadInfoLegacyAddress = 0x7fffffff00000000;
max-charlamb added a commit to dotnet/runtime that referenced this pull request Aug 7, 2026
## Summary

- write the macOS arm64 createdump thread-info region at a 47-bit-valid
address
- emit OS thread IDs using LLDB's `process metadata` `LC_NOTE` format
- this is for future support so we can eventually remove the
`SpecialThreadInfo`
- retain the existing special thread-info segment while consumers
migrate to the LLDB format

## Motivation

Apple Silicon LLDB rejects the legacy `0x7fffffff00000000` synthetic
segment and falls back to sequential thread IDs beginning at zero. SOS
then cannot correlate LLDB threads with runtime OS thread IDs or
retrieve the selected thread context.

Coordinated SOS reader change:
dotnet/diagnostics#5953

## Related precedent

This follows @steveisok's coordinated Apple Silicon fix for
`SpecialDiagInfoAddress`:

- runtime writer: #130443
- diagnostics readers: dotnet/diagnostics#5823

## Testing

Draft pending coordinated diagnostics validation on macOS arm64.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7805386d-16fd-4306-bcc9-54d4ea7b65cf
Keep the shared thread-info architecture condition symmetric with the
createdump producer; the definition is only consumed by macOS code.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7805386d-16fd-4306-bcc9-54d4ea7b65cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants