From 479518b10b99ef6b1e3a9e12c47754fbf4198694 Mon Sep 17 00:00:00 2001 From: wuzheng Date: Wed, 13 Sep 2023 21:57:42 +0800 Subject: [PATCH] fix problems from poll.h postion and range of rand(). --- api/arceos_posix_api/ctypes.h | 2 +- api/arceos_posix_api/src/imp/io_mpx/poll.rs | 4 ++-- ulib/axlibc/include/{sys => }/poll.h | 0 ulib/axlibc/src/rand.rs | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) rename ulib/axlibc/include/{sys => }/poll.h (100%) diff --git a/api/arceos_posix_api/ctypes.h b/api/arceos_posix_api/ctypes.h index 3a62a65b8..49fa1b5b9 100644 --- a/api/arceos_posix_api/ctypes.h +++ b/api/arceos_posix_api/ctypes.h @@ -12,10 +12,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include diff --git a/api/arceos_posix_api/src/imp/io_mpx/poll.rs b/api/arceos_posix_api/src/imp/io_mpx/poll.rs index 1f38163fb..f725d9b23 100644 --- a/api/arceos_posix_api/src/imp/io_mpx/poll.rs +++ b/api/arceos_posix_api/src/imp/io_mpx/poll.rs @@ -44,7 +44,7 @@ fn poll_all(fds: &mut [ctypes::pollfd]) -> LinuxResult { Ok(events_num) } -// used to monitor multiple file descriptors for events +/// Used to monitor multiple file descriptors for events pub unsafe fn sys_poll( fds: *mut ctypes::pollfd, nfds: ctypes::nfds_t, @@ -53,7 +53,7 @@ pub unsafe fn sys_poll( debug!("ax_poll <= nfds: {} timeout: {}", nfds, timeout); syscall_body!(ax_poll, { - if nfds <= 0 { + if nfds == 0 { return Err(LinuxError::EINVAL); } let fds = core::slice::from_raw_parts_mut(fds, nfds as usize); diff --git a/ulib/axlibc/include/sys/poll.h b/ulib/axlibc/include/poll.h similarity index 100% rename from ulib/axlibc/include/sys/poll.h rename to ulib/axlibc/include/poll.h diff --git a/ulib/axlibc/src/rand.rs b/ulib/axlibc/src/rand.rs index 0e67c30d0..09479ce92 100644 --- a/ulib/axlibc/src/rand.rs +++ b/ulib/axlibc/src/rand.rs @@ -12,14 +12,14 @@ use core::{ }; #[cfg(not(feature = "random-hw"))] -static SEED: AtomicU64 = AtomicU64::new(0xa2ce_a2ce); +static SEED: AtomicU64 = AtomicU64::new(1); /// Returns a 32-bit unsigned pseudo random interger from LCG. #[cfg(not(feature = "random-hw"))] fn random_lcg_32() -> u32 { let new_seed = SEED.load(SeqCst).wrapping_mul(25214903917).wrapping_add(11); SEED.store(new_seed, SeqCst); - new_seed as u32 + (new_seed>>33) as u32 } /// Returns a 64-bit unsigned pseudo random interger from LCG. @@ -65,7 +65,7 @@ fn has_rdrand() -> bool{ } } -/// Return 64-bit unsigned random interger from cpu instruction +/// Return 64-bit unsigned random interger using cpu instruction #[cfg(feature = "random-hw")] fn random_hw() -> u64 { let mut rand:u64; @@ -107,7 +107,7 @@ pub unsafe extern "C" fn rand() -> c_int { #[cfg(feature = "random-hw")]{ match has_rdrand() { true => { - random_hw() as c_int + (random_hw()>>33) as c_int } false => { random_lcg_32() as c_int