[libc-commits] [libc] [llvm] [libc] Implement pthread_cleanup_push and pthread_cleanup_pop (PR #223427)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Wed Sep 16 02:43:37 PDT 2026


================
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation of __pthread_cleanup_push.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/pthread/__pthread_cleanup_push.h"
+#include "hdr/types/struct___pthread_cleanup_frame.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/null_check.h"
+#include "src/__support/threads/thread.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(void, __pthread_cleanup_push,
+                   (struct __pthread_cleanup_frame * frame,
+                    void (*routine)(void *), void *arg)) {
+  LIBC_CRASH_ON_NULLPTR(frame);
+  LIBC_CRASH_ON_NULLPTR(routine);
+  auto *attrib = current_thread().attrib;
+  frame->__routine = routine;
----------------
labath wrote:

Makes sense. Do you have particular method in mind? Xoring in the stack guard is an obvious choice, but we're only setting that up for x86 right now..
(I can try to set it up on other arches as well, I just want to make sure I'm not missing something.)

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


More information about the libc-commits mailing list