Skip to content

Commit

Permalink
add real time clock
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw2002426 committed Oct 9, 2023
1 parent 2608519 commit be66b99
Show file tree
Hide file tree
Showing 65 changed files with 759 additions and 1,436 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/arceos_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ documentation = "https://rcore-os.github.io/arceos/arceos_api/index.html"
default = []

irq = ["axfeat/irq"]
rtc = ["axfeat/rtc"]
alloc = ["dep:axalloc", "axfeat/alloc"]
multitask = ["axtask/multitask", "axfeat/multitask"]
fs = ["dep:axfs", "axfeat/fs"]
Expand Down
1 change: 0 additions & 1 deletion api/arceos_posix_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ axnet = { path = "../../modules/axnet", optional = true }
# Other crates
axio = { path = "../../crates/axio" }
axerrno = { path = "../../crates/axerrno" }
memory_addr = { path = "../../crates/memory_addr" }
static_assertions = "1.1.0"
spin = { version = "0.9" }
lazy_static = { version = "1.4", features = ["spin_no_std"] }
Expand Down
32 changes: 0 additions & 32 deletions api/arceos_posix_api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,6 @@
fn main() {
use std::io::Write;

fn gen_pthread_cond(out_file: &str) -> std::io::Result<()> {
let (cond_size, _cond_init) = if cfg!(feature = "multitask") {
if cfg!(feature = "smp") {
(5, "{0, 0, 0, 0, 0}") // core::mem::transmute::<_, [usize; 6]>(axsync::Mutex::new(()))
} else {
(4, "{0, 0, 0, 0}") // core::mem::transmute::<_, [usize; 5]>(axsync::Mutex::new(()))
}
} else {
(1, "{0}")
};
let mut output = Vec::new();
writeln!(
output,
"// Generated by arceos_posix_api/build.rs, DO NOT edit!"
)?;
writeln!(
output,
r#"
typedef struct {{
long __l[{cond_size}];
}} pthread_cond_t;
"#
)?;
std::fs::write(out_file, output)?;
Ok(())
}

fn gen_pthread_mutex(out_file: &str) -> std::io::Result<()> {
// TODO: generate size and initial content automatically.
let (mutex_size, mutex_init) = if cfg!(feature = "multitask") {
Expand Down Expand Up @@ -91,10 +64,6 @@ typedef struct {{
"clockid_t",
"rlimit",
"aibuf",
"msghdr",
"pthread_cond_t",
"pthread_condattr_t",
"sysinfo",
];
let allow_vars = [
"O_.*",
Expand Down Expand Up @@ -144,6 +113,5 @@ typedef struct {{
}

gen_pthread_mutex("../../ulib/axlibc/include/ax_pthread_mutex.h").unwrap();
gen_pthread_cond("../../ulib/axlibc/include/ax_pthread_cond.h").unwrap();
gen_c_to_rust_bindings("ctypes.h", "src/ctypes_gen.rs");
}
1 change: 0 additions & 1 deletion api/arceos_posix_api/ctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/sysinfo.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
Expand Down
1 change: 0 additions & 1 deletion api/arceos_posix_api/src/imp/fd_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use spin::RwLock;
use super::stdio::{stdin, stdout};
use crate::ctypes;

/// Maximum number of files per process
pub const AX_FILE_LIMIT: usize = 1024;

pub trait FileLike: Send + Sync {
Expand Down
31 changes: 0 additions & 31 deletions api/arceos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,34 +224,3 @@ pub fn sys_rename(old: *const c_char, new: *const c_char) -> c_int {
Ok(0)
})
}

/// Remove a directory, which must be empty
pub fn sys_rmdir(pathname: *const c_char) -> c_int {
syscall_body!(sys_rmdir, {
let path = char_ptr_to_str(pathname)?;
debug!("sys_rmdir <= path: {:?}", path);
axfs::api::remove_dir(path)?;
Ok(0)
})
}

/// Removes a file from the filesystem.
pub fn sys_unlink(pathname: *const c_char) -> c_int {
syscall_body!(sys_unlink, {
let path = char_ptr_to_str(pathname)?;
debug!("ax_unlink <= path: {:?}", path);
axfs::api::remove_file(path)?;
Ok(0)
})
}

/// Creates a new, empty directory at the provided path.
pub fn sys_mkdir(pathname: *const c_char, mode: ctypes::mode_t) -> c_int {
// TODO: implement mode
syscall_body!(sys_mkdir, {
let path = char_ptr_to_str(pathname)?;
debug!("ax_mkdir <= path: {:?}, mode: {:?}", path, mode);
axfs::api::create_dir(path)?;
Ok(0)
})
}
39 changes: 0 additions & 39 deletions api/arceos_posix_api/src/imp/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,42 +588,3 @@ pub unsafe fn sys_getpeername(
Ok(0)
})
}

/// Send a message on a socket to the address connected.
/// The message is pointed to by the elements of the array msg.msg_iov.
///
/// Return the number of bytes sent if success.
pub unsafe fn sys_sendmsg(
socket_fd: c_int,
msg: *const ctypes::msghdr,
flags: c_int,
) -> ctypes::ssize_t {
debug!("sys_sendmsg <= {} {:#x} {}", socket_fd, msg as usize, flags);
syscall_body!(sys_sendmsg, {
if msg.is_null() {
return Err(LinuxError::EFAULT);
}
let msg = *msg;
if msg.msg_iov.is_null() {
return Err(LinuxError::EFAULT);
}
let iovs = core::slice::from_raw_parts(msg.msg_iov, msg.msg_iovlen as usize);
let socket = Socket::from_fd(socket_fd)?;
let mut ret = 0;

for iov in iovs.iter() {
if iov.iov_base.is_null() {
return Err(LinuxError::EFAULT);
}
let buf = core::slice::from_raw_parts(iov.iov_base as *const u8, iov.iov_len);
ret += match &socket as &Socket {
Socket::Udp(udpsocket) => udpsocket.lock().send_to(
buf,
from_sockaddr(msg.msg_name as *const ctypes::sockaddr, msg.msg_namelen)?,
)?,
Socket::Tcp(tcpsocket) => tcpsocket.lock().send(buf)?,
};
}
Ok(ret)
})
}
97 changes: 0 additions & 97 deletions api/arceos_posix_api/src/imp/pthread/condvar.rs

This file was deleted.

1 change: 0 additions & 1 deletion api/arceos_posix_api/src/imp/pthread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use spin::RwLock;

use crate::ctypes;

pub mod condvar;
pub mod mutex;

lazy_static::lazy_static! {
Expand Down
27 changes: 1 addition & 26 deletions api/arceos_posix_api/src/imp/pthread/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use crate::{ctypes, utils::check_null_mut_ptr};

use axerrno::{LinuxError, LinuxResult};
use axerrno::LinuxResult;
use axsync::Mutex;

use core::ffi::c_int;
Expand Down Expand Up @@ -37,16 +37,6 @@ impl PthreadMutex {
unsafe { self.0.force_unlock() };
Ok(())
}

fn trylock(&self) -> LinuxResult {
match self.0.try_lock() {
Some(mutex_guard) => {
let _guard = ManuallyDrop::new(mutex_guard);
Ok(())
}
None => Err(LinuxError::EBUSY),
}
}
}

/// Initialize a mutex.
Expand Down Expand Up @@ -87,18 +77,3 @@ pub fn sys_pthread_mutex_unlock(mutex: *mut ctypes::pthread_mutex_t) -> c_int {
Ok(0)
})
}

