280 likes | 598 Views
Thread Internals. 組員:王傳陞、林威丞 黃品舜、李盈賢. outline. what is a thread? Data Structures executive thread block kernel thread block thread environment block Thread-Related Kernel Variables Thread-Related Performance Counters Windows Thread Functions Birth of a Thread. What is a Thread?.
E N D
Thread Internals 組員:王傳陞、林威丞 黃品舜、李盈賢
outline • what is a thread? • Data Structures • executive thread block • kernel thread block • thread environment block • Thread-Related Kernel Variables • Thread-Related Performance Counters • Windows Thread Functions • Birth of a Thread
What is a Thread? • A thread is the basic object that executes instructions on a processor. All running processes have at least one thread.
What is a Thread?(cont.) • Traditional UNIX Process • Heavyweight process • Single thread • Mach Task • Thread • Lightweight process • Thread id, PC, register set, a stack • Dynamic Object • Mult-thread
What is a Thread?(cont.) Single-threaded process Multi-threaded process Resources Resources Threads Threads
outline • what is a thread? • Data Structures • executive thread block • kernel thread block • thread environment block • Thread-Related Kernel Variables • Thread-Related Performance Counters • Windows Thread Functions • Birth of a Thread
Data Structures EP : executive process KP : kernel process (PCB) PEB : process environment block ET : executive thread KT : kernel thread TEB : thread environment block
outline • what is a thread? • Data Structures • executive thread block • kernel thread block • thread environment block • Thread-Related Kernel Variables • Thread-Related Performance Counters • Windows Thread Functions • Birth of a Thread
executive thread block Thread time : Thread create and exit time information. Process identification : Process ID and pointer to EPROCESS block of the process that the thread belongs to. Start address : Address of thread start routine.
executive thread block(cont.) Impersonation information : Access token and impersonation level (if the thread is impersonating a client). LPC information : Message ID that the thread is waiting for and address of message. I/O information : List of pending I/O request packets (IRPs).
outline • what is a thread? • Data Structures • executive thread block • kernel thread block • thread environment block • Thread-Related Kernel Variables • Thread-Related Performance Counters • Windows Thread Functions • Birth of a Thread
kernel thread block Dispatcher header : A data structure that contains the object type, the signaled state, and a list of the threads waiting on that object. Execution time : Total user and kernel CPU time. Pointer to kernel stack information : Base and upper address of the kernel stack.
kernel thread block(cont.) Pointer to system service table : Each thread starts out with this field service table pointing to the main system service table (KeServiceDescriptorTable). When a thread first calls a Windows GUI service, its system service table is changed to one that includes the GDI and USER services in Win32k.sys.
kernel thread block(cont.) Scheduling information : Base and current priority, quantum, affinity mask, ideal processor, scheduling state, freeze count, and suspend count. Trap frame : Trap frame allow system to resume where if left off. APC queues : List of pending user-mode and kernelmode APCs, and alertable flag.
kernel thread block(cont.) Wait blocks : Each thread that is in a wait state has a list of the wait blocks that represent the objects the thread is waiting for. Timer block : Built-in timer block (also a corresponding wait block). Pointer to TEB : Thread ID, TLS information, PEB pointer, and GDI and OpenGL information.
outline • what is a thread? • Data Structures • executive thread block • kernel thread block • thread environment block • Thread-Related Kernel Variables • Thread-Related Performance Counters • Windows Thread Functions • Birth of a Thread
thread environment block TIB : One element in the TIB structure is a pointer to an EXCEPTION_RECORD structure, which in turn contains a pointer to an exception handling callback function. Thus, each thread has its own exception callback function. Fiber : lightweight” threads Others : Graphics Device Interface 、 Open Graphics Library、Transport Layer Security…
outline • What is a thread? • Data Structures • executive thread block • kernel thread block • thread environment block • Thread-Related Kernel Variables • Thread-Related Performance Counters • Windows Thread Functions • Birth of a Thread
Thread-Related Kernel Variables Example : 線程監控
outline • what is a thread? • Data Structures • executive thread block • kernel thread block • thread environment block • Thread-Related Kernel Variables • Thread-Related Performance Counters • Windows Thread Functions • Birth of a Thread
Thread-Related Performance Counters(cont.) Thread Object詳細資料連結
outline • what is a thread? • Data Structures • executive thread block • kernel thread block • thread environment block • Thread-Related Kernel Variables • Thread-Related Performance Counters • Windows Thread Functions • Birth of a Thread
outline • what is a thread? • Data Structures • executive thread block • kernel thread block • thread environment block • Thread-Related Kernel Variables • Thread-Related Performance Counters • Windows Thread Functions • Birth of a Thread