- 论坛徽章:
- 0
|
安装的CentOS 5.3,内核版本2.6.18-128 DELL R710服务器
在一个ko中申请内存
g_ct_addr = __get_free_pages(GFP_ATOMIC, 1);
mem_map_reserve(virt_to_page(g_ct_addr));
create_proc_read_entry("abc", 0, NULL, aaa, NULL);
memcpy((void *)g_ct_addr, "abcdefghijklmnopqrstuvwxyz", 27);
在应用程序中读出来
int fd=open("/dev/mem",O_RDWR);
int fd_procaddr = open("/proc/abc",O_RDONLY);
if( fd_procaddr == 0)
{
printf( "zero mem file no found!n" ;
exit(0);
}
char abc[4*1024] = {0};
read(fd_procaddr,abc, ;
close(fd_procaddr);
off_t CTRLADDR = 0;
sscanf( abc, "%08x", &CTRLADDR );
void *g_ct_addr = mmap(0, 1, PROT_READ, MAP_SHARED|MAP_LOCKED, fd, CTRLADDR);
if (MAP_FAILED == g_ct_addr)
{
printf("AAA %lu %s\n", errno, strerror(errno));
exit(0);
}
mmap是时候返回EPERM,dmesg显示tried to read /dev/mem between 3770e000->3770f000
看了一下内核代码,
int devmem_is_allowed(unsigned long pagenr)
{
if (pagenr <= 256)
{
printk("AAA: %lu\n", pagenr);
return 1;
}
if (!page_is_ram(pagenr))
{
printk("BBB: %lu\n", pagenr);
return 1;
}
return 0;
}返回了0
if (!devmem_is_allowed(pfn))
{
printk (" rogram %s tried to read /dev/mem between %Lx->%Lx.\n",
current->comm, from, to);
return 0;
}也返回0
这是怎么回事 |
|