Kernel: Fix Process APIs

This commit is contained in:
Bananymous 2024-02-07 15:34:28 +02:00
parent 132286895f
commit 572c4052f6
2 changed files with 8 additions and 4 deletions

View File

@ -96,7 +96,7 @@ namespace Kernel
BAN::ErrorOr<long> sys_getpgid(pid_t);
BAN::ErrorOr<void> create_file_or_dir(BAN::StringView name, mode_t mode);
BAN::ErrorOr<long> open_file(BAN::StringView path, int, mode_t = 0);
BAN::ErrorOr<long> open_file(BAN::StringView path, int oflag, mode_t = 0);
BAN::ErrorOr<long> sys_open(const char* path, int, mode_t);
BAN::ErrorOr<long> sys_openat(int, const char* path, int, mode_t);
BAN::ErrorOr<long> sys_close(int fd);
@ -180,6 +180,8 @@ namespace Kernel
// Return false if access was page violation (segfault)
BAN::ErrorOr<bool> allocate_page_for_demand_paging(vaddr_t addr);
BAN::ErrorOr<BAN::String> absolute_path_of(BAN::StringView) const;
private:
Process(const Credentials&, pid_t pid, pid_t parent, pid_t sid, pid_t pgrp);
static Process* create_process(const Credentials&, pid_t parent, pid_t sid = 0, pid_t pgrp = 0);
@ -189,8 +191,6 @@ namespace Kernel
BAN::ErrorOr<int> block_until_exit(pid_t pid);
BAN::ErrorOr<BAN::String> absolute_path_of(BAN::StringView) const;
BAN::ErrorOr<void> validate_string_access(const char*);
BAN::ErrorOr<void> validate_pointer_access(const void*, size_t);

View File

@ -710,6 +710,8 @@ namespace Kernel
BAN::ErrorOr<long> Process::open_file(BAN::StringView path, int flags, mode_t mode)
{
LockGuard _(m_lock);
BAN::String absolute_path = TRY(absolute_path_of(path));
if (flags & O_CREAT)
@ -717,6 +719,8 @@ namespace Kernel
if (flags & O_DIRECTORY)
return BAN::Error::from_errno(ENOTSUP);
auto file_or_error = VirtualFileSystem::get().file_from_absolute_path(m_credentials, absolute_path, O_WRONLY);
if (!file_or_error.is_error() && (flags & O_EXCL))
return BAN::Error::from_errno(EEXIST);
if (file_or_error.is_error())
{
if (file_or_error.error().get_error_code() == ENOENT)
@ -1744,7 +1748,7 @@ namespace Kernel
BAN::ErrorOr<BAN::String> Process::absolute_path_of(BAN::StringView path) const
{
ASSERT(m_lock.is_locked());
LockGuard _(m_lock);
if (path.empty() || path == "."sv)
return m_working_directory;