访问IRQ描述阵列模块内和显示操作名称 [英] Accessing IRQ description array within a module and displaying action names

查看:280
本文介绍了访问IRQ描述阵列模块内和显示操作名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编程在C内核模块是奋力访问IRQ描述数组元素和显示这些元素的所有动作名。

在开始的时候,我以为这irq_desc数组sonething像宏,但编译后,我明白事实并非如此。然后我用for_each_irq_desc(IRQ,DESC)功能。但这次返回的警告:

警告:irq_to_desc[/home/samet/Masaüstü/Assignment3/Ass-1.ko]未定义

和此警告后,我试图模块将insmod到内核这一次的错误消息弹出:

insmod的:错误插入'./Ass-1.ko':-1模块未知符号

在这之后我加入,我认为有关这一过程的所有头文件,但没有改变。

因为它是非常短的我附上code:

 的#include< Linux的/  -  module.h中GT;
#包括LT&;的Linux / kernel.h>
#包括LT&; Linux的/ init.h中>
#包括LT&; Linux的/ sched.h中>
#包括LT&; Linux的/ irq.h>
#包括LT&; Linux的/ irqdesc.h>
#包括LT&; Linux的/ irqnr.h>结构的task_struct * P;
结构irq_desc * irqElement;
INT IRQ,递减;静态INT __init ass_1_init(无效)
{
    printk的(KERN_INFO驴-1模块开始...... \\ n);    for_each_process(P){printk的(%d个\\ t%S \\ n,P-> PID,P-> COMM);}    for_each_irq_desc(IRQ,irqElement){printk的(%P \\ N,irqElement);}    返回0;
}静态无效__exit ass_1_exit(无效)
{
    printk的(KERN_INFO驴-1模块完成... \\ n);
}宏module_init(ass_1_init);
宏module_exit(ass_1_exit);


解决方案

我觉得你真的高估了自己的能力。这是我第一次的Hello World内核模块。但是,如果有的话,经验告诉我,程序员为王。如果你想要的东西,把它定义。

内核头不希望暴露IRQ对模块,这是明确的,所以我敢肯定,这将不被支持,这可能是一般一个坏主意。但我们不关心这个。我们是黑客!

 的#include< Linux的/  -  module.h中GT;
#包括LT&;的Linux / kernel.h>
#包括LT&; Linux的/ init.h中>
#包括LT&; Linux的/ sched.h中>
#包括LT&; Linux的/ irq.h>
#包括LT&; Linux的/ irqnr.h>
#包括LT&; Linux的/ irqdesc.h>#定义irq_to_desc(IRQ)(安培; irq_desc [IRQ])
#定义NR_IRQS NR_IRQS
结构irq_desc irq_desc [NR_IRQS]结构irq_desc * irqElement;
INT IRQ;
INT的init_module(无效)
{
    printk的(KERN_INFO我HAZ模块\\ n);
    for_each_irq_desc(IRQ,irqElement){printk的(%P \\ N,irqElement);}
    返回0;
}虚空在cleanup_module(无效)
{
    printk的(KERN_INFO白MODULE !!! 1 \\ n);
}

I am programming a kernel module in C which is struggling to access IRQ description array elements and to display all action names of these elements.

At the beginning, I thought that this irq_desc array is sonething like a macro but after compiling i understood it is not. Then I used for_each_irq_desc(irq, desc) function. but this time it returned a warning:

WARNING: "irq_to_desc" [/home/samet/Masaüstü/Assignment3/Ass-1.ko] undefined!

and after this warning, i tried to insmod the module into kernel this time an error message popped:

insmod: error inserting './Ass-1.ko': -1 Unknown symbol in module

after this i included all header files that i think relevant to this process, but nothing changed.

since it is very short i am attaching the code:

#include <linux/module.h>   
#include <linux/kernel.h>   
#include <linux/init.h>     
#include <linux/sched.h>    
#include <linux/irq.h>
#include <linux/irqdesc.h>
#include <linux/irqnr.h>

struct task_struct* p;
struct irq_desc* irqElement;
int irq, desc;

static int __init ass_1_init(void)
{
    printk(KERN_INFO "Ass-1 module is starting...\n");

    for_each_process(p){printk("%d\t%s\n", p->pid, p->comm);}

    for_each_irq_desc(irq, irqElement){printk("%p\n", irqElement);}

    return 0;
}

static void __exit ass_1_exit(void)
{
    printk(KERN_INFO "Ass-1 module is finishing...\n");
}

module_init(ass_1_init);
module_exit(ass_1_exit); 

解决方案

I think you really overestimate my abilities. This is my first hello world kernel module. But if anything, experience has taught me that the programmer is king. If you want something, define it.

The kernel headers don't want to expose irq's to modules, that's clear, so I'll bet this won't be supported and this may be generally a bad idea. But we don't care about that. We're hackers!

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>     
#include <linux/sched.h>    
#include <linux/irq.h>
#include <linux/irqnr.h>
#include <linux/irqdesc.h>

#define irq_to_desc(irq)        (&irq_desc[irq])
#define nr_irqs NR_IRQS
struct irq_desc irq_desc[NR_IRQS];

struct irq_desc *irqElement;
int irq;
int init_module(void)
{
    printk(KERN_INFO "I HAZ MODULE\n");
    for_each_irq_desc(irq, irqElement){printk("%p\n", irqElement);}
    return 0;
}

void cleanup_module(void)
{
    printk(KERN_INFO "BAI MODULE!!!1\n");
}

这篇关于访问IRQ描述阵列模块内和显示操作名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