Skip to content
Open
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
8 changes: 7 additions & 1 deletion src/drivers/fs/proc/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,18 @@ impl Inode for ProcTaskInode {
FileType::File,
8,
));
entries.push(Dirent::new(
"exe".to_string(),
InodeId::from_fsid_and_inodeid(PROCFS_ID, get_inode_id(&[&initial_str, "exe"])),
FileType::File,
9,
));
if self.desc.tid().value() == self.desc.tgid().value() && !self.is_task_dir {
entries.push(Dirent::new(
"task".to_string(),
InodeId::from_fsid_and_inodeid(PROCFS_ID, get_inode_id(&[&initial_str, "task"])),
FileType::Directory,
9,
10,
));
}

Expand Down
34 changes: 33 additions & 1 deletion src/drivers/fs/proc/task/task_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum TaskFileType {
State,
Stat,
Maps,
Exe,
}

impl TryFrom<&str> for TaskFileType {
Expand All @@ -32,6 +33,7 @@ impl TryFrom<&str> for TaskFileType {
"cwd" => Ok(TaskFileType::Cwd),
"root" => Ok(TaskFileType::Root),
"maps" => Ok(TaskFileType::Maps),
"exe" => Ok(TaskFileType::Exe),
_ => Err(()),
}
}
Expand All @@ -56,7 +58,7 @@ impl ProcTaskFileInode {
| TaskFileType::State
| TaskFileType::Maps
| TaskFileType::Stat => FileType::File,
TaskFileType::Cwd | TaskFileType::Root => FileType::Symlink,
TaskFileType::Cwd | TaskFileType::Root | TaskFileType::Exe => FileType::Symlink,
},
permissions: FilePermissions::from_bits_retain(0o444),
..FileAttr::default()
Expand Down Expand Up @@ -197,6 +199,14 @@ Threads:\t{tasks}\n",

output
}
TaskFileType::Exe => {
if let Some(exe) = task.process.executable.lock_save_irq().clone() {
// TODO: Check if exists
exe.as_str().to_string()
} else {
"(deleted)".to_string()
}
}
}
} else {
"State:\tGone\n".to_string()
Expand Down Expand Up @@ -243,6 +253,28 @@ Threads:\t{tasks}\n",
} else {
Err(FsError::NotFound.into())
};
} else if let TaskFileType::Exe = self.file_type {
let tid = self.tid;
let task_list = TASK_LIST.lock_save_irq();
let id = task_list
.iter()
.find(|(desc, _)| desc.tid() == tid)
.map(|(desc, _)| *desc);
drop(task_list);
let task_details = if let Some(desc) = id {
find_task_by_descriptor(&desc)
} else {
None
};
return if let Some(task) = task_details {
if let Some(exe) = task.process.executable.lock_save_irq().clone() {
Ok(exe.as_str().to_string().into())
} else {
Err(FsError::NotFound.into())
}
} else {
Err(FsError::NotFound.into())
};
}
Err(KernelError::NotSupported)
}
Expand Down
2 changes: 2 additions & 0 deletions src/process/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
process::{ctx::Context, thread_group::signal::SignalActionState},
sched::current::current_task,
};
use alloc::borrow::ToOwned;
use alloc::{string::String, vec};
use alloc::{string::ToString, sync::Arc, vec::Vec};
use auxv::{AT_BASE, AT_ENTRY, AT_NULL, AT_PAGESZ, AT_PHDR, AT_PHENT, AT_PHNUM, AT_RANDOM};
Expand Down Expand Up @@ -212,6 +213,7 @@ async fn exec_elf(
let mut fd_table = current_task().fd_table.lock_save_irq().clone();
fd_table.close_cloexec_entries().await;
*current_task().fd_table.lock_save_irq() = fd_table;
*current_task().process.executable.lock_save_irq() = Some(path.to_owned());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do that here


Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions src/process/thread_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use core::{
fmt::Display,
sync::atomic::{AtomicU32, Ordering},
};
use libkernel::fs::pathbuf::PathBuf;
use pid::PidT;
use rsrc_lim::ResourceLimits;
use signal::{SigId, SigSet, SignalActionState};
Expand Down Expand Up @@ -104,6 +105,7 @@ pub struct ThreadGroup {
pub utime: AtomicUsize,
pub stime: AtomicUsize,
pub last_account: AtomicUsize,
pub executable: SpinLock<Option<PathBuf>>,
next_tid: AtomicU32,
}

Expand Down
1 change: 1 addition & 0 deletions src/process/thread_group/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl ThreadGroupBuilder {
next_tid: AtomicU32::new(1),
state: SpinLock::new(ProcessState::Running),
tasks: SpinLock::new(BTreeMap::new()),
executable: SpinLock::new(None),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where during a clone() the new child process would copy the executable from it's parent. I think during a fork() the executable would be set to None.

});

TG_LIST
Expand Down
Loading