DangerousAddRef() private method

private DangerousAddRef ( bool &success ) : void
success bool
return void
Esempio n. 1
0
        internal void SetParent(SafeHandle parent)
        {
            bool addedRef = false;
            parent.DangerousAddRef(ref addedRef);
            Debug.Assert(addedRef);

            _parent = parent;
        }
Esempio n. 2
0
        internal void TransferOwnershipToParent(SafeHandle parent)
        {
            Debug.Assert(_parent == null, "Expected no existing parent");
            Debug.Assert(parent != null && !parent.IsInvalid, "Expected new parent to be non-null and valid");

            bool addedRef = false;
            parent.DangerousAddRef(ref addedRef);

            _parent = parent;
        }
        internal SafeProvOrNCryptKeyHandleUwp(IntPtr handle, SafeHandle parentHandle)
            : this(handle, true, true)
        {
            Debug.Assert(parentHandle != null && !parentHandle.IsClosed && !parentHandle.IsInvalid);

            // If the provided handle value wasn't valid we won't call dispose, so we shouldn't be doing this.
            Debug.Assert(!IsInvalid);

            bool addedRef = false;
            parentHandle.DangerousAddRef(ref addedRef);
            _parentHandle = parentHandle;
        }
      public static ArbitraryWaitHandle FromSafeHandle(SafeHandle safeHandle) {
         Contract.Requires(safeHandle != null);
         Boolean success = false;
         try {
            safeHandle.DangerousAddRef(ref success);
            if (!success) throw new InvalidOperationException("Couldn't AddRef");

            return new ArbitraryWaitHandle(safeHandle.DangerousGetHandle());
         }
         finally {
            safeHandle.DangerousRelease();
         }
      }
Esempio n. 5
0
        internal SafePipeHandle(Socket namedPipeSocket) : base(ownsHandle: true)
        {
            Debug.Assert(namedPipeSocket != null);
            _namedPipeSocket = namedPipeSocket;

            // TODO: Issue https://github.com/dotnet/corefx/issues/6807
            // This is unfortunately the only way of getting at the Socket's file descriptor right now, until #6807 is implemented.
            PropertyInfo safeHandleProperty = s_safeHandleProperty ?? (s_safeHandleProperty = typeof(Socket).GetTypeInfo().GetDeclaredProperty("SafeHandle"));
            Debug.Assert(safeHandleProperty != null, "Socket.SafeHandle could not be found.");
            _namedPipeSocketHandle = (SafeHandle)safeHandleProperty?.GetValue(namedPipeSocket, null);

            bool ignored = false;
            _namedPipeSocketHandle.DangerousAddRef(ref ignored);
            SetHandle(_namedPipeSocketHandle.DangerousGetHandle());
        }
