GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-144130: support getrandom syscall on non-linux by dankm · Pull Request #144131 · python/cpython Conversation
|
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
7b9fb51 to
5da4196
Compare
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
fe5aacd to
3e595a5
Compare
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.
3e595a5 to
f3af163
Compare
There was a problem 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?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
According to the FreeBSD manual page:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Victor Stinner <[email protected]>
I wasn't sure either. The code in bootstrap_hash.c already does the right thing, so I added a note about the BSDs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I meant that the code in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Ah, okay, that makes sense. You're suggesting I make |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@serhiy-storchaka: with this change, Linux getrandom() manual page mentions |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
//#ifndef MS_WINDOWS # ifdef HAVE_LINUX_RANDOM_H # include <linux/random.h> // GRND_NONBLOCK # endif # if defined(HAVE_SYS_RANDOM_H) && (defined(HAVE_GETRANDOM) || defined(HAVE_GETENTROPY)) # include <sys/random.h> // getrandom() # endif # if !defined(HAVE_GETRANDOM) && defined(HAVE_GETRANDOM_SYSCALL) # include <sys/syscall.h> // SYS_getrandom # endif The proposed code: #ifdef HAVE_SYS_RANDOM_H # include <sys/random.h> // GRND_RANDOM on FreeBSD and NetBSD #endif #ifdef HAVE_LINUX_RANDOM_H # include <linux/random.h> // GRND_RANDOM #endif #ifdef HAVE_GETRANDOM_SYSCALL # include <sys/syscall.h> // syscall() #endif They are not identical. Different order of includes. Different conditions. I suggest to make them identical, so we will not introduce subtle bugs in future. Also, if the code in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@dankm: Can you apply @serhiy-storchaka's suggestions? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Well that's what I get for not testing a proposed change, I'll fix it in the morning. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This was suggested by @serhiy-storchaka during review.
|
"Merge branch 'main' into dankm/getrandom": please avoid that unless there is a good reason to do that. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Noted for the future. If figured it might be the way to get past some failures on MacOS I was seeing with my previous update. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| #if defined(HAVE_SYS_RANDOM_H) && (defined(HAVE_GETRANDOM) || defined(HAVE_GETENTROPY)) | ||
| # include <sys/random.h> // getrandom(), GRND_NONBLOCK on FreeBSD and NetBSD | ||
| #endif | ||
| #ifdef HAVE_GETRANDOM_SYSCALL |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| #ifdef HAVE_GETRANDOM_SYSCALL | |
| #if !defined(HAVE_GETRANDOM) && defined(HAVE_GETRANDOM_SYSCALL) |
Also, in the code below which checks HAVE_GETRANDOM_SYSCALL, we should also check HAVE_GETRANDOM and use getrandom() if available.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to leave the PR as it is (#ifdef HAVE_GETRANDOM_SYSCALL). I will write a following PR to reuse Python/bootstrap_hash.c code in Modules/posixmodule.c. The bootstrap_hash.c code is more complete, it handles properly Solaris for example.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| #ifdef HAVE_LINUX_RANDOM_H | ||
| # include <linux/random.h> // GRND_RANDOM | ||
| #endif | ||
| #if defined(HAVE_SYS_RANDOM_H) && (defined(HAVE_GETRANDOM) || defined(HAVE_GETENTROPY)) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The code below does not use getentropy(), so it should be removed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Currently on my FreeBSD 15 (VM), With this change, the Note: I had to remove my configure cache to update properly the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.