Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAL netbsd, the 10th release finally supports getrandom syscall. #583

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/snmalloc/pal/pal_netbsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# include "pal_bsd_aligned.h"

# include <fcntl.h>
# include <sys/syscall.h>

/**
* We skip the pthread cancellation checkpoints by reaching directly
Expand Down Expand Up @@ -42,12 +43,20 @@ namespace snmalloc
PALBSD_Aligned::pal_features | Entropy;

/**
* Temporary solution while waiting getrandom support for the next release
* Temporary solution for NetBSD < 10
* random_device seems unimplemented in clang for this platform
* otherwise using getrandom
*/
static uint64_t get_entropy64()
{
# if defined(SYS_getrandom)
uint64_t result;
if (getrandom(&result, sizeof(result), 0) != sizeof(result))
error("Failed to get system randomness");
return result;
# else
return PALPOSIX::dev_urandom();
# endif
}
};
} // namespace snmalloc
Expand Down