' ########################################################################################
' Microsoft Windows
' File: wct.inc
' Contents: Private interfaces for thread wait chain traversal.
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_wct_PBI)
#DEFINE PBX_wct_PBI
%EQUATE `WCT_INC = 1
' enum WCT_OBJECT_TYPE
%EQUATE `WctCriticalSectionType = 1
%EQUATE `WctSendMessageType = 2
%EQUATE `WctMutexType = 3
%EQUATE `WctAlpcType = 4
%EQUATE `WctComType = 5
%EQUATE `WctThreadWaitType = 6
%EQUATE `WctProcessWaitType = 7
%EQUATE `WctThreadType = 8
%EQUATE `WctComActivationType = 9
%EQUATE `WctUnknownType = 10
%EQUATE `WctSocketIoType = 11
%EQUATE `WctSmbIoType = 12
%EQUATE `WctMaxType = 13
' enum WCT_OBJECT_STATUS
%EQUATE `WctStatusNoAccess = 1 ' // ACCESS_DENIED for this object
%EQUATE `WctStatusRunning = 2 ' // Thread status
%EQUATE `WctStatusBlocked = 3 ' // Thread status
%EQUATE `WctStatusPidOnly = 4 ' // Thread status
%EQUATE `WctStatusPidOnlyRpcss = 5 ' // Thread status
%EQUATE `WctStatusOwned = 6 ' // Dispatcher object status
%EQUATE `WctStatusNotOwned = 7 ' // Dispatcher object status
%EQUATE `WctStatusAbandoned = 8 ' // Dispatcher object status
%EQUATE `WctStatusUnknown = 9 ' // All objects
%EQUATE `WctStatusError = 10 ' // All objects
%EQUATE `WctStatusMax = 11
'// Max. number of nodes in the wait chain
%EQUATE `WCT_MAX_NODE_COUNT = 16
%EQUATE `WCT_OBJNAME_LENGTH = 128
' // Size = 272 bytes ' Must be 8 byte aligned
TYPE WAITCHAIN_NODE_INFO_LockObject
 ObjectName AS WSTRINGZ * %WCT_OBJNAME_LENGTH ' WCHAR
 Timeout AS QUAD ' LARGE_INTEGER // Not implemented in v1
 Alertable AS LONG ' BOOL // Not implemented in v1
 alignment__ AS DWORD ' // To keep 8 byte alignment
END TYPE
' // Size = 16 bytes
TYPE WAITCHAIN_NODE_INFO_ThreadObject
 ProcessId AS DWORD
 ThreadId AS DWORD
 WaitTime AS DWORD
 ContextSwitches AS DWORD
END TYPE
' // Size = 268 bytes
UNION WAITCHAIN_NODE_INFO_UNION
 LockObject AS WAITCHAIN_NODE_INFO_LockObject
 ThreadObject AS WAITCHAIN_NODE_INFO_ThreadObject
END UNION
' // Size = 280 bytes
TYPE WAITCHAIN_NODE_INFO
 ObjectType AS LONG ' WCT_OBJECT_TYPE
 ObjectStatus AS LONG ' WCT_OBJECT_STATUS
 WAITCHAIN_NODE_INFO_UNION
END TYPE
'typedef LPVOID HWCT;
'typedef VOID (CALLBACK *PWAITCHAINCALLBACK) (
' HWCT WctHandle,
' DWORD_PTR Context,
' DWORD CallbackStatus,
' LPDWORD NodeCount,
' PWAITCHAIN_NODE_INFO NodeInfoArray,
' LPBOOL IsCycle
' );
'SUB WAITCHAINCALLBACK ( ' BYVAL WctHandle AS DWORD ' , BYVAL Context AS DWORD ' , BYVAL CallbackStatus AS DWORD ' , BYREF NodeCount AS DWORD ' , BYREF NodeInfoArray AS PWAITCHAIN_NODE_INFO ' , BYREF IsCycle AS LONG ' )
%EQUATE `WCT_ASYNC_OPEN_FLAG = &H1
%EQUATE `WCTP_OPEN_ALL_FLAGS = %WCT_ASYNC_OPEN_FLAG
DECLARE FUNCTION OpenThreadWaitChainSession LIB "advapi32.dll" ALIAS "OpenThreadWaitChainSession" ( BYVAL Flags AS QUAD , BYVAL callback AS QUAD ) AS QUAD ' HWCT
DECLARE SUB CloseThreadWaitChainSession LIB "advapi32.dll" ALIAS "CloseThreadWaitChainSession" ( BYVAL WctHandle AS QUAD ) ' void
%EQUATE `WCT_OUT_OF_PROC_FLAG = &H1
%EQUATE `WCT_OUT_OF_PROC_COM_FLAG = &H2
%EQUATE `WCT_OUT_OF_PROC_CS_FLAG = &H4
%EQUATE `WCT_NETWORK_IO_FLAG = &H8
%EQUATE `WCTP_GETINFO_ALL_FLAGS = %WCT_OUT_OF_PROC_FLAG OR %WCT_OUT_OF_PROC_COM_FLAG OR %WCT_OUT_OF_PROC_CS_FLAG
DECLARE FUNCTION GetThreadWaitChain LIB "advapi32.dll" ALIAS "GetThreadWaitChain" ( BYVAL WctHandle AS QUAD , BYVAL Context AS QUAD , BYVAL Flags AS QUAD , BYVAL ThreadId AS QUAD , BYREF NodeCount AS QUAD , BYREF NodeInfoArray AS WAITCHAIN_NODE_INFO , BYREF IsCycle AS LONG ) AS LONG
'typedef HRESULT (*PCOGETCALLSTATE)(int, PULONG);
'typedef HRESULT (*PCOGETACTIVATIONSTATE)(GUID, DWORD, DWORD*);
DECLARE SUB RegisterWaitChainCOMCallback LIB "advapi32.dll" ALIAS "RegisterWaitChainCOMCallback" ( BYVAL CallStateCallback AS QUAD , BYVAL ActivationStateCallback AS QUAD ) ' void
#ENDIF
