mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:18:12 +00:00
Kernel: Put Process's current directory in a SpinlockProtected
Also let's call it "current_directory" instead of "cwd" everywhere.
This commit is contained in:
parent
71792e4b3f
commit
24f02bd421
5 changed files with 25 additions and 19 deletions
|
@ -15,8 +15,10 @@ ErrorOr<FlatPtr> Process::sys$chdir(Userspace<const char*> user_path, size_t pat
|
|||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
||||
TRY(require_promise(Pledge::rpath));
|
||||
auto path = TRY(get_syscall_path_argument(user_path, path_length));
|
||||
m_cwd = TRY(VirtualFileSystem::the().open_directory(path->view(), current_directory()));
|
||||
return 0;
|
||||
return m_current_directory.with([&](auto& current_directory) -> ErrorOr<FlatPtr> {
|
||||
current_directory = TRY(VirtualFileSystem::the().open_directory(path->view(), *current_directory));
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$fchdir(int fd)
|
||||
|
@ -28,7 +30,9 @@ ErrorOr<FlatPtr> Process::sys$fchdir(int fd)
|
|||
return ENOTDIR;
|
||||
if (!description->metadata().may_execute(*this))
|
||||
return EACCES;
|
||||
m_cwd = description->custody();
|
||||
m_current_directory.with([&](auto& current_directory) {
|
||||
current_directory = description->custody();
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -40,7 +44,7 @@ ErrorOr<FlatPtr> Process::sys$getcwd(Userspace<char*> buffer, size_t size)
|
|||
if (size > NumericLimits<ssize_t>::max())
|
||||
return EINVAL;
|
||||
|
||||
auto path = TRY(current_directory().try_serialize_absolute_path());
|
||||
auto path = TRY(current_directory()->try_serialize_absolute_path());
|
||||
size_t ideal_size = path->length() + 1;
|
||||
auto size_to_copy = min(ideal_size, size);
|
||||
TRY(copy_to_user(buffer, path->characters(), size_to_copy));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue