[libc-commits] [libc] [libc][i386] setjmp/longjmp (PR #112437)

James Y Knight via libc-commits libc-commits at lists.llvm.org
Tue Oct 15 15:29:43 PDT 2024


================
@@ -7,15 +7,34 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/setjmp/longjmp.h"
+#include "include/llvm-libc-macros/offsetof-macro.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 
-#if !defined(LIBC_TARGET_ARCH_IS_X86_64)
+#if !defined(LIBC_TARGET_ARCH_IS_X86)
 #error "Invalid file include"
 #endif
 
 namespace LIBC_NAMESPACE_DECL {
 
+#ifdef __i386__
+[[noreturn]]
+LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
+  asm(R"(
+      mov %[ebx], %%ebx
+      mov %[esi], %%esi
+      mov %[edi], %%edi
+      mov %[ebp], %%ebp
+      mov %[esp], %%esp
+
+      jmp *%[eip]
+      )" ::[ebx] "m"(buf->ebx),
+      [esi] "m"(buf->esi), [edi] "m"(buf->edi), [ebp] "m"(buf->ebp),
+      [esp] "m"(buf->esp), [eip] "m"(buf->eip), [val] "a"(val == 0 ? 1 : val));
+  __builtin_unreachable();
+}
+#else
+[[noreturn]]
 LLVM_LIBC_FUNCTION(void, longjmp, (jmp_buf buf, int val)) {
----------------
jyknight wrote:

(Of course this review isn't about the x86-64 longjmp, but just I see it's also broken similarly.)

https://github.com/llvm/llvm-project/pull/112437


More information about the libc-commits mailing list