Esempio n. 6
0
		public static bool DuplicateHandle(HandleRef hSourceProcessHandle, SafeHandle hSourceHandle, HandleRef hTargetProcess,
			out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
		{
			bool release = false;
			try {
				hSourceHandle.DangerousAddRef (ref release);

				MonoIOError error;
				IntPtr nakedTargetHandle;
				bool ret = MonoIO.DuplicateHandle (hSourceProcessHandle.Handle, hSourceHandle.DangerousGetHandle (), hTargetProcess.Handle,
					out nakedTargetHandle, dwDesiredAccess, bInheritHandle ? 1 : 0, dwOptions, out error);

				if (error != MonoIOError.ERROR_SUCCESS)
					throw MonoIO.GetException (error);

				targetHandle = new SafeWaitHandle (nakedTargetHandle, true);
				return ret;
			} finally {
				if (release)
					hSourceHandle.DangerousRelease ();
			}
		}
        private static IEnumerable<RecipientInfo> ToRecipientInfosForThisIndex(SafeHandle pCmsgCmsRecipientInfoMemory, int index)
        {
            bool mustRelease = false;
            pCmsgCmsRecipientInfoMemory.DangerousAddRef(ref mustRelease);
            try
            {
                unsafe
                {
                    CMSG_CMS_RECIPIENT_INFO* pCMsgCmsRecipientInfo = (CMSG_CMS_RECIPIENT_INFO*)(pCmsgCmsRecipientInfoMemory.DangerousGetHandle());
                    switch (pCMsgCmsRecipientInfo->dwRecipientChoice)
                    {
                        case CMsgCmsRecipientChoice.CMSG_KEY_TRANS_RECIPIENT:
                            return new KeyTransRecipientInfo[] { new KeyTransRecipientInfo(new KeyTransRecipientInfoPalWindows(pCmsgCmsRecipientInfoMemory, index)) };

                        case CMsgCmsRecipientChoice.CMSG_KEY_AGREE_RECIPIENT:
                            {
                                CMSG_KEY_AGREE_RECIPIENT_INFO* pCmsKeyAgreeRecipientInfo = pCMsgCmsRecipientInfo->KeyAgree;
                                int numKeys = pCmsKeyAgreeRecipientInfo->cRecipientEncryptedKeys;
                                KeyAgreeRecipientInfo[] recipients = new KeyAgreeRecipientInfo[numKeys];
                                for (int subIndex = 0; subIndex < numKeys; subIndex++)
                                {
                                    recipients[subIndex] = new KeyAgreeRecipientInfo(new KeyAgreeRecipientInfoPalWindows(pCmsgCmsRecipientInfoMemory, index, subIndex));
                                }
                                return recipients;
                            }

                        default:
                            throw ErrorCode.E_NOTIMPL.ToCryptographicException();
                    }
                }
            }
            finally
            {
                if (mustRelease)
                {
                    pCmsgCmsRecipientInfoMemory.DangerousRelease();
                }
            }
        }
 public static bool BindHandle(SafeHandle osHandle)
 {
     if (osHandle == null)
     {
         throw new ArgumentNullException("osHandle");
     }
     bool flag = false;
     bool success = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try
     {
         osHandle.DangerousAddRef(ref success);
         flag = BindIOCompletionCallbackNative(osHandle.DangerousGetHandle());
     }
     finally
     {
         if (success)
         {
             osHandle.DangerousRelease();
         }
     }
     return flag;
 }
Esempio n. 9
0
		public static void Unlock (SafeHandle safeHandle,
						  long position, long length,
						  out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				Unlock (safeHandle.DangerousGetHandle (), position, length, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Esempio n. 10
0
		public static bool SetFileTime (SafeHandle safeHandle,
						       long creation_time,
						       long last_access_time,
						       long last_write_time,
						       out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return SetFileTime (safeHandle.DangerousGetHandle (), creation_time, last_access_time, last_write_time, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Esempio n. 11
0
		public static bool SetLength (SafeHandle safeHandle,
						     long length,
						     out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return SetLength (safeHandle.DangerousGetHandle (), length, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Esempio n. 12
0
		public static bool Flush (SafeHandle safeHandle,
						 out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return Flush (safeHandle.DangerousGetHandle (), out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Esempio n. 13
0
		public static long Seek (SafeHandle safeHandle, long offset,
						SeekOrigin origin,
						out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return Seek (safeHandle.DangerousGetHandle (), offset, origin, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Esempio n. 14
0
        [System.Security.SecurityCritical]  // auto-generated
        static internal IntPtr SafeHandleAddRef(SafeHandle pHandle, ref bool success) 
        {
            if (pHandle == null) 
            { 
                throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_SafeHandle"));
            } 
            Contract.EndContractBlock();

            pHandle.DangerousAddRef(ref success);
 
            return (success ? pHandle.DangerousGetHandle() : IntPtr.Zero);
        } 
Esempio n. 15
0
		static int WaitOneNative (SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
		{
			bool release = false;
			try {
#if !DISABLE_REMOTING
				if (exitContext)
					SynchronizationAttribute.ExitContext ();
#endif

				waitableSafeHandle.DangerousAddRef (ref release);

				return WaitOne_internal (waitableSafeHandle.DangerousGetHandle (), (int) millisecondsTimeout);
			} finally {
				if (release)
					waitableSafeHandle.DangerousRelease ();

#if !DISABLE_REMOTING
				if (exitContext)
					SynchronizationAttribute.EnterContext ();
#endif
			}
		}
Esempio n. 16
0
 public static bool BindHandle(SafeHandle osHandle)
 {
     if (osHandle == null)
         throw new ArgumentNullException("osHandle");
     
     bool ret = false;
     bool mustReleaseSafeHandle = false;
     RuntimeHelpers.PrepareConstrainedRegions();
     try {
         osHandle.DangerousAddRef(ref mustReleaseSafeHandle);
         ret = BindIOCompletionCallbackNative(osHandle.DangerousGetHandle());
     }
     finally {
         if (mustReleaseSafeHandle)
             osHandle.DangerousRelease();
     }
     return ret;
 }
 internal static IntPtr SafeHandleAddRef(SafeHandle pHandle, ref bool success)
 {
     if (pHandle == null)
     {
         throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_SafeHandle"));
     }
     pHandle.DangerousAddRef(ref success);
     if (!success)
     {
         return IntPtr.Zero;
     }
     return pHandle.DangerousGetHandle();
 }
Esempio n. 18
0
		public static int Read (SafeHandle safeHandle, byte [] dest,
					       int dest_offset, int count,
					       out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return Read (safeHandle.DangerousGetHandle (), dest, dest_offset, count, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
Esempio n. 19
0
		public static int Write (SafeHandle safeHandle, byte [] src,
						int src_offset, int count,
						out MonoIOError error)
		{
			bool release = false;
			try {
				safeHandle.DangerousAddRef (ref release);
				return Write (safeHandle.DangerousGetHandle (), src, src_offset, count, out error);
			} finally {
				if (release)
					safeHandle.DangerousRelease ();
			}
		}
        internal void Bind(OciStatementHandle statementHandle, NativeBuffer parameterBuffer, OracleConnection connection, ref bool mustRelease, ref SafeHandle handleToBind)
        {
            if (IsDirection(this.Parameter, ParameterDirection.Output) || (this.Parameter.Value != null))
            {
                int num2;
                IntPtr ptr2;
                string parameterName = this.Parameter.ParameterName;
                OciErrorHandle errorHandle = connection.ErrorHandle;
                OciServiceContextHandle serviceContextHandle = connection.ServiceContextHandle;
                int num = 0;
                OCI.INDICATOR oK = OCI.INDICATOR.OK;
                OCI.DATATYPE ociType = this._bindingMetaType.OciType;
                IntPtr dataPtr = parameterBuffer.DangerousGetDataPtr(this._indicatorOffset);
                IntPtr alenp = parameterBuffer.DangerousGetDataPtr(this._lengthOffset);
                IntPtr valuep = parameterBuffer.DangerousGetDataPtr(this._valueOffset);
                OciHandle.SafeDispose(ref this._dateTimeDescriptor);
                if (IsDirection(this.Parameter, ParameterDirection.Input))
                {
                    if (System.Data.Common.ADP.IsNull(this._coercedValue))
                    {
                        oK = OCI.INDICATOR.ISNULL;
                        switch (ociType)
                        {
                            case OCI.DATATYPE.INT_TIMESTAMP:
                            case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                            case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                                this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection);
                                handleToBind = this._dateTimeDescriptor;
                                break;
                        }
                    }
                    else
                    {
                        num = this.PutOracleValue(this._coercedValue, parameterBuffer, this._valueOffset, this._bindingMetaType, connection, ref handleToBind);
                    }
                }
                else
                {
                    if (this._bindingMetaType.IsVariableLength)
                    {
                        num = 0;
                    }
                    else
                    {
                        num = this._bufferLength;
                    }
                    OciLobLocator.SafeDispose(ref this._locator);
                    OciHandle.SafeDispose(ref this._descriptor);
                    switch (ociType)
                    {
                        case OCI.DATATYPE.CLOB:
                        case OCI.DATATYPE.BLOB:
                        case OCI.DATATYPE.BFILE:
                            this._locator = new OciLobLocator(connection, this._bindingMetaType.OracleType);
                            handleToBind = this._locator.Descriptor;
                            break;

                        case OCI.DATATYPE.RSET:
                            this._descriptor = new OciStatementHandle(serviceContextHandle);
                            handleToBind = this._descriptor;
                            break;

                        case OCI.DATATYPE.INT_TIMESTAMP:
                        case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                        case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                            this._dateTimeDescriptor = OracleDateTime.CreateEmptyDescriptor(ociType, connection);
                            handleToBind = this._dateTimeDescriptor;
                            break;
                    }
                }
                if (handleToBind != null)
                {
                    handleToBind.DangerousAddRef(ref mustRelease);
                    parameterBuffer.WriteIntPtr(this._valueOffset, handleToBind.DangerousGetHandle());
                }
                parameterBuffer.WriteInt16(this._indicatorOffset, (short) oK);
                if ((OCI.DATATYPE.LONGVARCHAR == ociType) || (OCI.DATATYPE.LONGVARRAW == ociType))
                {
                    alenp = IntPtr.Zero;
                }
                else if (this._bindAsUCS2)
                {
                    parameterBuffer.WriteInt32(this._lengthOffset, num / System.Data.Common.ADP.CharSize);
                }
                else
                {
                    parameterBuffer.WriteInt32(this._lengthOffset, num);
                }
                if (IsDirection(this.Parameter, ParameterDirection.Output))
                {
                    num2 = this._bufferLength;
                }
                else
                {
                    num2 = num;
                }
                OCI.DATATYPE dty = ociType;
                switch (ociType)
                {
                    case OCI.DATATYPE.INT_TIMESTAMP:
                        dty = OCI.DATATYPE.TIMESTAMP;
                        break;

                    case OCI.DATATYPE.INT_TIMESTAMP_TZ:
                        dty = OCI.DATATYPE.TIMESTAMP_TZ;
                        break;

                    case OCI.DATATYPE.INT_TIMESTAMP_LTZ:
                        dty = OCI.DATATYPE.TIMESTAMP_LTZ;
                        break;
                }
                int rc = TracedNativeMethods.OCIBindByName(statementHandle, out ptr2, errorHandle, parameterName, parameterName.Length, valuep, num2, dty, dataPtr, alenp, OCI.MODE.OCI_DEFAULT);
                if (rc != 0)
                {
                    this._command.Connection.CheckError(errorHandle, rc);
                }
                this._bindHandle = new OciBindHandle(statementHandle, ptr2);
                if (this._bindingMetaType.IsCharacterType)
                {
                    if (OCI.ClientVersionAtLeastOracle9i && IsDirection(this.Parameter, ParameterDirection.Output))
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXCHAR_SIZE, this._bindSize, errorHandle);
                    }
                    if ((num2 > (this._bindingMetaType.MaxBindSize / System.Data.Common.ADP.CharSize)) || (!OCI.ClientVersionAtLeastOracle9i && this._bindingMetaType.UsesNationalCharacterSet))
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_MAXDATA_SIZE, this._bindingMetaType.MaxBindSize, errorHandle);
                    }
                    if (this._bindingMetaType.UsesNationalCharacterSet)
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_FORM, 2, errorHandle);
                    }
                    if (this._bindAsUCS2)
                    {
                        this._bindHandle.SetAttribute(OCI.ATTR.OCI_ATTR_CHARSET_ID, 0x3e8, errorHandle);
                    }
                }
                GC.KeepAlive(parameterBuffer);
            }
        }
Esempio n. 21
0
		static int WaitOneNative (SafeHandle waitableSafeHandle, uint millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
		{
#if MONOTOUCH
			if (exitContext)
				throw new NotSupportedException ("exitContext == true is not supported");
#endif

			bool release = false;
			try {
				if (exitContext)
					SynchronizationAttribute.ExitContext ();

				waitableSafeHandle.DangerousAddRef (ref release);

				return WaitOne_internal (waitableSafeHandle.DangerousGetHandle (), (int) millisecondsTimeout, exitContext);
			} finally {
				if (release)
					waitableSafeHandle.DangerousRelease ();

				if (exitContext)
					SynchronizationAttribute.EnterContext ();
			}
		}