Skip to content

Commit

Permalink
feat: first time could be compiled (#917)
Browse files Browse the repository at this point in the history
* feat: add options for socket

* feat: print prettier

* add cloud-seed

* feat: improve debug logging for syscall_handler

* 修复mprotect系统调用未正确设置vm_flags的错误 (#847)

* fix(time): modify update wall time (#836)

更改了时间子系统的update_wall_time函数,通过读取当前周期数,计算delta值进行更新,而不是通过传入delta值进行更新

* chore: 调整triagebot.toml以适应新的组织架构 (#848)

* doc: 完善README.md (#849)

* doc: 完善README.md

* chore: 更新sphinx相关配置,适应read the docs的更新 (#850)

根据read the docs在7月15日blog,进行此修改

https://about.readthedocs.com/blog/2024/07/addons-by-default/

* feat(driver/net): 实现Loopback网卡接口 (#845)

* 初步实现loopback设备

* fix: build-scripts和tools目录下的make check指定工具链版本 (#861)

* fix: tcp poll没有正确处理posix socket的listen状态的问题 (#859)

* chore: 将工具链更新到2024-07-23 (#864)

* chore: 将工具链更新到2024-07-23

* remove uneccecary import

* feat(fs): add eventfd syscall support (#858)

* feat(fs): add eventfd syscall support

* refactor: 删除过时的va-pa转换函数,改为统一使用MMArch (#862)

* 默认nightly-2024-07-23 & config改为config.toml (#872)

* fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。 (#870)

* fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。

* make some updates

* chore: 将工具链更新到2024-07-23 (#864)

* chore: 将工具链更新到2024-07-23

* feat(fs): add eventfd syscall support (#858)

* feat(fs): add eventfd syscall support

* refactor: 删除过时的va-pa转换函数,改为统一使用MMArch (#862)

* 默认nightly-2024-07-23 & config改为config.toml (#872)

* fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。 (#870)

* fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。

* feat(cred): 初步实现Cred (#846)

* 初步实现Cred

* 添加seteuid和setegid

* 添加cred测试程序

* 修改Cred::fscmp返回结果为CredFsCmp枚举

* 完善root用户相关信息

* feat: alloc 127.0.0.2 ~ 127.0.0.8 to loopback device

* chore: 将工具链更新到2024-07-23 (#864)

* chore: 将工具链更新到2024-07-23

* fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。 (#870)

* fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。

* feat(cred): 初步实现Cred (#846)

* 初步实现Cred

* 添加seteuid和setegid

* 添加cred测试程序

* 修改Cred::fscmp返回结果为CredFsCmp枚举

* 完善root用户相关信息

* allow deadcode

* allign syscall print

* change iface (origin netdevice)

* dev: rebuild net day1

* fix: 修复键盘码解析器没能正确处理类似ctrl C的控制字符的问题 (#877)

* fix: 修复键盘码解析器没能正确处理类似ctrl C的控制字符的问题

* fix: 解决ntty潜在的panic问题

* 重写datagram,构建inet socket底层

* feat: add tcp, add udp poll

* feat: redefine socket interface

* ci: enable ci workflow on branches other than master (#891)

* 修复unlink、unlinkat系统调用的路径错误 (#892)

* fix: socket shutdown wrong implement (#893)

* implment methods with poll_iface, and complete udp tcp poll.

* feat: add tcp connecting middle state

* fix: correct tcp connect state machine

* feat: tcp connect check

* feat: add inet socket iface

* fix net iface poll

* feat: 增加tokio异步运行时支持 (#894)

* fix the EventFdFlags error

* feat: support tokio (Single thread version)

Fix deadlock issue on closing file.
Add function for PipeInode and EventFdInode.

* fix font size problem

* fix: pipe 读取/写入阻塞时,无法kill进程的问题 (#889)

* diable file autoSave on FocusChange, fix tcp method logics

* fix: change back socket inode design.
必须要有一个SocketInode承担IndexNode操作与Socket层之间的交互。
然后发现fcntl是无法将nonblock等flag传入socket层的,需要再改。

* feat: define socket trait, move unused definitions into socket/define

* feat: add recv_msg and send_msg method

* fix: syscalls

* feat: 精简 epoll items

* feat: a "should be able to go though compilation" commit

---------

Co-authored-by: MemoryShore <[email protected]>
Co-authored-by: 黄铭涛 <[email protected]>
Co-authored-by: LoGin <[email protected]>
Co-authored-by: SMALLC <[email protected]>
Co-authored-by: linfeng <[email protected]>
Co-authored-by: Jomo <[email protected]>
Co-authored-by: Chiichen <[email protected]>
  • Loading branch information
8 people authored Sep 8, 2024
1 parent 575e175 commit 703b8e1
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 337 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,4 @@
],
"rust-analyzer.showUnlinkedFileNotification": false,
"editor.accessibilityPageSize": 15,
"makefile.configureOnOpen": false,
}
1 change: 1 addition & 0 deletions kernel/src/driver/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl IfaceCommon {
return Ok(());
}

// 需要bounds储存具体的Inet Socket信息,以提供不同种类inet socket的事件分发
pub fn bind_socket(&self, socket: Arc<InetSocket>) {
self.bounds.write().push(socket);
}
Expand Down
7 changes: 3 additions & 4 deletions kernel/src/filesystem/vfs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
libs::{rwlock::RwLock, spinlock::SpinLock},
net::{
event_poll::{EPollItem, EPollPrivateData, EventPoll},
socket::{Inode as SocketInode, Socket},
socket::Inode as SocketInode,
},
process::{cred::Cred, ProcessManager},
};
Expand Down Expand Up @@ -531,9 +531,8 @@ impl File {
pub fn remove_epoll(&self, epoll: &Weak<SpinLock<EventPoll>>) -> Result<(), SystemError> {
match self.file_type {
FileType::Socket => {
let inode = self.inode.downcast_ref::<SocketInode>().unwrap();

socket.remove_epoll(epoll)
let socket = self.inode.downcast_ref::<SocketInode>().unwrap();
socket.epoll_items().remove(epoll)
}
FileType::Pipe => {
let inode = self.inode.downcast_ref::<LockedPipeInode>().unwrap();
Expand Down
11 changes: 7 additions & 4 deletions kernel/src/net/net_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct NetWorkPollFunc;

impl TimerFunction for NetWorkPollFunc {
fn run(&mut self) -> Result<(), SystemError> {
poll_ifaces_try_lock(10).ok();
poll_ifaces();
let next_time = next_n_ms_timer_jiffies(10);
let timer = Timer::new(Box::new(NetWorkPollFunc), next_time);
timer.activate();
Expand Down Expand Up @@ -62,13 +62,16 @@ fn dhcp_query() -> Result<(), SystemError> {
// IMPORTANT: This should be removed in production.
dhcp_socket.set_max_lease_duration(Some(smoltcp::time::Duration::from_secs(10)));

let dhcp_handle = SOCKET_SET.lock_irqsave().add(dhcp_socket);
let sockets = || { net_face.sockets().lock_irqsave() };

// let dhcp_handle = SOCKET_SET.lock_irqsave().add(dhcp_socket);
let dhcp_handle = sockets().add(dhcp_socket);

const DHCP_TRY_ROUND: u8 = 10;
for i in 0..DHCP_TRY_ROUND {
debug!("DHCP try round: {}", i);
net_face.poll(&mut SOCKET_SET.lock_irqsave()).ok();
let mut binding = SOCKET_SET.lock_irqsave();
net_face.poll();
let mut binding = sockets();
let event = binding.get_mut::<dhcpv4::Socket>(dhcp_handle).poll();

match event {
Expand Down
20 changes: 4 additions & 16 deletions kernel/src/net/socket/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ use crate::net::syscall_util::MsgHdr;
/// ## Reference
/// - [Posix standard](https://pubs.opengroup.org/onlinepubs/9699919799/)
pub trait Socket: Sync + Send + Debug {
/// # `epoll_items`
/// socket的epoll事件集
fn epoll_items(&self) -> EPollItems;

/// # `wait_queue`
/// 获取socket的wait queue
fn wait_queue(&self) -> WaitQueue;
Expand Down Expand Up @@ -149,7 +145,7 @@ pub trait Socket: Sync + Send + Debug {
}

/// # `shutdown`
fn shutdown(&self, how: Shutdown) -> Result<(), SystemError> {
fn shutdown(&self, how: ShutdownTemp) -> Result<(), SystemError> {
Err(ENOSYS)
}

Expand All @@ -162,17 +158,9 @@ pub trait Socket: Sync + Send + Debug {
self.send(buffer, MessageFlag::empty())
}

// /// # `endpoint`
// fn endpoint(&self) -> Option<Endpoint> {
// None
// }

// /// # `peer_endpoint`
// /// 获取对端的端点
// fn peer_endpoint(&self) -> Option<Endpoint> {
// None
// }

fn send_buffer_size(&self) -> usize;
fn recv_buffer_size(&self) -> usize;

// fn write_buffer(&self, _buf: &[u8]) -> Result<usize, SystemError> {
// todo!()
// }
Expand Down
29 changes: 29 additions & 0 deletions kernel/src/net/socket/common/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ impl Shutdown {
// self.bit.load(core::sync::atomic::Ordering::SeqCst) == 0
// }

pub fn from_how(how: usize) -> Self {
Self::from(ShutdownBit::from_bits_truncate(how as u8))
}

pub fn get(&self) -> ShutdownTemp {
ShutdownTemp {
bit: self.bit.load(core::sync::atomic::Ordering::SeqCst),
Expand Down Expand Up @@ -95,4 +99,29 @@ impl ShutdownTemp {
pub fn is_empty(&self) -> bool {
self.bit == 0
}

pub fn from_how(how: usize) -> Self {
Self {
bit: how as u8 + 1,
}
}
}

impl From<ShutdownBit> for ShutdownTemp {
fn from(shutdown_bit: ShutdownBit) -> Self {
match shutdown_bit {
ShutdownBit::SHUT_RD => Self {
bit: RCV_SHUTDOWN,
},
ShutdownBit::SHUT_WR => Self {
bit: SEND_SHUTDOWN,
},
ShutdownBit::SHUT_RDWR => Self {
bit: SHUTDOWN_MASK,
},
_ => Self {
bit: 0,
},
}
}
}
31 changes: 18 additions & 13 deletions kernel/src/net/socket/inet/datagram/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use crate::filesystem::vfs::IndexNode;
use crate::net::event_poll::EPollEventType;
use crate::libs::rwlock::RwLock;
use crate::net::net_core::poll_ifaces;
use crate::net::socket::common::poll_unit::{WaitQueue, EPollItems};
use crate::net::socket::Socket;
use crate::net::socket::*;
use alloc::sync::{Arc, Weak};

pub type SmolUdpSocket = smoltcp::socket::udp::Socket<'static>;
Expand Down Expand Up @@ -207,24 +206,30 @@ impl Socket for UdpSocket {
self.wait_queue.clone()
}

fn epoll_items(&self) -> EPollItems {
self.epoll_items.clone()
}

fn update_io_events(&self) -> Result<EPollEventType, SystemError> {
todo!()
Ok(self.on_events())
}

fn bind(&self, local_endpoint: crate::net::Endpoint) -> Result<(), SystemError> {
match local_endpoint {
crate::net::Endpoint::Ip(local_endpoint) => {
self.do_bind(local_endpoint)
}
_ => Err(EAFNOSUPPORT),
fn bind(&self, local_endpoint: Endpoint) -> Result<(), SystemError> {
if let Endpoint::Ip(local_endpoint) = local_endpoint {
return self.do_bind(local_endpoint);
}
Err(EAFNOSUPPORT)
}

fn send_buffer_size(&self) -> usize {
match self.inner.read().as_ref().unwrap() {
UdpInner::Bound(bound) => bound.with_socket(|socket| socket.payload_send_capacity()),
_ => inner::DEFAULT_TX_BUF_SIZE
}
}

fn recv_buffer_size(&self) -> usize {
match self.inner.read().as_ref().unwrap() {
UdpInner::Bound(bound) => bound.with_socket(|socket| socket.payload_recv_capacity()),
_ => inner::DEFAULT_RX_BUF_SIZE
}
}
}

bitflags! {
Expand Down
37 changes: 36 additions & 1 deletion kernel/src/net/socket/inet/stream/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,39 @@ pub enum Inner {
Connecting(Connecting),
Listening(Listening),
Established(Established),
}
}

impl Inner {
pub fn send_buffer_size(&self) -> usize {
match self {
Inner::Init(_) => DEFAULT_TX_BUF_SIZE,
Inner::Connecting(conn)
=> conn.with_mut(|socket| socket.send_capacity()),
// only the first socket in the list is used for sending
Inner::Listening (listen)
=> listen
.inners[0]
.with_mut::<smoltcp::socket::tcp::Socket, _, _>(
|socket| socket.send_capacity()
),
Inner::Established(est)
=> est.with_mut(|socket| socket.send_capacity()),
}
}

pub fn recv_buffer_size(&self) -> usize {
match self {
Inner::Init(_) => DEFAULT_RX_BUF_SIZE,
Inner::Connecting(conn)
=> conn.with_mut(|socket| socket.recv_capacity()),
// only the first socket in the list is used for receiving
Inner::Listening (listen)
=> listen.inners[0]
.with_mut::<smoltcp::socket::tcp::Socket, _, _>(
|socket| socket.recv_capacity()
),
Inner::Established(est)
=> est.with_mut(|socket| socket.recv_capacity()),
}
}
}
Loading

0 comments on commit 703b8e1

Please sign in to comment.