From 8cb262d0c08f45745a3fb6b399faef3ddce6f7ca Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Tue, 4 Dec 2018 18:45:58 -0800 Subject: [PATCH] [LibOS] Modify restore_context() to avoid clobbering redzone. restore_context() happens to use %rsp - 8 to return which is in redzone. which clobbers redzone. It shouldn't be clobered. So far it seems we're simply lucky. Signed-off-by: Isaku Yamahata --- LibOS/shim/src/shim_checkpoint.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/LibOS/shim/src/shim_checkpoint.c b/LibOS/shim/src/shim_checkpoint.c index e2b66117..4a1d68d3 100644 --- a/LibOS/shim/src/shim_checkpoint.c +++ b/LibOS/shim/src/shim_checkpoint.c @@ -1253,8 +1253,10 @@ void restore_context (struct shim_context * context) debug("restore context: SP = %p, IP = %p\n", context->sp, context->ret_ip); - regs[nregs] = (void *) context->sp - 8; - *(void **) (context->sp - 8) = context->ret_ip; + regs[nregs] = (void *) context->sp; + /* don't clobber redzone. If sigaltstack is used, + * this area won't be clobbered by signal context */ + *(void **) (context->sp - 128 - 8) = context->ret_ip; /* Ready to resume execution, re-enable preemption. */ shim_tcb_t * tcb = SHIM_GET_TLS(); @@ -1279,6 +1281,6 @@ void restore_context (struct shim_context * context) "popq %%rbp\r\n" "popq %%rsp\r\n" "movq $0, %%rax\r\n" - "retq\r\n" + "jmp *-128-8(%%rsp)\r\n" :: "g"(®s) : "memory"); }