Skip to content

UnsafeAccessor with generic struct segfault #122678

@andykernahan

Description

@andykernahan

Description

Runtime segfaults (exit code 139) when using UnsafeAccessor to invoke method on generic struct constructed with class type.

Reproduction Steps

Given:

using System.Runtime.CompilerServices;

S<int> sInt32 = new();
Accessor<int>.M(ref sInt32);
Console.WriteLine("Int32 okay");

S<string> sString = new();
Accessor<string>.M(ref sString);
Console.WriteLine("string okay");

public struct S<T>
{
    private void M() { }
}

public static class Accessor<T>
{
    [UnsafeAccessor(UnsafeAccessorKind.Method, Name = "M")]
    public static extern void M(ref S<T> s);
}

Then:

$ dotnet run Program.cs 
Int32 okay
$ echo $?
139

Expected behavior

Does not segfault and prints string okay.

Actual behavior

Segfaults (exit code 139).

Regression?

No response

Known Workarounds

No response

Configuration

dotnet --info
.NET SDK:
 Version:           10.0.101
 Commit:            fad253f51b
 Workload version:  10.0.100-manifests.c57ac48b
 MSBuild version:   18.0.6+fad253f51

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  26.1
 OS Platform: Darwin
 RID:         osx-arm64
 Base Path:   /usr/local/share/dotnet/sdk/10.0.101/

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
  Version:      10.0.1
  Architecture: arm64
  Commit:       fad253f51b

.NET SDKs installed:
  10.0.100 [/usr/local/share/dotnet/sdk]
  10.0.101 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 10.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 10.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions