z572 pushed a commit to branch core-packages-team
in repository guix.

commit cb18d4103745c1f44f68b07187c1d9f7dc5c0b69
Author: Zheng Junjie <[email protected]>
AuthorDate: Thu Feb 6 23:59:21 2025 +0800

    DRAFT: gnu: glibc: update to 2.41.
    
    No test hurd.
    
    * gnu/packages/base.scm (glibc): Update to 2.41.
    (%glibc-patches): update it.
    (glibc/hurd)[sources]<patches>: Adjust it.
    * gnu/packages/patches/glibc-2.37-hurd-local-clock_gettime_MONOTONIC.patch:
    Adjust and rename to glibc-2.41-hurd-local-clock_gettime_MONOTONIC.patch.
    * gnu/packages/patches/glibc-2.41-ldd-x86_64.patch: Adjust and rename to
    glibc-2.41-ldd-x86_64.patch.
    * gnu/packages/patches/glibc-hurd64-intr-msg-clobber.patch: Adjust it.
    * gnu/packages/patches/glibc-2.40-CVE-2025-0.patch: Remove it.
    * gnu/packages/patches/glibc-hurd64-fault.patch: Remove it.
    * gnu/packages/patches/glibc-hurd64-sgms-context.patch: Remove it.
    * gnu/local.mk (dist_patch_DATA): Update it.
    
    Change-Id: Ic34f5d58cac7f670af0359ac4febc997c9069ff6
---
 gnu/local.mk                                       |   7 +-
 gnu/packages/base.scm                              |  11 +-
 gnu/packages/patches/glibc-2.40-CVE-2025-0.patch   |  63 ---
 ...-2.41-hurd-local-clock_gettime_MONOTONIC.patch} |  59 +--
 ...dd-x86_64.patch => glibc-2.41-ldd-x86_64.patch} |   6 +-
 gnu/packages/patches/glibc-hurd64-fault.patch      |  32 --
 .../patches/glibc-hurd64-intr-msg-clobber.patch    |  39 +-
 .../patches/glibc-hurd64-sgms-context.patch        | 505 ---------------------
 8 files changed, 16 insertions(+), 706 deletions(-)

diff --git a/gnu/local.mk b/gnu/local.mk
index 2248a5b98b..63116e8e90 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1446,7 +1446,6 @@ dist_patch_DATA =                                         
\
   %D%/packages/patches/glibc-2.39-git-updates.patch    \
   %D%/packages/patches/glibc-2.39-fmod-libm-a.patch            \
   %D%/packages/patches/glibc-2.40-dl-cache.patch               \
-  %D%/packages/patches/glibc-2.40-CVE-2025-0.patch             \
   %D%/packages/patches/glibc-CVE-2019-7309.patch               \
   %D%/packages/patches/glibc-CVE-2019-9169.patch               \
   %D%/packages/patches/glibc-CVE-2019-19126.patch              \
@@ -1465,9 +1464,9 @@ dist_patch_DATA =                                         
\
   %D%/packages/patches/glibc-hurd-clock_gettime_monotonic.patch        \
   %D%/packages/patches/glibc-2.31-hurd-clock_gettime_monotonic.patch   \
   %D%/packages/patches/glibc-2.37-hurd-clock_t_centiseconds.patch      \
-  %D%/packages/patches/glibc-2.37-hurd-local-clock_gettime_MONOTONIC.patch     
\
+  %D%/packages/patches/glibc-2.41-hurd-local-clock_gettime_MONOTONIC.patch     
\
   %D%/packages/patches/glibc-2.37-versioned-locpath.patch      \
-  %D%/packages/patches/glibc-2.38-ldd-x86_64.patch             \
+  %D%/packages/patches/glibc-2.41-ldd-x86_64.patch             \
   %D%/packages/patches/glibc-hurd-clock_t_centiseconds.patch   \
   %D%/packages/patches/glibc-hurd-getauxval.patch              \
   %D%/packages/patches/glibc-hurd-gettyent.patch               \
@@ -1475,9 +1474,7 @@ dist_patch_DATA =                                         
\
   %D%/packages/patches/glibc-hurd-pthread_setcancelstate.patch \
   %D%/packages/patches/glibc-hurd-signal-sa-siginfo.patch      \
   %D%/packages/patches/glibc-hurd64-gcc-14.2-tls-bug.patch     \
-  %D%/packages/patches/glibc-hurd64-fault.patch                        \
   %D%/packages/patches/glibc-hurd64-intr-msg-clobber.patch     \
-  %D%/packages/patches/glibc-hurd64-sgms-context.patch         \
   %D%/packages/patches/glibc-ldd-powerpc.patch                 \
   %D%/packages/patches/glibc-ldd-x86_64.patch                  \
   %D%/packages/patches/glibc-locales.patch                     \
