//------------------------------------------------------------------- // vma.c // // This module creates a '/proc' pseudo file which allows users // to view information about the process memory map for a task. // This Linux kernel structure lists the various virtual memory // areas that are associated with the particular task. // // programmer: ALLAN CRUSE // written on: 20 FEB 2003 // revised on: 26 APR 2003 -- to also show VM_SHARED (1=s, 0=p) // revised on: 20 SEP 2004 -- for Linux kernel version 2.4.26 //------------------------------------------------------------------- #include // for init_module() #include // for create_proc_read_entry() static int my_proc_read( char *buf, char **start, off_t off, int count, int *eof, void *data ) { struct task_struct *tsk = current; struct vm_area_struct *vma; unsigned long ptdb; int i = 0, len = 0; // display title len += sprintf( buf+len, "\n\nList of the Virtual Memory Areas " ); len += sprintf( buf+len, "for task \'%s\' ", tsk->comm ); len += sprintf( buf+len, "(pid=%d)\n", tsk->pid ); // loop to traverse the list of the task's vm_area_structs vma = tsk->mm->mmap; while ( vma ) { char ch; len += sprintf( buf+len, "\n%3d ", ++i ); len += sprintf( buf+len, " vm_start=%08X ", vma->vm_start ); len += sprintf( buf+len, " vm_end=%08X ", vma->vm_end ); ch = ( vma->vm_flags & VM_READ ) ? 'r' : '-'; len += sprintf( buf+len, "%c", ch ); ch = ( vma->vm_flags & VM_WRITE ) ? 'w' : '-'; len += sprintf( buf+len, "%c", ch ); ch = ( vma->vm_flags & VM_EXEC ) ? 'x' : '-'; len += sprintf( buf+len, "%c", ch ); ch = ( vma->vm_flags & VM_SHARED ) ? 's' : 'p'; len += sprintf( buf+len, "%c", ch ); vma = vma->vm_next; } len += sprintf( buf+len, "\n" ); // display additional information about tsk->mm asm(" movl %%cr3, %%eax \n movl %%eax, %0 " : "=m" (ptdb) ); len += sprintf( buf+len, "\nCR3=%08X ", ptdb ); len += sprintf( buf+len, " mm->pgd=%08X ", tsk->mm->pgd ); len += sprintf( buf+len, " mm->map_count=%d ", tsk->mm->map_count ); len += sprintf( buf+len, "\n\n" ); return len; } void cleanup_module( void ) { remove_proc_entry( "vma", NULL ); } int init_module( void ) { create_proc_read_entry( "vma", 0, NULL, my_proc_read, NULL ); return 0; // SUCCESS } MODULE_LICENSE("GPL");