#include <linux/module.h> // for printk()
#include <linux/mm.h> // for struct page
#include <asm/page.h> // for struct page
#include <asm/pgtable.h> // for ZERO_PAGE
static int __init init_hello( void )
{
int i;
struct page * zero_page;
printk(KERN_ALERT "\n Kello, the first! \n\n" );
i = 0x100;
zero_page = ZERO_PAGE(&i);
printk(KERN_ALERT " the ZERO address is %p", zero_page);
return 0;
}
static void __exit exit_hello( void )
{
printk(KERN_ALERT "\n Goodbye now... \n\n" );
}
MODULE_LICENSE("GPL");
module_init(init_hello);
module_exit(exit_hello);
Makefile
obj-m :=lx.o
KDIR= /lib/modules/$(shell uname -r)/build
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf $(wildcard *.o *.ko mo* Mo* *.mod.c)
____________________________________________________
Running make gives me(I’m in a Virtual Machine so the page addresses may be messed up):
sunny@ubuntu: make
make -C /lib/modules/3.11.0-12-generic/build SUBDIRS=/home/sunny/Documents/ modules
make[1]: Entering directory `/usr/src/linux-headers-3.11.0-12-generic'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory `/usr/src/linux-headers-3.11.0-12-generic'
sunny@ubuntu: sudo insmod lx.ko
sunny@ubuntu: sudo rmmod lx
sunny@ubuntu: sudo dmesg | tail -6
[48391.359434] Kello, the first!
[48391.359434]
[48320.368773] the ZERO address is ffffea0000079b40
[48391.359439] the ZERO address is ffffea0000079b40<1>[48411.409906]
[48411.409906] Goodbye now...
[48411.409906]
Hope this helps! Don’t forget to ‘reply all’ so that others in the mailing list could also see your/my problem/solution.
- Sunny
hi :
If i command the "insmod zero.ko"; the wrong messages is:
##############
insmod: error inserting 'zero.ko': -1 Unknown symbol in module
##############