Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/libraries/Common/src/System/Diagnostics/NetFrameworkUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ internal static void EnterMutex(string name, ref Mutex mutex)

internal static void EnterMutexWithoutGlobal(string mutexName, ref Mutex mutex)
{
Mutex tmpMutex = new Mutex(false, mutexName, out _);

// Specify a SID in case the mutex has not yet been created; this prevents it from using the SID from the current thread.
// This SID (AuthenticatedUserSid) is the same one used by .NET Framework.
MutexSecurity sec = new MutexSecurity();
SecurityIdentifier authenticatedUserSid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
sec.AddAccessRule(new MutexAccessRule(authenticatedUserSid, MutexRights.Synchronize | MutexRights.Modify, AccessControlType.Allow));
tmpMutex.SetAccessControl(sec);
Mutex tmpMutex = new Mutex(false, mutexName, out bool createdNew);

if (createdNew)
{
// Specify a SID in case the mutex has not yet been created; this prevents it from using the SID from the current thread.
// This SID (AuthenticatedUserSid) is the same one used by .NET Framework.
MutexSecurity sec = new MutexSecurity();
SecurityIdentifier authenticatedUserSid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
sec.AddAccessRule(new MutexAccessRule(authenticatedUserSid, MutexRights.Synchronize | MutexRights.Modify, AccessControlType.Allow));
tmpMutex.SetAccessControl(sec);
}

SafeWaitForMutex(tmpMutex, ref mutex);
}
Expand Down
Loading