Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ad0172f
Hook up initial infrastructure for unmanaged-to-managed vtable stubs.
jkoritzinsky Oct 17, 2022
f571cd0
Make the signatures for the UnmanagedCallersOnly wrapper have the cor…
jkoritzinsky Nov 1, 2022
c2f2fdf
Fix signature and add runtime tests for unmanaged->managed
jkoritzinsky Nov 2, 2022
32f856c
Update incremental generation liveness test to be a theory and add an…
jkoritzinsky Nov 10, 2022
9a38bee
Change IMarshallingGenerator.AsNativeType to return a ManagedTypeInfo…
jkoritzinsky Nov 10, 2022
71fa346
Use MarshalDirection to provide a nice abstraction for determining wh…
jkoritzinsky Nov 10, 2022
8646adf
Implement unmanaged->managed exception handling spec and get compilat…
jkoritzinsky Nov 10, 2022
baf8a36
Initial PR feedback.
jkoritzinsky Nov 10, 2022
6bf9f2c
Merge branch 'main' of github.com:dotnet/runtime into vtable-unmanged…
jkoritzinsky Nov 11, 2022
6819628
Fix function pointer signature
jkoritzinsky Nov 14, 2022
972fd18
Emit a PopulateUnmanagedVirtualMethodTable wrapper function to fill t…
jkoritzinsky Nov 15, 2022
ddaa876
Add methods for providing virtual method table length.
jkoritzinsky Nov 16, 2022
ec57196
Merge branch 'main' of github.com:dotnet/runtime into vtable-unmanged…
jkoritzinsky Nov 21, 2022
7f05abb
PR feedback
jkoritzinsky Nov 21, 2022
4132fd9
Fix bad merge that lost the native-to-managed-this marshaller factory.
jkoritzinsky Nov 21, 2022
96ac635
Enhance docs for the error case
jkoritzinsky Nov 21, 2022
76ce3f5
Internalize the "fallback-to-fowarder" logic to BoundGenerators and h…
jkoritzinsky Nov 29, 2022
8d89495
Pass in the fallback generator to BoundGenerators
jkoritzinsky Nov 30, 2022
7c05d70
Change the BoundGenerators constructor to a factory method.
jkoritzinsky Dec 1, 2022
d4e71c4
Add lots of comments and docs
jkoritzinsky Dec 2, 2022
0a45772
Fix a few missing init properties
jkoritzinsky Dec 2, 2022
9879853
PR feedback and finish wiring up the exception marshallers to actuall…
jkoritzinsky Dec 6, 2022
b7d1ab3
Add diagnostics for ExceptionMarshalling and other misc PR feedback.
jkoritzinsky Dec 7, 2022
8e9e5ca
Allow setting ExceptionMarshallingCustomType without setting Exceptio…
jkoritzinsky Dec 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add methods for providing virtual method table length.
  • Loading branch information
jkoritzinsky committed Nov 16, 2022
commit ddaa87685f5e62de6ef90096cbe8763eade8f3e6
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public sealed VirtualMethodTableInfo GetVirtualMethodTableInfoForKey<TUnmanagedI
return GetVirtualMethodTableInfoForKey(TUnmanagedInterfaceType.TypeKey);
}

public static int GetVirtualMethodTableLength<TUnmanagedInterfaceType>()
where TUnmanagedInterfaceType : IUnmanagedInterfaceType<TUnmanagedInterfaceType, T>
{
return TUnmanagedInterfaceType.VirtualMethodTableLength;
}

