LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1200|回复: 1

struct vm_area_struct **pprev双指针的 问题

[复制链接]
发表于 2007-12-23 15:40:58 | 显示全部楼层 |阅读模式
//linux/mm/mmap.c
/* Insert vm structure into process list sorted by address
* and into the inode's i_mmap ring.  If vm_file is non-NULL
* then the i_shared_lock must be held here.
*/
void __insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vmp)
{
        struct vm_area_struct **pprev;
        struct file * file;

        if (!mm->mmap_avl) {
                pprev = &mm->mmap;
                while (*pprev && (*pprev)->vm_start <= vmp->vm_start)
                        pprev = &(*pprev)->vm_next;
        } else {
                struct vm_area_struct *prev, *next;
                avl_insert_neighbours(vmp, &mm->mmap_avl, &prev, &next);
                pprev = (prev ? &prev->vm_next : &mm->mmap);
                if (*pprev != next)
                        printk("insert_vm_struct: tree inconsistent with list\n");
        }
        vmp->vm_next = *pprev;
        *pprev = vmp;

        mm->map_count++;
        if (mm->map_count >= AVL_MIN_MAP_COUNT && !mm->mmap_avl)
                build_mmap_avl(mm);

        file = vmp->vm_file;
        if (file) {
                struct inode * inode = file->f_dentry->d_inode;
                struct address_space *mapping = inode->i_mapping;
                struct vm_area_struct **head;

                if (vmp->vm_flags & VM_DENYWRITE)
                        atomic_dec(&inode->i_writecount);

                head = &mapping->i_mmap;
                if (vmp->vm_flags & VM_SHARED)
                        head = &mapping->i_mmap_shared;
      
                /* insert vmp into inode's share list */
                if((vmp->vm_next_share = *head) != NULL)
                        (*head)->vm_pprev_share = &vmp->vm_next_share;
                *head = vmp;
                vmp->vm_pprev_share = head;
        }
}




请问这里 struct vm_area_struct **pprev双指针 做什么 用 ?不用双指针 不行 吗
发表于 2007-12-27 13:19:43 | 显示全部楼层
二级指针的 使用主要是 为了 方便 对 链表头的 操作,在函数中如果没有使用二级指针直接改变了链表头,那么在该函数返回后,链表头就 不知道指的是那里了。在内核中我看到的 所有涉及链表头操作的函数都使用了二级指针。主要是C是值传递。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表