[libc-commits] [libc] [libc] implement sigsetjmp/siglongjmp for x86-64 (PR #136072)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Thu Apr 17 09:32:56 PDT 2025


================
@@ -0,0 +1,76 @@
+//===-- Unittests for sigsetjmp and siglongjmp ----------------------------===//
+//
+// 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/siglongjmp.h"
+#include "src/setjmp/sigsetjmp.h"
+#include "src/signal/sigprocmask.h"
+#include "src/string/memory_utils/inline_memcmp.h"
+#include "src/string/memory_utils/inline_memset.h"
+#include "test/UnitTest/Test.h"
+
+constexpr int MAX_LOOP = 123;
+int longjmp_called = 0;
+
+void jump_back(jmp_buf buf, int n) {
+  longjmp_called++;
+  LIBC_NAMESPACE::siglongjmp(buf, n); // Will return |n| out of setjmp
+}
+
+#define SMOKE_TESTS(SUFFIX, FLAG)                                              \
+  TEST(LlvmLibcSetJmpTest, SigSetAndJumpBack##SUFFIX) {                        \
+    jmp_buf buf;                                                               \
+    longjmp_called = 0;                                                        \
+    volatile int n = 0;                                                        \
+    sigset_t old;                                                              \
+    sigset_t mask_all;                                                         \
+    sigset_t recovered;                                                        \
+    LIBC_NAMESPACE::inline_memset(&mask_all, 0xFF, sizeof(mask_all));          \
+    LIBC_NAMESPACE::inline_memset(&old, 0, sizeof(old));                       \
+    LIBC_NAMESPACE::inline_memset(&recovered, 0, sizeof(recovered));           \
----------------
michaelrj-google wrote:

since this is a test, these can just use the regular `LIBC_NAMESPACE::memset`. Here and for memcmp.

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


More information about the libc-commits mailing list