473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Get address of function, not entry in jump table.

I have a function foo of which I need to get the address. The problem
is that when you say "&foo" (or just foo for that matter), you get the
address of this function's entry in a jump table and not the address of
the function itself. Are there any BKMs for getting the real address or
am I going to have to write a function that looks to see whether the
address is a jump instruction and if so compute the real address from
the jump target?

thanks,

Todd
Jun 20 '06 #1
6 5002
Todd A. Anderson wrote:
I have a function foo of which I need to get the address. The problem
is that when you say "&foo" (or just foo for that matter), you get the
address of this function's entry in a jump table and not the address
of the function itself. Are there any BKMs for getting the real
address or am I going to have to write a function that looks to see
whether the address is a jump instruction and if so compute the real
address from the jump target?


In C++ terms, when you say 'foo', you get a pointer to the function that
you can use to call it or compare it for equality with another pointer.
There is no other use for it. What would be your definition of the "real
address" and what are you going to do with it? Most likely, there is no
solution to your problem in terms of standard C++.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 20 '06 #2
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:e7**********@news.datemas.de...
Todd A. Anderson wrote:
I have a function foo of which I need to get the address. The problem
is that when you say "&foo" (or just foo for that matter), you get the
address of this function's entry in a jump table and not the address
of the function itself. Are there any BKMs for getting the real
address or am I going to have to write a function that looks to see
whether the address is a jump instruction and if so compute the real
address from the jump target?


In C++ terms, when you say 'foo', you get a pointer to the function that
you can use to call it or compare it for equality with another pointer.
There is no other use for it. What would be your definition of the "real
address" and what are you going to do with it? Most likely, there is no
solution to your problem in terms of standard C++.


I believe that if the function is not declared static that all calls to that
function are made via a jump table and that this is how linking/loading
is done. In essence, I have to walk my own stack and determine if
I'm in a particular function and for that I need the real address of the
function and not the address of the jump instruction in the jump table.
The debugger has to do this as well but I need to do it manually. The
reason why is long, complex, and uninteresting. I already wrote a
function in case I needed it that looks at the code address and determines
if it is a jump instruction and if so computes the real function address.
Obviously, this function is architecture dependent which is something I'd
like to avoid but I guess I can't.
Jun 20 '06 #3
Todd A. Anderson wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:e7**********@news.datemas.de...
Todd A. Anderson wrote:
I have a function foo of which I need to get the address. The problem
is that when you say "&foo" (or just foo for that matter), you get the
address of this function's entry in a jump table and not the address
of the function itself. Are there any BKMs for getting the real
address or am I going to have to write a function that looks to see
whether the address is a jump instruction and if so compute the real
address from the jump target?

In C++ terms, when you say 'foo', you get a pointer to the function that
you can use to call it or compare it for equality with another pointer.
There is no other use for it. What would be your definition of the "real
address" and what are you going to do with it? Most likely, there is no
solution to your problem in terms of standard C++.


I believe that if the function is not declared static that all calls to that
function are made via a jump table and that this is how linking/loading
is done. In essence, I have to walk my own stack and determine if
I'm in a particular function and for that I need the real address of the
function and not the address of the jump instruction in the jump table.
The debugger has to do this as well but I need to do it manually. The
reason why is long, complex, and uninteresting. I already wrote a
function in case I needed it that looks at the code address and determines
if it is a jump instruction and if so computes the real function address.
Obviously, this function is architecture dependent which is something I'd
like to avoid but I guess I can't.


I assume you are talking about *member* functions. In general,
functions are not accessed by a jump table, but by direct call.
However, this is an implementation detail.
Jun 20 '06 #4

"red floyd" <no*****@here.dude> wrote in message
news:Ss*******************@newssvr14.news.prodigy. com...
Todd A. Anderson wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:e7**********@news.datemas.de...
Todd A. Anderson wrote:
I have a function foo of which I need to get the address. The problem
is that when you say "&foo" (or just foo for that matter), you get the
address of this function's entry in a jump table and not the address
of the function itself. Are there any BKMs for getting the real
address or am I going to have to write a function that looks to see
whether the address is a jump instruction and if so compute the real
address from the jump target?
In C++ terms, when you say 'foo', you get a pointer to the function that
you can use to call it or compare it for equality with another pointer.
There is no other use for it. What would be your definition of the
"real
address" and what are you going to do with it? Most likely, there is no
solution to your problem in terms of standard C++.


I believe that if the function is not declared static that all calls to
that
function are made via a jump table and that this is how linking/loading
is done. In essence, I have to walk my own stack and determine if
I'm in a particular function and for that I need the real address of the
function and not the address of the jump instruction in the jump table.
The debugger has to do this as well but I need to do it manually. The
reason why is long, complex, and uninteresting. I already wrote a
function in case I needed it that looks at the code address and
determines
if it is a jump instruction and if so computes the real function address.
Obviously, this function is architecture dependent which is something I'd
like to avoid but I guess I can't.


