示例#1
0
 bool IsHealthy()
 {
     try
     {
         return(controlServiceGuid.ToString().Equals(SharedMemory.Read(sharedMemoryName)));
     }
     catch (Win32Exception)
     {
         return(false);
     }
 }
示例#2
0
        public static unsafe SharedMemory Create(string name, Guid content, List <SecurityIdentifier> allowedSids)
        {
            int errorCode = UnsafeNativeMethods.ERROR_SUCCESS;

            byte[] binarySecurityDescriptor = SecurityDescriptorHelper.FromSecurityIdentifiers(allowedSids, UnsafeNativeMethods.GENERIC_READ);
            SafeFileMappingHandle fileMapping;

            UnsafeNativeMethods.SECURITY_ATTRIBUTES securityAttributes = new UnsafeNativeMethods.SECURITY_ATTRIBUTES();
            fixed(byte *pinnedSecurityDescriptor = binarySecurityDescriptor)
            {
                securityAttributes.lpSecurityDescriptor = (IntPtr)pinnedSecurityDescriptor;
                fileMapping = UnsafeNativeMethods.CreateFileMapping((IntPtr)(-1), securityAttributes, UnsafeNativeMethods.PAGE_READWRITE, 0, sizeof(SharedMemoryContents), name);
                errorCode   = Marshal.GetLastWin32Error();
            }

            if (fileMapping.IsInvalid)
            {
                fileMapping.SetHandleAsInvalid();
                fileMapping.Close();
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(errorCode));
            }

            SharedMemory         sharedMemory = new SharedMemory(fileMapping);
            SafeViewOfFileHandle view;

            // Ignore return value.
            GetView(fileMapping, true, out view);

            try
            {
                SharedMemoryContents *contents = (SharedMemoryContents *)view.DangerousGetHandle();
                contents->pipeGuid = content;
                Thread.MemoryBarrier();
                contents->isInitialized = true;
                return(sharedMemory);
            }
            finally
            {
                view.Close();
            }
        }
