3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 /*============================================================
8 ** Class: SafeFileMapViewHandle
10 ** <EMAIL>Author: Brian Grunkemeyer ([....]) </EMAIL>
12 ** A wrapper for handles returned from MapViewOfFile, used
15 ** Date: August 7, 2002
17 ===========================================================*/
20 using System.Security;
21 using System.Security.Permissions;
22 using System.Runtime.InteropServices;
23 using System.Runtime.CompilerServices;
24 using Microsoft.Win32;
25 using Microsoft.Win32.SafeHandles;
26 using System.Runtime.ConstrainedExecution;
27 using System.Runtime.Versioning;
29 namespace Microsoft.Win32.SafeHandles {
30 [HostProtectionAttribute(MayLeakOnAbort = true)]
31 [SuppressUnmanagedCodeSecurityAttribute]
32 internal sealed class SafeFileMapViewHandle : SafeHandleZeroOrMinusOneIsInvalid
34 // Note that MapViewOfFile returns 0 on failure
36 internal SafeFileMapViewHandle() : base(true) {}
38 [DllImport(ExternDll.Kernel32, ExactSpelling=true, CharSet=CharSet.Auto)]
39 [ResourceExposure(ResourceScope.Machine)]
40 internal static extern SafeFileMapViewHandle MapViewOfFile(SafeFileMappingHandle hFileMappingObject, int dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, UIntPtr dwNumberOfBytesToMap);
42 [DllImport(ExternDll.Kernel32, ExactSpelling=true, SetLastError=true)]
43 [ResourceExposure(ResourceScope.None)]
44 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
45 private static extern bool UnmapViewOfFile(IntPtr handle);
47 override protected bool ReleaseHandle()
49 return UnmapViewOfFile(handle);