rust-random / getrandom

A small cross-platform library for retrieving random data from (operating) system source
Apache License 2.0
264 stars 166 forks source link

netbsd: Simplify weak lookup. #484

Closed briansmith closed 2 weeks ago

briansmith commented 2 weeks ago

Remove LazyPtr. Avoid constructing an invalid pointer as a sentinel to indicate that the pointer is uninitialized. Now, a null pointer means it is uninitialized, and a non-null pointer means it is initialized. This is less questionable from a safety perspective, and should also be more efficient.

Reduce duplication between the "getrandom is available" and the fallback case.

newpavlov commented 2 weeks ago

What about the following comment about KERN_ARND?

NetBSD will only return up to 256 bytes at a time, and older NetBSD kernels will fail on longer buffers.

Is it no longer relevant? To be safe it may be worth to use let buflen = min(buflen, 256) in the polyfill function.

briansmith commented 2 weeks ago

What about the following comment about KERN_ARND?

NetBSD will only return up to 256 bytes at a time, and older NetBSD kernels will fail on longer buffers.

Is it no longer relevant? To be safe it may be worth to use let buflen = min(buflen, 256) in the polyfill function.

Thanks. As I mentioned in the other comment, I did make this change.