caoshufengcao 2016-10-21 14:05 采纳率: 0%
浏览 2503

linux内核模块调用内核中的函数

我编写了一个简单的内核模块,想验证一下内核workqueue的功能。
如下:

 #include <linux/module.h>
#include <linux/init.h>
#include <linux/workqueue.h>
#include <linux/sched.h>
#include <linux/nsproxy.h>

//static struct workqueue_struct *queue=NULL;  
//extern int copy_namespaces(unsigned long flags, struct task_struct *tsk);
static struct work_struct   work;

static void work_handler(struct work_struct *data)
{
       struct task_struct *base_task = find_task_by_vpid(18572);
       printk(KERN_ALERT"work handler function.\n");
       printk(KERN_ALERT"current--------> %d.\n", current->pid);
       //copy_namespaces(CLONE_NEWUTS, current);
       get_nsproxy(base_task->nsproxy);
       switch_task_namespaces(current, base_task->nsproxy);
}

static int __init test_init(void)
{
      //queue=system_unbound_wq
      //create_singlethread_workqueue("hello world");/*创建一个单线程的工作队列*/  
      //if (!queue)  
      //      goto err;  

       INIT_WORK(&work,work_handler);
       queue_work(system_unbound_wq, &work);

      return 0;
}

static   void __exit test_exit(void)
{
       //destroy_workqueue(queue);  
        printk(KERN_ALERT "caoshufeng module exit");
}
MODULE_LICENSE("GPL");
module_init(test_init);
module_exit(test_exit);

这是makefile:
obj-m += queue.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

模块make成功,但是无法insomd

dmesg中有如下错误:
[ 9806.426471] queue: Unknown symbol switch_task_namespaces (err 0)
[ 9806.426554] queue: Unknown symbol find_task_by_vpid (err 0)

我已经include了相应的头文件,为啥还是找不到symbol呢?

  • 写回答

2条回答 默认 最新

  • devmiao 2016-10-21 15:37
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题