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
508 changes: 508 additions & 0 deletions docs/planning/SHELL_AND_APPS_ROADMAP.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions kernel/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fn main() {
println!("cargo:rerun-if-changed={}/http_test.rs", userspace_tests);
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={}/lib.rs", libbreenix_dir.to_str().unwrap());
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,10 @@ fn kernel_main_continue() -> ! {
log::info!("=== FS TEST: devfs device files ===");
test_exec::test_devfs();

// Test current working directory syscalls (getcwd, chdir)
log::info!("=== FS TEST: cwd syscalls (getcwd, chdir) ===");
test_exec::test_cwd();

// Test Rust std library support
log::info!("=== STD TEST: Rust std library support ===");
test_exec::test_hello_std_real();
Expand Down
7 changes: 3 additions & 4 deletions kernel/src/process/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ pub fn copy_stack_contents(
///
/// - **umask**: Not yet tracked per-process (uses global default). TODO when implemented.
///
/// - **Current working directory**: Not yet tracked per-process (uses global cwd).
/// TODO when per-process cwd is implemented.
/// - **Current working directory**: Inherited from parent in fork_internal().
///
/// Note: Memory (pages, heap bounds) and stack are copied separately by copy_user_pages()
/// and copy_stack_contents() before this function is called.
Expand Down Expand Up @@ -501,8 +500,8 @@ pub fn copy_process_state(
// 5. Copy umask (when per-process umask is implemented)
// TODO: child_process.umask = parent_process.umask;

// 6. Copy current working directory (when per-process cwd is implemented)
// TODO: child_process.cwd = parent_process.cwd.clone();
// 6. Current working directory: inherited from parent in fork_internal()
// (before copy_process_state is called)

log::debug!(
"copy_process_state: completed state copy for child {}",
Expand Down
18 changes: 12 additions & 6 deletions kernel/src/process/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ impl ProcessManager {
) -> Result<ProcessId, &'static str> {
// Get the parent process info we need (including page table for memory copying)
#[cfg_attr(not(feature = "testing"), allow(unused_variables))]
let (parent_name, parent_entry_point, parent_pgid, parent_sid, parent_thread_info, parent_heap_start, parent_heap_end) = {
let (parent_name, parent_entry_point, parent_pgid, parent_sid, parent_cwd, parent_thread_info, parent_heap_start, parent_heap_end) = {
let parent = self
.processes
.get(&parent_pid)
Expand All @@ -579,6 +579,7 @@ impl ProcessManager {
parent.entry_point,
parent.pgid,
parent.sid,
parent.cwd.clone(),
_parent_thread.clone(),
parent.heap_start,
parent.heap_end,
Expand All @@ -601,9 +602,10 @@ impl ProcessManager {
// Create the child process with the same entry point
let mut child_process = Process::new(child_pid, child_name.clone(), parent_entry_point);
child_process.parent = Some(parent_pid);
// POSIX: Child inherits parent's process group and session
// POSIX: Child inherits parent's process group, session, and working directory
child_process.pgid = parent_pgid;
child_process.sid = parent_sid;
child_process.cwd = parent_cwd.clone();

// COPY-ON-WRITE FORK: Share pages between parent and child
#[cfg(feature = "testing")]
Expand Down Expand Up @@ -672,7 +674,7 @@ impl ProcessManager {
) -> Result<ProcessId, &'static str> {
// Get the parent process info we need (including page table for memory copying)
#[cfg_attr(not(feature = "testing"), allow(unused_variables))]
let (parent_name, parent_entry_point, parent_pgid, parent_sid, parent_thread_info, parent_heap_start, parent_heap_end) = {
let (parent_name, parent_entry_point, parent_pgid, parent_sid, parent_cwd, parent_thread_info, parent_heap_start, parent_heap_end) = {
let parent = self
.processes
.get(&parent_pid)
Expand All @@ -689,6 +691,7 @@ impl ProcessManager {
parent.entry_point,
parent.pgid,
parent.sid,
parent.cwd.clone(),
_parent_thread.clone(),
parent.heap_start,
parent.heap_end,
Expand All @@ -711,9 +714,10 @@ impl ProcessManager {
// Create the child process with the same entry point
let mut child_process = Process::new(child_pid, child_name.clone(), parent_entry_point);
child_process.parent = Some(parent_pid);
// POSIX: Child inherits parent's process group and session
// POSIX: Child inherits parent's process group, session, and working directory
child_process.pgid = parent_pgid;
child_process.sid = parent_sid;
child_process.cwd = parent_cwd.clone();

// COPY-ON-WRITE FORK: Share pages between parent and child
// Pages are marked read-only and only copied when written to
Expand Down Expand Up @@ -1096,16 +1100,18 @@ impl ProcessManager {
// Create child process name
let child_name = format!("{}_child_{}", parent.name, child_pid.as_u64());

// Capture parent's pgid and sid before borrowing page_table
// Capture parent's pgid, sid, and cwd before borrowing page_table
let parent_pgid = parent.pgid;
let parent_sid = parent.sid;
let parent_cwd = parent.cwd.clone();

// Create the child process with the same entry point
let mut child_process = Process::new(child_pid, child_name.clone(), parent.entry_point);
child_process.parent = Some(parent_pid);
// POSIX: Child inherits parent's process group and session
// POSIX: Child inherits parent's process group, session, and working directory
child_process.pgid = parent_pgid;
child_process.sid = parent_sid;
child_process.cwd = parent_cwd;

// Extract parent heap bounds before we drop the parent borrow
let parent_heap_start = parent.heap_start;
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 @@ -54,6 +54,9 @@ pub struct Process {
/// a controlling terminal. Initially set to pid on process creation.
pub sid: ProcessId,

/// Current working directory (absolute path)
pub cwd: String,

/// Process name (for debugging)
pub name: String,

Expand Down Expand Up @@ -130,6 +133,8 @@ impl Process {
pgid: id,
// By default, a process's sid equals its pid (process is its own session leader)
sid: id,
// Default working directory is root
cwd: String::from("/"),
name,
state: ProcessState::Creating,
entry_point,
Expand Down
2 changes: 2 additions & 0 deletions kernel/src/syscall/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub fn dispatch_syscall(
SyscallNumber::GetSid => super::session::sys_getsid(arg1 as i32),
// Filesystem syscalls
SyscallNumber::Access => super::fs::sys_access(arg1, arg2 as u32),
SyscallNumber::Getcwd => super::fs::sys_getcwd(arg1, arg2),
SyscallNumber::Chdir => super::fs::sys_chdir(arg1),
SyscallNumber::Open => super::fs::sys_open(arg1, arg2 as u32, arg3 as u32),
SyscallNumber::Lseek => super::fs::sys_lseek(arg1 as i32, arg2 as i64, arg3 as i32),
SyscallNumber::Fstat => super::fs::sys_fstat(arg1 as i32, arg2),
Expand Down
3 changes: 3 additions & 0 deletions kernel/src/syscall/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub const ENOSPC: i32 = 28;
/// Broken pipe
pub const EPIPE: i32 = 32;

/// Result too large / buffer too small
pub const ERANGE: i32 = 34;

/// Function not implemented (used by syscall dispatcher)
#[allow(dead_code)]
pub const ENOSYS: i32 = 38;
Expand Down
Loading
Loading