* Strange /dev/mem behaviour on IA32, PPC64, (others?)
@ 2005-02-13 3:46 Ryan Lortie
0 siblings, 0 replies; only message in thread
From: Ryan Lortie @ 2005-02-13 3:46 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1174 bytes --]
There are a couple of problems that I have encountered with /dev/mem on
the 2.6.10 kernel.
The first problem is that lseek()/read() results in different data than
mmap() and reading from the mapped memory area. I've written a small
program to demonstrate the problem. I am fairly sure it is correct (a
few others haved looked over it). The program produces unexpected
output when I run it on both IA32 and PPC64. You need to have at least
1GB of RAM to run it, but it is easy to modify if you have less.
In short, lseek()/read() returns what I believe to be the correct
values. Reading from the mmap() region gives the correct values for the
first few reads but after that it starts giving zeros.
In testing this program on IA32 I ran into an additional problem. If
you lseek() to the (very suspicious) 896MB mark and read() then read
gives EFAULT (Bad address).
I have high memory support enabled and the 'free' command reports:
total
Mem: 1036172
so seeking should be OK all the way up to 1GB.
Any information about these problems (including "you're wrong
because....") is appreciated. I'm not on the list, so please Cc:
replies.
Cheers.
[-- Attachment #2: fetch.c --]
[-- Type: text/x-csrc, Size: 920 bytes --]
#include <sys/mman.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-02-13 3:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-13 3:46 Strange /dev/mem behaviour on IA32, PPC64, (others?) Ryan Lortie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®