From ead6745b53ac22c2a900fa28a485a8818a54ad91 Mon Sep 17 00:00:00 2001 From: Max Charlamb Date: Wed, 22 Apr 2026 12:47:27 -0400 Subject: [PATCH] [cDAC] Add Apple to RuntimeInfoOperatingSystem Adds a dedicated Apple value to the RuntimeInfoOperatingSystem enum in IRuntimeInfo so that cDAC consumers can distinguish Apple platforms (macOS / iOS / tvOS / MacCatalyst) from other Unix targets. The native data descriptor emits the new Apple string whenever TARGET_APPLE is defined, which is checked before the generic TARGET_UNIX arm. This is needed by CallingConventionInfo (see #127282) to reliably set IsAppleArm64ABI for Apple ARM64 stack-argument alignment rules, which differ from Linux ARM64. Existing != Windows callers (unwinders, SOSDacImpl) continue to behave correctly for Apple targets since Apple platforms are still POSIX for their purposes. The enum is parsed with Enum.TryParse(ignoreCase: true), so older cDACs reading dumps from updated runtimes will simply see Unknown, and newer cDACs reading dumps from older runtimes will still see Unix (no behavioral regression). No RuntimeInfo contract version bump is required. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docs/design/datacontracts/RuntimeInfo.md | 8 ++++++++ src/coreclr/vm/datadescriptor/datadescriptor.inc | 5 +++++ .../Contracts/IRuntimeInfo.cs | 1 + .../managed/cdac/tests/DumpTests/RuntimeInfoDumpTests.cs | 3 ++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/design/datacontracts/RuntimeInfo.md b/docs/design/datacontracts/RuntimeInfo.md index c56dbc5a58fcf7..94d4245e8fc208 100644 --- a/docs/design/datacontracts/RuntimeInfo.md +++ b/docs/design/datacontracts/RuntimeInfo.md @@ -21,6 +21,8 @@ public enum RuntimeInfoOperatingSystem : uint Unknown = 0, Win, Unix, + Browser, + Apple, } ``` @@ -50,6 +52,12 @@ Global variables used: The contract implementation returns the architecture and operating system global values parsed as the respective enum case-insensitively. If these globals are not available, the contract returns Unknown. +`Apple` covers all Apple platforms (macOS, iOS, tvOS, MacCatalyst) — i.e. any target where the +runtime is compiled with `TARGET_APPLE` defined. It is distinct from `Unix` so that consumers which +need to apply Apple-specific ABI or platform rules (for example, the Apple ARM64 stack-argument +alignment) can detect the target reliably. Apple platforms are still POSIX and will behave like +`Unix` for the purposes of any `GetTargetOperatingSystem() != Windows` check. + ### Reader versioning scheme When the .NET runtime team wants to signal that an update is recommended we update both the diff --git a/src/coreclr/vm/datadescriptor/datadescriptor.inc b/src/coreclr/vm/datadescriptor/datadescriptor.inc index be78f9c1bf6028..b7e13c1f8574db 100644 --- a/src/coreclr/vm/datadescriptor/datadescriptor.inc +++ b/src/coreclr/vm/datadescriptor/datadescriptor.inc @@ -1311,6 +1311,11 @@ CDAC_GLOBALS_BEGIN() #error Handle 'Browser' define #endif // Browser CDAC_GLOBAL_STRING(OperatingSystem, Browser) +#elif defined(TARGET_APPLE) +#ifdef Apple +#error Handle 'Apple' define +#endif // Apple +CDAC_GLOBAL_STRING(OperatingSystem, Apple) #elif defined(TARGET_UNIX) #ifdef Unix #error Handle 'Unix' define diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeInfo.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeInfo.cs index 42f567a60e9657..0f2dfe0615bd52 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeInfo.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeInfo.cs @@ -27,6 +27,7 @@ public enum RuntimeInfoOperatingSystem : uint Windows, Unix, Browser, + Apple, } public interface IRuntimeInfo : IContract diff --git a/src/native/managed/cdac/tests/DumpTests/RuntimeInfoDumpTests.cs b/src/native/managed/cdac/tests/DumpTests/RuntimeInfoDumpTests.cs index 7a3517cb285ace..5faac6d4794b64 100644 --- a/src/native/managed/cdac/tests/DumpTests/RuntimeInfoDumpTests.cs +++ b/src/native/managed/cdac/tests/DumpTests/RuntimeInfoDumpTests.cs @@ -52,7 +52,8 @@ public void RuntimeInfo_OperatingSystemMatchesDumpMetadata(TestConfiguration con RuntimeInfoOperatingSystem expected = DumpMetadata.Os switch { "windows" => RuntimeInfoOperatingSystem.Windows, - "linux" or "osx" or "freebsd" => RuntimeInfoOperatingSystem.Unix, + "osx" => RuntimeInfoOperatingSystem.Apple, + "linux" or "freebsd" => RuntimeInfoOperatingSystem.Unix, _ => RuntimeInfoOperatingSystem.Unknown, };