October 25, 2024
Chicago 12, Melborne City, USA
C#

Does the C runtime clear the home slots of args prior to function calls?


When you call a function from C/C++, that has some params smaller than 64bits, does the runtime zero out the stack memory at the home location of those params? Or does the top of each param contain garbage?

The space for each param is 8 bytes (64bits), but they might represent 8, 16, or 32bit values.

Assume that the params are not passed by register, as this question pertains to any param, not just the first 4.

void foobar(bool a, i32 b, float c, i64 d)
{
    int x = 0, y = 0, z = 0;    
}

----------------------------------------
# Stack Frame #

[... Previous StackFrame ...] // <HIGH ADDRESS>
[d]
[c]
[b]  // Do the top 32 most-significan-bits of param 'b' contain garbage, or zero?
[a]
[ReturnAddr]
[Saved rbp]
[x]
[y]
[z]


// read 'b' value -- if the top 32bits of 'b' contains garbage, rax has wrong value.
mov rax, qword ptr[rbp+24]



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video