lkml.org 
[lkml]   [2004]   [Jun]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: Inserting a module (2.6 kernel)
From
Date
Steve Hemond <steve.hemond@sympatico.ca> writes:

> Hi people,
>
> I am new to kernel module writing and I base myself on the Linux Device Drivers book from O'reilly. I have written this simple module :
>
> #include <linux/module.h>
>
> int init_module(void)
> {
> printk("<1>Module inserted\n");
> return 0;
> }
>
> void cleanup_module(void)
> {
> printk("<1>Module removed\n");
> }
>

For some reason that's probably far too complicated for my little
brain it's getting more and more complicated to write custom
modules for 2.6.

Compile all with:

gcc -O2 -c hello.c -I /path/to/kernel/include

or

gcc -O2 -mcmodel=kernel -mno-red-zone -c hello.c -I /path/to/kernel/include
if you're using x86-64.

In 2.4 what worked was:

#define MODULE 1
#define __KERNEL__ 1
#include <linux/module.h>

int init_module(void)
{
printk("Hello world\n");
return 0;
}

Then in 2.6 it needed

#define MODULE 1
#define __KERNEL__ 1
#define KBUILD_MODNAME "hello"
#include <linux/module.h>

int init_module(void)
{
printk("Hello world\n");
return 0;
}

Now since 2.6.5 or so it needs:

/* MODULE is not needed anymore */
#define __KERNEL__1
#include <linux/module.h>

int init_module(void)
{
printk("Hello world\n");
return 0;
}

struct module __this_module
__attribute__((section(".gnu.linkonce.this_module"))) = {
.name = "hello",
.init = init_module,
};

I'm sure there will be more surprises in the future. Keep tuned.

-Andi



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:03    [W:0.026 / U:0.180 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site