mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel: Make cloning of FileDescriptions OOM safe
This commit is contained in:
parent
e7fb70b05c
commit
296452a981
Notes:
sideshowbarker
2024-07-18 07:02:15 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/296452a9818 Pull-request: https://github.com/SerenityOS/serenity/pull/9374
2 changed files with 13 additions and 5 deletions
|
@ -631,18 +631,23 @@ public:
|
|||
|
||||
class ScopedDescriptionAllocation;
|
||||
class FileDescriptions {
|
||||
AK_MAKE_NONCOPYABLE(FileDescriptions);
|
||||
friend class Process;
|
||||
|
||||
public:
|
||||
ALWAYS_INLINE const FileDescriptionAndFlags& operator[](size_t i) const { return at(i); }
|
||||
ALWAYS_INLINE FileDescriptionAndFlags& operator[](size_t i) { return at(i); }
|
||||
|
||||
FileDescriptions& operator=(const Kernel::Process::FileDescriptions& other)
|
||||
KResult try_clone(const Kernel::Process::FileDescriptions& other)
|
||||
{
|
||||
ScopedSpinLock lock(m_fds_lock);
|
||||
ScopedSpinLock lock_other(other.m_fds_lock);
|
||||
m_fds_metadatas = other.m_fds_metadatas;
|
||||
return *this;
|
||||
if (!try_resize(other.m_fds_metadatas.size()))
|
||||
return ENOMEM;
|
||||
|
||||
for (size_t i = 0; i < other.m_fds_metadatas.size(); ++i) {
|
||||
m_fds_metadatas[i] = other.m_fds_metadatas[i];
|
||||
}
|
||||
return KSuccess;
|
||||
}
|
||||
|
||||
const FileDescriptionAndFlags& at(size_t i) const;
|
||||
|
|
|
@ -25,7 +25,10 @@ KResultOr<FlatPtr> Process::sys$fork(RegisterState& regs)
|
|||
child->m_root_directory_relative_to_global_root = m_root_directory_relative_to_global_root;
|
||||
child->m_veil_state = m_veil_state;
|
||||
child->m_unveiled_paths = m_unveiled_paths.deep_copy();
|
||||
child->m_fds = m_fds;
|
||||
|
||||
if (auto result = child->m_fds.try_clone(m_fds); result.is_error())
|
||||
return result.error();
|
||||
|
||||
child->m_pg = m_pg;
|
||||
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue