Skip to content

Conversation

@dankm
Copy link

@dankm dankm commented Jan 22, 2026

At least FreeBSD and NetBSD also implement getrandom using the same semantics as Linux >= 3.17. They don't define any of it it in linux/random.h, however. They do define all the necessary bits in sys/random.h. glibc >= 2.25 also defines it there as well as in linux/random.h. Simply use sys/random.h when checking for its existence.

@bedevere-app
Copy link

bedevere-app bot commented Jan 22, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@python-cla-bot
Copy link

python-cla-bot bot commented Jan 22, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jan 22, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

dankm and others added 2 commits January 22, 2026 16:25
At least FreeBSD and NetBSD also implement getrandom using the same
semantics as Linux >= 3.17. They don't define any of it it in
linux/random.h, however. They do define all the necessary bits in
sys/random.h. glibc >= 2.25 also defines it there as well as in
linux/random.h. Simply use sys/random.h when checking for its existence.
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

See Python/bootstrap_hash.c. Could you make the code similar?

@vstinner
Copy link
Member

According to the FreeBSD manual page:

The getrandom() system call first appeared in FreeBSD 12.0.

@dankm
Copy link
Author

dankm commented Jan 23, 2026

According to the FreeBSD manual page:

The getrandom() system call first appeared in FreeBSD 12.0.

Yup, FreeBSD since 12.0 (December 2018), and NetBSD since 10.0 (March 2024) both claim to support the syscall now. I've not tested this on NetBSD, but their documentation is similar to FreeBSD's.

To satisfy my own curiosity I checked DragonFly and OpenBSD's documentation too. DragonFly claims support as of version 5.7. OpenBSD does not claim support, so if it has it it's undocumented, but OpenBSD's man pages are usually complete.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

See Python/bootstrap_hash.c. Could you make the code similar?

@serhiy-storchaka: I didn't understand your comment. Which code should be made similar to Python/bootstrap_hash.c?

Co-authored-by: Victor Stinner <vstinner@python.org>
@dankm
Copy link
Author

dankm commented Jan 23, 2026

@serhiy-storchaka: I didn't understand your comment. Which code should be made similar to Python/bootstrap_hash.c?

I wasn't sure either. The code in bootstrap_hash.c already does the right thing, so I added a note about the BSDs.

@serhiy-storchaka
Copy link
Member

I meant that the code in Python/bootstrap_hash.c already supports sys/random.h (and it is presumably tested), so it would be better to just copy it from Python/bootstrap_hash.c to Modules/posixmodule.c.

@dankm
Copy link
Author

dankm commented Jan 23, 2026

I meant that the code in Python/bootstrap_hash.c already supports sys/random.h (and it is presumably tested), so it would be better to just copy it from Python/bootstrap_hash.c to Modules/posixmodule.c.

Ah, okay, that makes sense. You're suggesting I make Modules/posixmodule.c look like Python/bootstrap_hash.c, keeping Python/bootstrap_hash.c unmodified? I interpreted your suggestion as making modifications to Python/bootstrap_hash.c to reflect the current changes to Modules/posixmodule.c.

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