Accessing IRQ description array within a module an

2019-07-21 03:00发布

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); 

1条回答
劫难
2楼-- · 2019-07-21 03:22

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");
}
查看更多
登录 后发表回答