内核下的模块编译

内核中的模块编译如下:

 

makefile 文件:

ifneq ($(KERNELRELEASE),)

obj-m := param.o

else
	

KDIR := /lib/modules/2.6.32-358.el6.i686/build
all:
	
  make -C $(KDIR) M=$(PWD) modules

clean:
	rm -f *.ko *.o *.mod.o *.mod.c *.symvers

endif

 

待编译的模块:

#include <linux/init.h>                                
#include <linux/module.h>                                

MODULE_LICENSE("GPL"); 
         
static char *s;    
                               
module_param(s, charp, S_IRUGO);                             
                                
static int hello_init(void)                                
{            
    char c;
	int len,i;
	for(len=0; s[len]; len++);
	for(i=0;i<len/2;i++){
	   c=s[i];
	   s[i]=s[len-i-1];
	   s[len-1-i]=c;
	}
	printk(KERN_EMERG" ans: %s\n",s);    
    return 0;	
}                                
static void hello_exit(void)                                
{                                
	printk(KERN_INFO" Module Exit Success!\n ");                            
}
                                
module_init(hello_init);                                
module_exit(hello_exit);                                                                

  

posted @ 2016-12-29 19:47  茶飘香~  阅读(185)  评论(0编辑  收藏  举报