Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@@ -0,0 +1,54 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SafeEventLogReadHandle
**
** <EMAIL>Author: David Gutierrez ([....]) </EMAIL>
**
** A wrapper for event log handles
**
** Date: July 8, 2002
**
===========================================================*/
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
namespace Microsoft.Win32.SafeHandles {
[HostProtectionAttribute(MayLeakOnAbort = true)]
[SuppressUnmanagedCodeSecurityAttribute]
internal sealed class SafeEventLogReadHandle : SafeHandleZeroOrMinusOneIsInvalid
{
// Note: OpenEventLog returns 0 on failure.
internal SafeEventLogReadHandle () : base(true) { }
[DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern SafeEventLogReadHandle OpenEventLog(string UNCServerName, string sourceName);
[DllImport(ExternDll.Advapi32, SetLastError=true)]
[ResourceExposure(ResourceScope.None)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
private static extern bool CloseEventLog(IntPtr hEventLog);
override protected bool ReleaseHandle()
{
return CloseEventLog(handle);
}
}
}

View File

@@ -0,0 +1,54 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SafeEventLogWriteHandle
**
** <EMAIL>Author: David Gutierrez ([....]) </EMAIL>
**
** A wrapper for event log handles
**
** Date: July 8, 2002
**
===========================================================*/
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
namespace Microsoft.Win32.SafeHandles {
[HostProtectionAttribute(MayLeakOnAbort = true)]
[SuppressUnmanagedCodeSecurityAttribute]
internal sealed class SafeEventLogWriteHandle : SafeHandleZeroOrMinusOneIsInvalid
{
// Note: RegisterEventSource returns 0 on failure
internal SafeEventLogWriteHandle () : base(true) {}
[DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern SafeEventLogWriteHandle RegisterEventSource(string uncServerName, string sourceName);
[DllImport(ExternDll.Advapi32, SetLastError=true)]
[ResourceExposure(ResourceScope.None)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
private static extern bool DeregisterEventSource(IntPtr hEventLog);
override protected bool ReleaseHandle()
{
return DeregisterEventSource(handle);
}
}
}

View File

@@ -0,0 +1,53 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SafeFileMapViewHandle
**
** <EMAIL>Author: Brian Grunkemeyer ([....]) </EMAIL>
**
** A wrapper for handles returned from MapViewOfFile, used
** for shared memory.
**
** Date: August 7, 2002
**
===========================================================*/
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
namespace Microsoft.Win32.SafeHandles {
[HostProtectionAttribute(MayLeakOnAbort = true)]
[SuppressUnmanagedCodeSecurityAttribute]
internal sealed class SafeFileMapViewHandle : SafeHandleZeroOrMinusOneIsInvalid
{
// Note that MapViewOfFile returns 0 on failure
internal SafeFileMapViewHandle() : base(true) {}
[DllImport(ExternDll.Kernel32, ExactSpelling=true, CharSet=CharSet.Auto)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern SafeFileMapViewHandle MapViewOfFile(SafeFileMappingHandle hFileMappingObject, int dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, UIntPtr dwNumberOfBytesToMap);
[DllImport(ExternDll.Kernel32, ExactSpelling=true, SetLastError=true)]
[ResourceExposure(ResourceScope.None)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
private static extern bool UnmapViewOfFile(IntPtr handle);
override protected bool ReleaseHandle()
{
return UnmapViewOfFile(handle);
}
}
}

View File

@@ -0,0 +1,51 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SafeFileMappingHandle
**
** <EMAIL>Author: David Gutierrez ([....]) </EMAIL>
**
** A wrapper for handle to file mappings, returned by
** CreateFileMapping and OpenFileMapping. Used for shared
** memory.
**
** Date: July 8, 2002
**
===========================================================*/
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
namespace Microsoft.Win32.SafeHandles {
[HostProtectionAttribute(MayLeakOnAbort = true)]
[SuppressUnmanagedCodeSecurityAttribute]
internal sealed class SafeFileMappingHandle : SafeHandleZeroOrMinusOneIsInvalid
{
// Note that CreateFileMapping returns 0 on failure.
// Note that you can pass in -1 for the hFile parameter.
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)]
internal SafeFileMappingHandle() : base(true) {}
[DllImport(ExternDll.Kernel32, ExactSpelling=true, SetLastError=true)]
[ResourceExposure(ResourceScope.None)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
private static extern bool CloseHandle(IntPtr handle);
override protected bool ReleaseHandle()
{
return CloseHandle(handle);
}
}
}

View File

@@ -0,0 +1,58 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SafeLibraryHandle
**
** <EMAIL>Author: David Gutierrez ([....]) </EMAIL>
**
** A wrapper for a library handles
**
** Date: July 8, 2002
**
===========================================================*/
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
namespace Microsoft.Win32.SafeHandles {
[HostProtectionAttribute(MayLeakOnAbort = true)]
[SuppressUnmanagedCodeSecurityAttribute]
internal sealed class SafeLibraryHandle : SafeHandleZeroOrMinusOneIsInvalid
{
// Note that LoadLibraryEx returns 0 on failure
internal SafeLibraryHandle() : base(true) {}
[DllImport(ExternDll.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Unicode, SetLastError=true)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern SafeLibraryHandle LoadLibraryEx(string libFilename, IntPtr reserved, int flags);
[DllImport(ExternDll.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Unicode)]
[ResourceExposure(ResourceScope.None)]
#if !FEATURE_WINDOWSPHONE
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
#endif // !FEATURE_WINDOWSPHONE
private static extern bool FreeLibrary(IntPtr hModule);
override protected bool ReleaseHandle()
{
return FreeLibrary(handle);
}
}
}

View File

@@ -0,0 +1,61 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SafeLocalMemHandle
**
** <EMAIL>Author: David Gutierrez ([....]) </EMAIL>
**
** A wrapper for handle to local memory
**
** Date: July 8, 2002
**
===========================================================*/
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
namespace Microsoft.Win32.SafeHandles {
[HostProtectionAttribute(MayLeakOnAbort = true)]
[SuppressUnmanagedCodeSecurityAttribute]
internal sealed class SafeLocalMemHandle : SafeHandleZeroOrMinusOneIsInvalid
{
internal SafeLocalMemHandle() : base(true) {}
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)]
internal SafeLocalMemHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) {
SetHandle(existingHandle);
}
[DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true, BestFitMapping=false)]
[ResourceExposure(ResourceScope.None)]
internal static extern unsafe bool ConvertStringSecurityDescriptorToSecurityDescriptor(string StringSecurityDescriptor, int StringSDRevision, out SafeLocalMemHandle pSecurityDescriptor, IntPtr SecurityDescriptorSize);
[DllImport(ExternDll.Kernel32)]
[ResourceExposure(ResourceScope.None)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
private static extern IntPtr LocalFree(IntPtr hMem);
override protected bool ReleaseHandle()
{
return LocalFree(handle) == IntPtr.Zero;
}
}
}

View File

@@ -0,0 +1,70 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SafeProcessHandle
**
** A wrapper for a process handle
**
**
===========================================================*/
using System;
using System.Security;
using System.Diagnostics;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
namespace Microsoft.Win32.SafeHandles {
[SuppressUnmanagedCodeSecurityAttribute]
public sealed class SafeProcessHandle : SafeHandleZeroOrMinusOneIsInvalid
{
internal static SafeProcessHandle InvalidHandle = new SafeProcessHandle(IntPtr.Zero);
// Note that OpenProcess returns 0 on failure
internal SafeProcessHandle() : base(true) {}
internal SafeProcessHandle(IntPtr handle) : base(true) {
SetHandle(handle);
}
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public SafeProcessHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) {
SetHandle(existingHandle);
}
#if !MONO
[DllImport(ExternDll.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern SafeProcessHandle OpenProcess(int access, bool inherit, int processId);
#endif
internal void InitialSetHandle(IntPtr h){
Debug.Assert(base.IsInvalid, "Safe handle should only be set once");
base.handle = h;
}
override protected bool ReleaseHandle()
{
#if !MONO
return SafeNativeMethods.CloseHandle(handle);
#else
return NativeMethods.CloseProcess (handle);
#endif
}
}
}

View File

@@ -0,0 +1,47 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SafeThreadHandle
**
**
** A wrapper for a thread handle
**
**
===========================================================*/
using System;
using System.Security;
using System.Diagnostics;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
namespace Microsoft.Win32.SafeHandles {
[SuppressUnmanagedCodeSecurityAttribute]
internal sealed class SafeThreadHandle : SafeHandleZeroOrMinusOneIsInvalid
{
internal SafeThreadHandle() : base(true) {
}
internal void InitialSetHandle(IntPtr h){
Debug.Assert(base.IsInvalid, "Safe handle should only be set once");
base.SetHandle(h);
}
override protected bool ReleaseHandle() {
return SafeNativeMethods.CloseHandle(handle);
}
}
}

View File

@@ -0,0 +1,59 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SafeTimerHandle
**
** <EMAIL>Author: David Gutierrez ([....]) </EMAIL>
**
** A wrapper for a timer handle
**
** Date: July 23, 2002
**
===========================================================*/
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
namespace Microsoft.Win32.SafeHandles {
[HostProtectionAttribute(MayLeakOnAbort=true)]
[SuppressUnmanagedCodeSecurityAttribute]
internal sealed class SafeTimerHandle : SafeHandleZeroOrMinusOneIsInvalid
{
// Note that CreateWaitableTimer returns 0 on failure
internal SafeTimerHandle() : base (true) {}
// Not currently used
//[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)]
//internal SafeTimerHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) {
// SetHandle(existingHandle);
//}
[DllImport(ExternDll.Kernel32, ExactSpelling=true, SetLastError=true)]
[ResourceExposure(ResourceScope.None)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
private static extern bool CloseHandle(IntPtr handle);
override protected bool ReleaseHandle()
{
return CloseHandle(handle);
}
}
}

View File

@@ -0,0 +1,63 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SafeUserTokenHandle
**
** <EMAIL>Author: David Gutierrez ([....]) </EMAIL>
**
** A wrapper for a user token handle
**
** Date: July 8, 2002
**
===========================================================*/
using System;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
namespace Microsoft.Win32.SafeHandles {
[HostProtectionAttribute(MayLeakOnAbort = true)]
[SuppressUnmanagedCodeSecurityAttribute]
internal sealed class SafeUserTokenHandle : SafeHandleZeroOrMinusOneIsInvalid
{
// Note that OpenProcess returns 0 on failure.
internal SafeUserTokenHandle() : base (true) {}
internal SafeUserTokenHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) {
SetHandle(existingHandle);
}
#if !FEATURE_PAL
[DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true, BestFitMapping=false)]
[ResourceExposure(ResourceScope.None)]
internal extern static bool DuplicateTokenEx(SafeHandle hToken, int access, NativeMethods.SECURITY_ATTRIBUTES tokenAttributes, int impersonationLevel, int tokenType, out SafeUserTokenHandle hNewToken);
#endif // !FEATURE_PAL
[DllImport(ExternDll.Kernel32, ExactSpelling=true, SetLastError=true)]
[ResourceExposure(ResourceScope.None)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
private static extern bool CloseHandle(IntPtr handle);
override protected bool ReleaseHandle()
{
return CloseHandle(handle);
}
}
}