Skip to content

gh-153400: Add syscall fallbacks for copy_file_range/memfd_create - #155520

Open
daandemeyer wants to merge 1 commit into
python:mainfrom
daandemeyer:push-rwtvzrusrnyp
Open

gh-153400: Add syscall fallbacks for copy_file_range/memfd_create#155520
daandemeyer wants to merge 1 commit into
python:mainfrom
daandemeyer:push-rwtvzrusrnyp

Conversation

@daandemeyer

@daandemeyer daandemeyer commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

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().

@read-the-docs-community

read-the-docs-community Bot commented Aug 10, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34008302 | 📁 Comparing 0dc17c3 against main (219768f)

  🔍 Preview build  

2 files changed
± library/os.html
± whatsnew/changelog.html

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall change LGTM.

Comment thread Modules/posixmodule.c
Comment thread Modules/posixmodule.c
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>
@daandemeyer

Copy link
Copy Markdown
Contributor Author

@vstinner Addressed comments, no other changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jjhelmus

Copy link
Copy Markdown
Contributor

This also closes #153463 and makes #153464 unnecessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants