This repository has been archived by the owner on Nov 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plumbing to generate calli PInvoke stubs (#6002)
Contributes to #5587
- Loading branch information
Showing
13 changed files
with
281 additions
and
9 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/Common/src/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Mangling.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using Internal.TypeSystem; | ||
|
||
namespace Internal.IL.Stubs | ||
{ | ||
public partial class CalliMarshallingMethodThunk : IPrefixMangledSignature | ||
{ | ||
MethodSignature IPrefixMangledSignature.BaseSignature | ||
{ | ||
get | ||
{ | ||
return _targetSignature; | ||
} | ||
} | ||
|
||
string IPrefixMangledSignature.Prefix | ||
{ | ||
get | ||
{ | ||
return "Calli"; | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Common/src/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.Sorting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Internal.TypeSystem; | ||
|
||
namespace Internal.IL.Stubs | ||
{ | ||
// Functionality related to deterministic ordering of methods | ||
partial class CalliMarshallingMethodThunk | ||
{ | ||
protected internal override int ClassCode => 1594107963; | ||
|
||
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer) | ||
{ | ||
var otherMethod = (CalliMarshallingMethodThunk)other; | ||
return comparer.Compare(_targetSignature, otherMethod._targetSignature); | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/Common/src/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using Internal.TypeSystem; | ||
using Internal.TypeSystem.Interop; | ||
using Debug = System.Diagnostics.Debug; | ||
using Internal.TypeSystem.Ecma; | ||
|
||
namespace Internal.IL.Stubs | ||
{ | ||
/// <summary> | ||
/// Thunk to marshal calli PInvoke parameters and invoke the appropriate function pointer | ||
/// </summary> | ||
public partial class CalliMarshallingMethodThunk : ILStubMethod | ||
{ | ||
private readonly MethodSignature _targetSignature; | ||
private readonly InteropStateManager _interopStateManager; | ||
private readonly TypeDesc _owningType; | ||
|
||
private MethodSignature _signature; | ||
|
||
public CalliMarshallingMethodThunk(MethodSignature targetSignature, TypeDesc owningType, | ||
InteropStateManager interopStateManager) | ||
{ | ||
_targetSignature = targetSignature; | ||
_owningType = owningType; | ||
_interopStateManager = interopStateManager; | ||
} | ||
|
||
public MethodSignature TargetSignature | ||
{ | ||
get | ||
{ | ||
return _targetSignature; | ||
} | ||
} | ||
|
||
public override TypeSystemContext Context | ||
{ | ||
get | ||
{ | ||
return _owningType.Context; | ||
} | ||
} | ||
|
||
public override TypeDesc OwningType | ||
{ | ||
get | ||
{ | ||
return _owningType; | ||
} | ||
} | ||
|
||
public override MethodSignature Signature | ||
{ | ||
get | ||
{ | ||
if (_signature == null) | ||
{ | ||
// Prepend fnptr argument to the signature | ||
TypeDesc[] parameterTypes = new TypeDesc[_targetSignature.Length + 1]; | ||
|
||
parameterTypes[0] = Context.GetWellKnownType(WellKnownType.IntPtr); | ||
for (int i = 0; i < _targetSignature.Length; i++) | ||
parameterTypes[i + 1] = _targetSignature[i]; | ||
|
||
_signature = new MethodSignature(MethodSignatureFlags.Static, 0, _targetSignature.ReturnType, parameterTypes); | ||
} | ||
return _signature; | ||
} | ||
} | ||
|
||
public override string Name | ||
{ | ||
get | ||
{ | ||
return "CalliMarshallingMethodThunk"; | ||
} | ||
} | ||
|
||
public override MethodIL EmitIL() | ||
{ | ||
// TODO | ||
throw null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Common/src/TypeSystem/Mangling/IPrefixMangledSignature.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace Internal.TypeSystem | ||
{ | ||
/// <summary> | ||
/// When implemented by a <see cref="MethodDesc"/>, instructs a name mangler to use the same mangled name | ||
/// as another entity while prepending a specific prefix to that mangled name. | ||
/// </summary> | ||
public interface IPrefixMangledSignature | ||
{ | ||
/// <summary> | ||
/// Signature whose mangled name to use. | ||
/// </summary> | ||
MethodSignature BaseSignature { get; } | ||
|
||
/// <summary> | ||
/// Prefix to apply when mangling. | ||
/// </summary> | ||
string Prefix { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.