我正在尝试访问物理内存地址0x30000000
,我正在尝试使用mmap()
来完成此操作。当我将此地址映射到虚拟地址指针时,我无法从内存中读取正确的值。当我使用调试器(TI Code Composer Studio w / JTAG)查看内存时,我能够看到内存中的值,但我的代码中没有得到相同的值?我正确使用mmap()
吗?
off_t dev_base = 0x30000000;
size_t ldev = 0x3FFFFFF;
int offset = 0x00;
memfd = open("/dev/mem", O_RDWR | O_SYNC);
mapped_base = (int*)mmap(0, ldev, PROT_READ|PROT_WRITE, MAP_SHARED, memfd, dev_base);
if (mapped_base == MAP_FAILED)
{
errx(1, "mmap failure");
}
printf("mapped_base = %08p\n", mapped_base);
printf("The value at address [%08p] = %08p\n", offset + ((int)mapped_base), mapped_base[offset/4]);
munmap(mapped_base, ldev);
close(memfd);
答案 0 :(得分:0)