3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 /*============================================================
8 ** Class: SafeFileMappingHandle
10 ** <EMAIL>Author: David Gutierrez (Microsoft) </EMAIL>
12 ** A wrapper for handle to file mappings, returned by
13 ** CreateFileMapping and OpenFileMapping. Used for shared
18 ===========================================================*/
21 using System.Security;
22 using System.Security.Permissions;
23 using System.Runtime.InteropServices;
24 using System.Runtime.CompilerServices;
25 using Microsoft.Win32;
26 using Microsoft.Win32.SafeHandles;
27 using System.Runtime.ConstrainedExecution;
28 using System.Runtime.Versioning;
30 namespace Microsoft.Win32.SafeHandles {
31 [HostProtectionAttribute(MayLeakOnAbort = true)]
32 [SuppressUnmanagedCodeSecurityAttribute]
33 internal sealed class SafeFileMappingHandle : SafeHandleZeroOrMinusOneIsInvalid
35 // Note that CreateFileMapping returns 0 on failure.
37 // Note that you can pass in -1 for the hFile parameter.
38 [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)]
39 internal SafeFileMappingHandle() : base(true) {}
41 [DllImport(ExternDll.Kernel32, ExactSpelling=true, SetLastError=true)]
42 [ResourceExposure(ResourceScope.None)]
43 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
44 private static extern bool CloseHandle(IntPtr handle);
46 override protected bool ReleaseHandle()
48 return CloseHandle(handle);