- unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
- /* */
- 872 unsigned long len, unsigned long prot,
- 873 unsigned long flags, unsigned long pgoff)
- 874 {
- ......
- munmap_back:
- 1009 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
- 1010 if (vma && vma->vm_start < addr + len) {
- 1011 if (do_munmap(mm, addr, len))
- 1012 return -ENOMEM;
- 1013 goto munmap_back;
- 1014 }
刚开始始终对1009行后的代码很费解,为什么在
= 之后还要检查是否有老的已经被映射的区域?
按理说通过get_unmapped_area函数找到的空闲线性内存区 一定满足addr+len >vma_start
这里还要检查不是永远为假吗 除非出现BUG?
设想这样一种情况,我们人为的指定addr并且指定了MAP_FIXED标志,那么addr后的第一个VMA(如果存在)如果满足addr+len < VMA->vm_start OK....
但是如果这时我要求的addr+len 与你应经映射的线性区间重叠或者有交集,那么对不起,你必须给我让地,因为我有令牌 MAP_FIXED 这时就要调用do_munmap函数 解除这个VMA的映射。。。
Note:MAP_FIXED Do not select a different address than the one specified. If the memory region specified by start and len overlaps pages of any existing mapping(s), then the overlapped part of the existing mapping(s) will be discarded. If the specified address cannot be used, mmap() will fail. If MAP_FIXED is specified, start must be a multiple of the page size. Use of this option is discouraged.
阅读(2348) | 评论(0) | 转发(0) |