madscientist / google-coredumper

Google coredumper library
BSD 3-Clause "New" or "Revised" License
2 stars 4 forks source link

clone: __x86_64__: Align initial stack pointer to 10h. #3

Closed DoctorNoobingstoneIPresume closed 2 years ago

DoctorNoobingstoneIPresume commented 5 years ago

Compiler relies on RSP being aligned to 16-byte boundary before any CALL to a compiled function, in order to easily align stack objects.

When issuing a syscall with __NR_clone, we get to specify the initial stack pointer for the child thread.

This changeset ensures that the stack pointer specified by our caller (local_clone) is adjusted so that it is properly aligned to 16-byte boundary (as for i386).

Another thing that has been changed: In order to put 0 into RBP, "xor rbp, rbp" can be replaced with "xor ebp, ebp", thus saving one byte of machine code (the REX prefix). Reason: If the destination operand of an instruction is a 32-bit general purpose register, the other 32 bits of the 64-bit general purpose register are automatically filled with zero by the CPU (as per AMD64 documentation).

Thank you for your work and for considering this changeset ! (-:

madscientist commented 2 years ago

Thanks! Note, this needs a slight fix, found by @dutow, that I will push shortly.