[v2,1/3] support: Add support_process_shared_robust_mutex

Message ID 20260505190809.3898686-2-adhemerval.zanella@linaro.org (mailing list archive)
State New
Headers
Series nptl: Fix robust mutex support detection and defer robust list initialization |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella Netto May 5, 2026, 7:06 p.m. UTC
  Returns whether process-shared robust mutexes are supported.
---
 support/Makefile               |  1 +
 support/support_mutex_robust.c | 34 ++++++++++++++++++++++++++++++++++
 support/xthread.h              |  3 +++
 3 files changed, 38 insertions(+)
 create mode 100644 support/support_mutex_robust.c
  

Patch

diff --git a/support/Makefile b/support/Makefile
index 3f19a98bdc4..4facaaead6b 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -87,6 +87,7 @@  libsupport-routines = \
   support_isolate_in_subprocess \
   support_mem_access \
   support_mutex_pi_monotonic \
+  support_mutex_robust \
   support_need_proc \
   support_nscd \
   support_open_and_compare_file_bytes \
diff --git a/support/support_mutex_robust.c b/support/support_mutex_robust.c
new file mode 100644
index 00000000000..2957aca230d
--- /dev/null
+++ b/support/support_mutex_robust.c
@@ -0,0 +1,34 @@ 
+/* Returns whether process-shared robust mutexes are supported.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <support/xthread.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+bool
+support_process_shared_robust_mutex (void)
+{
+#ifdef __linux__
+  void *head;
+  size_t len;
+  int r = syscall (__NR_get_robust_list, 0, &head, &len);
+  return r == 0;
+#else
+  return true;
+#endif
+}
diff --git a/support/xthread.h b/support/xthread.h
index d585bd0c3c6..7afd96dd3b9 100644
--- a/support/xthread.h
+++ b/support/xthread.h
@@ -36,6 +36,9 @@  void delayed__exit (int seconds);
 /* Returns true if Priority Inheritance support CLOCK_MONOTONIC.  */
 bool support_mutex_pi_monotonic (void);
 
+/* Returns true if process-shared robust mutexes are supported.  */
+bool support_process_shared_robust_mutex (void);
+
 /* Terminate the process (with exit status 1) if VALUE is not zero.
    In that case, print a failure message to standard output mentioning
    FUNCTION.  The process is terminated with the exit function, so