文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>内核target中的checkentry和destroy函数使用时需..

内核target中的checkentry和destroy函数使用时需..

时间:2007-04-19  来源:目的

环境:linux-2.4.32 arm
有这样一段代码,本意是想在加载一条iptables rule的时候申请一块内存并且设定一个timer使得每隔一段时间去执行一个函数:

static int
checkentry(const char *tablename,
                   const struct ipt_entry *e,
           void *targinfo,
           unsigned int targinfosize,
           unsigned int hook_mask)
{
        int i;

        clog = kmalloc(sizeof(struct ipt_clog),GFP_KERNEL);
        spin_lock_init( &(clog->lock) );
        for( i = 0; i < 256; i++ )
                INIT_LIST_HEAD(&(clog->iphash[i]));
        init_timer( &(clog->timer) );
        clog->timer.expires = conn_limit_ip.interval * HZ + jiffies;
        clog->timer.function = log_push;
        clog->timer.data = clog ;
        add_timer(&(clog->timer));

        return 1;
}

destroy的代码:

static void destroy( void *targinfo, unsigned int targinfosize )
{
        struct timer_list *timer = &(clog->timer);
        if(timer_pending(timer))
        {
                del_timer(timer);
        }
        kfree( clog );
}


这两段代码从逻辑上和编写上看似没有问题。可是在系统启动自动加载该规则会出现kernel panic。调试后知道checkentry会被调用N次,这个N和什么有关还没有搞清楚。然后后面申请的内存和第一次申请的内存地址不相同。而且checkentry 被调用的时候destroy也会被调用。这两个是成对出现的。
具体的原因恐怕要看内核中的代码实现了。
相关阅读 更多 +
排行榜 更多 +
步行僵尸2无限金币版

步行僵尸2无限金币版

体育竞技 下载
狐狸一号特殊任务无限金币版

狐狸一号特殊任务无限金币版

体育竞技 下载
忍者之雷复仇无限金币钻石版

忍者之雷复仇无限金币钻石版

体育竞技 下载