scripts
This commit is contained in:
@@ -0,0 +1,235 @@
|
||||
using System;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Threading;
|
||||
|
||||
namespace System.Runtime.InteropServices
|
||||
{
|
||||
/// <summary>Represents a wrapper class for operating system handles. This class must be inherited.</summary>
|
||||
// Token: 0x0200033F RID: 831
|
||||
public abstract class SafeHandle : CriticalFinalizerObject, IDisposable
|
||||
{
|
||||
// Token: 0x06002316 RID: 8982 RVA: 0x0007A7F8 File Offset: 0x000789F8
|
||||
protected SafeHandle()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="T:System.Runtime.InteropServices.SafeHandle" /> class with the specified invalid handle value.</summary>
|
||||
/// <param name="invalidHandleValue">The value of an invalid handle (usually 0 or -1). Your implementation of <see cref="P:System.Runtime.InteropServices.SafeHandle.IsInvalid" /> should return true for this value.</param>
|
||||
/// <param name="ownsHandle">true to reliably let <see cref="T:System.Runtime.InteropServices.SafeHandle" /> release the handle during the finalization phase; otherwise, false (not recommended). </param>
|
||||
/// <exception cref="T:System.TypeLoadException">The derived class resides in an assembly without unmanaged code access permission. </exception>
|
||||
// Token: 0x06002317 RID: 8983 RVA: 0x0007A808 File Offset: 0x00078A08
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
protected SafeHandle(IntPtr invalidHandleValue, bool ownsHandle)
|
||||
{
|
||||
this.invalid_handle_value = invalidHandleValue;
|
||||
this.owns_handle = ownsHandle;
|
||||
this.refcount = 1;
|
||||
}
|
||||
|
||||
/// <summary>Marks the handle for releasing and freeing resources.</summary>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
|
||||
/// </PermissionSet>
|
||||
// Token: 0x06002318 RID: 8984 RVA: 0x0007A828 File Offset: 0x00078A28
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
public void Close()
|
||||
{
|
||||
if (this.refcount == 0)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().FullName);
|
||||
}
|
||||
int num;
|
||||
int num2;
|
||||
do
|
||||
{
|
||||
num = this.refcount;
|
||||
num2 = num - 1;
|
||||
}
|
||||
while (Interlocked.CompareExchange(ref this.refcount, num2, num) != num);
|
||||
if (num2 == 0 && this.owns_handle && !this.IsInvalid)
|
||||
{
|
||||
this.ReleaseHandle();
|
||||
this.handle = this.invalid_handle_value;
|
||||
this.refcount = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Manually increments the reference counter on <see cref="T:System.Runtime.InteropServices.SafeHandle" /> instances.</summary>
|
||||
/// <param name="success">true if the reference counter was successfully incremented; otherwise, false.</param>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
|
||||
/// </PermissionSet>
|
||||
// Token: 0x06002319 RID: 8985 RVA: 0x0007A8A8 File Offset: 0x00078AA8
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
public void DangerousAddRef(ref bool success)
|
||||
{
|
||||
if (this.refcount <= 0)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().FullName);
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
int num = this.refcount;
|
||||
int num2 = num + 1;
|
||||
if (num <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (Interlocked.CompareExchange(ref this.refcount, num2, num) == num)
|
||||
{
|
||||
goto Block_3;
|
||||
}
|
||||
}
|
||||
throw new ObjectDisposedException(base.GetType().FullName);
|
||||
Block_3:
|
||||
success = true;
|
||||
}
|
||||
|
||||
/// <summary>Returns the value of the <see cref="F:System.Runtime.InteropServices.SafeHandle.handle" /> field.</summary>
|
||||
/// <returns>An IntPtr representing the value of the <see cref="F:System.Runtime.InteropServices.SafeHandle.handle" /> field. If the handle has been marked invalid with <see cref="M:System.Runtime.InteropServices.SafeHandle.SetHandleAsInvalid" />, this method still returns the original handle value, which can be a stale value.</returns>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
|
||||
/// </PermissionSet>
|
||||
// Token: 0x0600231A RID: 8986 RVA: 0x0007A90C File Offset: 0x00078B0C
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
public IntPtr DangerousGetHandle()
|
||||
{
|
||||
if (this.refcount <= 0)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().FullName);
|
||||
}
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
/// <summary>Manually decrements the reference counter on a <see cref="T:System.Runtime.InteropServices.SafeHandle" /> instance.</summary>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
|
||||
/// </PermissionSet>
|
||||
// Token: 0x0600231B RID: 8987 RVA: 0x0007A934 File Offset: 0x00078B34
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
public void DangerousRelease()
|
||||
{
|
||||
if (this.refcount <= 0)
|
||||
{
|
||||
throw new ObjectDisposedException(base.GetType().FullName);
|
||||
}
|
||||
int num;
|
||||
int num2;
|
||||
do
|
||||
{
|
||||
num = this.refcount;
|
||||
num2 = num - 1;
|
||||
}
|
||||
while (Interlocked.CompareExchange(ref this.refcount, num2, num) != num);
|
||||
if (num2 == 0 && this.owns_handle && !this.IsInvalid)
|
||||
{
|
||||
this.ReleaseHandle();
|
||||
this.handle = this.invalid_handle_value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Releases all resources used by the <see cref="T:System.Runtime.InteropServices.SafeHandle" /> class.</summary>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
|
||||
/// </PermissionSet>
|
||||
// Token: 0x0600231C RID: 8988 RVA: 0x0007A9AC File Offset: 0x00078BAC
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>Marks a handle as no longer used.</summary>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
|
||||
/// </PermissionSet>
|
||||
// Token: 0x0600231D RID: 8989 RVA: 0x0007A9BC File Offset: 0x00078BBC
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
public void SetHandleAsInvalid()
|
||||
{
|
||||
this.handle = this.invalid_handle_value;
|
||||
}
|
||||
|
||||
/// <summary>Releases the unmanaged resources used by the <see cref="T:System.Runtime.InteropServices.SafeHandle" /> class specifying whether to perform a normal dispose operation.</summary>
|
||||
/// <param name="disposing">true for a normal dispose operation; false to finalize the handle.</param>
|
||||
// Token: 0x0600231E RID: 8990 RVA: 0x0007A9CC File Offset: 0x00078BCC
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>When overridden in a derived class, executes the code required to free the handle.</summary>
|
||||
/// <returns>true if the handle is released successfully; otherwise, in the event of a catastrophic failure, false. In this case, it generates a releaseHandleFailed MDA Managed Debugging Assistant.</returns>
|
||||
// Token: 0x0600231F RID: 8991
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
protected abstract bool ReleaseHandle();
|
||||
|
||||
/// <summary>Sets the handle to the specified pre-existing handle.</summary>
|
||||
/// <param name="handle">The pre-existing handle to use. </param>
|
||||
// Token: 0x06002320 RID: 8992 RVA: 0x0007A9E0 File Offset: 0x00078BE0
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
protected void SetHandle(IntPtr handle)
|
||||
{
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
/// <summary>Gets a value indicating whether the handle is closed.</summary>
|
||||
/// <returns>true if the handle is closed; otherwise, false.</returns>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
|
||||
/// </PermissionSet>
|
||||
// Token: 0x17000659 RID: 1625
|
||||
// (get) Token: 0x06002321 RID: 8993 RVA: 0x0007A9EC File Offset: 0x00078BEC
|
||||
public bool IsClosed
|
||||
{
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
get
|
||||
{
|
||||
return this.refcount <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>When overridden in a derived class, gets a value indicating whether the handle value is invalid.</summary>
|
||||
/// <returns>true if the handle value is invalid; otherwise, false.</returns>
|
||||
/// <PermissionSet>
|
||||
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
|
||||
/// </PermissionSet>
|
||||
// Token: 0x1700065A RID: 1626
|
||||
// (get) Token: 0x06002322 RID: 8994
|
||||
public abstract bool IsInvalid
|
||||
{
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>Frees all resources associated with the handle.</summary>
|
||||
// Token: 0x06002323 RID: 8995 RVA: 0x0007A9FC File Offset: 0x00078BFC
|
||||
~SafeHandle()
|
||||
{
|
||||
if (this.owns_handle && !this.IsInvalid)
|
||||
{
|
||||
this.ReleaseHandle();
|
||||
this.handle = this.invalid_handle_value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Specifies the handle to be wrapped.</summary>
|
||||
// Token: 0x04000DA7 RID: 3495
|
||||
protected IntPtr handle;
|
||||
|
||||
// Token: 0x04000DA8 RID: 3496
|
||||
private IntPtr invalid_handle_value;
|
||||
|
||||
// Token: 0x04000DA9 RID: 3497
|
||||
private int refcount;
|
||||
|
||||
// Token: 0x04000DAA RID: 3498
|
||||
private bool owns_handle;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user