-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cdac] Add basic cdacreader project (#100623)
This change adds a basic `cdacreader` project under src/native/managed. - Built as part of the clr subset (via runtime-prereqs referencing compile-native.proj) - Not yet integrated into anything in the product (that is, the dac doesn't try to use it yet) - Can return a class that can implement the ISOSDacInterface* interfaces - currently does ISOSDacInterface9
- Loading branch information
1 parent
4c20b21
commit b973027
Showing
7 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
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,2 @@ | ||
add_library(cdacreader_api INTERFACE) | ||
target_include_directories(cdacreader_api INTERFACE ${CLR_SRC_NATIVE_DIR}/managed/cdacreader/inc) |
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. | ||
|
||
#ifndef CDAC_READER_H | ||
#define CDAC_READER_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
int cdac_reader_init(intptr_t descriptor, intptr_t* handle); | ||
int cdac_reader_free(intptr_t handle); | ||
int cdac_reader_get_sos_interface(intptr_t handle, IUnknown** obj); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // CDAC_READER_H |
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,50 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.InteropServices.Marshalling; | ||
|
||
namespace Microsoft.Diagnostics.DataContractReader; | ||
|
||
internal static class Entrypoints | ||
{ | ||
private const string CDAC = "cdac_reader_"; | ||
|
||
[UnmanagedCallersOnly(EntryPoint = $"{CDAC}init")] | ||
private static unsafe int Init(nint descriptor, IntPtr* handle) | ||
{ | ||
Target target = new(descriptor); | ||
GCHandle gcHandle = GCHandle.Alloc(target); | ||
*handle = GCHandle.ToIntPtr(gcHandle); | ||
return 0; | ||
} | ||
|
||
[UnmanagedCallersOnly(EntryPoint = $"{CDAC}free")] | ||
private static unsafe int Free(IntPtr handle) | ||
{ | ||
GCHandle h = GCHandle.FromIntPtr(handle); | ||
h.Free(); | ||
return 0; | ||
} | ||
|
||
/// <summary> | ||
/// Get the SOS-DAC interface implementation. | ||
/// </summary> | ||
/// <param name="handle">Handle crated via cdac initialization</param> | ||
/// <param name="obj"><c>IUnknown</c> pointer that can be queried for ISOSDacInterface*</param> | ||
/// <returns></returns> | ||
[UnmanagedCallersOnly(EntryPoint = $"{CDAC}get_sos_interface")] | ||
private static unsafe int GetSOSInterface(IntPtr handle, nint* obj) | ||
{ | ||
ComWrappers cw = new StrategyBasedComWrappers(); | ||
Target? target = GCHandle.FromIntPtr(handle).Target as Target; | ||
if (target == null) | ||
return -1; | ||
|
||
SOSDacImpl impl = new(target); | ||
nint ptr = cw.GetOrCreateComInterfaceForObject(impl, CreateComInterfaceFlags.None); | ||
*obj = ptr; | ||
return 0; | ||
} | ||
} |
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,36 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.InteropServices.Marshalling; | ||
|
||
namespace Microsoft.Diagnostics.DataContractReader; | ||
|
||
[GeneratedComInterface] | ||
[Guid("4eca42d8-7e7b-4c8a-a116-7bfbf6929267")] | ||
internal partial interface ISOSDacInterface9 | ||
{ | ||
int GetBreakingChangeVersion(); | ||
} | ||
|
||
/// <summary> | ||
/// Implementation of ISOSDacInterface* interfaces intended to be passed out to consumers | ||
/// interacting with the DAC via those COM interfaces. | ||
/// </summary> | ||
[GeneratedComClass] | ||
internal sealed partial class SOSDacImpl : ISOSDacInterface9 | ||
{ | ||
private readonly Target _target; | ||
|
||
public SOSDacImpl(Target target) | ||
{ | ||
_target = target; | ||
} | ||
|
||
public int GetBreakingChangeVersion() | ||
{ | ||
// TODO: Return non-hard-coded version | ||
return 4; | ||
} | ||
} |
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,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.Diagnostics.DataContractReader; | ||
|
||
internal sealed class Target | ||
{ | ||
public Target(nint _) | ||
{ | ||
} | ||
} |
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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<!-- Do not produce a public package. This ships as part of the runtime --> | ||
<IsShippingPackage>false</IsShippingPackage> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<InstallRuntimeComponentDestination Include="." /> | ||
<!-- TODO: [cdac] Output to sharedFramework and add PlatformManifestFileEntry for Microsoft.NETCore.App once ready to include in shipping package --> | ||
<!-- <InstallRuntimeComponentDestination Include="sharedFramework" Condition="'$(RuntimeFlavor)' == 'coreclr'"/> --> | ||
</ItemGroup> | ||
|
||
</Project> |
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