Debian Codegraph @

mcs/class/referencesource/System/compmod/microsoft/win32/safehandles/SafeFileMapViewHandle.cs

raw
1 // ==++==
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // ==--==
6 /*============================================================
7 **
8 ** Class: SafeFileMapViewHandle
9 **
10 ** <EMAIL>Author: Brian Grunkemeyer (Microsoft) </EMAIL>
11 **
12 ** A wrapper for handles returned from MapViewOfFile, used
13 ** for shared memory.
14 **
15 ** Date: August 7, 2002
16 **
17 ===========================================================*/
18
19 using System;
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;
28
29 namespace Microsoft.Win32.SafeHandles {
30 [HostProtectionAttribute(MayLeakOnAbort = true)]
31 [SuppressUnmanagedCodeSecurityAttribute]
32 internal sealed class SafeFileMapViewHandle : SafeHandleZeroOrMinusOneIsInvalid
33 {
34 // Note that MapViewOfFile returns 0 on failure
35
36 internal SafeFileMapViewHandle() : base(true) {}
37
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);
41
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);
46
47 override protected bool ReleaseHandle()
48 {
49 return UnmapViewOfFile(handle);
50 }
51
52 }
53 }