More corelib cleanup (dotnet/coreclr#26993)
[mono-project.git] / netcore / System.Private.CoreLib / shared / Interop / Windows / Advapi32 / Interop.EventWriteTransfer.cs
blob1bc116fdd66a0cb635d4ed8496d0fc57248b3f27
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 using System;
6 using System.Runtime.InteropServices;
7 #if ES_BUILD_STANDALONE
8 using Microsoft.Diagnostics.Tracing;
9 #else
10 using System.Diagnostics.Tracing;
11 #endif
13 internal static partial class Interop
15 internal static partial class Advapi32
17 /// <summary>
18 /// Call the ETW native API EventWriteTransfer and checks for invalid argument error.
19 /// The implementation of EventWriteTransfer on some older OSes (Windows 2008) does not accept null relatedActivityId.
20 /// So, for these cases we will retry the call with an empty Guid.
21 /// </summary>
22 internal static unsafe int EventWriteTransfer(
23 long registrationHandle,
24 in EventDescriptor eventDescriptor,
25 Guid* activityId,
26 Guid* relatedActivityId,
27 int userDataCount,
28 EventProvider.EventData* userData)
30 int HResult = EventWriteTransfer_PInvoke(registrationHandle, in eventDescriptor, activityId, relatedActivityId, userDataCount, userData);
31 if (HResult == Errors.ERROR_INVALID_PARAMETER && relatedActivityId == null)
33 Guid emptyGuid = Guid.Empty;
34 HResult = EventWriteTransfer_PInvoke(registrationHandle, in eventDescriptor, activityId, &emptyGuid, userDataCount, userData);
37 return HResult;
40 [DllImport(Interop.Libraries.Advapi32, ExactSpelling = true, EntryPoint = "EventWriteTransfer")]
41 private static extern unsafe int EventWriteTransfer_PInvoke(
42 long registrationHandle,
43 in EventDescriptor eventDescriptor,
44 Guid* activityId,
45 Guid* relatedActivityId,
46 int userDataCount,
47 EventProvider.EventData* userData);