-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Issue的最下方有BUG的详细中文描述,十分感谢。
Stack Pointer
The end of the input argument area shall be aligned on a 16 (32 or 64, if __m256 or __m512 is passed on stack) byte boundary. In other words, the value (%esp + 4) is always a multiple of 16 (32 or 64) when control is transferred to the function entry point. The stack pointer, %esp, always points to the end of the latest allocated stack frame.
— Intel386-psABI-1.1:2.2.2 The Stack Frame
The stack pointer, %rsp, always points to the end of the latest allocated stack frame.
— Sys V ABI AMD64 Version 1.0:3.2.2 The Stack Frame
The ABI states that the (E|R)SP
should always point to the end of the latest allocated stack frame. But in file coctx_swap.S of libco, the (E|R)SP
had been used to address the memory on the heap.
By default, the signal handler is invoked on the normal process stack. It is possible to arrange that the signal handler uses an alternate stack; see sigalstack(2) for a discussion of how to do this and when it might be useful.
— man 7 signal : Signal dispositions
Terrible things may happend if the (E|R)SP
is pointing to the data structure on the heap when signal comes. (Using the breakpoint
and signal
commands of gdb could produce such bug conveniently. Although by using sigalstack
to change the default signal stack could alleviate the problem, but still, that kind of usage of (E|R)SP
still violates the ABI.)
Control Words of x87 FPU and MXCSR
The control words of x87 FPU and MXCSR should be preserved across function calls (callee saved) in the Sys V ABI of i386 and AMD64. But in the current implementation of coctx_swap
, there is no saving/restoring stuff about them.