Skip to content

Async work in R2R#3

Open
jtschuster wants to merge 37 commits into
mainfrom
AsyncR2R
Open

Async work in R2R#3
jtschuster wants to merge 37 commits into
mainfrom
AsyncR2R

Conversation

@jtschuster

Copy link
Copy Markdown
Owner

No description provided.

jtschuster and others added 30 commits October 15, 2025 14:08
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Introduced TaskReturningAsyncWrapperMethodDesc and TaskReturningAsyncWrapperMethodDescFactory to handle async-callable methods.
- Updated CorInfoTypes.cs to include new call convention for async methods.
- Enhanced ILEmitter to support async resumption stubs and exception handling for async methods.
- Modified ReadyToRunILProvider to generate IL for async methods, including proper handling of Task and ValueTask return types.
- Updated project files to include new async-related classes and ensure proper compilation.
Notably, I've tweak the cross module inlining feature to enable compilation of the tokens needed in these thunks. The tweak enables using these particular apis without enabling the cross module switch. It successfully finishes jitting a method.

- This does not ... handle the dependency graph issues
- I've noticed that we seem to make the thunks as temporary things, and assume they don't need process long lifetime. This is not likely to true, as they are actual useable symbols, so that needs to be fixed so that the various thunk methoddescs aren't treated as transient. (Anything which is a symbol or goes in the dependency graph needs to be non-transient, and able to be looked up later. Newing up a new instance is not a valid thing to do.)
- We seem to have a concept of thunks and whatnot in the MethodDescs... I'm seeing us compile the original method... with the IL for a thunk, and then I'm seeing something try to add to the dependency graph a thunk which is supposed to have the calling convention of the method we just compiled, but is MethodDesc of type TaskReturnAsyncMethodDescThunk or something.
Adjustment to get the compiler to finish the jitting
- Add AsyncVariant flag to readytorun async methods
- Comment assertions that fail async methods in readytoruninfo.cpp
jtschuster pushed a commit that referenced this pull request Oct 27, 2025
Currently, offsets are incorrectly treated as indices which is
leading to incorrect code being emitted.

e.g., `ScatterWithByteOffsets<long>` emits
`ST1D Zdata.D, Pg, [Xbase, Zoffsets.D, lsl #3]`
instead of,
`ST1D Zdata.D, Pg, [Xbase, Zoffsets.D]`
- Use EcmaMethod as the method with the implementation, whether Async or Task-returning. These go into the MethodDefTable in the R2Rimage
- Create TaskReturningThunk and use AsyncMethodDesc as MethodDescs for the async thunk. These go into the InstanceMethodEntryPoints table.
- Substitute signatures for Async variant methods
- Add AsyncMethodData analogous to the same type in the Runtime
jtschuster added a commit that referenced this pull request Feb 3, 2026
Implements change #3 from async methods R2R breakdown.

Adds helpers 0x113-0x115 for allocating continuation objects.
jtschuster pushed a commit that referenced this pull request Jun 4, 2026
An Android production app reported a native abort while building an
X.509 chain on arm64. The available tombstone snippet showed the process
aborting in `AndroidCryptoNative_X509ChainBuild` from `pal_x509chain.c`,
with the native guard reporting that parameter `ctx` was not a valid
pointer. The report did not include a repro or full tombstone, but the
observed failure mode means managed code reached the native build entry
point with a null `X509ChainContext*`.

```
Thread
/__w/1/s/src/native/libs/System.Security.Cryptography.Native.Android/pal_x509chain.c:113 (AndroidCryptoNative_X509ChainBuild): Parameter 'ctx' must be a valid pointer
 
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 31609 >>> com.app.name <<<
 
backtrace:
  #00  pc 0x000000000002232c  /system/lib64/libc.so (abort+116)
  #1  pc 0x0000000000021fe8  [removed]-KwPZdoEumri00C7kBm3pQw==/lib/arm64/libSystem.Security.Cryptography.Native.Android.so
  #2  pc 0x00000000000220b0  [removed]-KwPZdoEumri00C7kBm3pQw==/lib/arm64/libSystem.Security.Cryptography.Native.Android.so (AndroidCryptoNative_X509ChainBuild+88)
  #3  pc 0x000000000000cfcc
```

`X509ChainContext` is created by
`AndroidCryptoNative_X509ChainCreateContext`. That initialization can
fail if Android certificate store setup or PKIX parameter construction
throws, or if required JNI global references cannot be created.
Previously, the managed Android chain path stored the returned
`SafeHandle` without checking whether context creation failed, so a
later build could pass a null native context to
`AndroidCryptoNative_X509ChainBuild` and terminate the app process.

This change makes context creation fail gracefully:

- The native create path checks Java exceptions around object creation
and method calls more consistently.
- Partial native contexts are destroyed if global-reference creation
fails.
- The Android interop wrapper checks the returned chain context
immediately, including a null safe-handle return, and throws
`CryptographicException` if initialization failed.

No regression test is included because the reliable failure modes depend
on Android platform/provider state or artificial fault injection, and a
test hook would be fragile and not representative.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Kevin Jones <kevin@vcsjones.com>
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