From 0253754e786b12999e35fe9687f49c0ffd8d3eec Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Fri, 8 Mar 2019 08:27:54 +0100 Subject: [PATCH] Use platform specific implementation of GetCurrentProcessId (dotnet/coreclr#23084) * Use platform specific implementation of GetCurrentProcessId directly in shared location instead of relying on runtime export * Move GetCurrentProcessId to Interop class * Update ES_BUILD_STANDALONE build Commit migrated from https://github.com/dotnet/coreclr/commit/0fee55abb6b7c742cb487b12706dc54080e9e128 --- .../System.Private.CoreLib.csproj | 1 - .../System/Diagnostics/Eventing/EventPipeController.cs | 4 ++-- .../src/Interop/Unix/System.Native/Interop.GetPid.cs | 17 +++++++++++++++++ .../Windows/Kernel32/Interop.GetCurrentProcessId.cs | 2 ++ .../src/System.Private.CoreLib.Shared.projitems | 2 ++ .../src/System/Diagnostics/Tracing/EventSource.cs | 2 +- .../src/System/Diagnostics/Tracing/StubEnvironment.cs | 2 ++ 7 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Native/Interop.GetPid.cs diff --git a/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj index affbf3e..816d3ce 100644 --- a/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -267,7 +267,6 @@ - diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeController.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeController.cs index c03ba4f..cac4ac1 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeController.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipeController.cs @@ -212,7 +212,7 @@ namespace System.Diagnostics.Tracing { // If set, bail out early if the specified process does not match the current process. int processID = Convert.ToInt32(strProcessID); - if (processID != Interop.Kernel32.GetCurrentProcessId()) + if (processID != (int)Interop.GetCurrentProcessId()) { return null; } @@ -294,7 +294,7 @@ namespace System.Diagnostics.Tracing private static string BuildTraceFileName() { - return GetAppName() + "." + Interop.Kernel32.GetCurrentProcessId().ToString() + NetPerfFileExtension; + return GetAppName() + "." + Interop.GetCurrentProcessId().ToString() + NetPerfFileExtension; } private static string GetAppName() diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Native/Interop.GetPid.cs b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Native/Interop.GetPid.cs new file mode 100644 index 0000000..02d259d --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Native/Interop.GetPid.cs @@ -0,0 +1,17 @@ +// 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 System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Sys + { + [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPid")] + internal static extern int GetPid(); + } + + internal static uint GetCurrentProcessId() => (uint)Sys.GetPid(); +} diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs index a042bfe..3a1a353 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.GetCurrentProcessId.cs @@ -11,4 +11,6 @@ internal partial class Interop [DllImport(Libraries.Kernel32)] internal extern static uint GetCurrentProcessId(); } + + internal static uint GetCurrentProcessId() => Kernel32.GetCurrentProcessId(); } diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index ea3c7cc..a168f09 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -987,6 +987,7 @@ + @@ -1160,6 +1161,7 @@ + diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index de94f4f..3a18dce 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -2698,7 +2698,7 @@ namespace System.Diagnostics.Tracing // for non-BCL EventSource we must assert SecurityPermission new SecurityPermission(PermissionState.Unrestricted).Assert(); #endif - s_currentPid = Interop.Kernel32.GetCurrentProcessId(); + s_currentPid = Interop.GetCurrentProcessId(); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/StubEnvironment.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/StubEnvironment.cs index 4a054c9..d376389 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/StubEnvironment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/StubEnvironment.cs @@ -377,5 +377,7 @@ internal static partial class Interop [DllImport("kernel32.dll", CharSet = CharSet.Auto)] internal static extern uint GetCurrentProcessId(); } + + internal static uint GetCurrentProcessId() => Kernel32.GetCurrentProcessId(); } #endif -- 2.7.4