使用mmap从/ dev / mem读取

时间:2019-06-24 12:28:48

标签: c mmap

我正在尝试从物理地址读取。

printf函数的输出为空:“ value =”

我做错了什么?

int counter;
int fd;
char* mmap_res;

fd = open("/dev/mem", O_RDWR);

if (fd == -1)
{
    printf("can not access /dev/mem\n" );
    return -1;
}

mmap_res =
    (char*)mmap(NULL, 4096, PROT_READ | PROT_WRITE,
                MAP_SHARED, fd, 0x92000000);

for (counter = 0; counter < 10 ; counter++)
    printf("value=%c\n",mmap_res[counter]);

if (mmap_res == MAP_FAILED)
{
    printf("mmap failed\n" );
    return -1;
}

0 个答案:

没有答案