LinuxSir.cn,穿越时空的Linuxsir!

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

使用do_mmap_pgoff出现的问题

[复制链接]
发表于 2007-11-22 21:49:02 | 显示全部楼层 |阅读模式
我写了一个模块,反复映射内存,然后去除映射,结果总是出错,错误为:
Nov 22 14:22:15 node2 kernel: do_munmap error =-22  invalid argument
Nov 22 14:22:15 node2 kernel: end i=348837


以下为内核模块代码,请大家帮忙看看:



#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <asm/mman.h>


static int __init tpgoff_init(void)
{
  int error = 0;
  unsigned long ubuf=0;
  size_t count = 0;
  unsigned long i=0;
  unsigned long t=1000000;
  
  printk("tpgoff kernel module init!\n");

        count = 1024 * 1024;
        for (i=0;i<t;i++) {
                 ubuf = 0;
                 down_write(&current->mm->mmap_sem);
                 ubuf = do_mmap_pgoff(NULL, 0, count, PROT_READ|PROT_WRITE,
                                MAP_PRIVATE|MAP_ANONYMOUS, 0);
                 up_write(&current->mm->mmap_sem);
                 if (ubuf==0) {
                       printk("ubuf=0\n");
                       return 0;
                }
                if (ubuf!=0) {
                    error = do_munmap(NULL, ubuf, count);
                    if (error) {
                        printk("do_munmap error =%d\n",error);
                        break;
                   }
               }
          }

  printk("end i=%ld\n",i);
  return error;

}


static void __exit tpgoff_cleanup(void)
{

  printk("tpgoff kernel module exit!\n");

}

module_init(tpgoff_init);
module_exit(tpgoff_cleanup);
MODULE_LICENSE("Dual BSD/GPL");
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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