Ver Fonte

Kernel: Remove use of copy_ref() in favor of regular RefPtr copies.

This is obviously more readable. If we ever run into a situation where
ref count churn is actually causing trouble in the future, we can deal with
it then. For now, let's keep it simple. :^)
Andreas Kling há 6 anos atrás
pai
commit
5254a320d8

+ 2 - 2
Kernel/Devices/DiskPartition.cpp

@@ -2,12 +2,12 @@
 
 // #define OFFD_DEBUG
 
-NonnullRefPtr<DiskPartition> DiskPartition::create(NonnullRefPtr<DiskDevice>&& device, unsigned block_offset)
+NonnullRefPtr<DiskPartition> DiskPartition::create(NonnullRefPtr<DiskDevice> device, unsigned block_offset)
 {
     return adopt(*new DiskPartition(move(device), block_offset));
 }
 
-DiskPartition::DiskPartition(NonnullRefPtr<DiskDevice>&& device, unsigned block_offset)
+DiskPartition::DiskPartition(NonnullRefPtr<DiskDevice> device, unsigned block_offset)
     : m_device(move(device))
     , m_block_offset(block_offset)
 {

+ 2 - 2
Kernel/Devices/DiskPartition.h

@@ -5,7 +5,7 @@
 
 class DiskPartition final : public DiskDevice {
 public:
-    static NonnullRefPtr<DiskPartition> create(NonnullRefPtr<DiskDevice>&& device, unsigned block_offset);
+    static NonnullRefPtr<DiskPartition> create(NonnullRefPtr<DiskDevice>, unsigned block_offset);
     virtual ~DiskPartition();
 
     virtual unsigned block_size() const override;
@@ -17,7 +17,7 @@ public:
 private:
     virtual const char* class_name() const override;
 
-    DiskPartition(NonnullRefPtr<DiskDevice>&&, unsigned);
+    DiskPartition(NonnullRefPtr<DiskDevice>, unsigned block_offset);
 
     NonnullRefPtr<DiskDevice> m_device;
     unsigned m_block_offset;

+ 2 - 2
Kernel/Devices/MBRPartitionTable.cpp

@@ -3,7 +3,7 @@
 
 #define MBR_DEBUG
 
-MBRPartitionTable::MBRPartitionTable(NonnullRefPtr<DiskDevice>&& device)
+MBRPartitionTable::MBRPartitionTable(NonnullRefPtr<DiskDevice> device)
     : m_device(move(device))
 {
 }
@@ -65,5 +65,5 @@ RefPtr<DiskPartition> MBRPartitionTable::partition(unsigned index)
     kprintf("MBRPartitionTable::partition: found partition index=%d type=%x\n", index, entry.type);
 #endif
 
-    return DiskPartition::create(m_device.copy_ref(), entry.offset);
+    return DiskPartition::create(m_device, entry.offset);
 }

+ 1 - 1
Kernel/Devices/MBRPartitionTable.h

@@ -31,7 +31,7 @@ class MBRPartitionTable {
     AK_MAKE_ETERNAL
 
 public:
-    MBRPartitionTable(NonnullRefPtr<DiskDevice>&& device);
+    MBRPartitionTable(NonnullRefPtr<DiskDevice>);
     ~MBRPartitionTable();
 
     bool initialize();

+ 2 - 2
Kernel/FileSystem/Ext2FileSystem.cpp

@@ -31,7 +31,7 @@ static u8 to_ext2_file_type(mode_t mode)
     return EXT2_FT_UNKNOWN;
 }
 
-NonnullRefPtr<Ext2FS> Ext2FS::create(NonnullRefPtr<DiskDevice>&& device)
+NonnullRefPtr<Ext2FS> Ext2FS::create(NonnullRefPtr<DiskDevice> device)
 {
     return adopt(*new Ext2FS(move(device)));
 }
@@ -475,7 +475,7 @@ RefPtr<Inode> Ext2FS::get_inode(InodeIdentifier inode) const
         return (*it).value;
     auto new_inode = adopt(*new Ext2FSInode(const_cast<Ext2FS&>(*this), inode.index()));
     memcpy(&new_inode->m_raw_inode, reinterpret_cast<ext2_inode*>(block.offset_pointer(offset)), sizeof(ext2_inode));
-    m_inode_cache.set(inode.index(), new_inode.copy_ref());
+    m_inode_cache.set(inode.index(), new_inode);
     return new_inode;
 }
 

