Page 30 - DCAP408_WEB_PROGRAMMING
P. 30

Windows Programming




                    Notes          As discussed above, the whole address space is divided in 4KB pages. So when a PDE or PTE is
                                   used, its upper 20 bits gives a 4KB page aligned address and lower 12 bits are utilized to store the
                                   page defense  information and  some other  housekeeping information needed by an OS  for
                                   proper functioning.





                                     Notes  The upper 20 bits which shows the actual physical address are called Page Frame
                                     Number (or PFN). Details on defense bits and other bits in the lower 12 bits can be located
                                     in here.





                                      Task  Make distinction between page directory and page table.

                                   2.2.1 Windows Page Table Management

                                   In  windows every process has its own Page Directory and Page  Tables. Therefore windows
                                   assign 4 MB of this space per process. When a process is formed, every entry in Page Directory
                                   includes physical address of a Page  Table. The  entries in the page table are  either valid or
                                   invalid. Valid entries enclose physical address of 4KB page assigned to the process. An invalid
                                   entry includes some particular bits to mark it invalid and these entries are called Invalid PTEs.
                                   As the memory assigned by the process, these entries in Page Table are filled with the physical
                                   address of the assigned pages. You should keep in mind one thing here that a process doesn’t
                                   recognize anything regarding physical memory and it only utilizes logical addresses. The details
                                   of which logical address corresponds to which physical address is handled evidently by Windows
                                   Memory manager and the processor. The address at which the page directory of a process is
                                   positioned in physical memory is pointed to as Page Directory Base address. This Page Directory
                                   Base address is amassed in a special CPU register called CR3 (on x86). On context switch, Windows
                                   loads the new value of CR3 to point to the new process’s Page Directory Base. This manner every
                                   process gets its own division of  the whole  4GB physical  address space. Certainly the total
                                   memory assigned at one time to all the process’s in a system cannot go beyond the total amount
                                   of RAM + page file size but the method discussed above permits windows to give every process
                                   its own 4GB logical (or Virtual) address space. We call it Virtual Address space since although
                                   the process has the whole 4GB address range obtainable to it, it can only use the memory which
                                   is assigned to it. Compilers can generate a program that depends on the code being at an accurate
                                   location in memory, every time it is executed.


                                          Example: With virtual memory, the process considers, it is at 0x080482a0, but in fact it
                                   could be at physical memory position 0x1000000.

                                   If a process attempts to access an unallocated address, it will obtain an access violation since the
                                   PTE subsequent to that address refers to an invalid value. Also the process can’t assign more
                                   memory than what is obtainable in the system. This way of separating logical memory from
                                   physical memory has many benefits. A process gets a linear 4GB address space so application
                                   programmers don’t have to concern regarding segments and all unlike in old DOS days. It also
                                   permits windows to run multiple processes and let them employ physical memory on a machine
                                   without worrying about them stomping on each other’s address space. A logical address in one
                                   process will never refer to the physical memory assigned to another process (unless they are
                                   utilizing some sort of shared memory). Therefore, one process can never read from or write to
                                   another process’s memory.



          24                                LOVELY PROFESSIONAL UNIVERSITY
   25   26   27   28   29   30   31   32   33   34   35