Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System / compmod / microsoft / win32 / safehandles / SafeLocalMemHandle.cs
blob8f2c8f513fcf456c342f8e89aaf286f0a664901f
1 // ==++==
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // ==--==
6 /*============================================================
7 **
8 ** Class: SafeLocalMemHandle
9 **
10 ** <EMAIL>Author: David Gutierrez (Microsoft) </EMAIL>
12 ** A wrapper for handle to local memory
14 ** Date: July 8, 2002
15 **
16 ===========================================================*/
18 using System;
19 using System.Security;
20 using System.Security.Permissions;
21 using System.Runtime.InteropServices;
22 using System.Runtime.CompilerServices;
23 using Microsoft.Win32;
24 using Microsoft.Win32.SafeHandles;
25 using System.Runtime.ConstrainedExecution;
26 using System.Runtime.Versioning;
28 namespace Microsoft.Win32.SafeHandles {
29 [HostProtectionAttribute(MayLeakOnAbort = true)]
30 [SuppressUnmanagedCodeSecurityAttribute]
31 internal sealed class SafeLocalMemHandle : SafeHandleZeroOrMinusOneIsInvalid
33 internal SafeLocalMemHandle() : base(true) {}
35 [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)]
36 internal SafeLocalMemHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) {
37 SetHandle(existingHandle);
41 [DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true, BestFitMapping=false)]
42 [ResourceExposure(ResourceScope.None)]
43 internal static extern unsafe bool ConvertStringSecurityDescriptorToSecurityDescriptor(string StringSecurityDescriptor, int StringSDRevision, out SafeLocalMemHandle pSecurityDescriptor, IntPtr SecurityDescriptorSize);
45 [DllImport(ExternDll.Kernel32)]
46 [ResourceExposure(ResourceScope.None)]
47 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
48 private static extern IntPtr LocalFree(IntPtr hMem);
50 override protected bool ReleaseHandle()
52 return LocalFree(handle) == IntPtr.Zero;