public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* Loadable module and kernel gp
@ 2004-01-23  9:52 Christian Hildner
  2004-01-23 10:45 ` Erich Focht
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Christian Hildner @ 2004-01-23  9:52 UTC (permalink / raw)
  To: linux-ia64

Hi,

does anybody know a simple way for a loadable module to get the gp value 
of the kernel? Is there any sample code?

Christian


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Loadable module and kernel gp
  2004-01-23  9:52 Loadable module and kernel gp Christian Hildner
@ 2004-01-23 10:45 ` Erich Focht
  2004-01-23 22:28 ` David Mosberger
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Erich Focht @ 2004-01-23 10:45 UTC (permalink / raw)
  To: linux-ia64

At compile time you can get it from the System.map. The symbol is at
the end and called __gp. Of course you might want to have some
cross-checks that you pick up the right System.map. I usually take
some known and exported symbols.

But there's surely some dynamic way, too...

Regards,
Erich

On Friday 23 January 2004 10:52, Christian Hildner wrote:
> does anybody know a simple way for a loadable module to get the gp value
> of the kernel? Is there any sample code?
>
> Christian



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Loadable module and kernel gp
  2004-01-23  9:52 Loadable module and kernel gp Christian Hildner
  2004-01-23 10:45 ` Erich Focht
@ 2004-01-23 22:28 ` David Mosberger
  2004-01-23 23:14 ` Luck, Tony
  2004-01-26  8:05 ` Christian Hildner
  3 siblings, 0 replies; 5+ messages in thread
From: David Mosberger @ 2004-01-23 22:28 UTC (permalink / raw)
  To: linux-ia64

>>>>> On Fri, 23 Jan 2004 10:52:00 +0100, Christian Hildner <christian.hildner@hob.de> said:

  Christian> Hi, does anybody know a simple way for a loadable module
  Christian> to get the gp value of the kernel? Is there any sample
  Christian> code?

The safest way is probably to materialize a function pointer for a
function that is known to be in the kernel (and exported) and then to
read the second word.

	--david

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Loadable module and kernel gp
  2004-01-23  9:52 Loadable module and kernel gp Christian Hildner
  2004-01-23 10:45 ` Erich Focht
  2004-01-23 22:28 ` David Mosberger
@ 2004-01-23 23:14 ` Luck, Tony
  2004-01-26  8:05 ` Christian Hildner
  3 siblings, 0 replies; 5+ messages in thread
From: Luck, Tony @ 2004-01-23 23:14 UTC (permalink / raw)
  To: linux-ia64


> >>>>> On Fri, 23 Jan 2004 10:52:00 +0100, Christian Hildner 
> <christian.hildner@hob.de> said:
> 
>   Christian> Hi, does anybody know a simple way for a loadable module
>   Christian> to get the gp value of the kernel? Is there any sample
>   Christian> code?
> 
> The safest way is probably to materialize a function pointer for a
> function that is known to be in the kernel (and exported) and then to
> read the second word.

In case "materialzie a function pointer" is total greek:

#include <linux/slab.h>

struct fptr {
	unsigned long func_addr;
	unsigned long gp;
};

your_routine()
{
	struct fptr = (struct fptr *)kmalloc; /*function known to be in kernel */

	printk("Kernel gp is %lx\n", fptr->gp);
}


Untested ... kmalloc is declared "inline" so that might mess things
up.  Just choose some other exported thing if it is.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Loadable module and kernel gp
  2004-01-23  9:52 Loadable module and kernel gp Christian Hildner
                   ` (2 preceding siblings ...)
  2004-01-23 23:14 ` Luck, Tony
@ 2004-01-26  8:05 ` Christian Hildner
  3 siblings, 0 replies; 5+ messages in thread
From: Christian Hildner @ 2004-01-26  8:05 UTC (permalink / raw)
  To: linux-ia64

Luck, Tony schrieb:

>>>>>>>On Fri, 23 Jan 2004 10:52:00 +0100, Christian Hildner 
>>>>>>>              
>>>>>>>
>><christian.hildner@hob.de> said:
>>
>>  Christian> Hi, does anybody know a simple way for a loadable module
>>  Christian> to get the gp value of the kernel? Is there any sample
>>  Christian> code?
>>
>>The safest way is probably to materialize a function pointer for a
>>function that is known to be in the kernel (and exported) and then to
>>read the second word.
>>
Yes, that's it, thanks. Sometimes good solutions are also simple. I'll 
try it.

>
>In case "materialzie a function pointer" is total greek:
>
>#include <linux/slab.h>
>
>struct fptr {
>	unsigned long func_addr;
>	unsigned long gp;
>};
>
>your_routine()
>{
>	struct fptr = (struct fptr *)kmalloc; /*function known to be in kernel */
>
>	printk("Kernel gp is %lx\n", fptr->gp);
>}
>
>
>Untested ... kmalloc is declared "inline" so that might mess things
>up.  Just choose some other exported thing if it is.
>
I hope the compiler will not explode if I request the pointer to an 
inlined function ;-). I like the idea of using kmalloc since this symbol 
should be present in almost any kernel.

Thanks

Christian


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-01-26  8:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-23  9:52 Loadable module and kernel gp Christian Hildner
2004-01-23 10:45 ` Erich Focht
2004-01-23 22:28 ` David Mosberger
2004-01-23 23:14 ` Luck, Tony
2004-01-26  8:05 ` Christian Hildner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox