Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-04

find return adress of a procedure/function

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rainer Stratmann

How to find the return adress of the calling code of a procedure/function?

Where in the stack is the information to the return adress?

stack + - x?

How to acess to the information in assembler?
Is it in every processor architecture possible, for example ARM? (actually 80x86).
Is it different in 32 / 64 bit?

Rainer Stratmann
to Rainer Stratmann
Rainer Stratmann wrote 5 lines
How to find the return adress of the calling code of a procedure/function? Where in the stack is the information to the return adress? stack + - x?

asm
mov eax , [ ebp + 4 ]
end;

eax is the return adress

Show quoted text 7 lines
How to acess to the information in assembler? Is it in every processor architecture possible, for example ARM? (actually 80x86). Is it different in 32 / 64 bit? _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Sven Barth
to Rainer Stratmann
Rainer Stratmann wrote 14 lines
Am Sunday 24 April 2011 11:44:18 schrieb Rainer Stratmann: > How to find the return adress of the calling code of a procedure/function? > > Where in the stack is the information to the return adress? > > stack + - x? asm mov eax , [ ebp + 4 ] end; eax is the return adress

This will only work on i386 and might even work only with certain calling conventions (don't know exactly whether other calling conventions on i386 don't use EAX for the result value).

Show quoted text 5 lines
> How to acess to the information in assembler? > Is it in every processor architecture possible, for example ARM? > (actually 80x86). > Is it different in 32 / 64 bit?

Why don't you try this:
http://www.freepascal.org/docs-html/rtl/system/get_caller_addr.html

Regards,
Sven

Rainer Stratmann
to Sven Barth
Sven Barth wrote 26 lines
On 24.04.2011 12:14, Rainer Stratmann wrote: > Am Sunday 24 April 2011 11:44:18 schrieb Rainer Stratmann: >> How to find the return adress of the calling code of a >> procedure/function? >> >> Where in the stack is the information to the return adress? >> >> stack + - x? > > asm > mov eax , [ ebp + 4 ] > end; > > eax is the return adress This will only work on i386 and might even work only with certain calling conventions (don't know exactly whether other calling conventions on i386 don't use EAX for the result value). >> How to acess to the information in assembler? >> Is it in every processor architecture possible, for example ARM? >> (actually 80x86). >> Is it different in 32 / 64 bit? Why don't you try this: http://www.freepascal.org/docs-html/rtl/system/get_caller_addr.html

Because I didn't know before :-)

function get_caller_addr( framebp : pointer ) : pointer;

What does framepb mean?

Show quoted text 5 lines
Regards, Sven _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Sven Barth
to Rainer Stratmann
Rainer Stratmann wrote 30 lines
Am Sunday 24 April 2011 12:45:50 schrieb Sven Barth: > On 24.04.2011 12:14, Rainer Stratmann wrote: >> Am Sunday 24 April 2011 11:44:18 schrieb Rainer Stratmann: >>> How to find the return adress of the calling code of a >>> procedure/function? >>> >>> Where in the stack is the information to the return adress? >>> >>> stack + - x? >> >> asm >> mov eax , [ ebp + 4 ] >> end; >> >> eax is the return adress > > This will only work on i386 and might even work only with certain > calling conventions (don't know exactly whether other calling > conventions on i386 don't use EAX for the result value). > >>> How to acess to the information in assembler? >>> Is it in every processor architecture possible, for example ARM? >>> (actually 80x86). >>> Is it different in 32 / 64 bit? > > Why don't you try this: > http://www.freepascal.org/docs-html/rtl/system/get_caller_addr.html Because I didn't know before :-)

A good reason :P

function get_caller_addr( framebp : pointer ) : pointer; What does framepb mean?

The usual usage in the sources of the RTL is
"get_caller_addr(get_frame)" (get_frame is linked in the document I linked to in the last mail). Get_frame returns the frame address of the current function/procedure/method. Thus "get_caller_addr(get_frame)" will return the return address to the calling function.

Regards,
Sven