You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 257bac4
Browse filesBrowse the repository at this point in the historyBrowse files
[cDAC][wasm] Map portable entry points to interpreter code and R2R virtual IPs (#134756)
> [!IMPORTANT]
> Stacked on #134754 (targets its branch). Only the commits above
#134754's head belong to this PR; retarget to `main` once #134754
merges.
## Problem
On `FEATURE_PORTABLE_ENTRYPOINTS` targets (WebAssembly), a method's
entry point slot holds a `PortableEntryPoint` address. Native maps it
before handing it to diagnostics
(`GetInterpreterCodeFromEntryPointIfPresent` /
`GetDiagnosticCodeStartFromEntryPoint` in `precode.cpp`), but the cDAC
returned the raw address. SOS values such as
`DacpMethodDescData.NativeCodeAddr` and rejit `NativeCodeAddr`, plus the
DBI/`ClrDataMethodInstance` paths, therefore reported an address that
doesn't resolve through `ExecutionManager` for both interpreted and R2R
methods.
## Change
Adds `IExecutionManager.GetDiagnosticCodeStartFromEntryPoint`, which
mirrors the native `GetDiagnosticCodeStartFromEntryPoint`:
- **Without portable entrypoints:** delegates to
`PrecodeStubs.GetInterpreterCodeFromInterpreterPrecodeIfPresent`.
Behavior is unchanged.
- **With portable entrypoints:**
1. Returns the address unchanged if it lies in a code range. This is the
native `FindCodeRange` check and includes Wasm R2R virtual-IP ranges
from #133917.
2. Maps interpreted methods to `MethodDesc::m_interpreterCode`.
3. Maps native R2R methods from the function-table index in
`PortableEntryPoint._pActualCode` to the synthetic virtual IP, stepping
back past funclet entries. This matches
`ExecutionManager::GetWasmVirtualIPFromFunctionTableIndex`. As in native
code, it applies only to the method's own (temporary) entry point, and
only when the entry point doesn't prefer the interpreter.
The mapping lives in ExecutionManager rather than PrecodeStubs because
ExecutionManager owns the virtual-IP ranges and R2R lookup.
ExecutionManager already depends on PrecodeStubs, so this adds no
contract cycle.
Function-table-index resolution moves into
`ExecutionManagerHelpers.WasmFunctionTableIndexLookup`, which now bounds
the list walk and detects cycles, like the virtual-IP list walk. The
stack walk's `WasmR2RInfo` becomes a thin wrapper over it.
The Legacy SOS/DBI callers (`SOSDacImpl`, `ClrDataMethodInstance`,
`DacDbiImpl`) now call the new API. `DacDbiImpl.EnumerateAsyncLocals`
also maps its code address before querying async debug info. The native
DAC's `EnumerateAsyncLocals` gets the matching
`GetInterpreterCodeFromEntryPointIfPresent` mapping (as
`GetMethodVarInfo` already does), so the debug-build cDAC/DAC
cross-check stays consistent.
### Data descriptors
- `PortableEntryPoint.ActualCode` and `PortableEntryPoint.Flags` (only
under `FEATURE_PORTABLE_ENTRYPOINTS`).
- `MethodDesc.InterpreterCode` (only under `FEATURE_INTERPRETER`).
- The contract relies on `kPrefersInterpreterEntryPoint` and
`INTERPRETER_CODE_POISON`; the native side now has `[cDAC]` comments
marking that dependency.
### Interaction with #133890#133890 adds `TryGetFunctionIdentity` and `TryIsFunclet` to
`WasmR2RInfo`. Whichever PR lands second should add those two methods to
`WasmFunctionTableIndexLookup` and have `WasmR2RInfo` forward to them.
The `FunctionTableIndexRange*` descriptor meanings here already use
#133890's exact wording, so that JSON should merge cleanly.
## Validation
- cDAC: `./build.sh -s tools.cdac+tools.cdactests -c Debug -test`
passes: 3196 unit tests (17 new), usage tests (contract cycles and
generated docs up to date), and generator tests.
- New ExecutionManager tests cover:
- interpreted, R2R, funclet, poison, prefers-interpreter,
not-own-entry-point and unknown-index cases;
- an end-to-end check that the resolved virtual IP maps back to the
MethodDesc through `GetCodeBlockHandle`;
- readable `PortableEntryPoint`-shaped bytes inside a registered code
range staying unchanged. This test fails if the range check is removed.
- a cyclic function-table range list;
- the non-portable delegation path.
- CoreCLR `clr.runtime` builds for osx-arm64 Debug (with
`FEATURE_INTERPRETER`) and browser-wasm Debug. The generated wasm
descriptor has `PortableEntryPoint {ActualCode@0, MethodDesc@4,
Flags@12}`.
- A new `DacDbiImplTests` test covers `EnumerateAsyncLocals` mapping for
both the code-address and MethodDesc paths. It fails without the fix.
- cDAC dump tests (osx-arm64, local runtime): 260 passed, 0 failed. The
746 skips are net10.0 configurations plus by-design skips (Windows-only
COM debuggees, and dump types a debuggee doesn't produce).
- CoreCLR `clr.runtime` Release (osx-arm64) builds with the
`dacdbiimpl.cpp` change.
- Not run: any check against a live wasm target.
Fixes#134753
> [!NOTE]
> This PR description was generated with GitHub Copilot.
---------
Co-authored-by: Copilot App <[email protected]>
|`InterpreterRealCodeHeader`|`JitEHInfo`|`pointer`| Pointer to the `EE_ILEXCEPTION` containing exception clauses for interpreter code |
227
234
|`InterpreterRealCodeHeader`|`MethodDesc`|`pointer`| Pointer to the corresponding `MethodDesc` for interpreter code |
228
235
|`LoaderCodeHeap`|`LoaderHeap`|`pointer`| Offset of the embedded `ExplicitControlLoaderHeap` within the `LoaderCodeHeap` object; adding this to the object's base address yields the loader heap address |
236
+
|`MethodDesc`|`CodeData`|`pointer`| Pointer to per-method code data containing entry-point and code-versioning state |
237
+
|`MethodDesc`|`InterpreterCode`|`pointer`| Pointer to the method's `InterpByteCodeStart`, or the poison value 1 if the method will never be interpreted (only defined if `FEATURE_INTERPRETER` is enabled) |
238
+
|`MethodDescCodeData`|`TemporaryEntryPoint`|`CodePointer`| Temporary code entry point used before the method has a stable entry point |
229
239
|`Module`|`ReadyToRunInfo`|`pointer`| Pointer to the module's ReadyToRun information |
240
+
|`PortableEntryPoint`|`ActualCode`|`pointer`| Native code for the entrypoint; on WebAssembly R2R code this is a function-table index (only defined if `FeaturePortableEntrypoints` is enabled) |
241
+
|`PortableEntryPoint`|`Flags`|`int32`| Portable entrypoint flags; `0x4` means the interpreter entrypoint is preferred over `ActualCode` (only defined if `FeaturePortableEntrypoints` is enabled) |
230
242
|`PortableEntryPoint`|`MethodDesc`|`pointer`| Method desc of portable entrypoint (only defined if `FeaturePortableEntrypoints` is enabled) |
231
243
|`R2RExceptionClause`|*(type size)*|`uint32`| Size of a ReadyToRun exception clause in bytes |
232
244
|`R2RExceptionClause`|`ClassToken`|`uint32`| Union field: ClassToken or FilterOffset |
|`EEJitManagerAddress`|`pointer`| Address of the global pointer to the EEJitManager instance (read a TargetPointer from this address to obtain the instance address) |
289
301
|`ExecutionManagerCodeRangeMapAddress`|`pointer`| Pointer to the global RangeSectionMap |
302
+
|`FunctionTableIndexRangeList`|`pointer`| Pointer to the head pointer of the registered WASM R2R function-table range list |
290
303
|`GCInfoVersion`|`uint32`| JITted code GCInfo version |
291
304
|`HashMapSlotsPerBucket`|`uint32`| Number of slots in each bucket of a `HashMap`|
292
305
|`HashMapValueMask`|`uint64`| Bitmask used when storing values in a `HashMap`|
@@ -491,6 +504,60 @@ TargetPointer IExecutionManager.NonVirtualEntry2MethodDesc(TargetCodePointer ent
491
504
```
492
505
493
506
507
+
`GetDiagnosticCodeStartFromEntryPoint` mirrors the native `GetDiagnosticCodeStartFromEntryPoint` (`src/coreclr/vm/precode.cpp`). Without portable entrypoints it maps an interpreter precode to its bytecode through `PrecodeStubs.GetInterpreterCodeFromInterpreterPrecodeIfPresent`. With portable entrypoints (WebAssembly), an entry point is a `PortableEntryPoint` rather than code: an interpreted method maps to its `InterpByteCodeStart`, and a native ReadyToRun method maps its function-table index to the synthetic virtual IP registered in the virtual-IP range list, so that the result resolves through `GetCodeBlockHandle`.
Copy file name to clipboardExpand all lines: docs/design/datacontracts/RuntimeTypeSystem.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -603,6 +603,7 @@ static class RuntimeTypeSystem_1_Helpers
603
603
|`MethodDesc`|`Flags`|`uint16`| The method's flags |
604
604
|`MethodDesc`|`Flags3AndTokenRemainder`|`uint16`| More flags for the method, and the low bits of the method's token's RID |
605
605
|`MethodDesc`|`GCCoverageInfo`|`pointer`| The method's GCCover debug info, if supported |
606
+
|`MethodDesc`|`InterpreterCode`|`pointer`| Pointer to the method's `InterpByteCodeStart`, or the poison value 1 if the method will never be interpreted (only defined if `FEATURE_INTERPRETER` is enabled) |
606
607
|`MethodDesc`|`Slot`|`uint16`| The method's slot |
607
608
|`MethodDescChunk`|*(type size)*|`uint32`| Size of the data descriptor layout |
608
609
|`MethodDescChunk`|`Count`|`uint8`| The number of MethodDesc entries in this chunk, minus 1. |
"MethodDesc.Flags3AndTokenRemainder": "More flags for the method, and the low bits of the method's token's RID",
364
368
"MethodDesc.GCCoverageInfo": "The method's GCCover debug info, if supported",
369
+
"MethodDesc.InterpreterCode": "Pointer to the method's `InterpByteCodeStart`, or the poison value 1 if the method will never be interpreted (only defined if `FEATURE_INTERPRETER` is enabled)",
365
370
"MethodDesc.Size": "Base size for mcIL classification",
366
371
"MethodDesc.Slot": "The method's slot",
367
372
"MethodDescChunk.Count": "The number of MethodDesc entries in this chunk, minus 1.",
@@ -457,6 +462,8 @@
457
462
"PInvokeMethodDesc.Size": "Base size for mcPInvoke classification",
458
463
"PlatformMetadata.CodePointerFlags": "fields describing the behavior of target code pointers",
459
464
"PlatformMetadata.PrecodeMachineDescriptor": "precode stub-related platform specific properties",
465
+
"PortableEntryPoint.ActualCode": "Native code for the entrypoint; on WebAssembly R2R code this is a function-table index (only defined if `FeaturePortableEntrypoints` is enabled)",
466
+
"PortableEntryPoint.Flags": "Portable entrypoint flags; `0x4` means the interpreter entrypoint is preferred over `ActualCode` (only defined if `FeaturePortableEntrypoints` is enabled)",
460
467
"PortableEntryPoint.MethodDesc": "Method desc of portable entrypoint (only defined if `FeaturePortableEntrypoints` is enabled)",
461
468
"PrecodeMachineDescriptor.FixupBytes": "Assembly code of a FixupStub",
462
469
"PrecodeMachineDescriptor.FixupIgnoredBytes": "Bytes to ignore when comparing FixupBytes to an actual block of memory in the target process.",
@@ -760,6 +767,7 @@
760
767
"FieldOffsetDynamicRVA": "Sentinel FieldDesc offset for an EnC-added RVA field whose enclosing type is not yet loaded",
761
768
"FieldOffsetNewEnc": "Sentinel offset value stored in FieldDesc::DWord2 for added fields whose storage has not yet been allocated.",
762
769
"FinalizerThread": "Pointer to the finalizer thread",
770
+
"FunctionTableIndexRangeList": "Pointer to the head pointer of the registered WASM R2R function-table range list",
763
771
"FreeObjectMethodTable": "A pointer to the address of a MethodTable used by the GC to indicate reclaimed memory",
764
772
"GCGlobalMechanisms": "Pointer to counters recording use of global GC mechanisms",
765
773
"GCHeapAllocAllocated": "Highest address allocated by Alloc (in workstation builds)",
Copy file name to clipboardExpand all lines: src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IExecutionManager.cs
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -110,6 +110,11 @@ public interface IExecutionManager : IContract
0 commit comments