https://github.com/python/cpython/commit/4849a01020903a3d727c65130b9193198176c9af
commit: 4849a01020903a3d727c65130b9193198176c9af
branch: main
author: Jonathan J. Helmus <[email protected]>
committer: vstinner <[email protected]>
date: 2026-09-10T22:58:27+02:00
summary:

gh-153400: Support os.getrandom() on old glibc versions (#155762)

Use the libc-provided SYS_getrandom syscall number when available,
falling back to the kernel-provided __NR_getrandom when necessary.

files:
A Misc/NEWS.d/next/Build/2026-08-14-20-16-55.gh-issue-153400.9Oxi-N.rst
M Modules/posixmodule.c
M Python/bootstrap_hash.c
M configure
M configure.ac

diff --git 
a/Misc/NEWS.d/next/Build/2026-08-14-20-16-55.gh-issue-153400.9Oxi-N.rst 
b/Misc/NEWS.d/next/Build/2026-08-14-20-16-55.gh-issue-153400.9Oxi-N.rst
new file mode 100644
index 000000000000000..17241c897905b0e
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2026-08-14-20-16-55.gh-issue-153400.9Oxi-N.rst
@@ -0,0 +1 @@
+Support os.getrandom() when building Python with old glibc versions and recent 
Linux kernel (glibc 2.25 or older and Linux kernel 3.17 or newer). Get the 
syscall number from kernel headers, rather than glibc headers.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 7636d51485c730d..ead2371e3414414 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -161,6 +161,9 @@
 #ifdef HAVE_SYS_SYSCALL_H
 #  include <sys/syscall.h>        // syscall(), __NR_xxx syscall numbers
 #endif
+#if !defined(SYS_getrandom) && defined(__NR_getrandom)
+#  define SYS_getrandom __NR_getrandom
+#endif
 
 #ifdef HAVE_POSIX_SPAWN
 #  include <spawn.h>              // posix_spawn()
diff --git a/Python/bootstrap_hash.c b/Python/bootstrap_hash.c
index 5bc45d503360376..a22688827612657 100644
--- a/Python/bootstrap_hash.c
+++ b/Python/bootstrap_hash.c
@@ -23,7 +23,10 @@
 #    include <sys/random.h>       // getrandom()
 #  endif
 #  if !defined(HAVE_GETRANDOM) && defined(HAVE_GETRANDOM_SYSCALL)
-#    include <sys/syscall.h>      // SYS_getrandom
+#    include <sys/syscall.h>      // __NR_getrandom, SYS_getrandom
+#    if !defined(SYS_getrandom) && defined(__NR_getrandom)
+#      define SYS_getrandom __NR_getrandom
+#    endif
 #  endif
 #endif
 
diff --git a/configure b/configure
index ae3f0450dc7af1b..7d6c321ae38130b 100755
--- a/configure
+++ b/configure
@@ -34338,7 +34338,11 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
     #include <stddef.h>
     #include <unistd.h>
     #include <sys/syscall.h>
-    #include <linux/random.h>
+    #include <linux/random.h>  // GRND_NONBLOCK
+
+    #if !defined(SYS_getrandom) && defined(__NR_getrandom)
+    #  define SYS_getrandom __NR_getrandom
+    #endif
 
     int main(void) {
         char buffer[1];
diff --git a/configure.ac b/configure.ac
index 1c42900cb975c35..0cf27376015aef9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7895,7 +7895,11 @@ AC_LINK_IFELSE(
     #include <stddef.h>
     #include <unistd.h>
     #include <sys/syscall.h>
-    #include <linux/random.h>
+    #include <linux/random.h>  // GRND_NONBLOCK
+
+    #if !defined(SYS_getrandom) && defined(__NR_getrandom)
+    #  define SYS_getrandom __NR_getrandom
+    #endif
 
     int main(void) {
         char buffer[1];

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to