FreeBSD 12 has a getrandom syscall; see D471 for discussion
Description
Revisions and Commits
Status | Assigned | Task | ||
---|---|---|---|---|
Resolved | • gniibe | T4288 Add getrandom support for the BSDs | ||
Resolved | • werner | T4294 Release Libgcrypt 1.9.0 |
Event Timeline
In FreeBSD, getrandom(3) became available, when getrandom(2) was added. <-- This is my theory.
If this is true, just use getrandom(3), not using getrandom(2) by syscall.
Besides, glibc (>= 2.25) have getrandom(3) now (reference: https://old.lwn.net/Articles/711013/).
Confirmed my theory of getentropy(3): https://reviews.freebsd.org/rS331279
Since our usage of getrandom is with flag 0, which is same as getentropy, I think that it's good to add HAVE_GETENTROPY feature macro to support getentropy for *BSD (both of FreeBSD and OpenBSD in mind).
My point is: Let us support OpenBSD too.
In my patch, for OpenBSD and FreeBSD (well, other than GNU/Linux), it uses getentropy if available. For GNU/Linux, we use the local macro of getentropy (regardless of the availability of the function), keeping exactly same behavior of syscall with __NR_getrandom.
Sorry for long reply, your change looks ok even though dunno it is meaningful those _gcry_pre_syscall ()/_gcry_post_syscall () surrounding get entropy for example.
These are hooks so that co-operative thread libraries (like ntph) are able to yield control to the system's thread's implementation.
Pushed to master, fixing about return value of getentropy. Tested on FreeBSD 12. Tested on FreeBSD 11 where getentropy is not available.