On Mon, 8 Aug 2005, Hiroki Kaminaga wrote:
>
> Hi!
>
> I'm looking for *nice* way to get address of loaded module in 2.6.
> I'd like to know the address from driver.
>
> In 2.4, I wrote something like this:
>
> * * *
>
> (in kernel src)
> --- kernel/module.c
> +++ kernel/module.c
>
> struct module *module_list = &kernel_module;
>
> + struct module *get_module_queue(void)
> + {
> + return module_list;
> + }
> +
> +
>
> ... and in driver, I wrote:
>
> mod = get_module_queue();
> while (mod->next) {
> if (strcmp(mod->name, name) == 0)
> return (unsigned long)(mod + 1);
> mod = mod->next;
> }
> return 0;
>
> * * *
>
> I am now using 2.6 kernel. The choice I can think of is
>
> 1) make linux-2.6/kernel/module.c:find_module(const char *name)
> global func, not static, and use this func.
>
> 2) use linux-2.6/kernel/module.c:module_kallsyms_lookup_name(const char *name)
> and somehow get return value from module_get_kallsym(...)
>
> choice 1) doesn't sound nice since it changes static func -> global
> func, but cost of getting module address is low. On the other hand,
> choice 2) will not modify kernel src, which sounds nice, but costs more,
> and I'm not sure this method works.
>
> Any advice?!
>
>
> HK.
What do you want the address of in your driver? Do you want the
address of its various entry points (hint, the stuff you put
into the "struct file_operations"), or its startup code, module_init(),
exit code, module_exit(), etc.
These are can all be obtained using conventional 'C' syntax. You
don't need to search some list somehere. You driver isn't just
put somewhere en-masse. The code is in the .text segment, relocated
to exist in allocated memory. The data sections are also relocated
to different sections of allocated memory.
You get the address of a function by referencing its name:
static int ioctl(struct inode *inp, struct file *fp, size_t cmd, unsigned long
arg)
{
unsigned long val;
switch(cmd)
{
case GET_ADDRESS_OF_IOCTL:
val = (unsigned long) ioctl;
if(put_user(val, (unsigned long *)arg))
return -EFAULT
break;
case ETC:
}
Your driver probably has many functions, therefore it has many
addresses. It's not just a single "module" somewhere.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.12 on an i686 machine (5537.79 BogoMips).
Warning : 98.36% of all statistics are fiction.
.
I apologize for the following. I tried to kill it with the above dot :
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
|
|