You are not logged in.
Look:
//the file:Makefile
ifneq ($(KERNELRELEASE),)
obj-m += __module_address.o
else
PWD := $(shell pwd)
KVER := $(shell uname -r)
KDIR := /lib/modules/$(KVER)/build
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf *.o *.mod.c *.ko *.symvers *.order *.markers *~
endif
//the file __module_address.c
#include <linux/module.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");
static int __init __module_address_init(void);
static void __exit __module_address_exit(void);
int a_module(void)
{
return 0;
}
int __init __module_address_init(void)
{
struct module * ret ;
unsigned long addr = (unsigned long)a_module;
preempt_disable();
ret = __module_address(addr) ;
preempt_enable();
if( ret != NULL )
{
printk("<0>ret->name: %s\n",ret->name);
printk("<0>ret->state: %d\n",ret->state);
printk("<0>ret->core_size: %lu\n",ret->core_size);
printk("<0>refs of %s is %d\n",ret->name, module_refcount(ret));
}
else
{
printk("<0>__module_address return NULL !\n");
}
return 0;
}
void __exit __module_address_exit(void)
{
printk("<0>module exit ok!\n");
}
module_init(__module_address_init);
module_exit(__module_address_exit);
When I compile the file __module_address.c,it always display
the error: "implicit declaration of function '__module_address'",
how to correct it?
Offline
I don't get this warning (I get two format warning on the printks, but it's an unrelated issue). Tested on 3.11.2. The __module_address function is correctly defined in module.h.
btw I think your use of preempt_disable/enable is incorrect: first of all, for _this_ particular use, I think you can avoid disabling preemption at all, because the module can't disappear while executing its own code (if it happens, it's a serious bug). It doesn't hurt, anyway. If/when you'll use __module_addres for obtaining the information on *another* module, then you must extend the preempt-disabled region until you've done with the returned struct.
Last edited by ilsensine (2013-09-27 07:09:55)
Offline