Skip to content

Commit 99bf6a7

Browse files
committed
initial socket interface
1 parent a2a3714 commit 99bf6a7

File tree

19 files changed

+1152
-10
lines changed

19 files changed

+1152
-10
lines changed

Cargo.lock

Lines changed: 126 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ringbuf = { version = "0.4.8", default-features = false, features = ["alloc"] }
2222
bitflags = "2.9.1"
2323
futures = { version = "0.3.31", default-features = false, features = ["alloc", "async-await"] }
2424
rand = { version = "0.9.2", default-features = false, features = ["small_rng"] }
25+
smoltcp = { version = "0.12.0", default-features = false, features = ["alloc", "medium-ethernet", "medium-ip", "proto-ipv4", "proto-ipv6", "socket-tcp", "socket-udp"] }
2526

2627
[features]
2728
default = ["smp"]

libkernel/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ pub enum KernelError {
138138
#[error("Operation not supported")]
139139
NotSupported,
140140

141+
#[error("Address family not supported")]
142+
AddressFamilyNotSupported,
143+
141144
#[error("Device probe failed: {0}")]
142145
Probe(#[from] ProbeError),
143146

@@ -180,6 +183,9 @@ pub enum KernelError {
180183
#[error("Operation timed out")]
181184
TimedOut,
182185

186+
#[error("Not a socket")]
187+
NotASocket,
188+
183189
#[error("{0}")]
184190
Other(&'static str),
185191
}

src/arch/arm64/exceptions/syscall.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ use crate::{
7171
threading::{futex::sys_futex, sys_set_robust_list, sys_set_tid_address},
7272
},
7373
sched::{current::current_task, sys_sched_yield},
74+
socket::syscalls::{
75+
accept::sys_accept, bind::sys_bind, connect::sys_connect, listen::sys_listen,
76+
shutdown::sys_shutdown, socket::sys_socket,
77+
},
7478
};
7579
use alloc::boxed::Box;
7680
use libkernel::{
@@ -356,7 +360,12 @@ pub async fn handle_syscall() {
356360
0xb1 => sys_getegid().map_err(|e| match e {}),
357361
0xb2 => sys_gettid().map_err(|e| match e {}),
358362
0xb3 => sys_sysinfo(TUA::from_value(arg1 as _)).await,
359-
0xc6 => Err(KernelError::NotSupported),
363+
0xc6 => sys_socket(arg1 as _, arg2 as _, arg3 as _).await,
364+
0xc8 => sys_bind(arg1.into(), UA::from_value(arg2 as _), arg3 as _).await,
365+
0xc9 => sys_listen(arg1.into(), arg2 as _).await,
366+
0xca => sys_accept(arg1.into()).await,
367+
0xcb => sys_connect(arg1.into(), UA::from_value(arg2 as _), arg3 as _).await,
368+
0xd2 => sys_shutdown(arg1.into(), arg2 as _).await,
360369
0xd6 => sys_brk(VA::from_value(arg1 as _))
361370
.await
362371
.map_err(|e| match e {}),

src/fs/fops.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,12 @@ pub trait FileOps: Send + Sync {
137137
) -> Result<usize> {
138138
Err(KernelError::InvalidValue)
139139
}
140+
141+
fn is_socket(&self) -> bool {
142+
false
143+
}
144+
145+
fn as_socket(&mut self) -> Option<&mut dyn crate::socket::SocketOps> {
146+
None
147+
}
140148
}

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ mod kernel;
4444
mod memory;
4545
mod process;
4646
mod sched;
47+
mod socket;
4748
mod sync;
4849

4950
#[panic_handler]

0 commit comments

Comments
 (0)