Skip to content

[cDAC][wasm] MethodDesc validation rejects every MethodDesc: PrecodeStubs lookup needs PrecodeMachineDescriptor (absent with portable entry points) #135035

Description

@lewing

Description

On WebAssembly targets, IRuntimeTypeSystem.GetMethodDescHandle(ptr) throws ArgumentException: Invalid method desc pointer for valid MethodDescs. In practice that means no MethodDesc can be named on WASM, including every MethodDesc that IStackWalk.GetMethodDescPtr / IExecutionManager.GetMethodDesc returns.

Root cause

MethodValidation.ValidateMethodDescPointer checks the temporary entry point:

TargetCodePointer temporaryEntryPoint = GetTemporaryEntryPointIfExists(umd);
if (temporaryEntryPoint != TargetCodePointer.Null)
{
    Contracts.IPrecodeStubs precode = _target.Contracts.PrecodeStubs;
    TargetPointer methodDesc = precode.GetMethodDescFromStubAddress(temporaryEntryPoint);
    ...

PrecodeStubs_1.GetMethodDescFromStubAddress needs the PrecodeMachineDescriptor data type, which the descriptor compiles out under FEATURE_PORTABLE_ENTRYPOINTS:

// src/coreclr/vm/datadescriptor/datadescriptor.inc
#ifndef FEATURE_PORTABLE_ENTRYPOINTS
CDAC_TYPE_BEGIN(PrecodeMachineDescriptor)

The lookup throws InvalidOperationException: Field not found in any layout (names=[PrecodeMachineDescriptor]). The blanket catch (System.Exception) in ValidateMethodDescPointer swallows that and returns false, so every MethodDesc that has a temporary entry point is rejected.

I confirmed this by instrumenting each return false / catch in a local build. Every frame MethodDesc on a live browser target failed with exactly this exception at the temporary-entry-point check.

Expected

With portable entry points, the temporary entry point is a PortableEntryPoint whose MethodDesc field is the owner, matching the native FEATURE_PORTABLE_ENTRYPOINTS path. IExecutionManager already reads Data.PortableEntryPoint for GetDiagnosticCodeStartFromEntryPoint (#134827). Validation should take the same path when portable entry points are in use, instead of going through precode stubs.

A secondary concern: the blanket catch converts a reader/descriptor mismatch into "invalid pointer", which hid the root cause here.

Repro

  • Target: CoreCLR browser-wasm, nightly 12.0.0-alpha.1.26480.103 (runtime cd42bb5).
  • Reader: cDAC built from main @ bb1b237b389.
  • At any CDP pause, walk a thread with IStackWalk, then call RuntimeTypeSystem.GetMethodDescHandle(GetMethodDescPtr(frame)) on any frameless frame. It throws Invalid method desc pointer.

Notes

As a workaround, Blazor-Playground/nesm overrides PrecodeStubs c1 on WASM targets. The override resolves GetMethodDescFromStubAddress via PortableEntryPoint.MethodDesc. With it, R2R and interpreted frames on a live target resolve to names that match an independent static ReadyToRun (MethodDefEntryPoints) name oracle.

Found while validating a live IStackWalk consumer in Blazor-Playground/nesm; related to #130988 / #134827.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions