我正试图在用户空间使用微粒,读一下从肉体开始的记忆。 它包含所有物理页。 这台机器是1 386台,运行3台。
这部法典就是这样:
....
//define page size
//
#define PAGE_SIZE 0x1000 //4096 bytes
#define PAGE_MASK (PAGE_SIZE - 1)
....
/* open /dev/mem file*/
if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) {
printf("/dev/mem could not be opened.
");
perror("open");
exit(1);
} else {
printf("/dev/mem opened.
");
}
/* Map one page */
printf(" mem_map is at physical addr: 0x%x
", mem_map_phy_addr);
map_base = mmap(0, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, (mem_map_phy_addr & ~PAGE_MASK)); //mem_map_phy_addr is at 0x356f2000
if(map_base == (void *) -1) {
printf("Memory map failed. err num = %d
",errno);
perror("mmap"); //failed here
} else {
printf("Memory mapped at address %p.
", map_base);
}
I ran this as a root. The output is:
/dev/mem opened.
mem_map is at physical addr: 0x356f2000
Memory map failed. err num = 1
mmap: Operation not permitted
我肯定会把这一问题推向我/etc/sysctl.conf的档案,并添加以下内容:
vm.mmap_min_addr = 0
但这也不可行。
Anyone knows why mem_map operation like this is not permitted and how I can get around it?
感谢。