#include #include #include #include #include int main( void ) { char *ptr; int fd; long i; char z; fd = open( "/dev/mem", O_RDONLY, 0666 ); if( fd < 0 ) { perror( "open /dev/mem" ); exit( 1 ); } /* map in 1G worth of physical RAM */ ptr = mmap( NULL, 0x40000000L, PROT_READ, MAP_SHARED, fd, 0 ); if( ptr == (void *) -1 ) { perror( "mmap" ); exit( 1 ); } /* print out memory at 8 meg intervals. 8M * 128 = 1024M */ for( i = 0; i < 128; i++ ) { /* -> for mmap */ printf( "%02lx -> %x\n", i, ptr[8 * 1024 * 1024 * i] ); /* => for lseek/read */ if( lseek( fd, 8 * 1024 * 1024 * i, SEEK_SET ) < 0 ) { perror( "lseek" ); exit( 1 ); } if( read( fd, &z, 1 ) != 1 ) { perror( "read" ); exit( 1 ); } printf( "%02lx => %x\n", i, z ); } return 0; }