internal static extern bool DuplicateHandle(
     SafeProcessHandle hSourceProcessHandle,
     SafeHandle hSourceHandle,
     SafeProcessHandle hTargetProcess,
     out SafeWaitHandle targetHandle,
     int dwDesiredAccess,
     bool bInheritHandle,
     int dwOptions
 );
    public static void SafeWaitHandleExtensions_set()
    {
        var wh = new MyWaitHandle();

        var swhExpected = new SafeWaitHandle(new IntPtr(5), true);
        wh.SetSafeWaitHandle(swhExpected);

        var swh = wh.GetSafeWaitHandle();

        Assert.Equal(swhExpected, swh);

        wh.SetSafeWaitHandle(null);
        swh = wh.GetSafeWaitHandle();
        Assert.NotNull(swh);
        Assert.Equal(new IntPtr(-1), swh.DangerousGetHandle());
    }
Beispiel #3
0
 private Mutex(SafeWaitHandle handle)
 {
     SafeWaitHandle = handle;
 }
 public static void SetSafeWaitHandle(this WaitHandle waitHandle, SafeWaitHandle value);
Beispiel #5
0
 private EventWaitHandle(SafeWaitHandle handle)
 {
     SetHandleInternal(handle);
 }
Beispiel #6
0
 public static extern int CloseHandle(SafeWaitHandle handle);
Beispiel #7
0
 public static extern bool QueryFullProcessImageName(SafeWaitHandle handle, ImageNameType type, StringBuilder imagePath, ref int size);
Beispiel #8
0
 internal static extern bool TerminateJobObject(SafeWaitHandle hJob, int exitCode);
Beispiel #9
0
 public static void SafeWaitHandle_invalid()
 {
     SafeWaitHandle swh = new SafeWaitHandle(IntPtr.Zero, false);
     Assert.Equal(false, swh.IsClosed);
     Assert.Equal(true, swh.IsInvalid);
 }
Beispiel #10
0
 public static extern Int32 WaitForSingleObject(SafeWaitHandle hHandle, Int32 dwMilliseconds);
 internal extern static uint ResumeThread(SafeWaitHandle hThread);
 internal extern static ThreadPriority GetThreadPriority(SafeWaitHandle hThread);
Beispiel #13
0
 public static extern bool OpenProcessToken(SafeWaitHandle hProcess, TokenAccessMask accessMask, out SafeTokenHandle handle);
Beispiel #14
0
 internal static extern int WaitForSingleObject(SafeWaitHandle handle, int timeout);
 public static extern bool SetWaitableTimer(SafeWaitHandle handle, ref long dueTime, int period, IntPtr mustBeZero, IntPtr mustBeZeroAlso, bool resume);
 internal static extern bool ReleaseSemaphore(SafeWaitHandle handle, int releaseCount, out int previousCount);
Beispiel #17
0
 public static extern ProcessPriorityClass GetPriorityClass(SafeWaitHandle hProcess);
 internal extern static bool SetThreadPriority(SafeWaitHandle hThread, int nPriority);
Beispiel #19
0
 public static void SafeWaitHandle_valid()
 {
     SafeWaitHandle swh = new SafeWaitHandle(new IntPtr(1), true);
     Assert.Equal(false, swh.IsClosed);
     Assert.Equal(false, swh.IsInvalid);
 }
Beispiel #20
0
 public static extern int GetProcessId(SafeWaitHandle hProcess);
