Skip to content

Commit

Permalink
fix problems from poll.h postion and range of rand().
Browse files Browse the repository at this point in the history
  • Loading branch information
ken4647 committed Sep 13, 2023
1 parent 1ae6fdd commit 479518b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/arceos_posix_api/ctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include <netinet/in.h>
#include <pthread.h>
#include <stddef.h>
#include <poll.h>
#include <sys/epoll.h>
#include <sys/resource.h>
#include <sys/select.h>
#include <sys/poll.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
Expand Down
4 changes: 2 additions & 2 deletions api/arceos_posix_api/src/imp/io_mpx/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn poll_all(fds: &mut [ctypes::pollfd]) -> LinuxResult<usize> {
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,
Expand All @@ -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);
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions ulib/axlibc/src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 479518b

Please sign in to comment.