diff --git a/.cargo/config.toml b/.cargo/config.toml
new file mode 100644
index 00000000..e703cfb7
--- /dev/null
+++ b/.cargo/config.toml
@@ -0,0 +1,6 @@
+[profile.release]
+#strip = true
+#incremental = true
+#debug = true
+opt-level = 3
+lto = true
diff --git a/Cargo.lock b/Cargo.lock
index d8bcb5c2..9041b746 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1129,9 +1129,6 @@ dependencies = [
[[package]]
name = "ftest"
version = "0.1.0"
-dependencies = [
- "Mstd",
-]
[[package]]
name = "gethostname"
diff --git a/Cargo.toml b/Cargo.toml
index 57bdeab8..05e5f87d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,10 +7,6 @@ members = [
"user/apps/*",
"user/musl/hello",
"user/musl/async_test",
+ "user/musl/ftest",
]
-
-[profile.release]
-#lto = true
-#codegen-units = 1
-
diff --git a/kernel/src/net/mod.rs b/kernel/src/net/mod.rs
index 0a0dba4e..a53d8ac1 100644
--- a/kernel/src/net/mod.rs
+++ b/kernel/src/net/mod.rs
@@ -10,7 +10,7 @@ use alloc::{sync::Arc, vec, vec::Vec};
use constants::{io::OpenFlags, net::*, AlienResult, LinuxErrno};
use knet::{
addr::RawIpV4Addr,
- socket::{SocketData, SocketFile, SocketFileExt},
+ socket::{Socket, SocketData, SocketFile, SocketFileExt},
};
use vfs::kfile::File;
@@ -460,21 +460,45 @@ pub fn socket_pair(domain: usize, s_type: usize, protocol: usize, sv: usize) ->
}
// println_color!(32,
// "socketpair: {:?}, {:?}, {:?}, {:?}",
- // domain, s_type, protocol, sv
+ // domain, socket_type, protocol, sv
// );
let file1 = SocketData::new(domain, socket_type, protocol)?;
- let file2 = file1.clone();
- info!("socket domain: {:?}, type: {:?}", domain, socket_type);
+ let file2 = SocketData::new(domain, socket_type, protocol)?;
if s_type & SocketType::SOCK_NONBLOCK as usize != 0 {
let socket = file1.get_socketdata()?;
file1.set_open_flag(file1.get_open_flag() | OpenFlags::O_NONBLOCK);
socket.set_socket_nonblock(true);
+ let socket = file2.get_socketdata()?;
+ file2.set_open_flag(file2.get_open_flag() | OpenFlags::O_NONBLOCK);
+ socket.set_socket_nonblock(true);
info!("socket with nonblock");
}
if s_type & SocketType::SOCK_CLOEXEC as usize != 0 {
file1.set_close_on_exec();
+ file2.set_close_on_exec();
info!("socket with cloexec");
}
+
+ let socket_guard = file1.get_socketdata()?;
+ match &socket_guard.socket {
+ Socket::Unix(unix_socket) => {
+ unix_socket.set_remote(&(file2));
+ }
+ _ => {
+ panic!("socket_pair: unsupported socket type")
+ }
+ }
+ drop(socket_guard);
+ let socket_guard = file2.get_socketdata()?;
+ match &socket_guard.socket {
+ Socket::Unix(unix_socket) => {
+ unix_socket.set_remote(&file1);
+ }
+ _ => {
+ panic!("socket_pair: unsupported socket type")
+ }
+ }
+ drop(socket_guard);
let task = current_task().unwrap();
let fd1 = task.add_file(file1).map_err(|_| LinuxErrno::EMFILE)?;
let fd2 = task.add_file(file2).map_err(|_| LinuxErrno::EMFILE)?;
diff --git a/kernel/src/task/cpu.rs b/kernel/src/task/cpu.rs
index 313a1b97..6053248f 100644
--- a/kernel/src/task/cpu.rs
+++ b/kernel/src/task/cpu.rs
@@ -166,7 +166,7 @@ pub fn do_exit(exit_code: i32, exit_group: u8) -> isize {
/// 目前该系统调用直接调用[`do_exit`],有关进程组的相关功能有待实现。
#[syscall_func(94)]
pub fn exit_group(exit_code: i32) -> isize {
- do_exit(exit_code, 1)
+ do_exit(exit_code, 0)
}
pub fn check_exit_group() {
diff --git a/kernel/src/time.rs b/kernel/src/time.rs
index e18b2da5..0bddc3df 100644
--- a/kernel/src/time.rs
+++ b/kernel/src/time.rs
@@ -21,11 +21,30 @@ use constants::{
use log::{info, warn};
use platform::{config::CLOCK_FREQ, set_timer};
use syscall_table::syscall_func;
-use timer::{read_timer, TimeNow, Times, ToClock};
+use timer::{get_time_ms, read_timer, TimeNow, Times, ToClock};
use vfs::timerfd::TimerFile;
use crate::task::{current_task, do_suspend, StatisticalData};
+#[inline]
+#[allow(unused)]
+pub fn read_time_ms() -> u64 {
+ get_time_ms() as u64
+}
+
+#[inline]
+#[allow(unused)]
+pub fn read_time_ns() -> u64 {
+ let time = read_timer();
+ time as u64 * 1_000_000_000 / CLOCK_FREQ as u64
+}
+
+#[inline]
+#[allow(unused)]
+pub fn read_time_us() -> u64 {
+ let time = read_timer();
+ time as u64 * 1_000_000 / CLOCK_FREQ as u64
+}
/// 每秒包含的 时间片 数,每隔一个时间片,就会产生一个时钟中断
const TICKS_PER_SEC: usize = 10;
// const TICKS_PER_SEC_IN_KERNEL: usize = 1000;
diff --git a/subsystems/knet/src/socket.rs b/subsystems/knet/src/socket.rs
index b641272a..067e46cc 100644
--- a/subsystems/knet/src/socket.rs
+++ b/subsystems/knet/src/socket.rs
@@ -10,7 +10,7 @@
use alloc::{boxed::Box, sync::Arc};
use core::{
fmt::{Debug, Formatter},
- net::SocketAddr,
+ net::{Ipv4Addr, SocketAddr, SocketAddrV4},
};
use constants::{
@@ -266,7 +266,7 @@ impl SocketData {
.map_err(neterror2alien)?;
}
_ => {
- panic!("bind is not supported")
+ panic!("bind is not supported socket addr: {:?}", socket_addr);
}
}
Ok(())
@@ -329,8 +329,9 @@ impl SocketData {
udp.send(message).map_err(neterror2alien)
}
}
+ Socket::Unix(unix) => unix.send_to(message),
_ => {
- panic!("bind is not supported")
+ panic!("send_to is not supported")
}
}
}
@@ -348,6 +349,11 @@ impl SocketData {
// let peer_addr = udp.peer_addr().map_err(neterror2linux)?;
Ok((recv.0, recv.1))
}
+ Socket::Unix(unix) => {
+ let socket_addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(0, 0, 0, 0), 0));
+ let len = unix.recvfrom(message)?;
+ Ok((len, socket_addr))
+ }
_ => {
panic!("bind is not supported")
}
@@ -434,8 +440,9 @@ impl SocketData {
false
}
}
+ Socket::Unix(unix) => unix.ready_read(),
_ => {
- panic!("bind is not supported")
+ panic!("ready_read is not supported")
}
}
}
diff --git a/subsystems/knet/src/unix.rs b/subsystems/knet/src/unix.rs
index ba866cf5..33722978 100644
--- a/subsystems/knet/src/unix.rs
+++ b/subsystems/knet/src/unix.rs
@@ -1,30 +1,74 @@
//! 有关 Unix 协议族下的套接字结构。(目前有关的功能有待支持)
-use alloc::{string::String, sync::Arc};
+use alloc::{
+ string::String,
+ sync::{Arc, Weak},
+ vec::Vec,
+};
-use constants::LinuxErrno;
+use constants::{AlienResult, LinuxErrno};
use ksync::Mutex;
-use vfs::kfile::File;
+
+use crate::socket::{Socket, SocketFile, SocketFileExt};
/// Unix 协议族下的套接字结构
#[allow(unused)]
pub struct UnixSocket {
- /// 文件路径,即套接字地址
- file_path: Mutex