mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 21:54:40 +03:00
Kernel: Use KResultOr and TRY() for {Shared,Private}InodeVMObject
This commit is contained in:
parent
e3a716ceff
commit
6e3381ac32
Notes:
sideshowbarker
2024-07-18 04:38:32 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6e3381ac32e
@ -86,11 +86,9 @@ KResultOr<Memory::Region*> InodeFile::mmap(Process& process, FileDescription& de
|
||||
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.
|
||||
RefPtr<Memory::InodeVMObject> vmobject;
|
||||
if (shared)
|
||||
vmobject = Memory::SharedInodeVMObject::try_create_with_inode(inode());
|
||||
vmobject = TRY(Memory::SharedInodeVMObject::try_create_with_inode(inode()));
|
||||
else
|
||||
vmobject = Memory::PrivateInodeVMObject::try_create_with_inode(inode());
|
||||
if (!vmobject)
|
||||
return ENOMEM;
|
||||
vmobject = TRY(Memory::PrivateInodeVMObject::try_create_with_inode(inode()));
|
||||
return process.address_space().allocate_region_with_vmobject(range, vmobject.release_nonnull(), offset, description.absolute_path(), prot, shared);
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,9 @@
|
||||
|
||||
namespace Kernel::Memory {
|
||||
|
||||
RefPtr<PrivateInodeVMObject> PrivateInodeVMObject::try_create_with_inode(Inode& inode)
|
||||
KResultOr<NonnullRefPtr<PrivateInodeVMObject>> PrivateInodeVMObject::try_create_with_inode(Inode& inode)
|
||||
{
|
||||
return adopt_ref_if_nonnull(new (nothrow) PrivateInodeVMObject(inode, inode.size()));
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) PrivateInodeVMObject(inode, inode.size()));
|
||||
}
|
||||
|
||||
KResultOr<NonnullRefPtr<VMObject>> PrivateInodeVMObject::try_clone()
|
||||
|
@ -18,7 +18,7 @@ class PrivateInodeVMObject final : public InodeVMObject {
|
||||
public:
|
||||
virtual ~PrivateInodeVMObject() override;
|
||||
|
||||
static RefPtr<PrivateInodeVMObject> try_create_with_inode(Inode&);
|
||||
static KResultOr<NonnullRefPtr<PrivateInodeVMObject>> try_create_with_inode(Inode&);
|
||||
virtual KResultOr<NonnullRefPtr<VMObject>> try_clone() override;
|
||||
|
||||
private:
|
||||
|
@ -9,14 +9,12 @@
|
||||
|
||||
namespace Kernel::Memory {
|
||||
|
||||
RefPtr<SharedInodeVMObject> SharedInodeVMObject::try_create_with_inode(Inode& inode)
|
||||
KResultOr<NonnullRefPtr<SharedInodeVMObject>> SharedInodeVMObject::try_create_with_inode(Inode& inode)
|
||||
{
|
||||
size_t size = inode.size();
|
||||
if (auto shared_vmobject = inode.shared_vmobject())
|
||||
return shared_vmobject.release_nonnull();
|
||||
auto vmobject = adopt_ref_if_nonnull(new (nothrow) SharedInodeVMObject(inode, size));
|
||||
if (!vmobject)
|
||||
return nullptr;
|
||||
auto vmobject = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SharedInodeVMObject(inode, size)));
|
||||
vmobject->inode().set_shared_vmobject(*vmobject);
|
||||
return vmobject;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class SharedInodeVMObject final : public InodeVMObject {
|
||||
AK_MAKE_NONMOVABLE(SharedInodeVMObject);
|
||||
|
||||
public:
|
||||
static RefPtr<SharedInodeVMObject> try_create_with_inode(Inode&);
|
||||
static KResultOr<NonnullRefPtr<SharedInodeVMObject>> try_create_with_inode(Inode&);
|
||||
virtual KResultOr<NonnullRefPtr<VMObject>> try_clone() override;
|
||||
|
||||
private:
|
||||
|
@ -165,11 +165,7 @@ struct RequiredLoadRange {
|
||||
static KResultOr<RequiredLoadRange> get_required_load_range(FileDescription& program_description)
|
||||
{
|
||||
auto& inode = *(program_description.inode());
|
||||
auto vmobject = Memory::SharedInodeVMObject::try_create_with_inode(inode);
|
||||
if (!vmobject) {
|
||||
dbgln("get_required_load_range: Unable to allocate SharedInodeVMObject");
|
||||
return ENOMEM;
|
||||
}
|
||||
auto vmobject = TRY(Memory::SharedInodeVMObject::try_create_with_inode(inode));
|
||||
|
||||
size_t executable_size = inode.size();
|
||||
|
||||
@ -265,11 +261,7 @@ static KResultOr<LoadResult> load_elf_object(NonnullOwnPtr<Memory::AddressSpace>
|
||||
FlatPtr load_offset, ShouldAllocateTls should_allocate_tls, ShouldAllowSyscalls should_allow_syscalls)
|
||||
{
|
||||
auto& inode = *(object_description.inode());
|
||||
auto vmobject = Memory::SharedInodeVMObject::try_create_with_inode(inode);
|
||||
if (!vmobject) {
|
||||
dbgln("load_elf_object: Unable to allocate SharedInodeVMObject");
|
||||
return ENOMEM;
|
||||
}
|
||||
auto vmobject = TRY(Memory::SharedInodeVMObject::try_create_with_inode(inode));
|
||||
|
||||
if (vmobject->writable_mappings()) {
|
||||
dbgln("Refusing to execute a write-mapped program");
|
||||
|
@ -497,17 +497,14 @@ KResultOr<FlatPtr> Process::sys$mremap(Userspace<const Syscall::SC_mremap_params
|
||||
auto old_offset = old_region->offset_in_vmobject();
|
||||
NonnullRefPtr inode = static_cast<Memory::SharedInodeVMObject&>(old_region->vmobject()).inode();
|
||||
|
||||
auto new_vmobject = Memory::PrivateInodeVMObject::try_create_with_inode(inode);
|
||||
if (!new_vmobject)
|
||||
return ENOMEM;
|
||||
|
||||
auto new_vmobject = TRY(Memory::PrivateInodeVMObject::try_create_with_inode(inode));
|
||||
auto old_name = old_region->take_name();
|
||||
|
||||
// Unmap without deallocating the VM range since we're going to reuse it.
|
||||
old_region->unmap(Memory::Region::ShouldDeallocateVirtualRange::No);
|
||||
address_space().deallocate_region(*old_region);
|
||||
|
||||
auto new_region = TRY(address_space().allocate_region_with_vmobject(range, new_vmobject.release_nonnull(), old_offset, old_name->view(), old_prot, false));
|
||||
auto new_region = TRY(address_space().allocate_region_with_vmobject(range, move(new_vmobject), old_offset, old_name->view(), old_prot, false));
|
||||
new_region->set_mmap(true);
|
||||
return new_region->vaddr().get();
|
||||
}
|
||||
|
@ -185,10 +185,8 @@ KResult Process::poke_user_data(Userspace<u32*> address, u32 data)
|
||||
// If the region is shared, we change its vmobject to a PrivateInodeVMObject
|
||||
// to prevent the write operation from changing any shared inode data
|
||||
VERIFY(region->vmobject().is_shared_inode());
|
||||
auto vmobject = Memory::PrivateInodeVMObject::try_create_with_inode(static_cast<Memory::SharedInodeVMObject&>(region->vmobject()).inode());
|
||||
if (!vmobject)
|
||||
return ENOMEM;
|
||||
region->set_vmobject(vmobject.release_nonnull());
|
||||
auto vmobject = TRY(Memory::PrivateInodeVMObject::try_create_with_inode(static_cast<Memory::SharedInodeVMObject&>(region->vmobject()).inode()));
|
||||
region->set_vmobject(move(vmobject));
|
||||
region->set_shared(false);
|
||||
}
|
||||
const bool was_writable = region->is_writable();
|
||||
|
Loading…
Reference in New Issue
Block a user