/// Lock the given mutex like sys_pthread_mutex_lock, except that it does not
/// block the calling thread if the mutex is already locked.
///
/// Instead, it returns with the error code EBUSY.
pub fn sys_pthread_mutex_trylock(mutex: *mut ctypes::pthread_mutex_t) -> c_int {
debug!("sys_pthread_mutex_trylock <= {:#x}", mutex as usize);
syscall_body!(sys_pthread_mutex_trylock, {
check_null_mut_ptr(mutex)?;
unsafe {
(*mutex.cast::<PthreadMutex>()).trylock()?;
}
Ok(0)
})
}
32 changes: 0 additions & 32 deletions api/arceos_posix_api/src/imp/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,24 @@ pub unsafe fn sys_getrlimit(resource: c_int, rlimits: *mut ctypes::rlimit) -> c_
debug!("sys_getrlimit <= {} {:#x}", resource, rlimits as usize);
syscall_body!(sys_getrlimit, {
match resource as u32 {
ctypes::RLIMIT_CPU => {}
ctypes::RLIMIT_FSIZE => {}
ctypes::RLIMIT_DATA => {}
ctypes::RLIMIT_STACK => {}
ctypes::RLIMIT_CORE => {}
ctypes::RLIMIT_RSS => {}
ctypes::RLIMIT_NPROC => {}
ctypes::RLIMIT_NOFILE => {}
ctypes::RLIMIT_MEMLOCK => {}
ctypes::RLIMIT_AS => {}
ctypes::RLIMIT_LOCKS => {}
ctypes::RLIMIT_SIGPENDING => {}
ctypes::RLIMIT_MSGQUEUE => {}
ctypes::RLIMIT_NICE => {}
ctypes::RLIMIT_RTPRIO => {}
ctypes::RLIMIT_RTTIME => {}
ctypes::RLIMIT_NLIMITS => {}
_ => return Err(LinuxError::EINVAL),
}
if rlimits.is_null() {
return Ok(0);
}
match resource as u32 {
ctypes::RLIMIT_CPU => {}
ctypes::RLIMIT_FSIZE => {}
ctypes::RLIMIT_DATA => {}
ctypes::RLIMIT_STACK => unsafe {
(*rlimits).rlim_cur = axconfig::TASK_STACK_SIZE as _;
(*rlimits).rlim_max = axconfig::TASK_STACK_SIZE as _;
},
ctypes::RLIMIT_CORE => {}
ctypes::RLIMIT_RSS => {}
ctypes::RLIMIT_NPROC => unsafe {
(*rlimits).rlim_cur = 1;
(*rlimits).rlim_max = 1;
},
#[cfg(feature = "fd")]
ctypes::RLIMIT_NOFILE => unsafe {
(*rlimits).rlim_cur = super::fd_ops::AX_FILE_LIMIT as _;
(*rlimits).rlim_max = super::fd_ops::AX_FILE_LIMIT as _;
},
ctypes::RLIMIT_MEMLOCK => {}
ctypes::RLIMIT_AS => {}
ctypes::RLIMIT_LOCKS => {}
ctypes::RLIMIT_SIGPENDING => {}
ctypes::RLIMIT_MSGQUEUE => {}
ctypes::RLIMIT_NICE => {}
ctypes::RLIMIT_RTPRIO => {}
ctypes::RLIMIT_RTTIME => {}
ctypes::RLIMIT_NLIMITS => {}
_ => {}
}
Ok(0)
Expand Down
Loading

0 comments on commit be66b99

Please sign in to comment.