<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-17669545</id><updated>2011-07-28T08:07:20.102-07:00</updated><title type='text'>Saurabh's World</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://saurabhtangri.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17669545/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://saurabhtangri.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Saurabh</name><uri>http://www.blogger.com/profile/17088693645230593637</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-17669545.post-7071529024417674683</id><published>2007-08-13T22:48:00.000-07:00</published><updated>2007-08-13T23:27:27.095-07:00</updated><title type='text'>x86 System Boot up</title><content type='html'>After system powers up and completes BIOS POST, INT 19 is issued. This interrupt directs the Microprocessor to start loading the OS. The boot sector of the primary boot device(floppy,HDD, CD ROM) is loaded at 0x0000:0x7c00 &lt;br /&gt;&lt;br /&gt;The loaded bootsector is defined as bootable only if it has the flag 0xAA55 present at the end of the sector. This means bytes 511 and 512 should be 0x55 and 0xAA respectively.&lt;br /&gt;&lt;br /&gt;I used VMWARE Workstation to bootup a x86 virtual machine. I wrote some Linux/AT&amp;T assembly code in my experiments. &lt;br /&gt;I used the GNU GAS assembler using cygwin on a Windows PC.&lt;br /&gt;&lt;br /&gt;Simple Hello World Bootable program.&lt;br /&gt;====================================================================&lt;br /&gt;BootSector.s&lt;br /&gt;====================================================================&lt;br /&gt;# Saurabh Tangri&lt;br /&gt;  .text&lt;br /&gt;  .globl start&lt;br /&gt;  .code16&lt;br /&gt;.text&lt;br /&gt;start:&lt;br /&gt;    movb $0xE, %ah              # Function 0x0E(AH=0Eh Write Character in TTY Mode) of Interrupt 0x10&lt;br /&gt;    movb $'H', %al              # write 'H'&lt;br /&gt;    int  $0x10&lt;br /&gt;    movb $'e', %al              # write 'e'&lt;br /&gt;    int  $0x10&lt;br /&gt;    movb $'l', %al              # write 'l'&lt;br /&gt;    int  $0x10&lt;br /&gt;    movb $'l', %al              # write 'l'&lt;br /&gt;    int  $0x10&lt;br /&gt;    movb $'o', %al              # write 'o'&lt;br /&gt;    int  $0x10&lt;br /&gt;    movb $' ', %al              # write ' '&lt;br /&gt;    int  $0x10&lt;br /&gt;    movb $'W', %al              # write 'W'&lt;br /&gt;    int  $0x10&lt;br /&gt;    movb $'o', %al              # write 'o'&lt;br /&gt;    int  $0x10&lt;br /&gt;    movb $'r', %al              # write 'r'&lt;br /&gt;    int  $0x10&lt;br /&gt;    movb $'l', %al              # write 'l'&lt;br /&gt;    int  $0x10&lt;br /&gt;    movb $'d', %al              # write 'd'&lt;br /&gt;    int  $0x10    &lt;br /&gt;    ret&lt;br /&gt;&lt;br /&gt;.org 0x1fe, 0x90    # Last 2 bytes of the boot sector.&lt;br /&gt;# .org 0x1FE basically directs assembler to add NOPS(opcode =0x90)&lt;br /&gt;# till the base offset 0x1FE. After this it puts a flag 0xAA55 at the 512th word.&lt;br /&gt;# It is an indication that the generated floppy image would be bootable.&lt;br /&gt; &lt;br /&gt;boot_flag:  .word 0xAA55 # Flag indicating a boot disk&lt;br /&gt;====================================================================&lt;br /&gt;MakeFile&lt;br /&gt;====================================================================&lt;br /&gt;AS=as&lt;br /&gt;LD=ld&lt;br /&gt;OBJCOPY=objcopy&lt;br /&gt;&lt;br /&gt;.s.o:&lt;br /&gt; ${AS} -a $&lt; -o $*.o &gt;$*.map&lt;br /&gt;&lt;br /&gt;all: final.img&lt;br /&gt;&lt;br /&gt;final.img: bootsect&lt;br /&gt; mv bootsect final.img&lt;br /&gt;&lt;br /&gt;bootsect: bootsect.out&lt;br /&gt; $(OBJCOPY) -O binary -j .text $&lt; $@&lt;br /&gt;&lt;br /&gt;bootsect.out: bootsect.o&lt;br /&gt; ${LD} -r -Ttext 0x7c00 -e _start -s -o bootsect.out bootsect.o&lt;br /&gt;&lt;br /&gt;Next I want to dump study on PCI and x86 segmentation in my blogs.&lt;br /&gt;&lt;br /&gt;...blogging....&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17669545-7071529024417674683?l=saurabhtangri.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saurabhtangri.blogspot.com/feeds/7071529024417674683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17669545&amp;postID=7071529024417674683' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17669545/posts/default/7071529024417674683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17669545/posts/default/7071529024417674683'/><link rel='alternate' type='text/html' href='http://saurabhtangri.blogspot.com/2007/08/x86-system-boot-up.html' title='x86 System Boot up'/><author><name>Saurabh</name><uri>http://www.blogger.com/profile/17088693645230593637</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17669545.post-112970629657808126</id><published>2005-10-18T21:56:00.000-07:00</published><updated>2005-11-06T11:11:12.880-08:00</updated><title type='text'>IA-32 procedure calls and returns</title><content type='html'>&lt;strong&gt;The STACK&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://photos1.blogger.com/blogger/578/1708/400/stack.jpg" border="0" /&gt;The stack is a contiguous array of memory locations. IA32 programs utilize stack to support procedure calls. When using the flat memorymodel(in the case of Windows), the stack can be located anywhere in the linear address space for the program. A stack can be up to 4 GBytes long, the maximum size of a segment.Items are placed on the stack using the PUSH instruction and removed from the stack using thePOP instruction. A portion of the stack allocated for a single frame is called as a stack frame.&lt;br /&gt;&lt;br /&gt;&lt;img style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://photos1.blogger.com/blogger/578/1708/320/stack1.JPG" border="0" /&gt;&lt;br /&gt;When an item is pushed onto the stack, the processor decrements the ESP register, then writes the item at the new top of stack. When an item is popped off the stack, theprocessor reads the item from the top of stack, then increments the ESP register. In this manner,the stack grows down in memory (towards lesser addresses) when items are pushed on the stackand shrinks up (towards greater addresses) when the items are popped from the stack.&lt;br /&gt;&lt;br /&gt;The topmost stack frame is delimited by two pointers the %ebp serving as the &lt;strong&gt;frame/base pointer &lt;/strong&gt;and %esp serving as the &lt;strong&gt;stack pointer.&lt;/strong&gt; The %eax is called as the accumulator and is used to return values from functions.&lt;/p&gt;&lt;p&gt;The CALL machine code instruction decrements the ESP register by the size of a return address and stores the address of the immediately following machine code instruction to the address pointed to by the ESP register. Or in simple words it pushes the return address(the instruction after call) and jumps to the target instruction. Symetrically, the RET machine code instruction fetches the stored return address from the address pointed to by the ESP register and increments the ESP register by the size of a return address. The PUSH and POP machine code instructions can be used to store and fetch an arbitrary register to and from the stack in a similar manner. &lt;/p&gt;&lt;p&gt;Thus a call in assembly is the same as:&lt;br /&gt;&lt;strong&gt;push eip&lt;/strong&gt; ; pushes the current EIP onto the stack&lt;br /&gt;&lt;strong&gt;jmp&lt;/strong&gt; ; jump to the function address &lt;/p&gt;&lt;p&gt;Now lets analyze two small programs :&lt;br /&gt;The listings were disassembled using the intel compiler for windows(trial version).&lt;br /&gt;icl /FA /Od program.CPP (I have'nt enforced any calling conventions( cdecl,fastcall,stdcall) for this simple listing It creates a .asm file containing the translated code.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Program 1 :&lt;/strong&gt;&lt;br /&gt;&lt;em&gt;int main()&lt;br /&gt;{&lt;br /&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="color:#cc33cc;"&gt;int a = 7 ;&lt;br /&gt;return 0;&lt;br /&gt;&lt;/span&gt;}&lt;/em&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;_main PROC NEAR&lt;/li&gt;&lt;li&gt;B1$1:; Preds $B1$0&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc9933;"&gt;push ebp ;~~~ start of Prologue &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc9933;"&gt;mov ebp, esp &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc9933;"&gt;sub esp, 3 &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc9933;"&gt;and esp, -8 &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc9933;"&gt;add esp, 4 &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc9933;"&gt;push esi ;~~~ end of Prologue &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc33cc;"&gt;mov DWORD PTR [ebp-4], 7 &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc33cc;"&gt;xor eax, eax &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#3333ff;"&gt;leave ; ~~~ start of epilogue&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#3333ff;"&gt;ret ; ~~~ end of epilogue&lt;/span&gt;&lt;/li&gt;&lt;li&gt;; mark_end;&lt;/li&gt;&lt;/ol&gt;&lt;p align="justify"&gt;&lt;strong&gt;&lt;span style="color:#cc9933;"&gt;Prologue&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;&lt;span style="color:#cc9933;"&gt;At the beginning of any procedure, two things must always be done beforeanything else:&lt;br /&gt;1. Save the caller's frame pointer on the stack: &lt;strong&gt;push %ebp&lt;br /&gt;&lt;/strong&gt;2. Set as the callee's frame pointer the current stack pointer: &lt;strong&gt;movl %ebp, %esp&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;span style="color:#3333ff;"&gt;&lt;strong&gt;Epilogue &lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#3333ff;"&gt;Just as we had to set up stack frame for the callee procedure, we must restore it to its current state before returning. This involves three steps (the inverse of the setup steps):&lt;br /&gt;1. Set as the caller's stack pointer the current (callee's) frame pointer: &lt;strong&gt;movl %ebp, %esp&lt;/strong&gt;&lt;br /&gt;2. Restore the caller's frame pointer from the stack: &lt;strong&gt;popl %ebp&lt;/strong&gt;&lt;br /&gt;These two instructions may be replaced with a single &lt;strong&gt;leave&lt;/strong&gt; instruction.&lt;br /&gt;3. Once we have cleaned up after ourselves, a return (ret) instruction canbe executed. After the&lt;br /&gt;leave instruction, the stack pointer will be at thetop of the return address pushed by the&lt;br /&gt;call instruction. Therefore, the ret instruction acts to pop the return address off the stack and jump to it. (pop eip)&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;em&gt;&lt;strong&gt;Program 2 :&lt;/strong&gt; &lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;em&gt;&lt;span style="color:#ff0000;"&gt;int foo(){&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="color:#ff0000;"&gt;int b = 8 ;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="color:#ff0000;"&gt;return 5;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="color:#ff0000;"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="color:#009900;"&gt;int main(){&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="color:#009900;"&gt;int a = 7 ;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="color:#009900;"&gt;foo();&lt;br /&gt;return 0;&lt;br /&gt;}&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;PUBLIC &lt;/span&gt;&lt;a href="mailto:?foo@@YAHXZ"&gt;&lt;span style="color:#cc0000;"&gt;?foo@@YAHXZ&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="mailto:?foo@@YAHXZ"&gt;&lt;span style="color:#cc0000;"&gt;?foo@@YAHXZ&lt;/span&gt;&lt;/a&gt;&lt;span style="color:#cc0000;"&gt; PROC NEAR&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;$B1$1: ; Preds $B1$0&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;push ebp&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;mov ebp, esp &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;push esi&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;mov DWORD PTR [ebp-4], 8 &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;mov eax, 5&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;leave &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;ret &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;ALIGN 4&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;; LOE&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#cc0000;"&gt;; mark_end;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;_main PROC NEAR&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;$B2$1; Preds $B2$0&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;push ebp &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;mov ebp, esp&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;sub esp, 3 &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;and esp, -8 &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;add esp, 4 &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;push esi &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;mov DWORD PTR [ebp-4], 7 &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;call &lt;/span&gt;&lt;a href="mailto:?foo@@YAHXZ"&gt;&lt;span style="color:#009900;"&gt;?foo@@YAHXZ&lt;/span&gt;&lt;/a&gt;&lt;span style="color:#009900;"&gt; &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;; LOE&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;$B2$2: ; Preds $B2$1&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;xor eax, eax &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;leave &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;ret &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="color:#009900;"&gt;; mark_end;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17669545-112970629657808126?l=saurabhtangri.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saurabhtangri.blogspot.com/feeds/112970629657808126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17669545&amp;postID=112970629657808126' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17669545/posts/default/112970629657808126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17669545/posts/default/112970629657808126'/><link rel='alternate' type='text/html' href='http://saurabhtangri.blogspot.com/2005/10/ia-32-procedure-calls-and-returns.html' title='IA-32 procedure calls and returns'/><author><name>Saurabh</name><uri>http://www.blogger.com/profile/17088693645230593637</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17669545.post-112962262349627845</id><published>2005-10-17T23:41:00.000-07:00</published><updated>2005-10-30T10:04:21.540-08:00</updated><title type='text'>Windows Internal Structures 1</title><content type='html'>&lt;a href="http://photos1.blogger.com/blogger/578/1708/1600/strcutures1.JPG"&gt;&lt;/a&gt;&lt;br /&gt;In my efforts to document my understanding of windows internals, I have decided to blog my brains out.....&lt;br /&gt;&lt;br /&gt;Part of it is also rehearsed in my master's degree thesis.&lt;br /&gt;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++&lt;br /&gt;&lt;strong&gt;Windows Kernel Objects&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;PCR (Processor Control Region)&lt;/strong&gt;&lt;br /&gt;When in Kernel Mode FS Register is set to a GDT selector whose base address points to the beginning of the Processor Control Region (0xFFDFF000). PCR is a very important kernel structure and the operating system maintains a distinct copy of it for each processor. &lt;a href="http://www.geocities.com/saurabhtangri/Work/PCR.JPG"&gt;&lt;img style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://www.geocities.com/saurabhtangri/Work/PCR.JPG" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;typedef struct _KPCR {&lt;br /&gt;/*000*/ NT_TIB NtTib;&lt;br /&gt;/*01C*/ struct _KPCR *SelfPcr; // flat address of this PCR&lt;br /&gt;&lt;strong&gt;/*020*/ PKPRCB Prcb;&lt;br /&gt;&lt;/strong&gt;/*024*/ KIRQL Irql; // IRQL for each processor to arbitrate premption&lt;br /&gt;/*028*/ DWORD IRR;&lt;br /&gt;/*02C*/ DWORD IrrActive;&lt;br /&gt;/*030*/ DWORD IDR;&lt;br /&gt;/*034*/ DWORD Reserved2;&lt;br /&gt;&lt;strong&gt;/*038*/ struct _KIDTENTRY *IDT; // Interrupt description table&lt;br /&gt;/*03C*/ struct _KGDTENTRY *GDT; // Global description table&lt;br /&gt;&lt;/strong&gt;/*040*/ struct _TSS *TSS;&lt;br /&gt;/*044*/ WORD MajorVersion;&lt;br /&gt;/*046*/ WORD MinorVersion;&lt;br /&gt;/*048*/ KAFFINITY SetMember;&lt;br /&gt;/*04C*/ DWORD StallScaleFactor;&lt;br /&gt;/*050*/ BYTE DebugActive;&lt;br /&gt;/*051*/ BYTE Number;&lt;br /&gt;/*???*/ } KPCR, *PKPCR;&lt;/p&gt;&lt;p&gt;The picture shows the GDT showing the kernel mode segments&lt;/p&gt;&lt;p&gt;CS : Selector = 0008, Base = 00000000, Limit = FFFFFFFF, DPL0, Type = CODE -ra&lt;/p&gt;&lt;p&gt;DS : Selector = 0023, Base = 00000000, Limit = FFFFFFFF, DPL3, Type = DATA -wa&lt;/p&gt;&lt;p&gt;FS : Selector = 0030, Base = FFDFF000, Limit = 00001FFF, DPL0, Type = DATA -wa&lt;/p&gt;&lt;p&gt;This kernel structure points to another important structure called the PRCB(Processor control Block). This structure maintains the state of the processor and plays a sinificant role in thread scheduling.&lt;/p&gt;&lt;p&gt;struct _KPRCB /* sizeof 00000C50 3152 */ {&lt;br /&gt;/* off 0x00000000 */ unsigned short MinorVersion;&lt;br /&gt;/* off 0x00000002 */ unsigned short MajorVersion;&lt;br /&gt;/* off 0x00000004 */ struct _KTHREAD* CurrentThread;&lt;br /&gt;/* off 0x00000008 */ struct _KTHREAD* NextThread;&lt;br /&gt;/* off 0x0000000C */ struct _KTHREAD* IdleThread;&lt;br /&gt;/* off 0x00000010 */ char Number; /* off 0x00000011 */ char Reserved;&lt;br /&gt;/* off 0x00000012 */ unsigned short BuildType;&lt;br /&gt;/* off 0x00000014 */ unsigned long SetMember;&lt;br /&gt;/* off 0x00000018 */ char CpuType;&lt;br /&gt;/* off 0x00000019 */ char CpuID;&lt;br /&gt;/* off 0x0000001A */ unsigned short CpuStep;&lt;br /&gt;/* off 0x0000001C */ struct _KPROCESSOR_STATE ProcessorState;&lt;br /&gt;/* off 0x0000033C */ unsigned long KernelReserved[16];&lt;br /&gt;/* off 0x0000037C */ unsigned long HalReserved[16];&lt;br /&gt;/* off 0x000003BC */ unsigned char PrcbPad0[92];&lt;br /&gt;/* off 0x00000418 */ struct _KSPIN_LOCK_QUEUE LockQueue[16];&lt;br /&gt;/* off 0x00000498 */ unsigned char PrcbPad1[8]; /* off 0x000004A0&lt;/p&gt;&lt;p&gt;&lt;br /&gt;As we know that the fundamental schedulable entity in a system is a thread and not a process. We need to relate all these kernel structure for a better understanding. The KTHREAD structure is thread specific and is contained in the ETHREAD structure which contains other thread specific information. &lt;/p&gt;&lt;p&gt;The current thread can be found using the static PRCB structure. PRCB points to the KTHREAD structure of the current, idle and the next threads.&lt;a href="http://www.geocities.com/saurabhtangri/Work/threads.JPG"&gt;&lt;img style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://www.geocities.com/saurabhtangri/Work/threads.JPG" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The diagram shows the relationship. ETHREAD contains KTHREAD and KTHREAD points to TEB(Thread Enviroment Block). Also the ETHREAD has a relationship to its process via the pointer to the EPROCESS block.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;So we have 6 new structures (ETHREAD,KTHREAD,TEB,EPROCESS,KPROCESS,PEB)&lt;/p&gt;&lt;p&gt;Unlike the relationship that exists in the kernel thread structures. The EPROCESS structure contains both the KPROCESS structure and the Process enviroment block(PEB).&lt;/p&gt;&lt;p&gt;The Eprocess and Kprocess structures are contained in the kernel space whereas the PEB resides in the user memory.&lt;/p&gt;&lt;p&gt;The eprocess mains a linked list kind of mechanism which is used to traverse through the list of active processes(PsActiveprocessHead).&lt;a href="http://www.geocities.com/saurabhtangri/Work/strcutures.JPG"&gt;&lt;img style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://www.geocities.com/saurabhtangri/Work/strcutures.JPG" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The thread enviroment block also has a pointer to its processes enviroment block(PEB).&lt;/p&gt;&lt;p&gt;The PEB catalogs various process attributes like (image base address, module list, heap size and count etc). This information remains in user space and is utilized by the heap manager or image loader. THE PEB is always mapped at the address 0x7ffdf000.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17669545-112962262349627845?l=saurabhtangri.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saurabhtangri.blogspot.com/feeds/112962262349627845/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17669545&amp;postID=112962262349627845' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17669545/posts/default/112962262349627845'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17669545/posts/default/112962262349627845'/><link rel='alternate' type='text/html' href='http://saurabhtangri.blogspot.com/2005/10/windows-internal-structures-1.html' title='Windows Internal Structures 1'/><author><name>Saurabh</name><uri>http://www.blogger.com/profile/17088693645230593637</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-17669545.post-112892607538904134</id><published>2005-10-09T23:32:00.000-07:00</published><updated>2005-10-09T23:34:35.393-07:00</updated><title type='text'>Welcome to  my Blog</title><content type='html'>I know I am late in the game, but its never too late to score an ace. hahah trying to give a punchline to this first post. I hope I post enough to not get this account expired&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/17669545-112892607538904134?l=saurabhtangri.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://saurabhtangri.blogspot.com/feeds/112892607538904134/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=17669545&amp;postID=112892607538904134' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/17669545/posts/default/112892607538904134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/17669545/posts/default/112892607538904134'/><link rel='alternate' type='text/html' href='http://saurabhtangri.blogspot.com/2005/10/welcome-to-my-blog.html' title='Welcome to  my Blog'/><author><name>Saurabh</name><uri>http://www.blogger.com/profile/17088693645230593637</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
