Mega Search
23.2 Million


Sign Up

Make a donation  
Borland equivalent of _ReturnAddress()?  
News Group: borland.public.cppbuilder.language.cpp

Is there a borland equivalent of Microsofts _ReturnAddress():
http://msdn2.microsoft.com/en-us/library/64ez38eh.aspx
Im using BDS 2006.

Leo Havmøller. 


Vote for best question.
Score: 0  # Vote:  0
Date Posted: 3-Jan-2008, at 10:26 AM EST
From: iso-8859-1QLeo_HavmF8ller
 
Re: Borland equivalent of _ReturnAddress()?  
News Group: borland.public.cppbuilder.language.cpp
Good catch!

You are correct.  The alternative to mov eax,[dbp+4] that I put in the 
comment was wrong.

It was meant to be clearer for people more familiar with C/C++ than 
assembler.  To actually do what is needed is arguably as confusing as the 
assembly language.

So the "simplified" boils down to one of these:

 __declspec(naked) void* _ReturnAddress(void)
   {
    __asm mov eax, [ebp + 4]
    return _EAX;
   }

 __declspec(naked) void* _ReturnAddress(void)
   {
    _EAX = *((unsigned *) (_EBP + 4));
    return _EAX;
   }

> ...don't remember enough TASM from over a decade ago, and no BASM use 
> recently), but  ...

If for no other reason than Call Stack and CPU View you should feel at least 
somewhat comfortable with assembly.  Here are a couple of links from Borland 
veteran Matt Pietrek that serve it up candy coated:

Just Enough Assembly To Get By, parts 1 and 2
http://www.microsoft.com/msj/0298/hood0298.aspx
http://www.microsoft.com/msj/0698/hood0698.aspx

..  Ed

> dhoke wrote in message
> news:47822fb4$1@newsgroups.borland.com...
>
> Depending on the assembler (haven't experimented, don't remember enough 
> TASM from over a decade ago, and no BASM use recently), but your alternate 
> is not functionally equivalent for all assembler syntaxes, maybe not for 
> B/CG products either.
>
> The original, I would expect to add 4 to BP, and retrieve the value at 
> that location.  Your alternate just adds 4 to BP and returns that 
> (address) value, not what's located at that address...



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 7-Jan-2008, at 9:17 AM EST
From: Ed Mulroy [TeamB]
 
Re: Borland equivalent of _ReturnAddress()?  
News Group: borland.public.cppbuilder.language.cpp
Depending on the assembler (haven't experimented, don't remember enough TASM 
from over a decade ago, and no BASM use recently), but your alternate is not 
functionally equivalent for all assembler syntaxes, maybe not for B/CG 
products either.

The original, I would expect to add 4 to BP, and retrieve the value at that 
location.
Your alternate just adds 4 to BP and returns that (address) value, not 
what's located at that address...

Yes/No?

"Ed Mulroy [TeamB]"  wrote in message 
news:477e3bbe$1@newsgroups.borland.com...
> Not meant as a nitpick, just an alternative.
>
>  __declspec(naked) void* _ReturnAddress(void)
>   {
>    __asm mov eax, [ebp + 4] /* or  _EAX = _EBP + 4; */
>    return _EAX;
>   }
>
> .  Ed
>
>> Leo Havmøller wrote in message
>> news:477dd195$1@newsgroups.borland.com...
>>
>> Prototype:
>> #ifdef __cplusplus
>> extern "C"
>> #endif
>> void* _ReturnAddress(void);
>>
>> Implementation:
>> #pragma warn -8070 // W8070 Function should return a value
>> __declspec(naked) void* _ReturnAddress(void)
>> {
>>  __asm mov eax, [ebp + 4]
>>  __asm ret
>> }
>>
>> More info:
>> http://nedbatchelder.com/blog/20051006T065335.html
>
> 



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 7-Jan-2008, at 8:59 AM EST
From: dhoke
 
Re: Borland equivalent of _ReturnAddress()?  
News Group: borland.public.cppbuilder.language.cpp
Leo Havmøller wrote:

> __declspec(naked) void* _ReturnAddress(void)

Beware of bugs in compiler with naked functions (5042,5041,2955)

-- 
Alex

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 5-Jan-2008, at 11:30 PM EST
From: AlexB
 
Re: Borland equivalent of _ReturnAddress()?  
News Group: borland.public.cppbuilder.language.cpp
Not meant as a nitpick, just an alternative.

  __declspec(naked) void* _ReturnAddress(void)
   {
    __asm mov eax, [ebp + 4] /* or  _EAX = _EBP + 4; */
    return _EAX;
   }

..  Ed

> Leo Havmøller wrote in message
> news:477dd195$1@newsgroups.borland.com...
>
> Prototype:
> #ifdef __cplusplus
> extern "C"
> #endif
> void* _ReturnAddress(void);
>
> Implementation:
> #pragma warn -8070 // W8070 Function should return a value
> __declspec(naked) void* _ReturnAddress(void)
> {
>  __asm mov eax, [ebp + 4]
>  __asm ret
> }
>
> More info:
> http://nedbatchelder.com/blog/20051006T065335.html



Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 4-Jan-2008, at 8:59 AM EST
From: Ed Mulroy [TeamB]
 
Re: Borland equivalent of _ReturnAddress()?  
News Group: borland.public.cppbuilder.language.cpp
"Leo Havmøller"  wrote in message 
news:477caa41@newsgroups.borland.com...
> Is there a borland equivalent of Microsofts _ReturnAddress():
> http://msdn2.microsoft.com/en-us/library/64ez38eh.aspx
> Im using BDS 2006.

Prototype:
#ifdef __cplusplus
extern "C"
#endif
void* _ReturnAddress(void);

Implementation:
#pragma warn -8070 // W8070 Function should return a value
__declspec(naked) void* _ReturnAddress(void)
{
  __asm mov eax, [ebp + 4]
  __asm ret
}

More info:
http://nedbatchelder.com/blog/20051006T065335.html

Leo Havmøller. 


Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 4-Jan-2008, at 7:26 AM EST
From: iso-8859-1QLeo_HavmF8ller
 
Re: Borland equivalent of _ReturnAddress()?  
News Group: borland.public.cppbuilder.language.cpp
Leo Havmøller  wrote:

>Is there a borland equivalent of Microsofts _ReturnAddress():
>http://msdn2.microsoft.com/en-us/library/64ez38eh.aspx
>Im using BDS 2006.

I'm afraid I don't know the answer to this one, but I have a question of
my own - what on earth are you trying to do?!

(If you've got someone else's source code that uses this, I don't envy
you.)

Alan Bellingham
-- 
Team Browns
ACCU Conference 2008: 2-5 April 2008 - Oxford, UK

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 3-Jan-2008, at 10:54 AM EST
From: Alan Bellingham