Modify Jenkins scripts to enable babysitter script on Cygwin
[mono.git] / mcs / class / referencesource / mscorlib / microsoft / win32 / safehandles / saferegistryhandle.cs
1 // ==++==
2 //
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 //
5 // ==--==
6 //
7 // File: SafeRegistryHandle.cs
8 //
9 // <OWNER>[....]</OWNER>
10 //
11 // Implements Microsoft.Win32.SafeHandles.SafeRegistryHandle
12 //
13 // ======================================================================================
14 #if !FEATURE_PAL || MONO
15 namespace Microsoft.Win32.SafeHandles {
16     using System;
17     using System.Security;
18     using System.Security.Permissions;
19     using System.Runtime.InteropServices;
20     using System.Runtime.CompilerServices;
21     using System.Runtime.ConstrainedExecution;
22     using System.Runtime.Versioning;
23
24     [System.Security.SecurityCritical]
25     public sealed class SafeRegistryHandle : SafeHandleZeroOrMinusOneIsInvalid {
26         [System.Security.SecurityCritical]
27         internal SafeRegistryHandle() : base(true) {}
28
29         [System.Security.SecurityCritical]
30         public SafeRegistryHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) {
31             SetHandle(preexistingHandle);
32         }
33
34 #if MOBILE
35         override protected bool ReleaseHandle() {
36             return true;
37         }
38 #else
39         [System.Security.SecurityCritical]
40         override protected bool ReleaseHandle() {
41             return (RegCloseKey(handle) == Win32Native.ERROR_SUCCESS);
42         }
43
44         [DllImport(Win32Native.ADVAPI32),
45          SuppressUnmanagedCodeSecurity,
46          ResourceExposure(ResourceScope.None),
47          ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
48         internal static extern int RegCloseKey(IntPtr hKey);
49 #endif
50     }
51 }
52 #endif // !FEATURE_PAL