Beispiel #21
0
 /// <inheritdoc />
 public bool DuplicateHandle(ProcessHandle hSourceProcessHandle, SafeHandle hSourceHandle, ProcessHandle hTargetProcess, out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
 => throw new NotImplementedException();
Beispiel #22
0
 public static extern bool IsProcessInJob(SafeHandle hProcess, SafeWaitHandle hJob, out bool inJob);
 /// <inheritdoc />
 public bool DuplicateHandle(ProcessHandle hSourceProcessHandle, SafeHandle hSourceHandle, ProcessHandle hTargetProcess, out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
 => ExternDuplicateHandle(hSourceProcessHandle, hSourceHandle, hTargetProcess, out targetHandle, dwDesiredAccess, bInheritHandle, dwOptions);
Beispiel #24
0
 internal static extern bool CheckRemoteDebuggerPresent(SafeWaitHandle hProcess, out bool beingDebugged);
Beispiel #25
0
 private static extern Boolean QueryThreadCycleTime(SafeWaitHandle threadHandle, out UInt64 CycleTime);
Beispiel #26
0
        public unsafe EventWaitHandle(bool initialState, EventResetMode mode, string name, out bool createdNew, EventWaitHandleSecurity eventSecurity)
        {
            if (null != name && System.IO.Path.MAX_PATH < name.Length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", name));
            }
            Contract.EndContractBlock();
            Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
#if !MONO
#if FEATURE_MACL
            // For ACL's, get the security descriptor from the EventWaitHandleSecurity.
            if (eventSecurity != null)
            {
                secAttrs         = new Win32Native.SECURITY_ATTRIBUTES();
                secAttrs.nLength = (int)Marshal.SizeOf(secAttrs);

                byte[] sd             = eventSecurity.GetSecurityDescriptorBinaryForm();
                byte * pSecDescriptor = stackalloc byte[sd.Length];
                Buffer.Memcpy(pSecDescriptor, 0, sd, 0, sd.Length);
                secAttrs.pSecurityDescriptor = pSecDescriptor;
            }
#endif
#endif

            SafeWaitHandle _handle = null;
            Boolean        isManualReset;
            switch (mode)
            {
            case EventResetMode.ManualReset:
                isManualReset = true;
                break;

            case EventResetMode.AutoReset:
                isManualReset = false;
                break;

            default:
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag", name));
            }
            ;

#if MONO
            int errorCode;
            _handle = new SafeWaitHandle(NativeEventCalls.CreateEvent_internal(isManualReset, initialState, name, out errorCode), true);
#else
            _handle = Win32Native.CreateEvent(secAttrs, isManualReset, initialState, name);
            int errorCode = Marshal.GetLastWin32Error();
#endif

            if (_handle.IsInvalid)
            {
                _handle.SetHandleAsInvalid();
                if (null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode)
                {
                    throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle", name));
                }

                __Error.WinIOError(errorCode, name);
            }
            createdNew = errorCode != Win32Native.ERROR_ALREADY_EXISTS;
            SetHandleInternal(_handle);
        }
Beispiel #27
0
 private static extern Boolean QueryProcessCycleTime(SafeWaitHandle processHandle, out UInt64 CycleTime);
Beispiel #28
0
 public static extern bool ResetEvent(SafeWaitHandle handle);
Beispiel #29
0
 private CycleTime(Boolean trackingThreadTime, SafeWaitHandle handle)
 {
     m_trackingThreadTime = trackingThreadTime;
     m_handle             = handle;
     m_startCycleTime     = m_trackingThreadTime ? Thread() : Process(m_handle);
 }
Beispiel #30
0
 internal static extern bool SetPacketEvent(DriverHandle hOpen, IntPtr hAdapter, SafeWaitHandle hWin32Event);
Beispiel #31
0
 public static CycleTime StartThread(SafeWaitHandle threadHandle)
 {
     return(new CycleTime(true, threadHandle));
 }
Beispiel #32
0
 internal static extern bool ReleaseSemaphore(SafeWaitHandle handle, int releaseCount, out int previousCount);
Beispiel #33
0
 public static CycleTime StartProcess(SafeWaitHandle processHandle)
 {
     return(new CycleTime(false, processHandle));
 }
 int waveOutOpen( out IntPtr waveOutHandle,
                  int deviceId,
                  WAVEFORMATEX format,
                  SafeWaitHandle event_handle,
                  int instanceData,
                  int flags );
Beispiel #35
0
 internal MutexCleanupInfo(SafeWaitHandle mutexHandle, bool inCriticalRegion)
 {
     this.mutexHandle      = mutexHandle;
     this.inCriticalRegion = inCriticalRegion;
 }
Beispiel #36
0
 internal extern static uint Icmp6SendEcho2(SafeCloseIcmpHandle icmpHandle, SafeWaitHandle Event, IntPtr apcRoutine, IntPtr apcContext,
     byte[] sourceSocketAddress, byte[] destSocketAddress, [In] SafeLocalAllocHandle data, ushort dataSize, ref IPOptions options, SafeLocalAllocHandle replyBuffer, uint replySize, uint timeout);
Beispiel #37
0
 private Mutex(SafeWaitHandle handle)
 {
     SetHandleInternal(handle);
     hasThreadAffinity = true;
 }
Beispiel #38
0
        private static int CreateMutexHandle(bool initiallyOwned, String name, Win32Native.SECURITY_ATTRIBUTES securityAttribute, out SafeWaitHandle mutexHandle)
        {
            int errorCode;

            while (true)
            {
                mutexHandle = Win32Native.CreateMutex(securityAttribute, initiallyOwned, name);
                errorCode   = Marshal.GetLastWin32Error();
                if (!mutexHandle.IsInvalid)
                {
                    break;
                }

                if (errorCode != Win32Native.ERROR_ACCESS_DENIED)
                {
                    break;
                }

                // If a mutex with the name already exists, OS will try to open it with FullAccess.
                // It might fail if we don't have enough access. In that case, we try to open the mutex will modify and synchronize access.
                RuntimeHelpers.PrepareConstrainedRegions();

                mutexHandle = Win32Native.OpenMutex(
                    Win32Native.MUTEX_MODIFY_STATE | Win32Native.SYNCHRONIZE,
                    false,
                    name);

                errorCode = !mutexHandle.IsInvalid ? Win32Native.ERROR_ALREADY_EXISTS : Marshal.GetLastWin32Error();

                // There could be a race condition here, the other owner of the mutex can free the mutex,
                // We need to retry creation in that case.
                if (errorCode != Win32Native.ERROR_FILE_NOT_FOUND)
                {
                    if (errorCode == Win32Native.ERROR_SUCCESS)
                    {
                        errorCode = Win32Native.ERROR_ALREADY_EXISTS;
                    }
                    break;
                }
            }
            return(errorCode);
        }
 public static extern IntPtr EvtSubscribe(
                     IntPtr session,
                     SafeWaitHandle signalEvent,
                     [MarshalAs(UnmanagedType.LPWStr)]string path,
                     [MarshalAs(UnmanagedType.LPWStr)]string query,
                     IntPtr bookmark,
                     IntPtr context,
                     IntPtr callback,
                     int flags);