TEB(Thread Environment Block)

Windows의 스레드는 실행부 스레드 블록(ETHRED)에 정의된다. ETHREAD 블록과 여기에서 가리키는 구조체들은 시스템 주소 공간에 위치한다. 예외적으로 스레드환경블록(thread environment block,TEB)만은 프로세스 공간에 위치한다.

TEB에는 스레드ID, TLS정보, PEB포인터, GDI와 OpenGL정보 그리고 Ole를 위한 구조를 가지고 있다.

   
//
// Instead of using the Tls fields, use the Win32 TLS APIs
//     TlsAlloc, TlsGetValue, TlsSetValue, TlsFree
//
// Instead of using the ReservedForOle field, use the COM API
//     CoGetContextToken
//
typedef struct _TEB {
	union {
		struct {
			BYTE Reserved1[1952];
			PVOID Reserved2[412];
			PVOID TlsSlots[64];
			BYTE Reserved3[8];
			PVOID Reserved4[26];
			PVOID ReservedForOle;  // Windows 2000 only
			PVOID Reserved5[4];
			PVOID TlsExpansionSlots;
		};
		struct {
			NT_TIB          Tib;                        /* 000 */
			PVOID           EnvironmentPointer;         /* 01c */
			CLIENT_ID       ClientId;                   /* 020 */
			PVOID           ActiveRpcHandle;            /* 028 */
			PVOID           ThreadLocalStoragePointer;  /* 02c */
			PPEB            Peb;                        /* 030 */
			ULONG           LastErrorValue;             /* 034 */
			ULONG           CountOfOwnedCriticalSections;/* 038 */
			PVOID           CsrClientThread;            /* 03c */
			PVOID           Win32ThreadInfo;            /* 040 */
			ULONG           Win32ClientInfo[31];        /* 044 used for user32 private data in Wine */
			PVOID           WOW32Reserved;              /* 0c0 */
			ULONG           CurrentLocale;              /* 0c4 */
			ULONG           FpSoftwareStatusRegister;   /* 0c8 */
			PVOID           SystemReserved1[54];        /* 0cc used for kernel32 private data in Wine */
			LONG            ExceptionCode;              /* 1a4 */
			ACTIVATION_CONTEXT_STACK ActivationContextStack; /* 1a8 */
			BYTE            SpareBytes1[24];            /* 1bc used for ntdll private data in Wine */
			PVOID           SystemReserved2[10];        /* 1d4 used for ntdll private data in Wine */
			GDI_TEB_BATCH   GdiTebBatch;                /* 1fc used for vm86 private data in Wine */
			ULONG           gdiRgn;                     /* 6dc */
			ULONG           gdiPen;                     /* 6e0 */
			ULONG           gdiBrush;                   /* 6e4 */
			CLIENT_ID       RealClientId;               /* 6e8 */
			HANDLE          GdiCachedProcessHandle;     /* 6f0 */
			ULONG           GdiClientPID;               /* 6f4 */
			ULONG           GdiClientTID;               /* 6f8 */
			PVOID           GdiThreadLocaleInfo;        /* 6fc */
			PVOID           UserReserved[5];            /* 700 */
			PVOID           glDispachTable[280];        /* 714 */
			ULONG           glReserved1[26];            /* b74 */
			PVOID           glReserved2;                /* bdc */
			PVOID           glSectionInfo;              /* be0 */
			PVOID           glSection;                  /* be4 */
			PVOID           glTable;                    /* be8 */
			PVOID           glCurrentRC;                /* bec */
			PVOID           glContext;                  /* bf0 */
			ULONG           LastStatusValue;            /* bf4 */
			UNICODE_STRING  StaticUnicodeString;        /* bf8 used by advapi32 */
			WCHAR           StaticUnicodeBuffer[261];   /* c00 used by advapi32 */
			PVOID           DeallocationStack;          /* e0c */
			PVOID           TlsSlots_[64];              /* e10 */
			LIST_ENTRY      TlsLinks;                   /* f10 */
			PVOID           Vdm;                        /* f18 */
			PVOID           ReservedForNtRpc;           /* f1c */
			PVOID           DbgSsReserved[2];           /* f20 */
			ULONG           HardErrorDisabled;          /* f28 */
			PVOID           Instrumentation[16];        /* f2c */
			PVOID           WinSockData;                /* f6c */
			ULONG           GdiBatchCount;              /* f70 */
			ULONG           Spare2;                     /* f74 */
			ULONG           Spare3;                     /* f78 */
			ULONG           Spare4;                     /* f7c */
			PVOID           ReservedForOle_;            /* f80 */
			ULONG           WaitingOnLoaderLock;        /* f84 */
			PVOID           Reserved5_[3];              /* f88 */
			PVOID          *TlsExpansionSlots_;         /* f94 */
			ULONG           ImpersonationLocale;        /* f98 */
			ULONG           IsImpersonating;            /* f9c */
			PVOID           NlsCache;                   /* fa0 */
			PVOID           ShimData;                   /* fa4 */
			ULONG           HeapVirtualAffinity;        /* fa8 */
			PVOID           CurrentTransactionHandle;   /* fac */
			PVOID           ActiveFrame;                /* fb0 */
			PVOID          *FlsSlots;                   /* fb4 */
                        struct _TEB    *self;
		};
	};
} TEB;
typedef TEB *PTEB;
저작자 표시
신고
Posted by 지영아빠

티스토리 툴바