示例#3
0
        void CreateSharedMemory()
        {
            try
            {
                sharedMemory = SharedMemory.Create(ListenerConstants.GlobalPrefix + sharedMemoryName, controlServiceGuid,
                                                   ListenerConfig.GetAllowAccounts(this.transportType));

                Debug.Print("SharedMemory.Create() sharedMemoryName: " + sharedMemoryName);
            }
            catch (Win32Exception exception)
            {
                Debug.Print("SharedMemory.Create() exception: " + exception);
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                                                    (ushort)EventLogCategory.SharingService,
                                                    (uint)EventLogEventId.StartErrorPublish,
                                                    exception.ToString());

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new InvalidOperationException(SR.GetString(SR.ServiceStartErrorPublish, this.serviceName),
                                                        exception));
            }
        }
        public static unsafe SharedMemory Create(string name, Guid content, List <SecurityIdentifier> allowedSids)
        {
            SafeFileMappingHandle handle;
            SafeViewOfFileHandle  handle2;
            SharedMemory          memory2;
            int error = 0;

            byte[] buffer = SecurityDescriptorHelper.FromSecurityIdentifiers(allowedSids, -2147483648);
            UnsafeNativeMethods.SECURITY_ATTRIBUTES securityAttributes = new UnsafeNativeMethods.SECURITY_ATTRIBUTES();
            fixed(byte *numRef = buffer)
            {
                securityAttributes.lpSecurityDescriptor = (IntPtr)numRef;
                handle = UnsafeNativeMethods.CreateFileMapping((IntPtr)(-1), securityAttributes, 4, 0, sizeof(SharedMemoryContents), name);
                error  = Marshal.GetLastWin32Error();
            }

            if (handle.IsInvalid)
            {
                handle.SetHandleAsInvalid();
                handle.Close();
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error));
            }
            SharedMemory memory = new SharedMemory(handle);

            GetView(handle, true, out handle2);
            try
            {
                SharedMemoryContents *contentsPtr = (SharedMemoryContents *)handle2.DangerousGetHandle();
                contentsPtr->pipeGuid = content;
                Thread.MemoryBarrier();
                contentsPtr->isInitialized = true;
                memory2 = memory;
            }
            finally
            {
                handle2.Close();
            }
            return(memory2);
        }
        public static unsafe SharedMemory Create(string name, Guid content, List<SecurityIdentifier> allowedSids)
        {
            int errorCode = UnsafeNativeMethods.ERROR_SUCCESS;
            byte[] binarySecurityDescriptor = SecurityDescriptorHelper.FromSecurityIdentifiers(allowedSids, UnsafeNativeMethods.GENERIC_READ);
            SafeFileMappingHandle fileMapping;
            UnsafeNativeMethods.SECURITY_ATTRIBUTES securityAttributes = new UnsafeNativeMethods.SECURITY_ATTRIBUTES();
            fixed (byte* pinnedSecurityDescriptor = binarySecurityDescriptor)
            {
                securityAttributes.lpSecurityDescriptor = (IntPtr)pinnedSecurityDescriptor;
                fileMapping = UnsafeNativeMethods.CreateFileMapping((IntPtr)(-1), securityAttributes, UnsafeNativeMethods.PAGE_READWRITE, 0, sizeof(SharedMemoryContents), name);
                errorCode = Marshal.GetLastWin32Error();
            }

            if (fileMapping.IsInvalid)
            {
                fileMapping.SetHandleAsInvalid();
                fileMapping.Close();
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(errorCode));
            }

            SharedMemory sharedMemory = new SharedMemory(fileMapping);
            SafeViewOfFileHandle view;

            // Ignore return value.
            GetView(fileMapping, true, out view);

            try
            {
                SharedMemoryContents* contents = (SharedMemoryContents*)view.DangerousGetHandle();
                contents->pipeGuid = content;
                Thread.MemoryBarrier();
                contents->isInitialized = true;
                return sharedMemory;
            }
            finally
            {
                view.Close();
            }
        }
 public static unsafe SharedMemory Create(string name, Guid content, List<SecurityIdentifier> allowedSids)
 {
     SafeFileMappingHandle handle;
     SafeViewOfFileHandle handle2;
     SharedMemory memory2;
     int error = 0;
     byte[] buffer = SecurityDescriptorHelper.FromSecurityIdentifiers(allowedSids, -2147483648);
     UnsafeNativeMethods.SECURITY_ATTRIBUTES securityAttributes = new UnsafeNativeMethods.SECURITY_ATTRIBUTES();
     fixed (byte* numRef = buffer)
     {
         securityAttributes.lpSecurityDescriptor = (IntPtr) numRef;
         handle = UnsafeNativeMethods.CreateFileMapping((IntPtr) (-1), securityAttributes, 4, 0, sizeof(SharedMemoryContents), name);
         error = Marshal.GetLastWin32Error();
     }
     if (handle.IsInvalid)
     {
         handle.SetHandleAsInvalid();
         handle.Close();
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error));
     }
     SharedMemory memory = new SharedMemory(handle);
     GetView(handle, true, out handle2);
     try
     {
         SharedMemoryContents* contentsPtr = (SharedMemoryContents*) handle2.DangerousGetHandle();
         contentsPtr->pipeGuid = content;
         Thread.MemoryBarrier();
         contentsPtr->isInitialized = true;
         memory2 = memory;
     }
     finally
     {
         handle2.Close();
     }
     return memory2;
 }
示例#7
0
        void CreateSharedMemory()
        {
            try
            {
                sharedMemory = SharedMemory.Create(ListenerConstants.GlobalPrefix + sharedMemoryName, controlServiceGuid,
                    ListenerConfig.GetAllowAccounts(this.transportType));

                Debug.Print("SharedMemory.Create() sharedMemoryName: " + sharedMemoryName);
            }
            catch (Win32Exception exception)
            {
                Debug.Print("SharedMemory.Create() exception: " + exception);
                DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
                    (ushort)EventLogCategory.SharingService,
                    (uint)EventLogEventId.StartErrorPublish,
                    exception.ToString());

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                    new InvalidOperationException(SR.GetString(SR.ServiceStartErrorPublish, this.serviceName),
                    exception));
            }
        }