Skip to content

Add support for host callback to get information for platform-native composite R2R images#121363

Merged
elinor-fung merged 12 commits intodotnet:mainfrom
elinor-fung:r2r-host-runtime-callback
Nov 11, 2025
Merged

Add support for host callback to get information for platform-native composite R2R images#121363
elinor-fung merged 12 commits intodotnet:mainfrom
elinor-fung:r2r-host-runtime-callback

Conversation

@elinor-fung
Copy link
Member

Depends on #120777. (First commit is a merge from that PR)

Add the basic runtime flow for calling into the host to get information about a platform-native R2R - see ReadyToRun Platform Native Envelope.

  • Add get_native_code_data callback to host_runtime_contract
  • If a component R2R assembly has READYTORUN_FLAG_PLATFORM_NATIVE_IMAGE, invoke the callback to get the R2R header, image size, and image base address
  • Currently only implemented and tested on Windows (with local changes to include the flag)
  • Mach-O support will need Add support for emitting Mach-O R2R images #121186

Contributes to #120065.

@jkoritzinsky
Copy link
Member

cc: @adamperlin

@elinor-fung elinor-fung marked this pull request as ready for review November 6, 2025 21:32
Copilot AI review requested due to automatic review settings November 6, 2025 21:32
@elinor-fung
Copy link
Member Author

This should be ready for review now.

Copy link
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 adds support for platform-native R2R (ReadyToRun) composite image loading, enabling the runtime to load composite R2R images in native platform formats (e.g., Mach-O on macOS, PE on Windows) through a new host contract callback mechanism.

Key changes:

  • New host contract callback get_native_code_data to retrieve platform-native composite images from the host
  • New READYTORUN_FLAG_PLATFORM_NATIVE_IMAGE flag to mark component assemblies
  • Test infrastructure to validate platform-native R2R composite image loading

Reviewed Changes

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

Show a summary per file
File Description
src/native/corehost/host_runtime_contract.h Adds new structs and callback interface for native code data retrieval
src/installer/tests/Assets/Projects/HostApiInvokerApp/HostRuntimeContract.cs Updates managed representation of host contract with new callback
src/coreclr/inc/readytorun.h Defines new READYTORUN_FLAG_PLATFORM_NATIVE_IMAGE flag
src/coreclr/inc/hostinformation.h Declares GetNativeCodeData helper method
src/coreclr/vm/hostinformation.cpp Implements GetNativeCodeData to call host callback
src/coreclr/vm/readytoruninfo.cpp Passes platform-native flag when loading composite images
src/coreclr/vm/assemblybinder.h Adds isPlatformNative parameter to LoadNativeImage
src/coreclr/vm/assemblybinder.cpp Simplifies LoadNativeImage and passes isPlatformNative flag
src/coreclr/vm/nativeimage.h Updates Open signature with componentModulePath and isPlatformNative
src/coreclr/vm/nativeimage.cpp Refactors to support both host callback and PE-based loading paths
src/coreclr/hosts/corerun/corerun.hpp Adds platform-specific helpers for UTF-8 conversion and image introspection
src/coreclr/hosts/corerun/corerun.cpp Implements get_native_code_data callback for testing
src/tests/Loader/PlatformNativeR2R/PlatformNativeR2R.csproj Test project configuration
src/tests/Loader/PlatformNativeR2R/PlatformNativeR2R.cs Test implementation using R2RDump validation

@elinor-fung
Copy link
Member Author

/ba-g Android timeouts

@elinor-fung elinor-fung merged commit ad65508 into dotnet:main Nov 11, 2025
140 of 164 checks passed
@elinor-fung elinor-fung deleted the r2r-host-runtime-callback branch November 11, 2025 18:46
@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants