Has anyone else been caught out by the fact that x86_64 interrupt stack alignment must be 16 bytes ? And that the processor modifies the stack pointer to enforce this ? I've been getting weird crashes for days. My kmalloc was occasionally allocating thread structures on an 8 byte boundary, and the stack frame within those structures was subsequently misaligned and sometimes thngs got overwritten.
Caveat developor.
- gerryg400
x86_64 interrupt stack alignment
x86_64 interrupt stack alignment
If a trainstation is where trains stop, what is a workstation ?
- AndreaOrru
- Member
- Posts: 50
- Joined: Fri Apr 25, 2008 2:50 pm
- Location: New York
Re: x86_64 interrupt stack alignment
I had the same problem, it really made me crazy.
Close the world, txEn eht nepO
Re: x86_64 interrupt stack alignment
Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3A wrote:In IA-32e mode, the RSP is aligned to a 16-byte boundary before pushing the stack frame. The stack frame itself is aligned on a 16-byte boundary when the interrupt handler is called. The processor can arbitrarily realign the new RSP on interrupts because the previous (possibly unaligned) RSP is unconditionally saved on the newly aligned stack. The previous RSP will be automatically restored by a subsequent IRET.
Re: x86_64 interrupt stack alignment
Hmmm thanks... yes. I know. I just didn't know that my kmalloc was broken. It is supposed to return 16byte aligned memory but during the 64bit port things changed a little.
If a trainstation is where trains stop, what is a workstation ?
Re: x86_64 interrupt stack alignment
I didn't, I've never programmed in 64 bits mode.
- Owen
- Member
- Posts: 1700
- Joined: Fri Jun 13, 2008 3:21 pm
- Location: Cambridge, United Kingdom
- Contact:
Re: x86_64 interrupt stack alignment
To be standard conformant you must return 16-byte aligned memory on 32-bit too (And, with AVX being introduced, that is now increasing to 32-byte alignment)gerryg400 wrote:Hmmm thanks... yes. I know. I just didn't know that my kmalloc was broken. It is supposed to return 16byte aligned memory but during the 64bit port things changed a little.