I am trying to access physical address through the /dev/mem
without success. I can access the address space reserved for PCI devices but when I try to map my memory I get error. (I have mapped the virtual to physical through the pagemap interface).
I have added the nopat to the kernel command line and I am running my program as root.
- virtual address: 0x7f925a266000
- physical address: 0x1d3a66000
I have also tried aligning it to huge page boundaries without success.
Using the following code, mmap
returns -1.
int *addr;
if ((fd = open("/dev/mem", O_RDWR|O_SYNC)) < 0 ) {
printf("Error opening file. \n");
close(fd);
return (-1);
}
addr = (int *)mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0x1d3a66000);
//error message: Operation not permitted, no logs with dmesg
printf("addr: %p \n",addr);
printf("addr: %d \n",*addr); /* CRASH. */
Any ideas on how I can make it work, or if it's not possible through /dev/mem
is there other way to map physical addresses? I am running Ubuntu with the latest kernel version.
Edit: I have recompiled the kernel without the strict_devmem as @yano suggested and the problem is fixed.