Looking at the disassembly (along with an instruction trace) of ld.so installed in Ubuntu 9.04, I swear I'm seeing data being stored below the stack pointer (i.e., beyond the top of the stack) at times. This seems insane to me, but maybe this is more common than I think. Does this happen often?
Here's what I see:
ebp: 0xBF8269E8, esp: 0xBF8269DC
c98: 8b 45 f0 mov -0x10(%ebp),%eax
c9b: 8d 14 06 lea (%esi,%eax,1),%edx
c9e: 8b 83 28 03 00 00 mov 0x328(%ebx),%eax
ca4: 3b 50 04 cmp 0x4(%eax),%edx
Signal handlers need to be able to create a stack frame anytime. Therefore you always need to follow your ABI's stack protocol.
On PowerPC, a certain number of bytes (half a kilobyte?) are reserved below the stack pointer. (Of course, this may vary between platforms.) Signal handlers then have to waste that much space to avoid interfering with anything. The advantage being elimination of the store+subtract and add instructions that would create a frame for very small leaf functions.
What exactly leads you to believe that stuff is being stored below the stack pointer. All I can see is a negative offset from ebp which is the frame pointer.
This is typically used as a pointer to the next stack frame up from the current for a number of reasons.
ebp are the parameters passed in to this function (above ebp) and locals for this function (below ebp). Using -0x10(%ebp) just means that you're doing something with a local variable.%esp with %ebp and returning.Of course, you may be hitting something below %esp but that would depend on the data being loaded, which isn't actually shown in your sample.
A "diagram" may help:
+------------------------+
| Parameters passed to x |
+------------------------+
| Return address |
%ebp +------------------------+
| Locals for x |
%esp +------------------------+
My memory of this is rusty (the specific instruction may not be exact but they should be good enough to indicate the concept behind it), but the typical function calling sequence is:
push, push, ...).%ebp on to the stack (push %ebp).%ebp with %esp% (mov %ebp, %esp).call XYZ).sub %esp,N).(%ebp+N) for parameters, (%ebp-N) for locals.And, for returning:
%esp with %ebp (mov %esp, %ebp).ret).%ebp off the stack (pop %ebp).add %esp,N).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With