Exetools  

Go Back   Exetools > General > x64 OS

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2013, 07:44
mcp mcp is offline
Friend
 
Join Date: Dec 2011
Posts: 73
Rept. Given: 4
Rept. Rcvd 12 Times in 11 Posts
Thanks Given: 7
Thanks Rcvd at 47 Times in 35 Posts
mcp Reputation: 12
x64 calling convention and home space

In the x64 calling convention, each parameter to a function has a corresponding record in the parent's function home space. Now, it seems unclear to me what the purpose of this is? Why has this decision been made? Doesn't that render the advantages,i.e. passing parameters via registers instead of using the stack, of x64 useless?
Reply With Quote
The Following User Says Thank You to mcp For This Useful Post:
Indigo (07-19-2019)
  #2  
Old 11-10-2013, 09:33
qkumba qkumba is offline
Friend
 
Join Date: Nov 2011
Posts: 14
Rept. Given: 0
Rept. Rcvd 4 Times in 4 Posts
Thanks Given: 0
Thanks Rcvd at 3 Times in 3 Posts
qkumba Reputation: 4
Your question begins with an invalid assumption. That space is reserved for register "spill", so that any special registers can be saved there if they will be used, without affecting the stack. If a function uses no special registers then the space won't be used (and might not even exist - it's compiler-dependent if it's even there).
The size of the space is fixed, so it's completely independent of the number of parameters.
Reply With Quote
The Following User Says Thank You to qkumba For This Useful Post:
Indigo (07-19-2019)
  #3  
Old 11-10-2013, 22:59
mcp mcp is offline
Friend
 
Join Date: Dec 2011
Posts: 73
Rept. Given: 4
Rept. Rcvd 12 Times in 11 Posts
Thanks Given: 7
Thanks Rcvd at 47 Times in 35 Posts
mcp Reputation: 12
Nearly all of your points are completely wrong.
1) The space is not reserved for register spill, in fact there is no constraint on what the callee is supposed to do with that stack space: there is no reserved purpose for that area.
2) Since the callee can always rely on the existence of that area, he is free to use it for whatever he wants (if e.g. the optimizer decides to do so). That contradicts your "won't be used" claim.
3) It is not compiler dependent, all compilers for x64 on windows have to adhere to these conventions (at least when they interface with other compiler generated code or the OS API).
4) The size of the space is not fixed at all. To the contrary: the space depends on the number of parameters passed to the callee.

MSDN documentation

Quote:
It contains at least four entries, but always enough space to hold all the parameters needed by any function that may be called. Note that space is always allocated for the register parameters, even if the parameters themselves are never homed to the stack; a callee is guaranteed that space has been allocated for all its parameters
Reply With Quote
The Following User Says Thank You to mcp For This Useful Post:
Indigo (07-19-2019)
  #4  
Old 11-12-2013, 11:34
qkumba qkumba is offline
Friend
 
Join Date: Nov 2011
Posts: 14
Rept. Given: 0
Rept. Rcvd 4 Times in 4 Posts
Thanks Given: 0
Thanks Rcvd at 3 Times in 3 Posts
qkumba Reputation: 4
riiight, because MSDN documentation is always correct...
Reply With Quote
The Following User Says Thank You to qkumba For This Useful Post:
Indigo (07-19-2019)
  #5  
Old 11-12-2013, 17:51
mcp mcp is offline
Friend
 
Join Date: Dec 2011
Posts: 73
Rept. Given: 4
Rept. Rcvd 12 Times in 11 Posts
Thanks Given: 7
Thanks Rcvd at 47 Times in 35 Posts
mcp Reputation: 12
Well, MSDN is not the only source that describes the x64 calling convention exactly in this way. It also matches with the code I've seen being generated by compilers, so it is definitely correct.
I wonder though why you even try to answer a question which is obviously beyond your expertise, only to come up with a snarky response to my well founded criticism?!
Reply With Quote
The Following User Says Thank You to mcp For This Useful Post:
Indigo (07-19-2019)
  #6  
Old 11-14-2013, 04:01
qkumba qkumba is offline
Friend
 
Join Date: Nov 2011
Posts: 14
Rept. Given: 0
Rept. Rcvd 4 Times in 4 Posts
Thanks Given: 0
Thanks Rcvd at 3 Times in 3 Posts
qkumba Reputation: 4
1) it is intended for register spill. Nothing is stored there automatically. It avoids repeated push and pop sequences to save and restore the fastcall registers. If rcx and rdx are used as parameters, for example, and the compiler wants to use them for scratch registers, then they can be stored there.
2) your () in (3) contradicts your claim here.
3) your () here makes my point for me. It might not be there.
4) It is fixed. The first four parameters are in registers, and their space is reserved by the callee. The other parameters are pushed onto the stack by the caller. That's not home space anymore, that's regular stack calling convention.
Reply With Quote
The Following User Says Thank You to qkumba For This Useful Post:
Indigo (07-19-2019)
  #7  
Old 11-14-2013, 05:26
mcp mcp is offline
Friend
 
Join Date: Dec 2011
Posts: 73
Rept. Given: 4
Rept. Rcvd 12 Times in 11 Posts
Thanks Given: 7
Thanks Rcvd at 47 Times in 35 Posts
mcp Reputation: 12
1) well, your original claim was that if a called function doesn't use any special registers, then it won't be used. That however is clearly false, as the called function is free to use the home space for whatever it likes. There is no "requirement" or "intent" to use it for register spill, the optimizer is free to use this space.
2/3) Well, what other x64 calling convention on windows do you know of?
4) That seems to be correct, according to MSDN and to code I've seen. My initial claim that it is not fixed and dependent on number of parameters was wrong.
Reply With Quote
The Following User Says Thank You to mcp For This Useful Post:
Indigo (07-19-2019)
  #8  
Old 08-17-2015, 11:40
matt matt is offline
Friend
 
Join Date: Jan 2002
Posts: 41
Rept. Given: 2
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 6
Thanks Rcvd at 13 Times in 9 Posts
matt Reputation: 0
Using homing space to retrieve register paras is NOT reliable, but could work for most of the time.

If anyone is still interested in this topic, check this url:
http://www.codemachine.com/article_x64deepdive.html

<Got here accidentally during a google search. >
Reply With Quote
The Following User Says Thank You to matt For This Useful Post:
Indigo (07-19-2019)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling any function dynamically without typedef Succubus Source Code 0 10-21-2021 16:34
Calling function from a class AdamD General Discussion 0 02-17-2005 22:59
how do you stop a program from calling home? sb1855 General Discussion 4 03-29-2003 04:40
Softice - how do I return to calling code? sync General Discussion 16 08-22-2002 20:02


All times are GMT +8. The time now is 18:59.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( 1998 - 2024 )