* [HELP] How to get address of module
@ 2005-08-08 11:40 Hiroki Kaminaga
2005-08-08 11:48 ` Stephen Rothwell
2005-08-08 13:51 ` linux-os (Dick Johnson)
0 siblings, 2 replies; 8+ messages in thread
From: Hiroki Kaminaga @ 2005-08-08 11:40 UTC (permalink / raw)
To: linux-kernel
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.
--
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [HELP] How to get address of module
2005-08-08 11:40 [HELP] How to get address of module Hiroki Kaminaga
@ 2005-08-08 11:48 ` Stephen Rothwell
2005-08-08 12:06 ` Hiroki Kaminaga
2005-08-08 13:51 ` linux-os (Dick Johnson)
1 sibling, 1 reply; 8+ messages in thread
From: Stephen Rothwell @ 2005-08-08 11:48 UTC (permalink / raw)
To: Hiroki Kaminaga; +Cc: linux-kernel
On Mon, 08 Aug 2005 20:40:22 +0900 (JST) Hiroki Kaminaga
<kaminaga@sm.sony.co.jp> wrote:
>
> I'm looking for *nice* way to get address of loaded module in 2.6.
> I'd like to know the address from driver.
Maybe explaining why you need the address of a module would help.
--
Cheers,
Stephen Rothwell sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [HELP] How to get address of module
2005-08-08 11:48 ` Stephen Rothwell
@ 2005-08-08 12:06 ` Hiroki Kaminaga
2005-08-08 13:30 ` Arnd Bergmann
0 siblings, 1 reply; 8+ messages in thread
From: Hiroki Kaminaga @ 2005-08-08 12:06 UTC (permalink / raw)
To: sfr; +Cc: linux-kernel
> > I'm looking for *nice* way to get address of loaded module in 2.6.
> > I'd like to know the address from driver.
>
> Maybe explaining why you need the address of a module would help.
I'm currently writing a driver to diagnose/monitor the error, such as
core dump.
I inserted some hook in kernel, and when segfault occurs, control is
transfered to my driver to analyze.
If the cause is in some insmod'ed module, then I would like to get
info of that module. If I get the address of that module, I can get
info such as symbol name defined by that module, etc. Then I could say
in module mmm, at func fff, at addr xxx, there is segfault.
Core dump could be in userspace app, so, in the driver I'm writting now,
I'm using same data structure to hold info of ELF file. If it was in app,
I'm getting address from current->mm->mmap->vm_start.
HK.
--
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [HELP] How to get address of module
2005-08-08 12:06 ` Hiroki Kaminaga
@ 2005-08-08 13:30 ` Arnd Bergmann
2005-08-09 0:43 ` Hiroki Kaminaga
0 siblings, 1 reply; 8+ messages in thread
From: Arnd Bergmann @ 2005-08-08 13:30 UTC (permalink / raw)
To: Hiroki Kaminaga; +Cc: sfr, linux-kernel
On Maandag 08 August 2005 14:06, Hiroki Kaminaga wrote:
> If the cause is in some insmod'ed module, then I would like to get
> info of that module. If I get the address of that module, I can get
> info such as symbol name defined by that module, etc. Then I could say
> in module mmm, at func fff, at addr xxx, there is segfault.
You can do all that with module_address_lookup() using the KALLSYMS
infrastructure.
Arnd <><
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [HELP] How to get address of module
2005-08-08 11:40 [HELP] How to get address of module Hiroki Kaminaga
2005-08-08 11:48 ` Stephen Rothwell
@ 2005-08-08 13:51 ` linux-os (Dick Johnson)
2005-08-09 0:48 ` Hiroki Kaminaga
1 sibling, 1 reply; 8+ messages in thread
From: linux-os (Dick Johnson) @ 2005-08-08 13:51 UTC (permalink / raw)
To: Hiroki Kaminaga; +Cc: Linux kernel
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 DeliveryErrors@analogic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [HELP] How to get address of module
2005-08-08 13:30 ` Arnd Bergmann
@ 2005-08-09 0:43 ` Hiroki Kaminaga
2005-08-09 7:09 ` Jan Engelhardt
0 siblings, 1 reply; 8+ messages in thread
From: Hiroki Kaminaga @ 2005-08-09 0:43 UTC (permalink / raw)
To: arnd; +Cc: sfr, linux-kernel, kaminaga
From: Arnd Bergmann <arnd@arndb.de>
Subject: Re: [HELP] How to get address of module
Date: Mon, 8 Aug 2005 15:30:53 +0200
> You can do all that with module_address_lookup() using the KALLSYMS
> infrastructure.
Thank you.
What I wanted is: given the segfault address, I would like to
1) get which module it is in
2) in that module, within which function it segfaulted
module_address_lookup would do!
HK.
--
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [HELP] How to get address of module
2005-08-08 13:51 ` linux-os (Dick Johnson)
@ 2005-08-09 0:48 ` Hiroki Kaminaga
0 siblings, 0 replies; 8+ messages in thread
From: Hiroki Kaminaga @ 2005-08-09 0:48 UTC (permalink / raw)
To: linux-os; +Cc: linux-kernel
From: "linux-os \(Dick Johnson\)" <linux-os@analogic.com>
Subject: Re: [HELP] How to get address of module
Date: Mon, 8 Aug 2005 09:51:25 -0400
> 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.
Thank you.
What I wanted is: given the segfault address, I would like to
1) get which module it is in
2) in that module, within which function it segfaulted
module_address_lookup() would do!
HK.
--
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [HELP] How to get address of module
2005-08-09 0:43 ` Hiroki Kaminaga
@ 2005-08-09 7:09 ` Jan Engelhardt
0 siblings, 0 replies; 8+ messages in thread
From: Jan Engelhardt @ 2005-08-09 7:09 UTC (permalink / raw)
To: Hiroki Kaminaga; +Cc: arnd, sfr, linux-kernel
>What I wanted is: given the segfault address, I would like to
>
>1) get which module it is in
>2) in that module, within which function it segfaulted
>
>module_address_lookup would do!
If a kernel oopses or similar, it already prints where it faulted:
EIP is at schedule_timeout+0x1234/abcde
If you have the EIP, you can look at /proc/modules to find the module, and
then use "nm" to find the function. Note that inlining makes "nm" and
objdumpers less effective.
Jan Engelhardt
--
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-08-09 7:09 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-08 11:40 [HELP] How to get address of module Hiroki Kaminaga
2005-08-08 11:48 ` Stephen Rothwell
2005-08-08 12:06 ` Hiroki Kaminaga
2005-08-08 13:30 ` Arnd Bergmann
2005-08-09 0:43 ` Hiroki Kaminaga
2005-08-09 7:09 ` Jan Engelhardt
2005-08-08 13:51 ` linux-os (Dick Johnson)
2005-08-09 0:48 ` Hiroki Kaminaga
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.