1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
// All files in the project carrying such notice may not be copied, modified, or distributed
// except according to those terms.
use ctypes::c_int;
use shared::basetsd::{DWORD_PTR, SIZE_T};
use shared::guiddef::GUID;
use shared::minwindef::{BOOL, DWORD, LPBOOL, LPDWORD, PULONG};
use um::winnt::{HRESULT, LARGE_INTEGER, WCHAR};
ENUM!{enum WCT_OBJECT_TYPE {
    WctCriticalSectionType = 1,
    WctSendMessageType,
    WctMutexType,
    WctAlpcType,
    WctComType,
    WctThreadWaitType,
    WctProcessWaitType,
    WctThreadType,
    WctComActivationType,
    WctUnknownType,
    WctSocketIoType,
    WctSmbIoType,
    WctMaxType,
}}
ENUM!{enum WCT_OBJECT_STATUS {
    WctStatusNoAccess = 1,
    WctStatusRunning,
    WctStatusBlocked,
    WctStatusPidOnly,
    WctStatusPidOnlyRpcss,
    WctStatusOwned,
    WctStatusNotOwned,
    WctStatusAbandoned,
    WctStatusUnknown,
    WctStatusError,
    WctStatusMax,
}}
pub const WCT_MAX_NODE_COUNT: SIZE_T = 16;
pub const WCT_OBJNAME_LENGTH: SIZE_T = 128;
STRUCT!{struct WAITCHAIN_NODE_INFO_LOCK_OBJECT {
    ObjectName: [WCHAR; WCT_OBJNAME_LENGTH],
    Timeout: LARGE_INTEGER,
    Alertable: BOOL,
}}
STRUCT!{struct WAITCHAIN_NODE_INFO_THREAD_OBJECT {
    ProcessId: DWORD,
    ThreadId: DWORD,
    WaitTime: DWORD,
    ContextSwitches: DWORD,
}}
UNION!{union WAITCHAIN_NODE_INFO_u {
    [u64; 34],
    LockObject LockObject_mut: WAITCHAIN_NODE_INFO_LOCK_OBJECT,
    ThreadObject ThreadObject_mut: WAITCHAIN_NODE_INFO_THREAD_OBJECT,
}}
STRUCT!{struct WAITCHAIN_NODE_INFO {
    ObjectType: WCT_OBJECT_TYPE,
    ObjectStatus: WCT_OBJECT_STATUS,
    u: WAITCHAIN_NODE_INFO_u,
}}
pub type PWAITCHAIN_NODE_INFO = *mut WAITCHAIN_NODE_INFO;
DECLARE_HANDLE!{HWCT, HWCT__}
FN!{cdecl PWAITCHAINCALLBACK(
    WctHandle: HWCT,
    Context: DWORD_PTR,
    CallbackStatus: DWORD,
    NodeCount: LPDWORD,
    NodeInfoArray: PWAITCHAIN_NODE_INFO,
    IsCycle: LPBOOL,
) -> ()}
pub const WCT_ASYNC_OPEN_FLAG: DWORD = 1;
pub const WCTP_OPEN_ALL_FLAGS: DWORD = WCT_ASYNC_OPEN_FLAG;
extern "system" {
    pub fn OpenThreadWaitChainSession(
        Flags: DWORD,
        callback: PWAITCHAINCALLBACK,
    ) -> HWCT;
    pub fn CloseThreadWaitChainSession(
        WctHandle: HWCT,
    );
}
pub const WCT_OUT_OF_PROC_FLAG: DWORD = 0x1;
pub const WCT_OUT_OF_PROC_COM_FLAG: DWORD = 0x2;
pub const WCT_OUT_OF_PROC_CS_FLAG: DWORD = 0x4;
pub const WCT_NETWORK_IO_FLAG: DWORD = 0x8;
pub const WCTP_GETINFO_ALL_FLAGS: DWORD = WCT_OUT_OF_PROC_FLAG | WCT_OUT_OF_PROC_COM_FLAG
    | WCT_OUT_OF_PROC_CS_FLAG;
extern "system" {
    pub fn GetThreadWaitChain(
        WctHandle: HWCT,
        Context: DWORD_PTR,
        Flags: DWORD,
        ThreadId: DWORD,
        NodeCount: LPDWORD,
        NodeInfoArray: PWAITCHAIN_NODE_INFO,
        IsCycle: LPBOOL,
    ) -> BOOL;
}
FN!{cdecl PCOGETCALLSTATE(
    c_int,
    PULONG,
) -> HRESULT}
FN!{cdecl PCOGETACTIVATIONSTATE(
    GUID,
    DWORD,
    *mut DWORD,
) -> HRESULT}
extern "system" {
    pub fn RegisterWaitChainCOMCallback(
        CallStateCallback: PCOGETCALLSTATE,
        ActivationStateCallback: PCOGETACTIVATIONSTATE,
    );
}