[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPid")]
internal static extern int GetPid();
}
-
- internal static uint GetCurrentProcessId() => (uint)Sys.GetPid();
}
[DllImport(Libraries.Kernel32)]
internal static extern uint GetCurrentProcessId();
}
-
- internal static uint GetCurrentProcessId() => Kernel32.GetCurrentProcessId();
}
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetHostName.cs">
<Link>Common\Interop\Unix\System.Native\Interop.GetHostName.cs</Link>
</Compile>
- <Compile Include="$(CommonPath)\Interop\Unix\System.Native\Interop.GetPid.cs">
- <Link>Common\Interop\Unix\System.Native\Interop.GetPid.cs</Link>
- </Compile>
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.GetPwUid.cs">
<Link>Common\Interop\Unix\System.Native\Interop.GetPwUid.cs</Link>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Unix.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
+ <Compile Include="$(CommonPath)\Interop\Unix\System.Native\Interop.GetPid.cs">
+ <Link>Common\Interop\Unix\System.Native\Interop.GetPid.cs</Link>
+ </Compile>
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.GetDisplayName.cs" />
</ItemGroup>
#if ES_BUILD_STANDALONE
using System;
using System.Diagnostics;
+using Environment = Microsoft.Diagnostics.Tracing.Internal.Environment;
#else
using System.Threading.Tasks;
#endif
uint* sumPtr = (uint*)outPtr;
// We set the last DWORD the sum of the first 3 DWORDS in the GUID. This
// This last number is a random number (it identifies us as us) the process ID to make it unique per process.
- sumPtr[3] = (sumPtr[0] + sumPtr[1] + sumPtr[2] + 0x599D99AD) ^ EventSource.s_currentPid;
+ sumPtr[3] = (sumPtr[0] + sumPtr[1] + sumPtr[2] + 0x599D99AD) ^ (uint)Environment.ProcessId;
return (int)(ptr - ((byte*)outPtr));
}
DefineEventPipeEvents();
#endif
}
- if (s_currentPid == 0)
- {
-#if ES_BUILD_STANDALONE
- // for non-BCL EventSource we must assert SecurityPermission
- new SecurityPermission(PermissionState.Unrestricted).Assert();
-#endif
- s_currentPid = Interop.GetCurrentProcessId();
- }
}
// Send out the ETW manifest XML out to ETW
private string[]? m_traits; // Used to implement GetTraits
- internal static uint s_currentPid; // current process id, used in synthesizing quasi-GUIDs
[ThreadStatic]
private static byte m_EventSourceExceptionRecurenceCount; // current recursion count inside ThrowEventSourceException
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
+using System.Security.Permissions;
#endif
#if ES_BUILD_AGAINST_DOTNET_V35
using Microsoft.Internal;
namespace System.Diagnostics.Tracing.Internal
#endif
{
+#if ES_BUILD_STANDALONE
internal static class Environment
{
- public static readonly string NewLine = System.Environment.NewLine;
-
- public static int TickCount => System.Environment.TickCount;
-
- public static string GetResourceString(string key, params object?[] args)
- {
- string? fmt = rm.GetString(key);
- if (fmt != null)
- return string.Format(fmt, args);
-
- string sargs = string.Join(", ", args);
+ public static int ProcessId = GetCurrentProcessId();
- return key + " (" + sargs + ")";
- }
-
- public static string GetRuntimeResourceString(string key, params object?[] args)
+ private static int GetCurrentProcessId()
{
- return GetResourceString(key, args);
+ new SecurityPermission(PermissionState.Unrestricted).Assert();
+ return (int)Interop.Kernel32.GetCurrentProcessId();
}
-
- private static readonly System.Resources.ResourceManager rm = new System.Resources.ResourceManager("Microsoft.Diagnostics.Tracing.Messages", typeof(Environment).Assembly());
}
-#if ES_BUILD_STANDALONE
internal static class BitOperations
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
internal static extern uint GetCurrentProcessId();
}
-
- internal static uint GetCurrentProcessId() => Kernel32.GetCurrentProcessId();
}
#endif
{
return new OperatingSystem(PlatformID.Other, new Version(1, 0, 0, 0));
}
+
+ private static int GetCurrentProcessId() => 42;
}
-}
\ No newline at end of file
+}
// Otherwise, fail.
throw new IOException(errorInfo.GetErrorMessage(), errorInfo.RawErrno);
}
+
+ private static int GetCurrentProcessId() => Interop.Sys.GetPid();
}
}
private static bool Is64BitOperatingSystemWhen32BitProcess => false;
- private static int GetCurrentProcessId() => Interop.Sys.GetPid();
-
internal const string NewLineConst = "\n";
public static string SystemDirectory => GetFolderPathCore(SpecialFolder.System, SpecialFolderOption.None);
// using the taskGuid, the appdomain ID, and 8 bytes of 'randomization' chosen by
// using the last 8 bytes as the provider GUID for this provider.
// These were generated by CreateGuid, and are reasonably random (and thus unlikely to collide
- uint pid = EventSource.s_currentPid;
+ int pid = Environment.ProcessId;
return new Guid(taskID,
(short)DefaultAppDomainID, (short)(DefaultAppDomainID >> 16),
(byte)pid, (byte)(pid >> 8), (byte)(pid >> 16), (byte)(pid >> 24),