summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/backend/libc/rand
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:32 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:32 +0000
commit4547b622d8d29df964fa2914213088b148c498fc (patch)
tree9fc6b25f3c3add6b745be9a2400a6e96140046e9 /vendor/rustix/src/backend/libc/rand
parentReleasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz
rustc-4547b622d8d29df964fa2914213088b148c498fc.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/backend/libc/rand')
-rw-r--r--vendor/rustix/src/backend/libc/rand/mod.rs2
-rw-r--r--vendor/rustix/src/backend/libc/rand/syscalls.rs16
-rw-r--r--vendor/rustix/src/backend/libc/rand/types.rs19
3 files changed, 37 insertions, 0 deletions
diff --git a/vendor/rustix/src/backend/libc/rand/mod.rs b/vendor/rustix/src/backend/libc/rand/mod.rs
new file mode 100644
index 000000000..1e0181a99
--- /dev/null
+++ b/vendor/rustix/src/backend/libc/rand/mod.rs
@@ -0,0 +1,2 @@
+pub(crate) mod syscalls;
+pub(crate) mod types;
diff --git a/vendor/rustix/src/backend/libc/rand/syscalls.rs b/vendor/rustix/src/backend/libc/rand/syscalls.rs
new file mode 100644
index 000000000..1c4286235
--- /dev/null
+++ b/vendor/rustix/src/backend/libc/rand/syscalls.rs
@@ -0,0 +1,16 @@
+//! libc syscalls supporting `rustix::rand`.
+
+#[cfg(target_os = "linux")]
+use {super::super::c, super::super::conv::ret_ssize_t, crate::io, crate::rand::GetRandomFlags};
+
+#[cfg(target_os = "linux")]
+pub(crate) fn getrandom(buf: &mut [u8], flags: GetRandomFlags) -> io::Result<usize> {
+ // `getrandom` wasn't supported in glibc until 2.25.
+ weak_or_syscall! {
+ fn getrandom(buf: *mut c::c_void, buflen: c::size_t, flags: c::c_uint) via SYS_getrandom -> c::ssize_t
+ }
+
+ let nread =
+ unsafe { ret_ssize_t(getrandom(buf.as_mut_ptr().cast(), buf.len(), flags.bits()))? };
+ Ok(nread as usize)
+}
diff --git a/vendor/rustix/src/backend/libc/rand/types.rs b/vendor/rustix/src/backend/libc/rand/types.rs
new file mode 100644
index 000000000..2ba3f1119
--- /dev/null
+++ b/vendor/rustix/src/backend/libc/rand/types.rs
@@ -0,0 +1,19 @@
+#[cfg(target_os = "linux")]
+use super::super::c;
+#[cfg(target_os = "linux")]
+use bitflags::bitflags;
+
+#[cfg(target_os = "linux")]
+bitflags! {
+ /// `GRND_*` flags for use with [`getrandom`].
+ ///
+ /// [`getrandom`]: crate::rand::getrandom
+ pub struct GetRandomFlags: u32 {
+ /// `GRND_RANDOM`
+ const RANDOM = c::GRND_RANDOM;
+ /// `GRND_NONBLOCK`
+ const NONBLOCK = c::GRND_NONBLOCK;
+ /// `GRND_INSECURE`
+ const INSECURE = c::GRND_INSECURE;
+ }
+}