+ 1 - 1
Kernel/FileSystem/Ext2FileSystem.h

@@ -60,7 +60,7 @@ class Ext2FS final : public DiskBackedFS {
     friend class Ext2FSInode;
 
 public:
-    static NonnullRefPtr<Ext2FS> create(NonnullRefPtr<DiskDevice>&&);
+    static NonnullRefPtr<Ext2FS> create(NonnullRefPtr<DiskDevice>);
     virtual ~Ext2FS() override;
     virtual bool initialize() override;
 

+ 4 - 4
Kernel/FileSystem/FileDescription.cpp

@@ -22,7 +22,7 @@ NonnullRefPtr<FileDescription> FileDescription::create(RefPtr<Custody>&& custody
     return description;
 }
 
-NonnullRefPtr<FileDescription> FileDescription::create(RefPtr<File>&& file, SocketRole role)
+NonnullRefPtr<FileDescription> FileDescription::create(RefPtr<File> file, SocketRole role)
 {
     return adopt(*new FileDescription(move(file), role));
 }
@@ -64,9 +64,9 @@ NonnullRefPtr<FileDescription> FileDescription::clone()
     if (is_fifo()) {
         description = fifo()->open_direction(m_fifo_direction);
     } else {
-        description = FileDescription::create(m_file.copy_ref(), m_socket_role);
-        description->m_custody = m_custody.copy_ref();
-        description->m_inode = m_inode.copy_ref();
+        description = FileDescription::create(m_file, m_socket_role);
+        description->m_custody = m_custody;
+        description->m_inode = m_inode;
     }
     ASSERT(description);
     description->m_current_offset = m_current_offset;

+ 1 - 1
Kernel/FileSystem/FileDescription.h

@@ -22,7 +22,7 @@ class SharedMemory;
 class FileDescription : public RefCounted<FileDescription> {
 public:
     static NonnullRefPtr<FileDescription> create(RefPtr<Custody>&&);
-    static NonnullRefPtr<FileDescription> create(RefPtr<File>&&, SocketRole = SocketRole::None);
+    static NonnullRefPtr<FileDescription> create(RefPtr<File>, SocketRole = SocketRole::None);
     ~FileDescription();
 
     NonnullRefPtr<FileDescription> clone();

+ 9 - 9
Kernel/Process.cpp

@@ -115,7 +115,7 @@ Region* Process::allocate_file_backed_region(VirtualAddress vaddr, size_t size,
     return &m_regions.last();
 }
 
-Region* Process::allocate_region_with_vmo(VirtualAddress vaddr, size_t size, NonnullRefPtr<VMObject>&& vmo, size_t offset_in_vmo, const String& name, int prot)
+Region* Process::allocate_region_with_vmo(VirtualAddress vaddr, size_t size, NonnullRefPtr<VMObject> vmo, size_t offset_in_vmo, const String& name, int prot)
 {
     auto range = allocate_range(vaddr, size);
     if (!range.is_valid())
@@ -229,7 +229,7 @@ int Process::sys$gethostname(char* buffer, ssize_t size)
 
 Process* Process::fork(RegisterDump& regs)
 {
-    auto* child = new Process(String(m_name), m_uid, m_gid, m_pid, m_ring, m_cwd.copy_ref(), m_executable.copy_ref(), m_tty, this);
+    auto* child = new Process(String(m_name), m_uid, m_gid, m_pid, m_ring, m_cwd, m_executable, m_tty, this);
     if (!child)
         return nullptr;
 
@@ -334,7 +334,7 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
 
     auto vmo = VMObject::create_file_backed(description->inode());
     vmo->set_name(description->absolute_path());
-    RefPtr<Region> region = allocate_region_with_vmo(VirtualAddress(), metadata.size, vmo.copy_ref(), 0, vmo->name(), PROT_READ);
+    RefPtr<Region> region = allocate_region_with_vmo(VirtualAddress(), metadata.size, vmo, 0, vmo->name(), PROT_READ);
     ASSERT(region);
 
     if (this != &current->process()) {
@@ -358,7 +358,7 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
                 prot |= PROT_WRITE;
             if (is_executable)
                 prot |= PROT_EXEC;
-            (void)allocate_region_with_vmo(vaddr, size, vmo.copy_ref(), offset_in_image, String(name), prot);
+            (void)allocate_region_with_vmo(vaddr, size, vmo, offset_in_image, String(name), prot);
             return vaddr.as_ptr();
         };
         loader->alloc_section_hook = [&](VirtualAddress vaddr, size_t size, size_t alignment, bool is_readable, bool is_writable, const String& name) {
@@ -520,7 +520,7 @@ Process* Process::create_user_process(const String& path, uid_t uid, gid_t gid,
     {
         InterruptDisabler disabler;
         if (auto* parent = Process::from_pid(parent_pid))
-            cwd = parent->m_cwd.copy_ref();
+            cwd = parent->m_cwd;
     }
 
     if (!cwd)
@@ -562,7 +562,7 @@ Process* Process::create_kernel_process(String&& name, void (*e)())
     return process;
 }
 
-Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring, RefPtr<Custody>&& cwd, RefPtr<Custody>&& executable, TTY* tty, Process* fork_parent)
+Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty, Process* fork_parent)
     : m_name(move(name))
     , m_pid(next_pid++) // FIXME: RACE: This variable looks racy!
     , m_uid(uid)
@@ -2370,14 +2370,14 @@ struct SharedBuffer {
         if (m_pid1 == process.pid()) {
             ++m_pid1_retain_count;
             if (!m_pid1_region) {
-                m_pid1_region = process.allocate_region_with_vmo(VirtualAddress(), size(), m_vmo.copy_ref(), 0, "SharedBuffer", PROT_READ | (m_pid1_writable ? PROT_WRITE : 0));
+                m_pid1_region = process.allocate_region_with_vmo(VirtualAddress(), size(), m_vmo, 0, "SharedBuffer", PROT_READ | (m_pid1_writable ? PROT_WRITE : 0));
                 m_pid1_region->set_shared(true);
             }
             return m_pid1_region->vaddr().as_ptr();
         } else if (m_pid2 == process.pid()) {
             ++m_pid2_retain_count;
             if (!m_pid2_region) {
-                m_pid2_region = process.allocate_region_with_vmo(VirtualAddress(), size(), m_vmo.copy_ref(), 0, "SharedBuffer", PROT_READ | (m_pid2_writable ? PROT_WRITE : 0));
+                m_pid2_region = process.allocate_region_with_vmo(VirtualAddress(), size(), m_vmo, 0, "SharedBuffer", PROT_READ | (m_pid2_writable ? PROT_WRITE : 0));
                 m_pid2_region->set_shared(true);
             }
             return m_pid2_region->vaddr().as_ptr();
@@ -2506,7 +2506,7 @@ int Process::sys$create_shared_buffer(pid_t peer_pid, int size, void** buffer)
     auto shared_buffer = make<SharedBuffer>(m_pid, peer_pid, size);
     shared_buffer->m_shared_buffer_id = shared_buffer_id;
     ASSERT((int)shared_buffer->size() >= size);
-    shared_buffer->m_pid1_region = allocate_region_with_vmo(VirtualAddress(), shared_buffer->size(), shared_buffer->m_vmo.copy_ref(), 0, "SharedBuffer", PROT_READ | PROT_WRITE);
+    shared_buffer->m_pid1_region = allocate_region_with_vmo(VirtualAddress(), shared_buffer->size(), shared_buffer->m_vmo, 0, "SharedBuffer", PROT_READ | PROT_WRITE);
     shared_buffer->m_pid1_region->set_shared(true);
     *buffer = shared_buffer->m_pid1_region->vaddr().as_ptr();
 #ifdef SHARED_BUFFER_DEBUG

+ 2 - 2
Kernel/Process.h

@@ -249,7 +249,7 @@ public:
 
     bool is_superuser() const { return m_euid == 0; }
 
-    Region* allocate_region_with_vmo(VirtualAddress, size_t, NonnullRefPtr<VMObject>&&, size_t offset_in_vmo, const String& name, int prot);
+    Region* allocate_region_with_vmo(VirtualAddress, size_t, NonnullRefPtr<VMObject>, size_t offset_in_vmo, const String& name, int prot);
     Region* allocate_file_backed_region(VirtualAddress, size_t, RefPtr<Inode>&&, const String& name, int prot);
     Region* allocate_region(VirtualAddress, size_t, const String& name, int prot = PROT_READ | PROT_WRITE, bool commit = true);
     bool deallocate_region(Region& region);
@@ -274,7 +274,7 @@ private:
     friend class Scheduler;
     friend class Region;
 
-    Process(String&& name, uid_t, gid_t, pid_t ppid, RingLevel, RefPtr<Custody>&& cwd = nullptr, RefPtr<Custody>&& executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
+    Process(String&& name, uid_t, gid_t, pid_t ppid, RingLevel, RefPtr<Custody> cwd = nullptr, RefPtr<Custody> executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
 
     Range allocate_range(VirtualAddress, size_t);
 

+ 1 - 1
Kernel/VM/MemoryManager.cpp

@@ -155,7 +155,7 @@ RefPtr<PhysicalPage> MemoryManager::allocate_page_table(PageDirectory& page_dire
     auto physical_page = allocate_supervisor_physical_page();
     if (!physical_page)
         return nullptr;
-    page_directory.m_physical_pages.set(index, physical_page.copy_ref());
+    page_directory.m_physical_pages.set(index, physical_page);
     return physical_page;
 }
 

+ 2 - 2
Kernel/VM/Region.cpp

@@ -25,7 +25,7 @@ Region::Region(const Range& range, RefPtr<Inode>&& inode, const String& name, u8
     MM.register_region(*this);
 }
 
-Region::Region(const Range& range, NonnullRefPtr<VMObject>&& vmo, size_t offset_in_vmo, const String& name, u8 access, bool cow)
+Region::Region(const Range& range, NonnullRefPtr<VMObject> vmo, size_t offset_in_vmo, const String& name, u8 access, bool cow)
     : m_range(range)
     , m_offset_in_vmo(offset_in_vmo)
     , m_vmo(move(vmo))
@@ -78,7 +78,7 @@ NonnullRefPtr<Region> Region::clone()
             vaddr().get());
 #endif
         // Create a new region backed by the same VMObject.
-        return adopt(*new Region(m_range, m_vmo.copy_ref(), m_offset_in_vmo, String(m_name), m_access));
+        return adopt(*new Region(m_range, m_vmo, m_offset_in_vmo, String(m_name), m_access));
     }
 
 #ifdef MM_DEBUG

+ 1 - 1
Kernel/VM/Region.h

@@ -19,7 +19,7 @@ public:
     };
 
     Region(const Range&, const String&, u8 access, bool cow = false);
-    Region(const Range&, NonnullRefPtr<VMObject>&&, size_t offset_in_vmo, const String&, u8 access, bool cow = false);
+    Region(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmo, const String&, u8 access, bool cow = false);
     Region(const Range&, RefPtr<Inode>&&, const String&, u8 access);
     ~Region();
 

+ 4 - 4
Kernel/init.cpp

@@ -86,7 +86,7 @@ VFS* vfs;
 
     auto dev_hd0 = IDEDiskDevice::create(IDEDiskDevice::DriveType::MASTER);
 
-    NonnullRefPtr<DiskDevice> root_dev = dev_hd0.copy_ref();
+    NonnullRefPtr<DiskDevice> root_dev = dev_hd0;
 
     root = root.substring(strlen("/dev/hda"), root.length() - strlen("/dev/hda"));
 
@@ -104,7 +104,7 @@ VFS* vfs;
             hang();
         }
 
-        MBRPartitionTable mbr(root_dev.copy_ref());
+        MBRPartitionTable mbr(root_dev);
         if (!mbr.initialize()) {
             kprintf("init_stage2: couldn't read MBR from disk\n");
             hang();
@@ -119,13 +119,13 @@ VFS* vfs;
         root_dev = *partition;
     }
 
-    auto e2fs = Ext2FS::create(root_dev.copy_ref());
+    auto e2fs = Ext2FS::create(root_dev);
     if (!e2fs->initialize()) {
         kprintf("init_stage2: couldn't open root filesystem\n");
         hang();
     }
 
-    vfs->mount_root(e2fs.copy_ref());
+    vfs->mount_root(e2fs);
 
     dbgprintf("Load ksyms\n");
     load_ksyms();