Download pdf - winMM32

Transcript
  • 7/28/2019 winMM32

    1/11

    Copyright http://www.intellectualheaven.com

    Page 1 of 5

    Windows Memory Management (Written by: Pankaj Garg)

    1. Introduction Windows on 32 bit x86 systems can access up to 4GB of physical

    memory. This is due to the fact that the processors address bus which is 32 lines

    or 32 bits can only access address range from 0x00000000 to 0xFFFFFFFF which

    is 4GB. Windows also allows each process to have its own 4GB logical address

    space. The lower 2GB of this address space is available for the user mode

    process and upper 2GB is reserved for Windows Kernel mode code. How does

    Windows give 4GB address space each to multiple processes when the total

    memory it can access is also limited to 4GB. To achieve this Windows uses a

    feature of x86 processor (386 and above) known as paging. Paging allows the

    software to use a different memory address (known as logical address) than the

    physical memory address. The Processors paging unit translates this logicaladdress to the physical address transparently. This allows every process in the

    system to have its own 4GB logical address space. To understand this in more

    details, let us first take a look at how the paging in x86 works. 2. Paging in x86

    Processor The x86 processor divides the physical address space (or physical

    memory) in 4 KB pages. Thus to address 4GB of memory, we will need 1 Mega

    (1024x1024) 4KB pages. The processor uses a two level structure to refer to

    these 1 Mega pages. You can think of it as a two dimensional matrix of

    1024x1024 elements. The first dimension is known as Page Directory and second

    dimension is known as Page Table. Thus we can create 1 Page directory with

    1024 entries, each of which points to a Page Table. This will allow us to have1024 page tables. Each page table in turn can have 1024 entries, each of which

    points to a 4 KB page. Graphically it looks something like:

    Page Directory Page Tables Index = 0, Address = X Index = 0, Address = X1

    Index = 1, Address = X2 Index = 2, Address = X3 Index = 1023, Address = Xn

    Index = 1, Address = Y Index = 0, Address = Y1 Index = 1, Address = Y2 Index

    = 2, Address = Y3 Index = 1023, Address = Yn Index = 1023,

    Address = Z Index = 0, Address = Z1 Index = 1, Address = Z2 Index = 2,

    Address = Z3 Index = 1023, Address = Zn

    Physical Address Address X1 4 KB Page Address Yn 4 KB Page Address X3 4

    KB Page Unused Address Xn 4 KB Page Unused Address Y1 4KB Page Address

    X2 4KB Page Address Z2 4KB Page Address Y2 4KB Page Address Z3 4KB

    Page Unused Unused Address Zn 4KB Page Address Y3 4KB Page Address Z1

    4KB Page Unused Unused so on

    Copyright http://www.intellectualheaven.com

    Page 2 of 5

    Each Page Directory Entry (or PDE) is 4 bytes in size and points to a Page Table.

    Similarly each Page Table Entry (or PTE) is 4 bytes and points to a physical

    address of a 4KB page. To store 1024 PDE each containing 1024 PTE, we will

  • 7/28/2019 winMM32

    2/11

    need a total memory of 4 x 1024 x 1024 bytes i.e. 4MB. Thus to divide the whole

    4GB address space into 4 KB pages, we need 4 MB of memory.

    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 used to store the page protection information and some other house-keeping information required by an OS for proper functioning. The upper 20 bits

    which represents the actual physical address are known as Page Frame Number

    (or PFN). Details on protection bits and other bits in the lower 12 bits can be

    found in here1. 3. Windows Page Table Management In windows each process

    has its own Page Directory and Page Tables. Thus windows allocate 4 MB of this

    space per process. When a process is created, each entry in Page Directory

    contains physical address of a Page Table. The entries in the page table are

    either valid or invalid. Valid entries contain physical address of 4KB page

    allocated to the process. An invalid entry contains some special bits to mark it

    invalid and these entreis are known as Invalid PTEs1. As the memory allocatedby the process, these entries in Page Table are filled with the physical address of

    the allocated pages. You should remember one thing here that a process doesnt

    know anything about physical memory and it only uses logical addresses. The

    details of which logical address corresponds to which physical address is

    managed transparently by Windows Memory manager and the processor. The

    address at which the page directory of a process is located in physical memory is

    referred to as Page Directory Base address. This Page Directory Base address is

    stored in a special CPU register called CR3 (on x86). On context switch, Windows

    loads the new value of CR3 to point to the new processs Page Directory Base.

    This way each process gets its own division of the whole 4GB physical addressspace. Of course the total memory allocated at one time to all the processs in a

    system cannot exceed the total amount of RAM + pagefile size but the scheme

    discussed above allows windows to give each process its own 4GB logical (or

    Virtual) address space. We call it Virtual Address space because even though the

    process has the whole 4GB address range available to it, it can only use the

    memory which is allocated to it. If a process tries to access an unallocated

    address, it will get an access violation because the PTE corresponding to that

    address points to an invalid value. Also the process cant allocate more memory

    than what is available in the system. This method of separating logical memory

    from physical memory has lots of advantages. A process gets a linear 4GBaddress space so application programmers dont have to worry about segments

    and all unlike in old DOS days. It also allows windows to run multiple processes

    and let them use physical memory on a machine without worrying about them

    stomping on each others address space. A logical address in one process will

    never point to the physical memory allocated to another process (unless they are

    using some sort of shared memory). Thus, one process can never read from or

    write to another processs memory.

    The translation from logical to physical address is done by the processor. A 32 bit

    logical address is divided in to three parts as shown below. The processor loads

    the physical address of the page 10 bits 10 bits 12 bits directory base stored inCR3. It then uses the upper 10 bits from the logical address as an index in the

  • 7/28/2019 winMM32

    3/11

    Page directory. This gives the processor a page directory entry (PDE) which

    points to a Page Table. The next 10 bits are used as an index in the page table.

    Using these 10 bits, it gets a page

    Copyright http://www.intellectualheaven.com

    Page 3 of 5

    table entry (or PTE) which points to a 4KB physical page. The lowest 12 bits are

    used to address the individual bytes on a page. 4. Memory Protection Windows

    provide memory protection to all the processes such that one process cant

    access other processs memory. This ensures smooth operation of multiple

    processes simultaneously. Windows ensure this protection by doing following: o

    It only puts the physical address of allocated memory in PTE for a process. This

    ensures that the processs gets an access violation if it tries to access an address

    which is not allocated. o A rouge process may try to modify its page tables so

    that it can access the physical memory belonging to another process. Windowsprotect this kind of attacks by storing page tables in kernel address space. Recall

    from our earlier discussion that out of the 4GB logical address space given to a

    process, 2GB is given to user mode and 2GB is reserved for windows kernel. So a

    user mode application can not directly access or modify the page tables. Of

    course if a kernel mode driver wants to do that, it can do it because once you are

    in kernel mode, you virtually own the whole system. To understand this in more

    details, read the next section on Windows Logical memory layout below. 5.

    Windows Logical Memory Layout Windows gives lower 2GB (or 3GB depending

    upon boot.ini switch) logical address space of a process to user mode and upper

    2GB (or 1GB depending upon boot.ini switch) to Windows kernel. Out of the totalkernel address space, it reserves addresses from 0xC0000000 to 0xC03FFFFF for

    Page Tables and Page Directory. Every process has its Page Tables located at the

    logical address 0xC0000000 and page directory located at logical address

    0xC0300000. This logical memory arrangement is shown below:

    Logical address 0x00000000 0x80000000 0xC0000000

    0xC0400000 0xFFFFFFFF

    8VHU0 RGH. HUQHO0 RGH

    Copyright http://www.intellectualheaven.com

    Page 4 of 5

    You can use Windows kernel debugger kd or windbg to verify this (refer to !pte

    and !vtop debugger extenstions). The physical address to this page directory is

    stored in CR3. The 1024 addresses starting from 0xC0300000 represents Page

    Directory Entry (PDE). Each PDE contains a 4 byte physical address which points

    to a Page Table. Each Page Table has 1024 entries which either contains a

    physical address pointing to a physical page of 4KB or contains an invalid entry.

    This was also discussed above in the processors paging and Windows page table

    management section but repeated here for clarity sake.

  • 7/28/2019 winMM32

    4/11

    So why does Windows use logical address 0xC000000000 to store the Page

    Tables and address 0xC0300000 to store page directory? The requirement for

    storing the page tables in memory is that a rouge user mode application should

    not be able to manipulate the page tables. Hence page tables should be in the

    kernel logical address space. Windows usually gives lower 2GB space to

    processes and reserves upper 2GB to kernel. But with a special boot.ini switch /3GB, it allows user mode process to access lower 3GB memory. 0xC0000000 is

    the next address after 3GB and so I guess that is why it is chosen for storing

    page directory and page tables. There are some other important aspects to page

    tables and page directory layout in memory. To understand that, let us look at

    how page tables and page directory is laid out. To make it easy to understand, I

    have drawn page tables for a fake process with relevant entries highlighted. Note

    that each index entry is 4 bytes in size. P_PT represents the physical address of a

    Page Table.

    Index

    Logical Address

    0x0

    0x1

    .

    0x80

    .

    0x300 (768)

    0x34A (842)

    .

    .

    0x400 (1023)

    0xC0000000 0x6A078###

    0x10480### - -

    0xC0001000 0x45045###

    - - 0x34005###

    0xC0002000 - - 0xC0100000 - -

    0xC0300000 0x13453### P_PT 0x6A078### - P_PT 0x45045### - PDB

    0x13453### - 0xC0301000 - - 0xC03FF000

    PDB represents the physical address of page directory base of the correspondingprocess i.e. it represents the physical address corresponding to logical address

  • 7/28/2019 winMM32

    5/11

    0xC0300000 for that process. This value is also stored in CR3. Remember

    Windows can only use logical address to access any memory location including

    page directory, so to access page directory and page tables, it is necessary to

    put some self referencing entry in page directory. The physical address entries

    shown

    Copyright http://www.intellectualheaven.com

    Page 5 of 5

    above will be different for each process but each process will have its PDB entry

    stored at index 0x300 of Page directory.

    We will perform logical to physical address translation on 4 different addresses to

    see the significance of PDB entry, Page tables layout and how exactly the

    address translation works. The addresses which we will translate are

    0x2034AC54, 0xC0000000, 0xC0300000, 0xC0300000[0x300] i.e. 0xC030C00.First address is a normal user mode logical address for a process, the second

    address is the first logical address of first page table in logical address space,

    third address is logical address of page directory base and fourth address is

    logical address of a special entry as you will see during translation. Assume CR3

    points to a physical address 0x13453###. As pointed earlier, lower 12 bits are

    used to store page protection information and other information needed by an

    OS. These are out of the scope of our current discussion so I have shown them as

    ###. The upper 20 bits represents the Page Frame Number or PFN which is the

    physical address of a 4KB aligned page. The actual physical address

    corresponding to the PFN will be 0x13453000. Let us now do the translation:

    1. 0x2034AC54 o 0x2034AC54 can be represented as 0010000000 1101001010

    110001010100 o The upper 10 bits which are 0010000000 gives the index into

    page directory. Converting to hexadecimal, the upper 10 bits give a value of

    0x080 o From CR3, we know the Page Directory is located at physical address

    0x13453000 and from discussion above we also know that Page Directory is

    located at logical address 0xC0300000 o Thus 0xC0300000 [0x080] will give the

    address of page table which is P_PT. From the table above, we can see that this

    address is represented by page table at logical address 0xC00001000 (or

    physical address 0x45045000). Now we use next 10 bits i.e. 1101001010 (or

    0x34A) to index into the page table. o The address 0xC00001000 [0x34A] will

    give us the physical address of a 4KB page which is 0x34005000 from the table

    above. o The number represented by lower 12 bits, which is 110001010100 (or

    0xC54), is used to refer to the actual byte on the 4KB page located at

    0x34005000. The final physical address corresponding to 0x2034AC54 comes

    out to be 0x34005C54

    I will leave the address translation of other

    3 addresses as an exercise to the reader.

  • 7/28/2019 winMM32

    6/11

    Once you do that translation, you will

    understand why the PDB entry is stored

    at index 0x300 in the table above and itcauses processor to treat page directory

    as a page table during address

    translation. Also this translation will give

    you more information on why this

    particular layout was chosen by windows

    designers. 6. Reference 1. Inside Windows

    2000 by David A. Solomon & Mark E.

    Russinovich 2. Undocumented Windows

    2000 secrets by Sven B. Schreiber

  • 7/28/2019 winMM32

    7/11

    Versi terjemahan dari winMM32.docCopyright http://www.intellectualheaven.com

    Halaman 1 dari 5

    Windows Memory Manajemen (Ditulis oleh: Pankaj Garg)1.Pengenalan Windows pada sistem x86 32 bit dapat mengakses sampai dengan4GB memori fisik.Hal ini disebabkan fakta bahwa bus alamat prosesor yang 32baris atau 32 bit hanya dapat mengakses berbagai alamat dari 0x00000000 ke0xFFFFFFFF yang 4GB.Jendela juga memungkinkan setiap proses memiliki ruangalamat sendiri 4GB logis.2GB bawah ini ruang alamat yang tersedia untukproses mode pengguna dan 2GB atas dicadangkan untuk Windows kode modeKernel.Bagaimana Windows Berikan ruang alamat 4GB masing-masing untukbeberapa proses ketika total memori yang dapat mengakses juga terbatas pada4GB.Untuk mencapai ini Windows menggunakan fitur prosesor x86 (386 ke atas)yang dikenal sebagai paging.Pager memungkinkan perangkat lunak untukmenggunakan alamat memori yang berbeda (dikenal sebagai alamat logis) darialamat memori fisik.Unit paging Processor menerjemahkan alamat logis kealamat fisik secara transparan.Hal ini memungkinkan setiap proses dalamsistem untuk memiliki ruang alamat sendiri 4GB logis.Untuk memahami hal inisecara lebih rinci, mari kita lihatlah bagaimana paging dalam karyax86.2.Paging di x86 Processor x86 prosesor membagi ruang alamat fisik (ataumemori fisik) di 4 KB halaman.Jadi untuk mengatasi memori 4GB, kita akanmembutuhkan 1 mega (1024x1024) 4KB halaman.Prosesor menggunakanstruktur dua tingkat untuk merujuk pada 1 halaman mega.Anda dapatmenganggap itu sebagai matriks dua dimensi 1024x1024 elemen.Dimensipertama dikenal sebagai direktori Page dan dimensi kedua dikenal sebagai tabelhalaman.Dengan demikian kita dapat membuat 1 direktori Halaman dengan1024 entri, masing-masing menunjuk ke sebuah Tabel Halaman.Ini akanmemungkinkan kita untuk memiliki 1024 tabel halaman.Setiap tabel halamanpada gilirannya dapat memiliki 1.024 entri, yang masing-masing menunjuk kesebuah halaman 4 KB.Grafis itu terlihat seperti:Halaman Direktori Halaman Tabel Indeks = 0, Alamat = X Indeks = 0, Alamat =X1 Indeks = 1, Alamat = X2 Indeks = 2, Alamat = X3 ... Index = 1023, Alamat =Xn Indeks = 1, Alamat = Y Index = 0 , Alamat = Y1 Indeks = 1, Alamat = Y2Indeks = 2, Alamat = Y3 ... Index = 1023, Alamat = Yn ............ Indeks = 1023,Alamat = Z Index = 0, Alamat = Z1 Indeks = 1, Alamat = Z2 Indeks = 2, Alamat= Z3 ... Index = 1023, Alamat = Zn

    Alamat Fisik Alamat X1 - 4 KB Halaman Alamat Yn - 4 KB Halaman Alamat X3 - 4KB Halaman tidak digunakan Alamat Xn - 4 KB Halaman tidak digunakan Alamat

    Y1 - 4KB Halaman Alamat X2 - 4KB Halaman Alamat Z2 - 4KB Halaman Alamat Y2- 4KB Halaman Alamat Z3 - Halaman 4KB Alamat belum digunakan tidakdigunakan Zn - 4KB Halaman Alamat Y3 - 4KB Halaman Alamat Z1 - 4KBHalaman tidak digunakan tidak digunakan ...... seterusnya

    Copyright http://www.intellectualheaven.com

    Halaman 2 dari 5

    Setiap Halaman Direktori entri (atau PDE) adalah 4 byte dalam ukuran dan

    menunjuk ke sebuah Tabel Halaman.Demikian pula setiap entri tabel halaman(PTE atau) adalah 4 byte dan menunjuk ke sebuah alamat fisik dari sebuah

  • 7/28/2019 winMM32

    8/11

    halaman 4KB.Untuk menyimpan 1024 PDE masing-masing berisi 1.024 PTE, kitaakan membutuhkan memori total 4 x 1024 x 1024 byte yaitu 4MB. Jadi untukmembagi seluruh ruang alamat 4GB menjadi 4 KB halaman, kita perlu 4 MBmemori.

    Sebagaimana dibahas di atas, ruang alamat keseluruhan dibagi dalam 4KBhalaman.Jadi ketika PDE atau PTE digunakan, yang atas 20 bit memberikanhalaman 4KB alamat selaras dan bit 12 lebih rendah digunakan untukmenyimpan informasi perlindungan halaman dan beberapa informasi pekerjaanrumah tangga lain yang dibutuhkan oleh OS untuk memfungsikan. Atas 20 bityang mewakili alamat fisik yang sebenarnya dikenal sebagai Halaman FrameNomor (atau PFN).Rincian bit perlindungan dan bit lainnya di bawah 12 bit dapatditemukan di here1.3.Halaman jendela Manajemen Tabel Pada jendela setiapproses memiliki direktori Halaman sendiri dan Halaman Tabel. Sehingga jendelamengalokasikan 4 MB ruang ini per proses. Ketika sebuah proses dibuat, setiapentri dalam direktori Halaman berisi alamat fisik dari Tabel Halaman.Entri dalamtabel halaman yang baik valid atau tidak valid.Entri yang valid berisi alamat fisikdari halaman 4KB dialokasikan untuk proses.Entri yang tidak valid berisibeberapa bit khusus untuk menandainya tidak valid dan entreis ini dikenalsebagai PTEs1 valid.Sebagai memori yang dialokasikan oleh proses, entri-entridalam tabel halaman diisi dengan alamat fisik dari halaman dialokasikan. Andaharus ingat satu hal di sini bahwa proses tidak tahu apa-apa tentang memorifisik dan hanya menggunakan alamat logis. Rincian yang alamat logis sesuaidengan alamat fisik yang dikelola secara transparan oleh Windows Memorymanager dan prosesor.Alamat di mana direktori halaman dari sebuah prosesberada di memori fisik disebut sebagai Halaman alamat Direktori Base.Halamanini Alamat Direktori Basis disimpan dalam CPU khusus mendaftar disebut CR3(pada x86).Pada konteks switch, Windows memuat nilai baru dari CR3 untukmenunjuk ke proses baru Page Direktori Base.Dengan cara ini setiap prosesakan mendapatkan pembagian sendiri seluruh ruang alamat fisik 4GB. Tentu saja

    jumlah memori yang dialokasikan pada satu waktu untuk semua proses yangada di sistem tidak dapat melebihi jumlah total RAM + ukuran pagefile tetapiskema yang dibahas di atas memungkinkan jendela untuk memberikan setiapproses logis (atau Virtual) ruang alamat 4GB sendiri.Kami menyebutnya AlamatVirtual ruang karena meskipun proses memiliki seluruh 4GB kisaran alamat yangtersedia untuk itu, hanya dapat menggunakan memori yang dialokasikan untukitu.Jika proses mencoba untuk mengakses alamat yang belum dialokasikan,maka akan mendapatkan pelanggaran akses karena PTE sesuai dengan alamatyang menunjuk ke nilai yang tidak valid.Juga proses tidak dapat mengalokasikanmemori lebih dari apa yang tersedia di sistem. Metode ini memisahkan memorilogis dari memori fisik memiliki banyak keuntungan.

    Sebuah proses mendapatruang alamat 4GB linier sehingga programmer aplikasi tidak perlu khawatir

    tentang segmen dan semua tidak seperti di hari DOS. Hal ini juga memungkinkanjendela untuk menjalankan beberapa proses dan membiarkan merekamenggunakan memori fisik pada mesin tanpa khawatir tentang merekamenginjak ruang alamat masing-masing.Sebuah alamat logis dalam satu prosestidak akan pernah menunjuk ke memori fisik dialokasikan untuk proses lain(kecuali mereka menggunakan semacam memori bersama).Dengan demikian,salah satu proses yang tidak pernah dapat membaca dari atau menulis kememori proses lain itu.

    Terjemahan dari logis ke alamat fisik dilakukan oleh prosesor.Sebuah 32 bitalamat logis dibagi dalam tiga bagian seperti yang ditunjukkan di bawahini.Prosesor memuat alamat fisik dari halaman 10 bit 10 bit 12 bit basis direktori

  • 7/28/2019 winMM32

    9/11

    disimpan dalam CR3.Ia kemudian menggunakan atas 10 bit dari alamat logissebagai indeks di direktori halaman.Hal ini memberikan prosesor direktorihalaman masuk (PDE) yang menunjuk ke sebuah Tabel Halaman.10 bitberikutnya digunakan sebagai indeks dalam tabel halaman.Denganmenggunakan 10 bit, mendapat halaman

    Copyright http://www.intellectualheaven.com

    Halaman 3 dari 5

    entri tabel (atau PTE) yang menunjuk ke halaman fisik 4KB.Yang terendah 12 bityang digunakan untuk mengatasi byte individu pada halaman.4.Perlindunganmemori Windows menyediakan proteksi memori untuk semua proses sedemikianrupa sehingga satu proses tidak dapat mengakses memori proses lain. Hal inimenjamin kelancaran beberapa proses secara bersamaan.Jendela memastikanperlindungan ini dengan melakukan hal berikut: o Ini hanya menempatkanalamat fisik memori yang dialokasikan di PTE untuk proses. Hal ini memastikanbahwa proses itu mendapat pelanggaran akses jika mencoba untuk mengaksesalamat yang tidak dialokasikan.o Sebuah proses rouge mungkin mencoba untukmemodifikasi tabel halaman sehingga dapat mengakses memori fisik milikproses lain.Jendela melindungi jenis serangan tabel halaman menyimpan dalamruang alamat kernel.Ingat dari diskusi kita sebelumnya bahwa dari ruang alamatlogis 4GB diberikan kepada proses, 2GB diberikan ke mode pengguna dan 2GBdisediakan untuk jendela kernel.Jadi aplikasi modus pengguna tidak dapatlangsung mengakses atau memodifikasi tabel halaman. Tentu saja jika moduskernel driver ingin melakukan itu, ia bisa melakukan hal itu karena sekali Andaberada dalam mode kernel, Anda hampir memiliki seluruh sistem.Untukmemahami hal ini secara lebih rinci, baca bagian berikutnya pada Windows tataletak memori logis di bawah ini.5.Jendela Logical Memory Tata Letak Windowsmemberikan 2GB lebih rendah (atau 3GB tergantung pada boot.ini switch) ruangalamat logis dari suatu proses ke mode pengguna dan 2GB atas (atau 1GBtergantung pada boot.ini switch) untuk kernel Windows.Dari total ruang alamatkernel, itu cadangan alamat dari 0xC0000000 sampai 0xC03FFFFF untukHalaman Tabel dan Direktori Halaman.Setiap proses memiliki Halaman Tabelyang terletak di alamat logis 0xC0000000 dan direktori halaman yang terletak dialamat logis 0xC0300000.Ini pengaturan memori logis adalah sebagai berikut:Alamat logis 0x00000000 0x80000000 ........................ ...... 0xC0000000 ...0xC0400000 ...... 0xFFFFFFFF

    8VHU0 RGH.HUQHO0 RGHCopyright http://www.intellectualheaven.com

    Halaman 4 dari 5

    Anda dapat menggunakan Windows kernel debugger kd atau WinDbg untukmemverifikasi ini (lihat pte! Dan! Vtop debugger extenstions).Alamat fisik inidirektori halaman disimpan dalam CR3.1024 alamat mulai dari 0xC0300000mewakili Halaman Direktori entri (PDE).Setiap PDE berisi alamat fisik 4 byteyang menunjuk ke sebuah Tabel Halaman.Setiap Tabel Halaman memiliki 1024entri yang baik berisi alamat fisik menunjuk ke halaman fisik 4KB atau berisientri yang tidak valid.Hal ini juga dibahas di atas paging prosesor dan bagianhalaman manajemen tabel Windows, tetapi diulang lagi di sini demi kejelasan.

  • 7/28/2019 winMM32

    10/11

    Jadi kenapa Windows yang menggunakan alamat logis 0xC000000000 untukmenyimpan Tabel Page dan alamat 0xC0300000 untuk menyimpan direktorihalaman?Persyaratan untuk menyimpan tabel halaman dalam memori adalahbahwa aplikasi modus pengguna rouge tidak harus dapat memanipulasi tabelhalaman.Oleh karena tabel halaman harus dalam ruang alamat logiskernel.

    Windows biasanya memberikan ruang 2GB lebih rendah untuk proses dancadangan 2GB atas untuk kernel.Tapi dengan boot.ini khusus switch / 3GB,

    memungkinkan proses mode pengguna untuk mengakses memori 3GB lebihrendah.0xC0000000 adalah alamat berikutnya setelah 3GB dan jadi saya kira itusebabnya dipilih untuk direktori halaman menyimpan dan tabel halaman. Adabeberapa aspek penting lainnya untuk halaman tabel dan tata letak halamandirektori dalam memori.Untuk memahami itu, mari kita lihat bagaimanahalaman tabel dan direktori halaman diletakkan.Untuk membuatnya mudahdipahami, saya telah menarik tabel halaman untuk proses palsu denganmasukan yang relevan disorot.Perhatikan bahwa setiap entri indeks adalah 4byte dalam ukuran.P_PT mewakili alamat fisik Tabel Halaman.Indeks

    Alamat logis

    0x0

    0x1

    .

    0x80

    .

    0x300 (768)

    0x34A (842)

    .

    .

    0x400 (1023)

    0xC0000000 0x6A078 # # #

    0x10480 # # # -

    0xC0001000 0x45045 # # #

    - 0x34005 # # #

    0xC0002000 - 0xC0100000 - 0xC0300000 0x13453 # # # P_PT 0x6A078 # # # -P_PT 0x45045 # # # - PDB 0x13453 # # # - 0xC0301000 - 0xC03FF000

    PDB merupakan alamat fisik dari halaman direktori dasar proses yang sesuaiyakni mewakili alamat fisik yang sesuai dengan alamat logis 0xC0300000 untukproses itu.Nilai ini juga disimpan dalam CR3.Ingat hanya Windows dapatmenggunakan alamat logis untuk mengakses lokasi memori termasuk direktori

    halaman, sehingga untuk mengakses direktori halaman dan tabel, perlu untuk

  • 7/28/2019 winMM32

    11/11

    menempatkan beberapa entri referensi diri dalam direktori halaman.Entrialamat fisik ditampilkan

    Copyright http://www.intellectualheaven.com

    Halaman 5 dari 5

    di atas akan berbeda untuk setiap proses tetapi setiap proses akan memilikientri PDB yang disimpan pada indeks 0x300 direktori PT.

    Kami akan melakukan logis untuk terjemahan alamat fisik pada 4 alamat yangberbeda untuk melihat pentingnya pemasukan PDB, Halaman meja tata letakdan bagaimana sebenarnya bekerja terjemahan alamat. Alamat yang akan kitamenerjemahkan adalah 0x2034AC54, 0xC0000000, 0xC0300000, 0xC0300000[0x300] yaitu 0xC030C00.Alamat pertama adalah pengguna modus alamat logisnormal untuk sebuah proses, alamat kedua adalah alamat logis pertama daritabel halaman pertama dalam ruang alamat logis, alamat ketiga adalah alamatlogis halaman basis direktori dan alamat keempat adalah alamat logis dari entri

    khusus sebagai Anda akan melihat selama terjemahan.Asumsikan CR3 poin kealamat fisik 0x13453 # # #.Seperti yang ditunjukkan sebelumnya, bit 12 lebihrendah digunakan untuk menyimpan informasi perlindungan halaman daninformasi lainnya yang dibutuhkan oleh sebuah OS.Ini adalah keluar dari ruanglingkup pembahasan kita saat ini sehingga saya telah menunjukkan merekasebagai # # #.Atas 20 bit mewakili Jumlah Halaman Bingkai atau PFN yangmerupakan alamat fisik dari sebuah halaman selaras 4KB.Alamat fisik yangsebenarnya sesuai PFN akan 0x13453000.Mari kita melakukan terjemahan:1.0x2034AC54 o 0x2034AC54 dapat direpresentasikan sebagai 00100000001101001010 110001010100 o atas 10 bit yang 0010000000 memberikan indekske direktori halaman.Konversi ke heksadesimal, atas 10 bit memberikan nilai0x080 o Dari CR3, kita tahu Direktori Halaman terletak di alamat fisik0x13453000 dan dari pembahasan di atas kita juga tahu bahwa DirektoriHalaman terletak di alamat logis 0xC0300000 o Jadi 0xC0300000 [0x080] akanmemberikan alamat tabel halaman yang P_PT.Dari tabel di atas, kita dapatmelihat bahwa alamat ini diwakili oleh tabel halaman di alamat logis0xC00001000 (atau alamat fisik 0x45045000).Sekarang kita menggunakan 10bit berikutnya yaitu 1101001010 (atau 0x34A) untuk indeks ke tabel halaman. oAlamat 0xC00001000 [0x34A] akan memberi kita alamat fisik dari sebuahhalaman 4KB yang 0x34005000 dari tabel di atas.o Jumlah diwakili oleh bit yanglebih rendah 12, yaitu 110.001.010.100 (atau 0xC54), digunakan untuk merujukpada byte yang sebenarnya pada halaman 4KB terletak di 0x34005000. Alamatfisik akhir sesuai dengan 0x2034AC54 keluar menjadi 0x34005C54

    Aku akan meninggalkan terjemahan alamat 3 alamat lain sebagai latihan bagipembaca.Setelah Anda melakukan terjemahan itu, Anda akan memahamimengapa entri PDB disimpan pada indeks 0x300 pada tabel di atas dan hal itumenyebabkan prosesor untuk mengobati direktori halaman sebagai tabelhalaman selama terjemahan alamat.Juga terjemahan ini akan memberikaninformasi lebih lanjut tentang mengapa hal ini tata letak khusus dipilih olehdesainer jendela.6.Referensi 1.Di dalam Windows 2000 oleh David A. Solomon& Mark Russinovich E. 2.Berdokumen Windows 2000 rahasia oleh Sven B.Schreiber