I assume you are talking about *member* functions. In general, functions
are not accessed by a jump table, but by direct call. However, this is an
implementation detail.


No. I'm not talking about a *member* function. At least for me, with both
VC6 and VS2005, I've noticed that sometimes when I do a call of a regular
non-member function and hit F11 (step-into) in the debugger, that rather
than
taking me directly to the called function, it takes me to a region of code
that
consists of one jump instruction after another. Think about what happens
when you call a function from file A in which it is declared extern. The
code
in the obj for file A has to include a call but to what address? You can't
use an offset from the start of the obj because the function is extern so
you
have no such offset. It seems what is done is that the compiler creates
what I called a jump table and it emits a call to an entry in this jump
table.
At load time, once the real address of the function is known, you just have
to update the jump tables to jump to the right spot rather than having to
update
every call site for each externed function.

I know about vtables and the use of indirect calls for them. What I'm
talking
about is different. The compiler still uses a direct call but it is a
direct call
of a memory location contains a jump instruction rather than the true start
of the method prolog.
Jun 20 '06 #5
Todd A. Anderson schrieb:
I assume you are talking about *member* functions. In general, functions
are not accessed by a jump table, but by direct call. However, this is an
implementation detail.


No. I'm not talking about a *member* function. At least for me, with both
VC6 and VS2005, I've noticed that sometimes when I do a call of a regular
non-member function and hit F11 (step-into) in the debugger, that rather
than
taking me directly to the called function, it takes me to a region of code
that
consists of one jump instruction after another. Think about what happens
when you call a function from file A in which it is declared extern. The
code
in the obj for file A has to include a call but to what address? You can't
use an offset from the start of the obj because the function is extern so
you
have no such offset. It seems what is done is that the compiler creates
what I called a jump table and it emits a call to an entry in this jump
table.
At load time, once the real address of the function is known, you just have
to update the jump tables to jump to the right spot rather than having to
update
every call site for each externed function.


I guess this only occurs when calling a function in a DLL. The jump
tables are in the .lib files that belong to the DLL, and the DLL loader
has to update only the jump table entry in the .lib file.

But this is offtopic in this group, you have to ask in a windows
specific group for this.

Thomas
Jun 20 '06 #6

Todd A. Anderson wrote:
I believe that if the function is not declared static that all calls to that
function are made via a jump table and that this is how linking/loading
is done.
One particular implementation, and one that is very often cut out by an
optimizer. I.e. don't assume that it's there just because you can see
it
in a debugger.
In essence, I have to walk my own stack and determine if
I'm in a particular function and for that I need the real address of the
function and not the address of the jump instruction in the jump table.
Won't work anyway. You're assuming contiguous functions at the very
least.
The case you encountered was a special case, but there are more
compilers
that implement functions as multiple blocks of memory. In fact, with
inlining,
the same logical code maps to multiple blocks of memory. Other cases
are
hot/cold splits where the optimizer guesses which code will be used
less
often and put that in a separate location. This can be used for e.g.
exception code, to keep it out of the CPU cache if nothing throws.
From a C++ point of view, this doesn't matter. Functions aren't objects

and can't be treated as such. You know you're in a function foo() if
you're
executing a statement of function foo (and a few other rare cases
dealing
with argument initialization)

Jun 21 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
14
by: Rudi Hansen | last post by:
I dont seem to be able to find the switch statement in Python. I would like to be able to do switch(var) case 1 : print "var = 1" case 2: print "var = 2"
11
by: Brian Henry | last post by:
I have a domain cluster with AD running, and I want to lookup a users email address (exchange 2000 server is integrated with the AD system) so i can email the user based on their user name. does...
1
by: Don | last post by:
Environment: VB6 under W98 I have to use a DLL which has a single entry point expressed as an absolute address. Any function to be invoked is then specified as one of the arguments. The number...
20
by: hippomedon | last post by:
Hello everyone, I'm looking for some advice on whether I should break the normalization rule. Normally, I would not consider it, but this seems to be a special case. I have created an...
1
by: zhang | last post by:
what's the problem?? Remote_Addr = "hotmail.com" sFrom = "<makefriend8@" & Remote_Addr + ">" Dim oConnection As New TcpClient() Try oConnection.SendTimeout = 3000 ...
7
by: Guillaume Dargaud | last post by:
Hello all, I have an example of working code under my eyes that goes as follow: unsigned long address=0x400000; (void (*)(void)address)(); It's supposed to jump start a kernel loaded at that...
4
by: Immortal_Nephi | last post by:
I had a lot of research to see how function pointer works. Sometimes, programmers choose switch keyword and function in each case block can be called. Sometimes, they choose ordinary function...
0
by: ling2000 | last post by:
Hello all, I'm trying to upgrade a VB6 project into VB.net, and the problem I had is in converting 'address of' to 'delegate'. I had the error "Value of type 'DelegateIDccManSink_OnLogIpAddr'...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.