Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test_userspace = []
test_all_exceptions = []
external_test_bins = []
vmnet = [] # Use vmnet network config (192.168.64.x) instead of SLIRP (10.0.2.x)
interactive = [] # Boot into init_shell instead of running automated tests
interactive = ["testing"] # Boot into init_shell instead of running automated tests

[dependencies]
bootloader_api = { git = "https://github.com/rust-osdev/bootloader.git", branch = "main" }
Expand Down
2 changes: 2 additions & 0 deletions kernel/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ fn main() {
println!("cargo:rerun-if-changed={}/fork_test.rs", userspace_tests);
println!("cargo:rerun-if-changed={}/clock_gettime_test.rs", userspace_tests);
println!("cargo:rerun-if-changed={}/udp_socket_test.rs", userspace_tests);
println!("cargo:rerun-if-changed={}/unix_socket_test.rs", userspace_tests);
println!("cargo:rerun-if-changed={}/tty_test.rs", userspace_tests);
println!("cargo:rerun-if-changed={}/job_control_test.rs", userspace_tests);
println!("cargo:rerun-if-changed={}/session_test.rs", userspace_tests);
Expand All @@ -111,6 +112,7 @@ fn main() {
println!("cargo:rerun-if-changed={}/pipeline_test.rs", userspace_tests);
println!("cargo:rerun-if-changed={}/sigchld_job_test.rs", userspace_tests);
println!("cargo:rerun-if-changed={}/cwd_test.rs", userspace_tests);
println!("cargo:rerun-if-changed={}/demo.rs", userspace_tests);
println!("cargo:rerun-if-changed={}/lib.rs", libbreenix_dir.to_str().unwrap());
}
} else {
Expand Down
11 changes: 11 additions & 0 deletions kernel/src/ipc/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ pub enum FdKind {
/// Allow unused - constructed when opening /dev/pts/N in Phase 2
#[allow(dead_code)]
PtySlave(u32),
/// Unix stream socket (AF_UNIX, SOCK_STREAM) - for socketpair IPC
UnixStream(alloc::sync::Arc<spin::Mutex<crate::socket::unix::UnixStreamSocket>>),
}

impl core::fmt::Debug for FdKind {
Expand All @@ -133,6 +135,10 @@ impl core::fmt::Debug for FdKind {
FdKind::DevptsDirectory { position } => write!(f, "DevptsDirectory(pos={})", position),
FdKind::PtyMaster(n) => write!(f, "PtyMaster({})", n),
FdKind::PtySlave(n) => write!(f, "PtySlave({})", n),
FdKind::UnixStream(s) => {
let sock = s.lock();
write!(f, "UnixStream({:?})", sock.endpoint)
}
}
}
}
Expand Down Expand Up @@ -497,6 +503,11 @@ impl Drop for FdTable {
// PTY slave doesn't own the pair, just decrement reference
log::debug!("FdTable::drop() - released PTY slave fd {}", i);
}
FdKind::UnixStream(socket) => {
// Close the Unix socket endpoint
socket.lock().close();
log::debug!("FdTable::drop() - closed Unix stream socket fd {}", i);
}
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions kernel/src/ipc/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,25 @@ pub fn poll_fd(fd_entry: &FileDescriptor, events: i16) -> i16 {
revents |= events::POLLERR;
}
}
FdKind::UnixStream(socket_ref) => {
let socket = socket_ref.lock();
// Check for readable data
if (events & events::POLLIN) != 0 {
if socket.has_data() {
revents |= events::POLLIN;
}
}
// Check for writable
if (events & events::POLLOUT) != 0 {
if !socket.peer_closed() {
revents |= events::POLLOUT;
}
}
// Check for peer closed
if socket.peer_closed() && !socket.has_data() {
revents |= events::POLLHUP;
}
}
}

revents
Expand Down
4 changes: 4 additions & 0 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,10 @@ fn kernel_main_continue() -> ! {
log::info!("=== IPC TEST: Pipe syscall functionality ===");
test_exec::test_pipe();

// Test Unix domain socket (AF_UNIX) socketpair syscall
log::info!("=== IPC TEST: Unix domain socket (socketpair) functionality ===");
test_exec::test_unix_socket();

// NOTE: Pipe + fork and concurrent pipe tests removed to reduce test load.
// The core pipe functionality is validated by test_pipe() above.
// These complex multi-process tests cause timing-related timeouts.
Expand Down
5 changes: 5 additions & 0 deletions kernel/src/process/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ impl Process {
// PTY slave doesn't own the pair, just decrement reference
log::debug!("Process::close_all_fds() - released PTY slave fd {}", fd);
}
FdKind::UnixStream(socket) => {
// Close Unix socket endpoint
socket.lock().close();
log::debug!("Process::close_all_fds() - closed Unix stream socket fd {}", fd);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions kernel/src/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

pub mod types;
pub mod udp;
pub mod unix;

use spin::Mutex;

Expand Down
13 changes: 13 additions & 0 deletions kernel/src/socket/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
//!
//! POSIX-compatible socket address structures.

/// Address family: Unix (local)
pub const AF_UNIX: u16 = 1;

/// Address family: Unix (alias for AF_UNIX)
#[allow(dead_code)]
pub const AF_LOCAL: u16 = 1;

/// Address family: IPv4
pub const AF_INET: u16 = 2;

Expand All @@ -11,6 +18,12 @@ pub const SOCK_STREAM: u16 = 1;
/// Socket type: Datagram (UDP)
pub const SOCK_DGRAM: u16 = 2;

/// Socket flag: Non-blocking mode
pub const SOCK_NONBLOCK: u32 = 0x800;

/// Socket flag: Close-on-exec
pub const SOCK_CLOEXEC: u32 = 0x80000;

/// IPv4 socket address structure (matches Linux sockaddr_in)
#[repr(C)]
#[derive(Debug, Clone, Copy)]
Expand Down
Loading
Loading