//------------------------------------------------------------------- // showvmap.cpp // // This program shows a map of the virtual memory space, based // on information in the task_struct's 'mm->pgd[]' array which // is obtained by reading the '/proc/vmap' pseudo-file. (Note // that the 'vmap.o' module must be in the current directory.) // // programmer: ALLAN CRUSE // written on: 03 OCT 2004 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for read(), close() char filename[] = "/proc/vmap"; int main( int argc, char **argv ) { //------------------------------------ // install the required kernel module //------------------------------------ system( "/sbin/insmod vmap.o" ); //---------------------------------- // open the pseudo-file for reading //---------------------------------- int fd = open( filename, O_RDONLY ); if ( fd < 0 ) { perror( filename ); exit(1); } //------------------------------ // read the array of characters //------------------------------ char buffer[ 1024 ]; int nbytes = read( fd, buffer, 1024 ); if ( nbytes < 1024 ) { perror( "read" ); exit(1); } //---------------------------------------------------- // close the pseudo-file and unload the kernel module //---------------------------------------------------- close( fd ); system( "/sbin/rmmod vmap" ); //-------------------------------------------------- // display a nicely formatted map of virtual memory //-------------------------------------------------- printf( "\n\t\t\tMap of virtual memory-space\n" ); for (int i = 0; i < 1024; i++) { if ( ( i % 64 ) == 0 ) printf( "\n " ); if ( ( i % 16 ) == 0 ) printf( " " ); int ch = ( buffer[i] & 7 ) | 0x30; if ( ch == '0' ) ch = '.'; printf( "%c", ch ); } printf( "\n\n" ); }