gh-153400: Add syscall fallbacks for copy_file_range/memfd_create · python/cpython@fe87313 · GitHub
Skip to content

Commit fe87313

Browse files
committed
gh-153400: Add syscall fallbacks for copy_file_range/memfd_create
glibc only grew copy_file_range() and memfd_create() in 2.27, and we compile the os functions out when the libc we build against doesn't have them. That loses them for good in a redistributable built against an older glibc, such as the python-build-standalone builds targeting glibc 2.17, even when the kernel it runs on implements the syscalls. Keep calling the libc wrappers when they are available, so we don't lose their symbol versioning and _FORTIFY_SOURCE checks, and issue the syscall directly when they aren't. If the syscall number is missing as well, the functions are still left out. pidfd_open() and pidfd_getfd() already use raw syscalls, so nothing changes for them. Include <sys/syscall.h> whenever it exists rather than only when the getrandom() syscall was detected, since __NR_* is now needed for more than getrandom(). Signed-off-by: Daan De Meyer <daan@amutable.com>
1 parent b4db948 commit fe87313

4 files changed

Lines changed: 46 additions & 15 deletions

File tree

Doc/library/os.rst

Lines changed: 10 additions & 2 deletions
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
On Linux, :func:`os.copy_file_range` and :func:`os.memfd_create` now fall back
2+
to the raw syscall when the libc Python is built against does not provide the
3+
wrapper function, so they stay available on interpreters built against a libc
4+
older than glibc 2.27.

Modules/clinic/posixmodule.c.h

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

Modules/posixmodule.c

Lines changed: 27 additions & 8 deletions

0 commit comments

Comments
 (0)