Browse Source

[Pal, LibOS] Clear RFLAGS on program entry

SYSV x86-64 ABI requires RFLAGS to be cleared in initial register state.
Isaku Yamahata 5 years ago
parent
commit
8890b325b4
2 changed files with 8 additions and 3 deletions
  1. 3 1
      LibOS/shim/src/elf/shim_rtld.c
  2. 5 2
      Pal/src/db_rtld.c

+ 3 - 1
LibOS/shim/src/elf/shim_rtld.c

@@ -1586,13 +1586,15 @@ int execute_elf_object (struct shim_handle * exec,
 
 #if defined(__x86_64__)
     asm volatile (
+                    "pushq $0\r\n"
+                    "popfq\r\n"
                     "movq %%rbx, %%rsp\r\n"
                     "jmp *%%rax\r\n"
                     :
                     : "a"(entry),
                       "b"(argcp),
                       "d"(0)
-                    : "memory");
+                    : "memory", "cc");
 #else
 # error "architecture not supported"
 #endif

+ 5 - 2
Pal/src/db_rtld.c

@@ -1284,7 +1284,10 @@ void * stack_before_call __attribute_unused = NULL;
 
 #define CALL_ENTRY(l, cookies)                                          \
     ({  long ret;                                                       \
-        __asm__ volatile("movq %%rsp, stack_before_call(%%rip)\r\n"     \
+        __asm__ volatile(                                               \
+                     "pushq $0\r\n"                                     \
+                     "popfq\r\n"                                        \
+                     "movq %%rsp, stack_before_call(%%rip)\r\n"         \
                      "leaq 1f(%%rip), %%rdx\r\n"                        \
                      "movq %2, %%rsp\r\n"                               \
                      "jmp *%1\r\n"                                      \
@@ -1292,7 +1295,7 @@ void * stack_before_call __attribute_unused = NULL;
                                                                         \
                      : "=a"(ret) : "a"(l->l_entry), "b"(cookies)        \
                      : "rcx", "rdx", "rdi", "rsi", "r8", "r9",          \
-                       "r10", "r11", "memory");                         \
+                       "r10", "r11", "memory", "cc");                   \
         ret; })
 #else
 # error "unsupported architecture"