private unsafe PipeHandle CreatePipe() { byte[] buffer; PipeHandle handle; int num2; PipeHandle handle2; int openMode = 0x40000003; if (!this.anyPipesCreated) { openMode |= 0x80000; } try { buffer = SecurityDescriptorHelper.FromSecurityIdentifiers(this.allowedSids, -1073741824); } catch (Win32Exception exception) { Exception innerException = new PipeException(exception.Message, exception); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(innerException.Message, innerException)); } fixed(byte *numRef = buffer) { UnsafeNativeMethods.SECURITY_ATTRIBUTES securityAttributes = new UnsafeNativeMethods.SECURITY_ATTRIBUTES { lpSecurityDescriptor = numRef }; handle = UnsafeNativeMethods.CreateNamedPipe(this.sharedMemory.PipeName, openMode, 6, this.maxInstances, this.bufferSize, this.bufferSize, 0, securityAttributes); num2 = Marshal.GetLastWin32Error(); } if (handle.IsInvalid) { handle.SetHandleAsInvalid(); Exception exception3 = new PipeException(System.ServiceModel.SR.GetString("PipeListenFailed", new object[] { this.pipeUri.AbsoluteUri, PipeError.GetErrorString(num2) }), num2); switch (num2) { case 5: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new AddressAccessDeniedException(exception3.Message, exception3)); case 0xb7: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new AddressAlreadyInUseException(exception3.Message, exception3)); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(exception3.Message, exception3)); } bool flag = true; try { if (this.useCompletionPort) { ThreadPool.BindHandle(handle); } this.anyPipesCreated = true; flag = false; handle2 = handle; } finally { if (flag) { handle.Close(); } } return(handle2); }
public static unsafe bool TryCreate(List <SecurityIdentifier> allowedSids, Uri pipeUri, string sharedMemoryName, out PipeSharedMemory result) { byte[] buffer; SafeFileMappingHandle handle; int num; bool flag2; Guid guid = Guid.NewGuid(); string pipeName = BuildPipeName(guid); try { buffer = SecurityDescriptorHelper.FromSecurityIdentifiers(allowedSids, -2147483648); } catch (Win32Exception exception) { Exception innerException = new PipeException(exception.Message, exception); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(innerException.Message, innerException)); } result = null; fixed(byte *numRef = buffer) { UnsafeNativeMethods.SECURITY_ATTRIBUTES securityAttributes = new UnsafeNativeMethods.SECURITY_ATTRIBUTES { lpSecurityDescriptor = numRef }; handle = UnsafeNativeMethods.CreateFileMapping((IntPtr)(-1), securityAttributes, 4, 0, sizeof(SharedMemoryContents), sharedMemoryName); num = Marshal.GetLastWin32Error(); } if (handle.IsInvalid) { handle.SetHandleAsInvalid(); if (num == 5) { return(false); } Exception exception3 = new PipeException(System.ServiceModel.SR.GetString("PipeNameCantBeReserved", new object[] { pipeUri.AbsoluteUri, PipeError.GetErrorString(num) }), num); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new AddressAccessDeniedException(exception3.Message, exception3)); } if (num == 0xb7) { handle.Close(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreatePipeNameInUseException(num, pipeUri)); } PipeSharedMemory memory = new PipeSharedMemory(handle, pipeUri, pipeName); bool flag = true; try { memory.InitializeContents(guid); flag = false; result = memory; flag2 = true; } finally { if (flag) { memory.Dispose(); } } return(flag2); }