Kernel: Add /proc/<pid>/exe
This commit is contained in:
parent
e4abe75043
commit
abbe7b79d6
|
@ -226,6 +226,8 @@ namespace Kernel
|
||||||
size_t proc_cmdline(off_t offset, BAN::ByteSpan) const;
|
size_t proc_cmdline(off_t offset, BAN::ByteSpan) const;
|
||||||
size_t proc_environ(off_t offset, BAN::ByteSpan) const;
|
size_t proc_environ(off_t offset, BAN::ByteSpan) const;
|
||||||
|
|
||||||
|
BAN::StringView executable() const { return m_executable; }
|
||||||
|
|
||||||
// Returns error if page could not be allocated
|
// Returns error if page could not be allocated
|
||||||
// Returns true if the page was allocated successfully
|
// Returns true if the page was allocated successfully
|
||||||
// Return false if access was page violation (segfault)
|
// Return false if access was page violation (segfault)
|
||||||
|
@ -339,6 +341,7 @@ namespace Kernel
|
||||||
|
|
||||||
BAN::Vector<BAN::String> m_cmdline;
|
BAN::Vector<BAN::String> m_cmdline;
|
||||||
BAN::Vector<BAN::String> m_environ;
|
BAN::Vector<BAN::String> m_environ;
|
||||||
|
BAN::String m_executable;
|
||||||
|
|
||||||
BAN::Vector<ChildExitStatus> m_child_exit_statuses;
|
BAN::Vector<ChildExitStatus> m_child_exit_statuses;
|
||||||
ThreadBlocker m_child_exit_blocker;
|
ThreadBlocker m_child_exit_blocker;
|
||||||
|
|
|
@ -18,6 +18,16 @@ namespace Kernel
|
||||||
TRY(inode->link_inode(*MUST(ProcROProcessInode::create_new(process, &Process::proc_cmdline, fs, 0400)), "cmdline"_sv));
|
TRY(inode->link_inode(*MUST(ProcROProcessInode::create_new(process, &Process::proc_cmdline, fs, 0400)), "cmdline"_sv));
|
||||||
TRY(inode->link_inode(*MUST(ProcROProcessInode::create_new(process, &Process::proc_environ, fs, 0400)), "environ"_sv));
|
TRY(inode->link_inode(*MUST(ProcROProcessInode::create_new(process, &Process::proc_environ, fs, 0400)), "environ"_sv));
|
||||||
|
|
||||||
|
TRY(inode->link_inode(*MUST(ProcSymlinkInode::create_new(
|
||||||
|
[](void* process) -> BAN::ErrorOr<BAN::String>
|
||||||
|
{
|
||||||
|
BAN::String result;
|
||||||
|
TRY(result.append(static_cast<Process*>(process)->executable()));
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
&process, fs, 0400, process.credentials().ruid(), process.credentials().ruid()
|
||||||
|
)), "exe"_sv));
|
||||||
|
|
||||||
return inode;
|
return inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +42,7 @@ namespace Kernel
|
||||||
(void)TmpDirectoryInode::unlink_impl("meminfo"_sv);
|
(void)TmpDirectoryInode::unlink_impl("meminfo"_sv);
|
||||||
(void)TmpDirectoryInode::unlink_impl("cmdline"_sv);
|
(void)TmpDirectoryInode::unlink_impl("cmdline"_sv);
|
||||||
(void)TmpDirectoryInode::unlink_impl("environ"_sv);
|
(void)TmpDirectoryInode::unlink_impl("environ"_sv);
|
||||||
|
(void)TmpDirectoryInode::unlink_impl("exe"_sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<BAN::RefPtr<ProcROProcessInode>> ProcROProcessInode::create_new(Process& process, size_t (Process::*callback)(off_t, BAN::ByteSpan) const, TmpFileSystem& fs, mode_t mode)
|
BAN::ErrorOr<BAN::RefPtr<ProcROProcessInode>> ProcROProcessInode::create_new(Process& process, size_t (Process::*callback)(off_t, BAN::ByteSpan) const, TmpFileSystem& fs, mode_t mode)
|
||||||
|
|
|
@ -132,6 +132,8 @@ namespace Kernel
|
||||||
auto executable = TRY(ELF::load_from_inode(process->m_root_file.inode, executable_inode, process->m_credentials, process->page_table()));
|
auto executable = TRY(ELF::load_from_inode(process->m_root_file.inode, executable_inode, process->m_credentials, process->page_table()));
|
||||||
process->m_mapped_regions = BAN::move(executable.regions);
|
process->m_mapped_regions = BAN::move(executable.regions);
|
||||||
|
|
||||||
|
TRY(process->m_executable.append(executable_file.canonical_path));
|
||||||
|
|
||||||
if (executable_inode->mode().mode & +Inode::Mode::ISUID)
|
if (executable_inode->mode().mode & +Inode::Mode::ISUID)
|
||||||
process->m_credentials.set_euid(executable_inode->uid());
|
process->m_credentials.set_euid(executable_inode->uid());
|
||||||
if (executable_inode->mode().mode & +Inode::Mode::ISGID)
|
if (executable_inode->mode().mode & +Inode::Mode::ISGID)
|
||||||
|
@ -672,6 +674,9 @@ namespace Kernel
|
||||||
auto executable = TRY(ELF::load_from_inode(m_root_file.inode, executable_inode, m_credentials, *new_page_table));
|
auto executable = TRY(ELF::load_from_inode(m_root_file.inode, executable_inode, m_credentials, *new_page_table));
|
||||||
auto new_mapped_regions = BAN::move(executable.regions);
|
auto new_mapped_regions = BAN::move(executable.regions);
|
||||||
|
|
||||||
|
BAN::String executable_path;
|
||||||
|
TRY(executable_path.append(executable_file.canonical_path));
|
||||||
|
|
||||||
BAN::Vector<LibELF::AuxiliaryVector> auxiliary_vector;
|
BAN::Vector<LibELF::AuxiliaryVector> auxiliary_vector;
|
||||||
TRY(auxiliary_vector.reserve(1 + executable.open_execfd));
|
TRY(auxiliary_vector.reserve(1 + executable.open_execfd));
|
||||||
|
|
||||||
|
@ -756,6 +761,7 @@ namespace Kernel
|
||||||
|
|
||||||
m_cmdline = BAN::move(str_argv);
|
m_cmdline = BAN::move(str_argv);
|
||||||
m_environ = BAN::move(str_envp);
|
m_environ = BAN::move(str_envp);
|
||||||
|
m_executable = BAN::move(executable_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_has_called_exec = true;
|
m_has_called_exec = true;
|
||||||
|
|
Loading…
Reference in New Issue