Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4849a01

Browse files
authored
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.
1 parent f64ebfb commit 4849a01

5 files changed

Lines changed: 18 additions & 3 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

Modules/posixmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
#ifdef HAVE_SYS_SYSCALL_H
162162
# include <sys/syscall.h> // syscall(), __NR_xxx syscall numbers
163163
#endif
164+
#if !defined(SYS_getrandom) && defined(__NR_getrandom)
165+
# define SYS_getrandom __NR_getrandom
166+
#endif
164167

165168
#ifdef HAVE_POSIX_SPAWN
166169
# include <spawn.h> // posix_spawn()

Python/bootstrap_hash.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
# include <sys/random.h> // getrandom()
2424
# endif
2525
# if !defined(HAVE_GETRANDOM) && defined(HAVE_GETRANDOM_SYSCALL)
26-
# include <sys/syscall.h> // SYS_getrandom
26+
# include <sys/syscall.h> // __NR_getrandom, SYS_getrandom
27+
# if !defined(SYS_getrandom) && defined(__NR_getrandom)
28+
# define SYS_getrandom __NR_getrandom
29+
# endif
2730
# endif
2831
#endif
2932

configure

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7895,7 +7895,11 @@ AC_LINK_IFELSE(
78957895
#include <stddef.h>
78967896
#include <unistd.h>
78977897
#include <sys/syscall.h>
7898-
#include <linux/random.h>
7898+
#include <linux/random.h> // GRND_NONBLOCK
7899+
7900+
#if !defined(SYS_getrandom) && defined(__NR_getrandom)
7901+
# define SYS_getrandom __NR_getrandom
7902+
#endif
78997903
79007904
int main(void) {
79017905
char buffer[1];

0 commit comments

Comments
 (0)