[libc-commits] [libc] [libc] Implement getcontext and setcontext for x86_64 (PR #192343)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Thu Apr 16 01:16:05 PDT 2026


================
@@ -0,0 +1,78 @@
+//===-- Unittests for ucontext routines -----------------------------------===//
+//
+// 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/ucontext/getcontext.h"
+#include "src/ucontext/setcontext.h"
+
+#include "src/signal/sigaddset.h"
+#include "src/signal/sigemptyset.h"
+#include "src/signal/sigprocmask.h"
+
+#include "test/UnitTest/Test.h"
+
+#include "include/llvm-libc-macros/signal-macros.h"
+
+namespace LIBC_NAMESPACE {
+
+static bool is_signal_set(const sigset_t *set, int signum) {
+  // NSIG is 64, sigset_t is an array of unsigned long.
+  // Signum is 1-indexed.
+  int word = (signum - 1) / (sizeof(unsigned long) * 8);
+  int bit = (signum - 1) % (sizeof(unsigned long) * 8);
+  return (set->__signals[word] & (1UL << bit)) != 0;
+}
+
+volatile int jumped = 0;
----------------
labath wrote:

Could you move this inside the function (as a static), to match the other test?

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


More information about the libc-commits mailing list