From: Carlos Sanchez Lopez <1175054+carlossanlop@users.noreply.github.com> Date: Fri, 8 Nov 2019 00:27:37 +0000 (-0800) Subject: Add Semaphore creation extension methods that take an ACL (dotnet/coreclr#42377) X-Git-Tag: submit/tizen/20210909.063632~11030^2~72 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f444fcdef11a59310fca4283a81a954551fccb60;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Add Semaphore creation extension methods that take an ACL (dotnet/coreclr#42377) Approved API Proposal: dotnet/coreclr#41662 Description We don't currently have a way to create a Semaphore with a given ACL in .NET Core. We can modify the ACL, but it would be more secure to have the proper ACL on the object from the start. Customer impact Before this change, customers had to create a Semaphore, then set its ACLs. This presents a few problems: - Potential security hole as semaphores can be accessed between creation and modification. - Porting difficulties as there isn't a 1-1 API replacement This change addresses those problems by adding a new extension method that allows creating a Semaphore and ensuring the provided ACLs are set during creation. Signed-off-by: dotnet-bot Commit migrated from https://github.com/dotnet/coreclr/commit/74c369c25ea866ff71350346d6c33d1d383e2593 --- diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.Semaphore.cs b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.Semaphore.cs index d2904df..4f6d8de 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.Semaphore.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.Semaphore.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using Microsoft.Win32.SafeHandles; using System; using System.Runtime.InteropServices; @@ -10,13 +11,13 @@ internal static partial class Interop { internal static partial class Kernel32 { - [DllImport(Interop.Libraries.Kernel32, EntryPoint = "OpenSemaphoreW", SetLastError = true, CharSet = CharSet.Unicode)] + [DllImport(Libraries.Kernel32, EntryPoint = "OpenSemaphoreW", SetLastError = true, CharSet = CharSet.Unicode)] internal static extern SafeWaitHandle OpenSemaphore(uint desiredAccess, bool inheritHandle, string name); [DllImport(Libraries.Kernel32, EntryPoint = "CreateSemaphoreExW", SetLastError = true, CharSet = CharSet.Unicode)] internal static extern SafeWaitHandle CreateSemaphoreEx(IntPtr lpSecurityAttributes, int initialCount, int maximumCount, string? name, uint flags, uint desiredAccess); - [DllImport(Interop.Libraries.Kernel32, SetLastError = true)] + [DllImport(Libraries.Kernel32, SetLastError = true)] internal static extern bool ReleaseSemaphore(SafeWaitHandle handle, int releaseCount, out int previousCount); } }