1,318
社区成员
发帖
与我相关
我的任务
分享
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/preempt.h>
MODULE_LICENSE("GPL");
static int _init_module_address(void);
static void _exit_module_address(void);
struct module;
int amodule(void)
{
return 0;
}
int _init_module_address(void)
{
struct moudle* ret = NULL;
const unsigned long addr = (const unsigned long)amodule;
preempt_disable();
ret = __module_address(addr);
preempt_enable();
if (ret != NULL)
{
//ret->name; //dereferencing pointer to incomplete type
printk(KERN_INFO "name=%s\n", ret->name);
printk(KERN_INFO "state=%d\n", int(ret->state));
printk(KERN_INFO "core_size=%d\n", int(ret->core_size));
printk(KERN_INFO "module addr return not NULL\n");
return 0;
}
printk(KERN_INFO "module addr return NULL\n");
return 0;
}
void _exit_module_address(void)
{
printk(KERN_INFO "module exit\n");
}
module_init(_init_module_address);
module_exit(_exit_module_address);
ifneq ($(KERNELRELEASE),)
obj-m = _module_address.o
else
PWD := $(shell pwd)
KVER := $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
endif
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.mod.c *.ko *.symvers *.order *.makers *~