#ifndef xtib_h
#define xtib_h
// Call setthreadname (), AND THEN PASTE this Expression INTO The Watch Window:
// (char *) (DW (@ TIB 0x14))
#pragma pack (1)
TypeDef struct _exception_registration_record
{
Struct_exception_registration_record * pnext;
FarProc PfnHandler;
} EXCEPTION_REGISTRATION_RECORD, * PEXCEPTION_REGISTRATION_RECORD;
Typedef struct tagxtib
{
PEXCEPTION_REGISTRATION_RECORD PVEXCEPT; // 00h Head of Exception Record List
Pvoid PvStackUsertop; // 04h Top of User Stack
Pvoid PvStackuserBase; // 08H Base of User Stack
Union // 0ch (NT / WIN95 DIFFERENCES)
{
Struct // Win95 Fields
{
Word pvtdb; // 0ch tdb
Word pvthunkss; // 0eh ss selector used for thunking to 16 bits
DWORD UNKNOWN1; // 10h
} Win95;
Struct // Winnt Fields
{
Pvoid subsystemtib; // 0ch
Ulong fiberdata; // 10h
Winnt;
} TIB_Union1;
PVOID PVARBITRARY; / / 14H Available for Application USE
Struct_tib * ptibself; // 18h Linear Address of Tib Structure
Union // 1CH (NT / Win95 Differences)
{
Struct // Win95 Fields
{
Word Tibflags; // 1ch
Word win16mutexcount; // 1eh
DWORD DebugContext; // 20h
DWORD PCURRENTPRIORITY; / / 24H
DWORD PVQUE; / / 28H Message Queue Selector} WIN95;
Struct // Winnt Fields
{
DWORD UNKNOWN1; // 1CH
DWORD processID; // 20h
DWORD thREADID; // 24h
DWORD UNKNOWN2; / / 28H
Winnt;
} TIB_Union2;
PVOID * PVTLSARRAY; // 2ch thread local storage array
Union // 30h (NT / WIN95 DIFFERENCES)
{
Struct // Win95 Fields
{
PVOID * PPRocess; // 30h Pointer to Owning Process Database
} Win95;
} TIB_UNION3;
// Internal function to get the Tib
/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------
Function: Gettib
Description: Returns Pointer to Tib for Current Thread.
Parameters: None.
Returns: Null - a really bad thing
! Null - Pointer to Tib for current thread
-------------------------------------------------- -------------------- * /
Static tagxtib * gettib ()
{
Tagxtib * PTIB;
__ASM
{
Mov Eax, FS: [18h]
MOV PTIB, EAX
}
Return PTIB;
}
/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------
Function: setthreadname
Description: setthreadname provides a way to "name" your threads so that you can
See at a glance Which thread is active when you are in the debugger.
Calling setthreadname sets the string pointer parameter INTO THREAD
Information Block (TIB) Pvarbitrary Field (Offset 0x14). Matt Pietrek
Discussed The Tib Structure in His May 1996 "Under The Hood" Column.
I incrude Matt's Tib.h as part of this process if you want to see the the
REST of the fields in the tib.pvarbitrary is an unused spot in the Tib That Applications Can Uses
As They Wish. Setthreadname Does The Right Thing and Checks IF THE
Pvarbitrary is not 0 and will not write the string pointer to avoid
TROMPING ON ANY Other Data Written There.
To View Which Thread Is Active In The Watch Window, Use
"(CHAR *) (DW (@ TIB 0x14))" As you swap threads, you can number TELL AT A
Glance Which thread you are in!
Parameters: szname - a Pointer to the string which you would be to name the
Current Thread. You Should Make The String Pointer A
Constant Name.
Returns: True - The Thread Name WAS SET.
False - Something else Overwrote The Pvarbitrary Field.
-------------------------------------------------- -------------------- * /
Static Bool SetthreadName (LPCTSTR SZNAME)
{
// grab the Tib.
TAGXTIB * PTIB = Gettib ();
// if someone Has Already Written to the Arbitrary Field, I don't
// Want to be overwriting it.
IF (ptib-> pvarbitrary! = null)
Return False;
// Nothing's there. Set the name.
PTIB-> pvarbitrary = (void *) szname;
Return True;
}
/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------
Function: GetthreadName
Description: returns the string pointer to the name assigned to the
Current thread.
Parameters: None.
Returns: null - no name...
Null - The Value At The Tib Pvarbitrary Offset. Please
Note That The Pointer Could Be Invalid of iF Something
Other Than SetthreadName Used The Pvarbitrary Offset.
-------------------------------------------------- -------------------- * /
Static lpctstr getthreadname ()
{
// grab the Tib.
TAGXTIB * PTIB = Gettib ();
Return (LPCTSTR) PTIB-> Pvarbitrary;
} Xtib;
#pragma pack ()
#ENDIF // xtib_h