diff --git a/gnu/packages/base.scm b/gnu/packages/base.scm
index 7fb5607b9b..638e5d205f 100644
--- a/gnu/packages/base.scm
+++ b/gnu/packages/base.scm
@@ -896,15 +896,14 @@ the store.")
 
 (define %glibc-patches
   (list "glibc-ldd-powerpc.patch"
-        "glibc-2.38-ldd-x86_64.patch"
+        "glibc-2.41-ldd-x86_64.patch"
         "glibc-2.40-dl-cache.patch"
         "glibc-2.37-versioned-locpath.patch"
         ;; "glibc-allow-kernel-2.6.32.patch"
         "glibc-reinstate-prlimit64-fallback.patch"
         "glibc-supported-locales.patch"
-        "glibc-2.40-CVE-2025-0.patch"
         "glibc-2.37-hurd-clock_t_centiseconds.patch"
-        "glibc-2.37-hurd-local-clock_gettime_MONOTONIC.patch"
+        "glibc-2.41-hurd-local-clock_gettime_MONOTONIC.patch"
         "glibc-hurd-mach-print.patch"
         "glibc-hurd-gettyent.patch"
         "glibc-hurd-getauxval.patch"))
@@ -914,13 +913,13 @@ the store.")
   ;; version 2.28, GNU/Hurd used a different glibc branch.
   (package
    (name "glibc")
-   (version "2.40")
+   (version "2.41")
    (source (origin
             (method url-fetch)
             (uri (string-append "mirror://gnu/glibc/glibc-" version ".tar.xz"))
             (sha256
              (base32
-              "18h50b0zm8dkpzj81w033v99rbxiykk3v697yr4dfqwjbqbr1a0r"))
+              "00g95047sshv0zxk9ja3mi7lzwi8wh8qx0nxngbvgmj5yli6p8m5"))
             (patches (map search-patch %glibc-patches))))
    (properties `((lint-hidden-cve . ("CVE-2024-2961"
                                      "CVE-2024-33601" "CVE-2024-33602"
@@ -1669,9 +1668,7 @@ command.")
        (patches
         (append (origin-patches (package-source glibc))
                 (search-patches "glibc-hurd-pthread_setcancelstate.patch"
-                                "glibc-hurd64-fault.patch"
                                 "glibc-hurd64-intr-msg-clobber.patch"
-                                "glibc-hurd64-sgms-context.patch"
                                 "glibc-hurd64-gcc-14.2-tls-bug.patch")))))))
 
 (define-public glibc/hurd-headers
diff --git a/gnu/packages/patches/glibc-2.40-CVE-2025-0.patch 
b/gnu/packages/patches/glibc-2.40-CVE-2025-0.patch
deleted file mode 100644
index 9dd4eee074..0000000000
--- a/gnu/packages/patches/glibc-2.40-CVE-2025-0.patch
+++ /dev/null
@@ -1,63 +0,0 @@
-From 7d4b6bcae91f29d7b4daf15bab06b66cf1d2217c Mon Sep 17 00:00:00 2001
-From: Siddhesh Poyarekar <[email protected]>
-Date: Tue, 21 Jan 2025 16:11:06 -0500
-Subject: [PATCH] Fix underallocation of abort_msg_s struct (CVE-2025-0395)
-
-Include the space needed to store the length of the message itself, in
-addition to the message string.  This resolves BZ #32582.
-
-Signed-off-by: Siddhesh Poyarekar <[email protected]>
-Reviewed: Adhemerval Zanella  <[email protected]>
-(cherry picked from commit 68ee0f704cb81e9ad0a78c644a83e1e9cd2ee578)
----
- assert/assert.c            | 4 +++-
- sysdeps/posix/libc_fatal.c | 4 +++-
- 2 files changed, 6 insertions(+), 2 deletions(-)
-
-diff --git a/assert/assert.c b/assert/assert.c
-index c29629f5f6..b6e37d694c 100644
---- a/assert/assert.c
-+++ b/assert/assert.c
-@@ -18,6 +18,7 @@
- #include <assert.h>
- #include <atomic.h>
- #include <ldsodefs.h>
-+#include <libc-pointer-arith.h>
- #include <libintl.h>
- #include <stdio.h>
- #include <stdlib.h>
-@@ -65,7 +66,8 @@ __assert_fail_base (const char *fmt, const char *assertion, 
const char *file,
-       (void) __fxprintf (NULL, "%s", str);
-       (void) fflush (stderr);
- 
--      total = (total + 1 + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1);
-+      total = ALIGN_UP (total + sizeof (struct abort_msg_s) + 1,
-+                      GLRO(dl_pagesize));
-       struct abort_msg_s *buf = __mmap (NULL, total, PROT_READ | PROT_WRITE,
-                                       MAP_ANON | MAP_PRIVATE, -1, 0);
-       if (__glibc_likely (buf != MAP_FAILED))
-diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c
-index f9e3425e04..089c47b04b 100644
---- a/sysdeps/posix/libc_fatal.c
-+++ b/sysdeps/posix/libc_fatal.c
-@@ -20,6 +20,7 @@
- #include <errno.h>
- #include <fcntl.h>
- #include <ldsodefs.h>
-+#include <libc-pointer-arith.h>
- #include <paths.h>
- #include <stdarg.h>
- #include <stdbool.h>
-@@ -105,7 +106,8 @@ __libc_message_impl (const char *fmt, ...)
-     {
-       WRITEV_FOR_FATAL (fd, iov, iovcnt, total);
- 
--      total = (total + 1 + GLRO(dl_pagesize) - 1) & ~(GLRO(dl_pagesize) - 1);
-+      total = ALIGN_UP (total + sizeof (struct abort_msg_s) + 1,
-+                      GLRO(dl_pagesize));
-       struct abort_msg_s *buf = __mmap (NULL, total,
-                                       PROT_READ | PROT_WRITE,
-                                       MAP_ANON | MAP_PRIVATE, -1, 0);
--- 
-2.46.0
-
diff --git 
a/gnu/packages/patches/glibc-2.37-hurd-local-clock_gettime_MONOTONIC.patch 
b/gnu/packages/patches/glibc-2.41-hurd-local-clock_gettime_MONOTONIC.patch
similarity index 68%
rename from 
gnu/packages/patches/glibc-2.37-hurd-local-clock_gettime_MONOTONIC.patch
rename to 
gnu/packages/patches/glibc-2.41-hurd-local-clock_gettime_MONOTONIC.patch
index 63e06b8519..ffac180a7b 100644
--- a/gnu/packages/patches/glibc-2.37-hurd-local-clock_gettime_MONOTONIC.patch
+++ b/gnu/packages/patches/glibc-2.41-hurd-local-clock_gettime_MONOTONIC.patch
@@ -8,6 +8,8 @@ vlc however doesn't build when _POSIX_CLOCK_SELECTION is 
enabled but
 _POSIX_TIMERS is not, and they refuse to fix that (see #765578), so disable the
 former.
 
+Adjust for glibc-2.41.
+
 ---
  sysdeps/mach/hurd/bits/posix_opt.h |    2 +-
  sysdeps/unix/clock_gettime.c       |    1 +
@@ -48,8 +50,7 @@ Index: glibc-2.27/sysdeps/mach/hurd/bits/posix_opt.h
  #define _POSIX_THREAD_PROCESS_SHARED  -1
  
  /* The monotonic clock might be available.  */
--#define _POSIX_MONOTONIC_CLOCK        0
-+#define _POSIX_MONOTONIC_CLOCK        200809L
+ #define _POSIX_MONOTONIC_CLOCK        200809L
  
 -/* The clock selection interfaces are available.  */
 -#define _POSIX_CLOCK_SELECTION        200809L
@@ -75,61 +76,13 @@ Index: glibc-upstream/sysdeps/posix/clock_getres.c
  
 --- ./sysdeps/mach/clock_nanosleep.c.original  2020-07-21 00:31:35.226113142 
+0200
 +++ ./sysdeps/mach/clock_nanosleep.c   2020-07-21 00:31:49.026185761 +0200
-@@ -62,7 +62,7 @@
+@@ -62,8 +62,8 @@
  __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
                   struct timespec *rem)
  {
--  if (clock_id != CLOCK_REALTIME
+-  if ((clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC)
 +  if ((clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC && clock_id 
!= CLOCK_MONOTONIC_RAW && clock_id != CLOCK_REALTIME_COARSE && clock_id != 
CLOCK_MONOTONIC_COARSE)
+       || req->tv_sec < 0
        || !valid_nanoseconds (req->tv_nsec)
        || (flags != 0 && flags != TIMER_ABSTIME))
      return EINVAL;
-Index: glibc-2.32/hurd/hurdlock.c
-===================================================================
---- glibc-2.32.orig/hurd/hurdlock.c
-+++ glibc-2.32/hurd/hurdlock.c
-@@ -47,7 +47,7 @@ int
- __lll_abstimed_wait (void *ptr, int val,
-   const struct timespec *tsp, int flags, int clk)
- {
--  if (clk != CLOCK_REALTIME)
-+  if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC)
-     return EINVAL;
- 
-   int mlsec = compute_reltime (tsp, clk);
-@@ -59,7 +59,7 @@ int
- __lll_abstimed_wait_intr (void *ptr, int val,
-   const struct timespec *tsp, int flags, int clk)
- {
--  if (clk != CLOCK_REALTIME)
-+  if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC)
-     return EINVAL;
- 
-   int mlsec = compute_reltime (tsp, clk);
-@@ -79,7 +79,7 @@ int
- __lll_abstimed_xwait (void *ptr, int lo, int hi,
-   const struct timespec *tsp, int flags, int clk)
- {
--  if (clk != CLOCK_REALTIME)
-+  if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC)
-     return EINVAL;
- 
-   int mlsec = compute_reltime (tsp, clk);
-@@ -91,7 +91,7 @@ int
- __lll_abstimed_lock (void *ptr,
-   const struct timespec *tsp, int flags, int clk)
- {
--  if (clk != CLOCK_REALTIME)
-+  if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC)
-     return EINVAL;
- 
-   if (__lll_trylock (ptr) == 0)
-@@ -177,7 +177,7 @@ __lll_robust_abstimed_lock (void *ptr,
-   int wait_time = 25;
-   unsigned int val;
- 
--  if (clk != CLOCK_REALTIME)
-+  if (clk != CLOCK_REALTIME && clk != CLOCK_MONOTONIC)
-     return EINVAL;
- 
-   while (1)
diff --git a/gnu/packages/patches/glibc-2.38-ldd-x86_64.patch 
b/gnu/packages/patches/glibc-2.41-ldd-x86_64.patch
similarity index 72%
rename from gnu/packages/patches/glibc-2.38-ldd-x86_64.patch
rename to gnu/packages/patches/glibc-2.41-ldd-x86_64.patch
index 9db412b5f2..e5e7220ab1 100644
--- a/gnu/packages/patches/glibc-2.38-ldd-x86_64.patch
+++ b/gnu/packages/patches/glibc-2.41-ldd-x86_64.patch
@@ -3,6 +3,6 @@ it's in 'lib/' for us.  This patch fixes that.
 
 --- glibc-2.38/sysdeps/unix/sysv/linux/x86_64/ldd-rewrite.sed
 +++ glibc-2.38/sysdeps/unix/sysv/linux/x86_64/ldd-rewrite.sed
-@@ -1 +1 @@
--s_^\(RTLDLIST=\)\(.*lib\)\(\|64\|x32\)\(/[^/]*\)\(-x86-64\|-x32\)\(\.so\.[0-9.]*\)[
   ]*$_\1"\2\4\6 \264\4-x86-64\6 \2x32\4-x32\6"_
-+s_^\(RTLDLIST=\)\(.*lib\)\(\|64\|x32\)\(/[^/]*\)\(-x86-64\|-x32\)\(\.so\.[0-9.]*\)[
   ]*$_\1"\2\4\6 \2\4-x86-64\6 \2x32\4-x32\6"_
+@@ -1,1 +1,1 @@
+-s_^\(RTLDLIST=\)\(.*lib\)\(\|64\|x32\)\(/[^/]*\)\(-x86-64\|-x32\)\(\.so\.[0-9.]*\)[
   ]*$_\1"\264\4-x86-64\6 \2\4\6 \2x32\4-x32\6"_
++s_^\(RTLDLIST=\)\(.*lib\)\(\|64\|x32\)\(/[^/]*\)\(-x86-64\|-x32\)\(\.so\.[0-9.]*\)[
   ]*$_\1"\2\4-x86-64\6 \2\4\6 \2x32\4-x32\6"_
diff --git a/gnu/packages/patches/glibc-hurd64-fault.patch 
b/gnu/packages/patches/glibc-hurd64-fault.patch
deleted file mode 100644
index 24980e8c2a..0000000000
--- a/gnu/packages/patches/glibc-hurd64-fault.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-Upstream-status: Taken from: 
<https://salsa.debian.org/glibc-team/glibc/-/blob/c36c87acb1a35d6e06db6cef1e28cf2f405e1a9e/debian/patches/hurd-i386/git-fault-64bit.diff>.
-
-See <https://lists.gnu.org/archive/html/bug-hurd/2024-11/msg00115.html>.
-
-commit 11ad033e1c09c8b8e7bbaa72420f41ab8bcf0f63
-Author: Flavio Cruz <[email protected]>
-Date:   Tue Jul 30 00:51:20 2024 -0400
-
-    x86_64 hurd: ensure we have a large enough buffer to receive 
exception_raise requests.
-    
-    Message-ID: 
<gtxd6s4s7fi7hdrlb7zayq3akij7x6jqawwq3zfl3v4nqspulo@euucuzeonrl6>
-
-diff --git a/hurd/hurdfault.c b/hurd/hurdfault.c
-index 5110c6030f..1fe973f54d 100644
---- a/hurd/hurdfault.c
-+++ b/hurd/hurdfault.c
-@@ -121,7 +121,14 @@ faulted (void)
-   struct
-     {
-       mach_msg_header_t head;
--      char buf[64];
-+        /* This is the size of the exception_raise request
-+         * including mach_msg_header_t.
-+         * See generated code in faultexc_server.c.  */
-+#ifdef __LP64__
-+        char buf[112];
-+#else
-+        char buf[64];
-+#endif
-     } request;
-   mig_reply_header_t reply;
-   extern int _hurdsig_fault_exc_server (mach_msg_header_t *,
diff --git a/gnu/packages/patches/glibc-hurd64-intr-msg-clobber.patch 
b/gnu/packages/patches/glibc-hurd64-intr-msg-clobber.patch
index 600f89a711..4cfbd6b313 100644
--- a/gnu/packages/patches/glibc-hurd64-intr-msg-clobber.patch
+++ b/gnu/packages/patches/glibc-hurd64-intr-msg-clobber.patch
@@ -1,40 +1,3 @@
-Upstream-status: Taken from 
<https://salsa.debian.org/glibc-team/glibc/-/blob/c36c87acb1a35d6e06db6cef1e28cf2f405e1a9e/debian/patches/hurd-i386/git-intr-msg-clobber.diff>.
-
-See <https://lists.gnu.org/archive/html/bug-hurd/2024-11/msg00115.html>,
-and <https://lists.debian.org/debian-hurd/2024/07/msg00063.html>.
-
-Commited for 2.40
-
-commit c8b4ce0b368115714bd4cce131e1683759471099
-Author: Samuel Thibault <[email protected]>
-Date:   Sat Jul 13 17:00:55 2024 +0200
-
-    hurd: Fix restoring message to be retried
-    
-    save_data stores the start of the original message to be retried,
-    overwritten by the EINTR reply. In 64b builds the overwrite is however
-    rounded up to the 64b pointer size, so we have to save more than just
-    the 32b err.
-    
-    Thanks a lot to Luca Dariz for the investigation!
-
-diff --git a/hurd/intr-msg.c b/hurd/intr-msg.c
-index 2c2e7dc463..424c1fc700 100644
---- a/hurd/intr-msg.c
-+++ b/hurd/intr-msg.c
-@@ -42,7 +42,10 @@ _hurd_intr_rpc_mach_msg (mach_msg_header_t *msg,
-   struct clobber
-   {
-     mach_msg_type_t type;
--    error_t err;
-+    union {
-+      error_t err;
-+      uintptr_t align;
-+    };
-   };
-   union msg
-   {
-
 Taken from: 
<https://salsa.debian.org/glibc-team/glibc/-/blob/027f94215a633cbf53794d4b48675fde36706e35/debian/patches/hurd-i386/local-intr-msg-clobber.diff>
 
 Force putting save_data on the stack rather than in SSE register
@@ -51,7 +14,7 @@ Index: glibc-2.38/hurd/intr-msg.c
 ===================================================================
 --- glibc-2.38.orig/hurd/intr-msg.c
 +++ glibc-2.38/hurd/intr-msg.c
-@@ -79,7 +79,7 @@ _hurd_intr_rpc_mach_msg (mach_msg_header
+@@ -66,7 +66,7 @@ _hurd_intr_rpc_mach_msg (mach_msg_header
    mach_msg_bits_t msgh_bits;
    mach_port_t remote_port;
    mach_msg_id_t msgid;
diff --git a/gnu/packages/patches/glibc-hurd64-sgms-context.patch 
b/gnu/packages/patches/glibc-hurd64-sgms-context.patch
deleted file mode 100644
index 7ae45542c1..0000000000
--- a/gnu/packages/patches/glibc-hurd64-sgms-context.patch
+++ /dev/null
@@ -1,505 +0,0 @@
-Upstream-status: Taken from 
<https://salsa.debian.org/glibc-team/glibc/-/blob/62c59900cfdf6b9af187f4ae03addcd7cd226bfc/debian/patches/hurd-i386/git-context.diff>.
-
-commit 88b771ab5e1169e746dbf4a990d90cffc5fa54ea
-Author: Flavio Cruz <[email protected]>
-Date:   Sat Feb 17 15:25:35 2024 -0500
-
-    Implement setcontext/getcontext/makecontext/swapcontext for Hurd x86_64
-    
-    Tested with the tests provided by glibc plus some other toy examples.
-    Message-ID: <[email protected]>
-
-diff --git a/sysdeps/mach/hurd/x86_64/Makefile 
b/sysdeps/mach/hurd/x86_64/Makefile
-index 80cf2eb6dc..2b43f5d625 100644
---- a/sysdeps/mach/hurd/x86_64/Makefile
-+++ b/sysdeps/mach/hurd/x86_64/Makefile
-@@ -3,3 +3,7 @@ ifeq ($(subdir),conform)
- # (missing SA_NOCLDWAIT)
- conformtest-xfail-conds += x86_64-gnu
- endif
-+
-+ifeq ($(subdir),stdlib)
-+sysdep_routines += __start_context
-+endif
-diff --git a/sysdeps/mach/hurd/x86_64/__start_context.S 
b/sysdeps/mach/hurd/x86_64/__start_context.S
-new file mode 100644
-index 0000000000..3cb4c6b5a9
---- /dev/null
-+++ b/sysdeps/mach/hurd/x86_64/__start_context.S
-@@ -0,0 +1,49 @@
-+/* Copyright (C) 2024 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 <sysdep.h>
-+
-+/* This is the helper code which gets called if a function which is
-+   registered with 'makecontext' returns.  In this case we have to
-+   install the context listed in the uc_link element of the context
-+   'makecontext' manipulated at the time of the 'makecontext' call.
-+   If the pointer is NULL the process must terminate.  */
-+
-+
-+ENTRY(__start_context)
-+      /* This removes the parameters passed to the function given to
-+         'makecontext' from the stack.  RBX contains the address
-+         on the stack pointer for the next context.  */
-+      movq    %rbx, %rsp
-+
-+      /* Don't use pop here so that stack is aligned to 16 bytes.  */
-+      movq    (%rsp), %rdi            /* This is the next context.  */
-+      testq   %rdi, %rdi
-+      je      2f                      /* If it is zero exit.  */
-+
-+      call    __setcontext
-+      /* If this returns (which can happen if __sigprocmask fails) we'll
-+         exit the program with the return error value (-1).  */
-+      movq    %rax,%rdi
-+
-+2:
-+      call    HIDDEN_JUMPTARGET(exit)
-+      /* The 'exit' call should never return.  In case it does cause
-+         the process to terminate.  */
-+L(hlt):
-+      hlt
-+END(__start_context)
-diff --git a/sysdeps/mach/hurd/x86_64/getcontext.S 
b/sysdeps/mach/hurd/x86_64/getcontext.S
-new file mode 100644
-index 0000000000..ef431be1a3
---- /dev/null
-+++ b/sysdeps/mach/hurd/x86_64/getcontext.S
-@@ -0,0 +1,68 @@
-+/* Save current context.
-+   Copyright (C) 2024 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 <sysdep.h>
-+
-+#include "ucontext_i.h"
-+
-+
-+ENTRY(__getcontext)
-+      /* Save the preserved registers, the registers used for passing
-+         args, and the return address.  */
-+      movq    %rbx, oRBX(%rdi)
-+      movq    %rbp, oRBP(%rdi)
-+      movq    %r12, oR12(%rdi)
-+      movq    %r13, oR13(%rdi)
-+      movq    %r14, oR14(%rdi)
-+      movq    %r15, oR15(%rdi)
-+
-+      movq    %rdi, oRDI(%rdi)
-+      movq    %rsi, oRSI(%rdi)
-+      movq    %rdx, oRDX(%rdi)
-+      movq    %rcx, oRCX(%rdi)
-+      movq    %r8, oR8(%rdi)
-+      movq    %r9, oR9(%rdi)
-+
-+      movq    (%rsp), %rcx
-+      movq    %rcx, oRIP(%rdi)
-+      leaq    8(%rsp), %rcx           /* Exclude the return address.  */
-+      movq    %rcx, oRSP(%rdi)
-+
-+      /* We have separate floating-point register content memory on the
-+         stack.  We use the __fpregs_mem block in the context.  Set the
-+         links up correctly.  */
-+
-+      leaq    oFPREGSMEM(%rdi), %rcx
-+      movq    %rcx, oFPREGS(%rdi)
-+      /* Save the floating-point environment.  */
-+      fnstenv (%rcx)
-+      fldenv  (%rcx)
-+      stmxcsr oMXCSR(%rdi)
-+
-+      /* Save the current signal mask with
-+       * __sigprocmask(SIG_BLOCK, NULL, oSIGMASK(%rdi)); */
-+      leaq    oSIGMASK(%rdi), %rdx
-+      movq $0, %rsi
-+      movl $SIG_BLOCK, %edi
-+      call    HIDDEN_JUMPTARGET (__sigprocmask)
-+
-+      /* Propagate %rax (and errno, in case).  */
-+      ret
-+PSEUDO_END(__getcontext)
-+
-+weak_alias (__getcontext, getcontext)
-diff --git a/sysdeps/mach/hurd/x86_64/makecontext.c 
b/sysdeps/mach/hurd/x86_64/makecontext.c
-new file mode 100644
-index 0000000000..6990a7775c
---- /dev/null
-+++ b/sysdeps/mach/hurd/x86_64/makecontext.c
-@@ -0,0 +1,119 @@
-+/* Create new context.
-+   Copyright (C) 2024 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 <sysdep.h>
-+#include <stdarg.h>
-+#include <stdint.h>
-+#include <ucontext.h>
-+
-+#include "ucontext_i.h"
-+
-+/* This implementation can handle any ARGC value but only
-+   normal integer parameters.
-+   makecontext sets up a stack and the registers for the
-+   user context. The stack looks like this:
-+               +-----------------------+
-+               | next context          |
-+               +-----------------------+
-+               | parameter 7-n         |
-+             +-----------------------+
-+             | trampoline address    |
-+    %rsp ->    +-----------------------+
-+
-+   The registers are set up like this:
-+     %rdi,%rsi,%rdx,%rcx,%r8,%r9: parameter 1 to 6
-+     %rbx   : address of next context
-+     %rsp   : stack pointer.
-+*/
-+
-+/* XXX: This implementation currently only handles integer arguments.
-+   To handle long int and pointer arguments the va_arg arguments needs
-+   to be changed to long and also the stdlib/tst-setcontext.c file needs
-+   to be changed to pass long arguments to makecontext.  */
-+
-+
-+void
-+__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
-+{
-+  extern void __start_context (void) attribute_hidden;
-+  greg_t *sp;
-+  unsigned int idx_uc_link;
-+  va_list ap;
-+  int i;
-+
-+  /* Generate room on stack for parameter if needed and uc_link.  */
-+  sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp
-+                 + ucp->uc_stack.ss_size);
-+  sp -= (argc > 6 ? argc - 6 : 0) + 1;
-+  /* Align stack and make space for trampoline address.  */
-+  sp = (greg_t *) ((((uintptr_t) sp) & -16L) - 8);
-+
-+  idx_uc_link = (argc > 6 ? argc - 6 : 0) + 1;
-+
-+  /* Setup context ucp.  */
-+  /* Address to jump to.  */
-+  ucp->uc_mcontext.gregs[REG_RIP] = (uintptr_t) func;
-+  /* Setup rbx.*/
-+  ucp->uc_mcontext.gregs[REG_RBX] = (uintptr_t) &sp[idx_uc_link];
-+  ucp->uc_mcontext.gregs[REG_RSP] = (uintptr_t) sp;
-+
-+  /* Setup stack.  */
-+  sp[0] = (uintptr_t) &__start_context;
-+  sp[idx_uc_link] = (uintptr_t) ucp->uc_link;
-+
-+  va_start (ap, argc);
-+  /* Handle arguments.
-+
-+     The standard says the parameters must all be int values.  This is
-+     an historic accident and would be done differently today.  For
-+     x86-64 all integer values are passed as 64-bit values and
-+     therefore extending the API to copy 64-bit values instead of
-+     32-bit ints makes sense.  It does not break existing
-+     functionality and it does not violate the standard which says
-+     that passing non-int values means undefined behavior.  */
-+  for (i = 0; i < argc; ++i)
-+    switch (i)
-+      {
-+      case 0:
-+      ucp->uc_mcontext.gregs[REG_RDI] = va_arg (ap, greg_t);
-+      break;
-+      case 1:
-+      ucp->uc_mcontext.gregs[REG_RSI] = va_arg (ap, greg_t);
-+      break;
-+      case 2:
-+      ucp->uc_mcontext.gregs[REG_RDX] = va_arg (ap, greg_t);
-+      break;
-+      case 3:
-+      ucp->uc_mcontext.gregs[REG_RCX] = va_arg (ap, greg_t);
-+      break;
-+      case 4:
-+      ucp->uc_mcontext.gregs[REG_R8] = va_arg (ap, greg_t);
-+      break;
-+      case 5:
-+      ucp->uc_mcontext.gregs[REG_R9] = va_arg (ap, greg_t);
-+      break;
-+      default:
-+      /* Put value on stack.  */
-+      sp[i - 5] = va_arg (ap, greg_t);
-+      break;
-+      }
-+  va_end (ap);
-+}
-+
-+
-+weak_alias (__makecontext, makecontext)
-diff --git a/sysdeps/mach/hurd/x86_64/setcontext.S 
b/sysdeps/mach/hurd/x86_64/setcontext.S
-new file mode 100644
-index 0000000000..99919ee2a8
---- /dev/null
-+++ b/sysdeps/mach/hurd/x86_64/setcontext.S
-@@ -0,0 +1,96 @@
-+/* Install given context.
-+   Copyright (C) 2024 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 <sysdep.h>
-+
-+#include "ucontext_i.h"
-+
-+
-+ENTRY(__setcontext)
-+      /* Save argument since call will destroy it.  */
-+      pushq   %rdi
-+      cfi_adjust_cfa_offset(8)
-+
-+      /* Set the signal mask with
-+         __sigprocmask (SIG_SETMASK, mask, NULL).  */
-+      xorl    %edx, %edx
-+      leaq    oSIGMASK(%rdi), %rsi
-+      movl    $SIG_SETMASK, %edi
-+      call    HIDDEN_JUMPTARGET (__sigprocmask)
-+      /* Pop the pointer into RDX. The choice is arbitrary, but
-+         leaving RDI and RSI available for use later can avoid
-+         shuffling values.  */
-+      popq    %rdx
-+
-+      test    %rax, %rax
-+      jne     L(pseudo_end)
-+
-+      /* Restore the floating-point context.  Not the registers, only the
-+         rest.  */
-+      movq    oFPREGS(%rdx), %rcx
-+      fldenv  (%rcx)
-+      ldmxcsr oMXCSR(%rdx)
-+
-+      /* Load the new stack pointer, the preserved registers and
-+         registers used for passing args.  */
-+      cfi_def_cfa(%rdx, 0)
-+      cfi_offset(%rbx,oRBX)
-+      cfi_offset(%rbp,oRBP)
-+      cfi_offset(%r12,oR12)
-+      cfi_offset(%r13,oR13)
-+      cfi_offset(%r14,oR14)
-+      cfi_offset(%r15,oR15)
-+      cfi_offset(%rsp,oRSP)
-+      cfi_offset(%rip,oRIP)
-+
-+      movq    oRSP(%rdx), %rsp
-+      movq    oRBX(%rdx), %rbx
-+      movq    oRBP(%rdx), %rbp
-+      movq    oR12(%rdx), %r12
-+      movq    oR13(%rdx), %r13
-+      movq    oR14(%rdx), %r14
-+      movq    oR15(%rdx), %r15
-+
-+      /* The following ret should return to the address set with
-+      getcontext.  Therefore push the address on the stack.  */
-+      movq    oRIP(%rdx), %rcx
-+      pushq   %rcx
-+
-+      movq    oRSI(%rdx), %rsi
-+      movq    oRDI(%rdx), %rdi
-+      movq    oRCX(%rdx), %rcx
-+      movq    oR8(%rdx), %r8
-+      movq    oR9(%rdx), %r9
-+
-+      /* Setup finally %rdx.  */
-+      movq    oRDX(%rdx), %rdx
-+
-+      /* End FDE here, we fall into another context.  */
-+      cfi_endproc
-+      cfi_startproc
-+
-+      /* Clear rax to indicate success.  */
-+      xorl    %eax, %eax
-+L(pseudo_end):
-+      /* The following 'ret' will pop the address of the code and jump
-+         to it.  */
-+      ret
-+PSEUDO_END(__setcontext)
-+libc_hidden_def (__setcontext)
-+
-+weak_alias (__setcontext, setcontext)
-diff --git a/sysdeps/mach/hurd/x86_64/swapcontext.S 
b/sysdeps/mach/hurd/x86_64/swapcontext.S
-new file mode 100644
-index 0000000000..79718a1fdd
---- /dev/null
-+++ b/sysdeps/mach/hurd/x86_64/swapcontext.S
-@@ -0,0 +1,120 @@
-+/* Save current context and install the given one.
-+   Copyright (C) 2024 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 <sysdep.h>
-+
-+#include "ucontext_i.h"
-+
-+
-+/* int __swapcontext (ucontext_t *oucp, const ucontext_t *ucp);
-+
-+  Saves the machine context in oucp such that when it is activated,
-+  it appears as if __swapcontextt() returned again, restores the
-+  machine context in ucp and thereby resumes execution in that
-+  context.
-+
-+  This implementation is intended to be used for *synchronous* context
-+  switches only.  Therefore, it does not have to save anything
-+  other than the PRESERVED state.  */
-+
-+ENTRY(__swapcontext)
-+      /* Save the preserved registers, the registers used for passing args,
-+         and the return address.  */
-+      movq    %rbx, oRBX(%rdi)
-+      movq    %rbp, oRBP(%rdi)
-+      movq    %r12, oR12(%rdi)
-+      movq    %r13, oR13(%rdi)
-+      movq    %r14, oR14(%rdi)
-+      movq    %r15, oR15(%rdi)
-+
-+      movq    %rdi, oRDI(%rdi)
-+      movq    %rsi, oRSI(%rdi)
-+      movq    %rdx, oRDX(%rdi)
-+      movq    %rcx, oRCX(%rdi)
-+      movq    %r8, oR8(%rdi)
-+      movq    %r9, oR9(%rdi)
-+
-+      movq    (%rsp), %rcx
-+      movq    %rcx, oRIP(%rdi)
-+      leaq    8(%rsp), %rcx           /* Exclude the return address.  */
-+      movq    %rcx, oRSP(%rdi)
-+
-+      /* We have separate floating-point register content memory on the
-+         stack.  We use the __fpregs_mem block in the context.  Set the
-+         links up correctly.  */
-+      leaq    oFPREGSMEM(%rdi), %rcx
-+      movq    %rcx, oFPREGS(%rdi)
-+      /* Save the floating-point environment.  */
-+      fnstenv (%rcx)
-+      stmxcsr oMXCSR(%rdi)
-+
-+
-+      /* The function call destroys some registers, save ucp.  */
-+      movq    %rsi, %r12
-+
-+      /* Save the current signal mask and install the new one with
-+         __sigprocmask (SIG_BLOCK, newset, oldset).  */
-+      leaq    oSIGMASK(%rdi), %rdx
-+      leaq    oSIGMASK(%rsi), %rsi
-+      movl    $SIG_SETMASK, %edi
-+      call    HIDDEN_JUMPTARGET (__sigprocmask)
-+      test    %rax, %rax
-+      jne     L(pseudo_end)
-+
-+      /* Restore destroyed register into RDX. The choice is arbitrary,
-+         but leaving RDI and RSI available for use later can avoid
-+         shuffling values.  */
-+      movq    %r12, %rdx
-+
-+      /* Restore the floating-point context.  Not the registers, only the
-+         rest.  */
-+      movq    oFPREGS(%rdx), %rcx
-+      fldenv  (%rcx)
-+      ldmxcsr oMXCSR(%rdx)
-+
-+      /* Load the new stack pointer and the preserved registers.  */
-+      movq    oRSP(%rdx), %rsp
-+      movq    oRBX(%rdx), %rbx
-+      movq    oRBP(%rdx), %rbp
-+      movq    oR12(%rdx), %r12
-+      movq    oR13(%rdx), %r13
-+      movq    oR14(%rdx), %r14
-+      movq    oR15(%rdx), %r15
-+
-+      /* The following ret should return to the address set with
-+      getcontext.  Therefore push the address on the stack.  */
-+      movq    oRIP(%rdx), %rcx
-+      pushq   %rcx
-+
-+      /* Setup registers used for passing args.  */
-+      movq    oRDI(%rdx), %rdi
-+      movq    oRSI(%rdx), %rsi
-+      movq    oRCX(%rdx), %rcx
-+      movq    oR8(%rdx), %r8
-+      movq    oR9(%rdx), %r9
-+
-+      /* Setup finally %rdx.  */
-+      movq    oRDX(%rdx), %rdx
-+
-+      /* Clear rax to indicate success.  */
-+      xorl    %eax, %eax
-+L(pseudo_end):
-+      ret
-+PSEUDO_END(__swapcontext)
-+
-+weak_alias (__swapcontext, swapcontext)

Reply via email to