public static void* GetVirtualMethodTableManagedImplementation<TUnmanagedInterfaceType>()
where TUnmanagedInterfaceType : IUnmanagedInterfaceType<TUnmanagedInterfaceType, T>
{
Expand All @@ -60,6 +66,8 @@ public unsafe interface IUnmanagedInterfaceType<TInterface, TKey>
where TInterface : IUnmanagedInterfaceType<TInterface, TKey>
where TKey : IEquatable<TKey>
{
public static abstract int VirtualMethodTableLength { get; }

public static abstract void* VirtualMethodTableManagedImplementation { get; }

public static abstract void* GetUnmanagedWrapperForObject(TInterface obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ internal partial class ImplicitThis

internal partial interface INativeObject : IUnmanagedInterfaceType<INativeObject, NoCasting>
{
static int IUnmanagedInterfaceType<INativeObject, NoCasting>.VirtualMethodTableLength => 2;

static NoCasting IUnmanagedInterfaceType<INativeObject, NoCasting>.TypeKey => default;

private static void** s_vtable = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(INativeObject), sizeof(void*) * 2);
private static void** s_vtable = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(INativeObject), sizeof(void*) * IUnmanagedVirtualMethodTableProvider<NoCasting>.GetVirtualMethodTableLength<INativeObject>());
static void* IUnmanagedInterfaceType<INativeObject, NoCasting>.VirtualMethodTableManagedImplementation
{
get
{
if (s_vtable[0] == null)
{
Native.PopulateUnmanagedVirtualMethodTable(new Span<IntPtr>(s_vtable, 2));
Native.PopulateUnmanagedVirtualMethodTable(new Span<IntPtr>(s_vtable, IUnmanagedVirtualMethodTableProvider<NoCasting>.GetVirtualMethodTableLength<INativeObject>()));
}
return s_vtable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal partial class NoImplicitThis

internal partial interface IStaticMethodTable : IUnmanagedInterfaceType<IStaticMethodTable, NoCasting>
{
static int IUnmanagedInterfaceType<IStaticMethodTable, NoCasting>.VirtualMethodTableLength => 2;
static void* IUnmanagedInterfaceType<IStaticMethodTable, NoCasting>.VirtualMethodTableManagedImplementation => null;

static void* IUnmanagedInterfaceType<IStaticMethodTable, NoCasting>.GetUnmanagedWrapperForObject(IStaticMethodTable obj) => null;
Expand All @@ -40,7 +41,8 @@ public StaticMethodTable(void* vtableStart)
_vtableStart = vtableStart;
}

public VirtualMethodTableInfo GetVirtualMethodTableInfoForKey(NoCasting typeKey) => new VirtualMethodTableInfo(IntPtr.Zero, new ReadOnlySpan<IntPtr>(_vtableStart, 2));
public VirtualMethodTableInfo GetVirtualMethodTableInfoForKey(NoCasting typeKey) =>
new VirtualMethodTableInfo(IntPtr.Zero, new ReadOnlySpan<IntPtr>(_vtableStart, IUnmanagedVirtualMethodTableProvider<NoCasting>.GetVirtualMethodTableLength<IStaticMethodTable>()));
}

[CustomMarshaller(typeof(StaticMethodTable), MarshalMode.ManagedToUnmanagedOut, typeof(StaticMethodTableMarshaller))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static unsafe class VTableGCHandlePair<TUnmanagedInterface, TKey>
{
public static void* Allocate(TUnmanagedInterface obj)
{
void** unmanaged = (void**)NativeMemory.Alloc((nuint)sizeof(void*) * 2);
void** unmanaged = (void**)NativeMemory.Alloc((nuint)sizeof(void*) * (nuint)IUnmanagedVirtualMethodTableProvider<TKey>.GetVirtualMethodTableLength<TUnmanagedInterface>());
unmanaged[0] = TUnmanagedInterface.VirtualMethodTableManagedImplementation;
unmanaged[1] = (void*)GCHandle.ToIntPtr(GCHandle.Alloc(obj));
return unmanaged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ partial interface INativeAPI
""";

public const string INativeAPI_NoCasting_IUnmanagedInterfaceTypeMethodImpl = """
static int IUnmanagedInterfaceType<INativeAPI, NoCasting>.VirtualMethodTableLength => 1;
static unsafe void* IUnmanagedInterfaceType<INativeAPI, NoCasting>.VirtualMethodTableManagedImplementation => null;
static unsafe void* IUnmanagedInterfaceType<INativeAPI, NoCasting>.GetUnmanagedWrapperForObject(INativeAPI obj) => null;
static unsafe INativeAPI IUnmanagedInterfaceType<INativeAPI, NoCasting>.GetObjectForUnmanagedWrapper(void* ptr) => null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ partial interface INativeAPI
""";

public const string INativeAPI_NoCasting_IUnmanagedInterfaceTypeMethodImpl = """
static int IUnmanagedInterfaceType<INativeAPI, NoCasting>.VirtualMethodTableLength => 1;
static unsafe void* IUnmanagedInterfaceType<INativeAPI, NoCasting>.VirtualMethodTableManagedImplementation => null;
static unsafe void* IUnmanagedInterfaceType<INativeAPI, NoCasting>.GetUnmanagedWrapperForObject(INativeAPI obj) => null;
static unsafe INativeAPI IUnmanagedInterfaceType<INativeAPI, NoCasting>.GetObjectForUnmanagedWrapper(void* ptr) => null;
Expand Down