[libc-commits] [libc] [libc] implement sigsetjmp/siglongjmp for x86-64 (PR #136072)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Fri Apr 18 12:30:14 PDT 2025
================
@@ -0,0 +1,70 @@
+//===-- Implementation of setjmp ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/setjmp/sigsetjmp.h"
+#include "include/llvm-libc-macros/offsetof-macro.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/setjmp/setjmp_impl.h"
+#include "src/setjmp/sigsetjmp_epilogue.h"
+
+#if !defined(LIBC_TARGET_ARCH_IS_X86)
+#error "Invalid file include"
+#endif
+
+namespace LIBC_NAMESPACE_DECL {
+
+#ifdef __i386__
+[[gnu::naked]]
+LLVM_LIBC_FUNCTION(int, sigsetjmp, (sigjmp_buf buf)) {
+ asm(R"(
+ mov 8(%%esp), %%ecx
+ jecxz .Lnosave
+
+ mov 4(%%esp), %%eax
+ pop %c[retaddr](%%eax)
+ mov %%ebx, %c[extra](%%eax)
+ mov %%eax, %%ebx
+ call %P[setjmp]
+ push %c[retaddr](%%ebx)
+ mov %%ebx,4(%%esp)
+ mov %%eax,8(%%esp)
+ mov %c[extra](%%ebx), %%ebx
+ jmp %P[epilogue]
+
+.Lnosave:
+ jmp %P[setjmp])" ::[retaddr] "i"(offsetof(__jmp_buf, sig_retaddr)),
+ [extra] "i"(offsetof(__jmp_buf, sig_extra)), [setjmp] "i"(setjmp),
+ [epilogue] "i"(sigsetjmp_epilogue)
+ : "eax", "ebx", "ecx");
----------------
SchrodingerZhu wrote:
I don't think this is linux-specific.
see https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/siglongjmp.3.html
https://github.com/llvm/llvm-project/pull/136072
More information about the libc-commits
mailing list