Hi All,
I am using the Linux kernel 2.6.11 and I am having problems reading from /dev/kmem (though /dev/mem works fine). Both mmap and read on kmem is having problem. On my i386 machine I am trying to execute the following code and I am getting the errors
mmap failed: Input/output error
lseek returns c04a6000
read returns -1
read: Invalid argument
Would appreciate if someone could point out the problem.
Regards
Don
Send instant messages to your online friends http://in.messenger.yahoo.com
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/mman.h> #include <stdio.h> #include <unistd.h> #include <errno.h> main() { int fd; int addr; int x; fd = open("/dev/kmem", O_RDWR | O_SYNC ); if(fd < 0) { perror("opening /dev/mem error:"); exit(1); } addr = (int) mmap(NULL, 4096 , PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0xC04a6000); if(addr == -1) { perror("mmap failed:"); //exit(1); } else printf("addreass read is %x\n",*(unsigned int *) (addr )); printf("lseek returns %x\n",lseek(fd, 0xC04a6000,SEEK_SET)); printf("read returns %d\n",read(fd, (char *)&x, 4)); }