阅读:1836回复:1
使用mmap发生错误,谁知道这是怎么回事
字符驱动的mmap函数是这么写的:
static int led_mmap (struct file *file, struct vm_area_struct *vma){ char *p; int size = vma->vm_end - vma->vm_start; p = (char *)vmalloc(PAGE_SIZE); vma->vm_pgoff=(int)virt_to_phys(p)>>PAGE_SHIFT; vma->vm_flags ¦= VM_IO; printk("\nled_mmap:%s[%d]:%s() mmap %dbytes\n",__FILE__,__LINE__,__FUNCTION__,size); printk("mmap succeded size=%x\n",size); printk(KERN_NOTICE "Simple VMA open, virt %lx, phys %lx\n", vma->vm_start, vma->vm_pgoff < < PAGE_SHIFT); if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, vma->vm_end - vma->vm_start, vma->vm_page_prot)) return -EAGAIN; return 0; } 应用程序是这些写的: char *maddr; int fd; fd = open("/dev/led",O_RDONLY); if(fd <0)exit(1); maddr = mmap(NULL,0x100, PROT_NONE, MAP_SHARED, fd,0); printf("maddr=%x errno =%x\n", (int )maddr,errno); *maddr = 0; printf(" %.2x ",*(char *)maddr); 结果却是这样的,有谁知道这是怎么回事吗? maddr=40006000 errno =0 Segmentation fault |
|
沙发#
发布于:2008-03-28 18:29
出现了段错误,一般是内存访问出错造成的,可能是内存范围超出了
|
|