u-hurd-getrandom
authorDebian Rust Maintainers <pkg-rust-maintainers@alioth-lists.debian.net>
Wed, 12 Jun 2024 15:33:10 +0000 (17:33 +0200)
committerFabian Grünbichler <debian@fabian.gruenbichler.email>
Wed, 12 Jun 2024 15:33:10 +0000 (17:33 +0200)
https://github.com/rust-random/getrandom/pull/370

commit c96bfff10ba20326fc5a89bc7f51056ce8e19e38
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Tue Aug 29 19:45:37 2023 +0000

    Add GNU/Hurd support

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Gbp-Pq: Name u-hurd-getrandom.patch

vendor/getrandom/src/hurd.rs [new file with mode: 0644]
vendor/getrandom/src/lib.rs
vendor/getrandom/src/util_libc.rs

diff --git a/vendor/getrandom/src/hurd.rs b/vendor/getrandom/src/hurd.rs
new file mode 100644 (file)
index 0000000..842b9bc
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2021 Developers of the Rand project.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Implementation for GNU/Hurd
+use crate::util_libc::sys_fill_exact;
+use crate::Error;
+use core::mem::MaybeUninit;
+
+pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
+    sys_fill_exact(dest, |buf| unsafe {
+        libc::getrandom(buf.as_mut_ptr() as *mut libc::c_void, buf.len(), 0)
+    })
+}
index cd8a96020d7096990fe3840230d12c948b75f268..a0f83a563379049c4f2ce2587a16c67e5ca19aa6 100644 (file)
@@ -25,6 +25,7 @@
 //! | Redox             | `*‑redox`          | `/dev/urandom`
 //! | Haiku             | `*‑haiku`          | `/dev/urandom` (identical to `/dev/random`)
 //! | Hermit            | `*-hermit`         | [`sys_read_entropy`]
+//! | Hurd              | `*-hurd-*`         | [`getrandom`][17]
 //! | SGX               | `x86_64‑*‑sgx`     | [`RDRAND`]
 //! | VxWorks           | `*‑wrs‑vxworks‑*`  | `randABytes` after checking entropy pool initialization with `randSecure`
 //! | ESP-IDF           | `*‑espidf`         | [`esp_fill_random`]
 //! [14]: https://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.neutrino.utilities/topic/r/random.html
 //! [15]: https://www.ibm.com/docs/en/aix/7.3?topic=files-random-urandom-devices
 //! [16]: https://man.netbsd.org/getrandom.2
+//! [17]: https://www.gnu.org/software/libc/manual/html_mono/libc.html#index-getrandom
 //!
 //! [`BCryptGenRandom`]: https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom
 //! [`Crypto.getRandomValues`]: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
@@ -278,6 +280,9 @@ cfg_if! {
                         any(target_arch = "wasm32", target_arch = "wasm64"),
                         target_os = "unknown"))] {
         #[path = "js.rs"] mod imp;
+    } else if #[cfg(target_os = "hurd")] {
+        mod util_libc;
+        #[path = "hurd.rs"] mod imp;
     } else if #[cfg(feature = "custom")] {
         use custom as imp;
     } else if #[cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"),
index 4b94144d5400e8274a8df6b36a75b381f99c61e0..99bee3824bf7b1923d02ea1269ca24e632abf5d5 100644 (file)
@@ -19,7 +19,7 @@ use libc::c_void;
 cfg_if! {
     if #[cfg(any(target_os = "netbsd", target_os = "openbsd", target_os = "android"))] {
         use libc::__errno as errno_location;
-    } else if #[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "redox"))] {
+    } else if #[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "hurd", target_os = "redox"))] {
         use libc::__errno_location as errno_location;
     } else if #[cfg(any(target_os = "solaris", target_os = "illumos"))] {
         use libc::___errno as errno_location;