sim: Restore stack alignemnt
Reapply the following commit [1], which has been reverted by the recent change [2] with no obvious reasons. Also, add a comment block to explain the calculation. [1] ``` commit298c2e5e4f
Author: YAMAMOTO Takashi <yamamoto@midokura.com> Date: Wed Jan 29 03:26:43 2020 +0900 sim: Fix stack alignment The recent x86-64 convention requires 16-byte alignment before (not after) calling a function. This fixes snprintf crash I observed on macOS while saving XMM registers. ``` [2] ``` commit2335b69120
Author: Xiang Xiao <xiaoxiang@xiaomi.com> Date: Mon Apr 12 23:44:08 2021 +0800 arch: Allocate the space from the beginning in up_stack_frame arch: Allocate the space from the beginning in up_stack_frame and modify the affected portion: 1.Correct the stack dump and check 2.Allocate tls_info_s by up_stack_frame too 3.Move the stack fork allocation from arch to sched Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> ```
This commit is contained in:
parent
64f46b7f7e
commit
7f307f9765
@ -60,7 +60,18 @@ void up_initial_state(struct tcb_s *tcb)
|
||||
}
|
||||
|
||||
memset(&tcb->xcp, 0, sizeof(struct xcptcontext));
|
||||
|
||||
/* Note: The amd64 ABI requires 16-bytes alignment _before_ a function
|
||||
* call.
|
||||
* On the other hand, our way to set up and switch to a new context
|
||||
* is basically a JUMP.
|
||||
* Thus, we need to emulate the effect of a CALL here, by subtracting
|
||||
* sizeof(xcpt_reg_t), which is the amount a CALL would move RSP to store
|
||||
* the return address.
|
||||
*/
|
||||
|
||||
tcb->xcp.regs[JB_SP] = (xcpt_reg_t)tcb->stack_base_ptr +
|
||||
tcb->adj_stack_size;
|
||||
tcb->adj_stack_size -
|
||||
sizeof(xcpt_reg_t);
|
||||
tcb->xcp.regs[JB_PC] = (xcpt_reg_t)tcb->start;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user