public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Let me know EIP address
@ 2005-01-04 15:18 Lethalman
  2005-01-04 16:05 ` linux-os
  2005-01-04 16:10 ` Paolo Ornati
  0 siblings, 2 replies; 5+ messages in thread
From: Lethalman @ 2005-01-04 15:18 UTC (permalink / raw)
  To: linux-kernel

I'm trying to get the EIP value from a simple program in C but i don't 
how to do it. I need it to know the current address position on the code 
segment.

main() {
   long *eip;
   asm("mov %%eip,%0" : "=g"(eip));
   printf("%p\n", eip);
}

Unfortunately EIP is not that kind of register :P
Does anyone know how to get EIP?

-- 
www.iosn.it * Amministratore Italian Open Source Network
www.fyrebird.net * Fyrebird Hosting Provider - Technical Department

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

* Re: Let me know EIP address
  2005-01-04 15:18 Let me know EIP address Lethalman
@ 2005-01-04 16:05 ` linux-os
  2005-01-04 16:21   ` Paulo Marques
  2005-01-04 16:10 ` Paolo Ornati
  1 sibling, 1 reply; 5+ messages in thread
From: linux-os @ 2005-01-04 16:05 UTC (permalink / raw)
  To: Lethalman; +Cc: linux-kernel

On Tue, 4 Jan 2005, Lethalman wrote:

> I'm trying to get the EIP value from a simple program in C but i don't how to 
> do it. I need it to know the current address position on the code segment.
>
> main() {
>  long *eip;
>  asm("mov %%eip,%0" : "=g"(eip));
>  printf("%p\n", eip);
> }
>
> Unfortunately EIP is not that kind of register :P
> Does anyone know how to get EIP?
>

You get the offset of a label, i.e., "foo:\t movl $foo,%0\n" in the asm 
code.


Cheers,
Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 BogoMips).
  Notice : All mail here is now cached for review by Dictator Bush.
                  98.36% of all statistics are fiction.

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

* Re: Let me know EIP address
  2005-01-04 15:18 Let me know EIP address Lethalman
  2005-01-04 16:05 ` linux-os
@ 2005-01-04 16:10 ` Paolo Ornati
  2005-01-04 17:50   ` Bernd Eckenfels
  1 sibling, 1 reply; 5+ messages in thread
From: Paolo Ornati @ 2005-01-04 16:10 UTC (permalink / raw)
  To: Lethalman; +Cc: linux-kernel

On Tue, 04 Jan 2005 16:18:02 +0100
Lethalman <lethalman@fyrebird.net> wrote:

> I'm trying to get the EIP value from a simple program in C but i don't
> how to do it. I need it to know the current address position on the
> code segment.
> 
> main() {
>    long *eip;
>    asm("mov %%eip,%0" : "=g"(eip));
>    printf("%p\n", eip);
> }
> 
> Unfortunately EIP is not that kind of register :P
> Does anyone know how to get EIP?


IA-32 Intel® Architecture
    Software Developer's
                    Manual
                    Volume 1:
            Basic Architecture


3.5. INSTRUCTION POINTER

[...]

The EIP register cannot be accessed directly by software; it is
controlled implicitly by control- transfer instructions (such as JMP,
Jcc, CALL, and RET), interrupts, and exceptions. The only way to read
the EIP register is to execute a CALL instruction and then read the
value of the return instruction pointer from the procedure stack. The
EIP register can be loaded indirectly by modifying the value of a return
instruction pointer on the procedure stack and executing a return
instruction (RET or IRET). See Section 6.2.4.2., "Return Instruction
Pointer".

[...]

-- 
	Paolo Ornati
	Gentoo Linux (kernel 2.6.10-cko2)

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

* Re: Let me know EIP address
  2005-01-04 16:05 ` linux-os
@ 2005-01-04 16:21   ` Paulo Marques
  0 siblings, 0 replies; 5+ messages in thread
From: Paulo Marques @ 2005-01-04 16:21 UTC (permalink / raw)
  To: linux-os; +Cc: Lethalman, linux-kernel

linux-os wrote:
> On Tue, 4 Jan 2005, Lethalman wrote:
> 
>> I'm trying to get the EIP value from a simple program in C but i don't 
>> how to do it. I need it to know the current address position on the 
>> code segment.
>>
>> main() {
>>  long *eip;
>>  asm("mov %%eip,%0" : "=g"(eip));
>>  printf("%p\n", eip);
>> }
>>
>> Unfortunately EIP is not that kind of register :P
>> Does anyone know how to get EIP?
>>
> 
> You get the offset of a label, i.e., "foo:\t movl $foo,%0\n" in the asm 
> code.

Or use a gcc extension, so that you don't have to write assembly code:

int main(int argc, char *argv[])
{
   address:
     printf("this is my address %p\n", &&address);
   return 0;
}

-- 
Paulo Marques - www.grupopie.com

"A journey of a thousand miles begins with a single step."
Lao-tzu, The Way of Lao-tzu


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

* Re: Let me know EIP address
  2005-01-04 16:10 ` Paolo Ornati
@ 2005-01-04 17:50   ` Bernd Eckenfels
  0 siblings, 0 replies; 5+ messages in thread
From: Bernd Eckenfels @ 2005-01-04 17:50 UTC (permalink / raw)
  To: linux-kernel

In article <20050104171043.21c7c4ef@tux.homenet> you wrote:
>> I'm trying to get the EIP value from a simple program in C but i don't

> The EIP register cannot be accessed directly by software

I guess most often is enough to get the address of a C function

printf("%p", &func);

Greetings
Bernd

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

end of thread, other threads:[~2005-01-04 17:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-04 15:18 Let me know EIP address Lethalman
2005-01-04 16:05 ` linux-os
2005-01-04 16:21   ` Paulo Marques
2005-01-04 16:10 ` Paolo Ornati
2005-01-04 17:50   ` Bernd Eckenfels

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