3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 /*============================================================
8 ** Class: SafeMemoryMappedViewHandle
10 ** Purpose: Safe handle wrapping a MMF view pointer
12 ** Date: February 7, 2007
14 ===========================================================*/
17 using System.Runtime.InteropServices;
18 using System.Runtime.Versioning;
19 using System.Security.Permissions;
20 using Microsoft.Win32;
21 using Microsoft.Win32.SafeHandles;
24 namespace Microsoft.Win32.SafeHandles {
27 // ReleaseHandle has reliability guarantee of Cer.Success, as defined by SafeHandle.
28 // It gets prepared as a CER at instance construction time. This safe handle doesn't
29 // need to override IsInvalid because the one it inherits from
30 // SafeHandleZeroOrMinusOneIsInvalid is correct.
32 #pragma warning disable 618 // Have not migrated to v4 transparency yet
33 [System.Security.SecurityCritical(System.Security.SecurityCriticalScope.Everything)]
34 #pragma warning restore 618
35 public sealed class SafeMemoryMappedViewHandle : SafeBuffer {
37 [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
38 internal SafeMemoryMappedViewHandle() : base(true) { }
40 [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
41 internal SafeMemoryMappedViewHandle(IntPtr handle, bool ownsHandle) : base(ownsHandle) {
42 base.SetHandle(handle);
45 [ResourceExposure(ResourceScope.Machine)]
46 [ResourceConsumption(ResourceScope.Machine)]
47 override protected bool ReleaseHandle() {
48 if (UnsafeNativeMethods.UnmapViewOfFile(handle)) {