CS 635 PROJECT 5 Due Date: Noon Friday 05/09/2003 The purpose of this project is to construct a tool for studying the mapping of virtual memory areas and to acquaint students with details of of the processor's paging mechanism for virtual address translations. PROJECT STATEMENT Write an enhanced version of the 'vma.c' module (named 'vmaplus.c') that will display the physical address to which each virtual memory area has been mapped, together with that virtual memory area's size expressed as a hexadecimal number of bytes. Use the 'mmstudy1.cpp' program (found on our class website) to test your enhanced module: ----------------------------- SAMPLE OUTPUT ----------------------------- List of the Virtual Memory Areas for task 'mmstudy1' (pid=882) 1 vm_start=08048000 vm_end=08049000 r-xp base=1D2FA000 size=00001000 2 vm_start=08049000 vm_end=0804A000 rw-p base=1CDDA000 size=00001000 3 vm_start=0804A000 vm_end=0804B000 rwxp base=00000000 size=00001000 4 vm_start=40000000 vm_end=40012000 r-xp base=1FC87000 size=00012000 5 vm_start=40012000 vm_end=40013000 rw-p base=1D2EA000 size=00001000 ........... --------------------------------------------------------------------------- METHODOLOGY Linux provides several kernel functions to help systems programmers manipulate the paging structures in a manner which is independent of the particular underlying cpu architecture: struct mm_struct *mmp = vma->vm_mm; pgd_t *pgd = pgd_offset( mmp, virt_address ); pmd_t *pmd = pmd_offset( pgd, virt_address ); pte_t *pte = pte_offset( pmd, virt_address ); unsigned long page_base = pte->pte_low & PAGE_MASK; unsigned long page_part = virt_address % PAGE_SIZE; unsigned long phys_address = page_base + page_part; Alternatively, you may write your own code that directly manipulates the Pentium progessor's Page Directory and Page Tables (which is instructive as an exercise in itself, to clarify the operation of these structures). struct mm_struct *mmp = vma->vm_mm; unsigned long *dir = (unsigned long*)mmp->pgd; unsigned long dir_index = virt_address >> 22; unsigned long *tbl = dir[ dir_index ] & PAGE_MASK; unsigned long tbl_index = virt_address >> 12; unsigned long *frm = tbl[ dir_index ] & PAGE_MASK; unsigned long page_base = (unsigned long)frm; unsigned long page_part = virt_address % PAGE_SIZE; unsigned long phys_address = page_base + page_part; ________________________________________________________________________ (C) Allan B. Cruse University of San Francisco Spring 2003