|
|
@@ -1,9 +1,10 @@
|
|
|
use crate::{
|
|
|
+ io::Buffer as _,
|
|
|
kernel::{
|
|
|
- constants::{CLOCK_MONOTONIC, CLOCK_REALTIME, EINVAL},
|
|
|
+ constants::{CLOCK_MONOTONIC, CLOCK_REALTIME, EINTR, EINVAL},
|
|
|
task::Thread,
|
|
|
timer::{Instant, Ticks},
|
|
|
- user::UserPointerMut,
|
|
|
+ user::{UserBuffer, UserPointerMut},
|
|
|
},
|
|
|
prelude::*,
|
|
|
};
|
|
|
@@ -162,4 +163,22 @@ fn times(tms: *mut TMS) -> KResult<()> {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+#[eonix_macros::define_syscall(SYS_GETRANDOM)]
|
|
|
+fn get_random(buf: *mut u8, len: usize, flags: u32) -> KResult<usize> {
|
|
|
+ if flags != 0 {
|
|
|
+ return Err(EINVAL);
|
|
|
+ }
|
|
|
+
|
|
|
+ let mut buffer = UserBuffer::new(buf, len)?;
|
|
|
+ for i in (0u8..=255).cycle().step_by(53) {
|
|
|
+ let _ = buffer.fill(&[i])?;
|
|
|
+
|
|
|
+ if Thread::current().signal_list.has_pending_signal() {
|
|
|
+ return Err(EINTR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Ok(len)
|
|
|
+}
|
|
|
+
|
|
|
pub fn keep_alive() {}
|