Browse Source

[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 <isaku.yamahata@gmail.com>
Isaku Yamahata 6 years ago
parent
commit
8cb262d0c0
1 changed files with 5 additions and 3 deletions
  1. 5 3
      LibOS/shim/src/shim_checkpoint.c

+ 5 - 3
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"(&regs) : "memory");
 }