From 2cfcbdc735e7578a22ed2f9ae25492a72abe3f3f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 25 Feb 2019 12:43:52 +0100 Subject: [PATCH] AK: Add Retained, like RetainPtr, but never null. Also use some Clang attribute wizardry to get a warning for use-after-move. --- AK/Buffer.h | 16 ++-- AK/RetainPtr.h | 25 +----- AK/Retained.h | 123 ++++++++++++++++++++++++++++++ AK/StdLibExtras.h | 7 ++ Kernel/DevPtsFS.cpp | 4 +- Kernel/DevPtsFS.h | 4 +- Kernel/DiskBackedFileSystem.cpp | 3 +- Kernel/DiskBackedFileSystem.h | 4 +- Kernel/Ext2FileSystem.cpp | 4 +- Kernel/Ext2FileSystem.h | 4 +- Kernel/FIFO.cpp | 2 +- Kernel/FIFO.h | 2 +- Kernel/FileDescriptor.cpp | 17 ++--- Kernel/FileDescriptor.h | 12 +-- Kernel/IDEDiskDevice.cpp | 2 +- Kernel/IDEDiskDevice.h | 2 +- Kernel/LocalSocket.cpp | 2 +- Kernel/LocalSocket.h | 2 +- Kernel/Makefile | 6 +- Kernel/MemoryManager.cpp | 14 ++-- Kernel/MemoryManager.h | 16 ++-- Kernel/ProcFS.cpp | 2 +- Kernel/ProcFS.h | 2 +- Kernel/SyntheticFileSystem.cpp | 10 +-- Kernel/SyntheticFileSystem.h | 10 +-- Kernel/init.cpp | 2 +- LibGUI/GAction.h | 8 +- LibGUI/GToolBar.cpp | 3 +- LibGUI/GToolBar.h | 2 +- SharedGraphics/GraphicsBitmap.cpp | 4 +- SharedGraphics/GraphicsBitmap.h | 4 +- 31 files changed, 214 insertions(+), 104 deletions(-) create mode 100644 AK/Retained.h diff --git a/AK/Buffer.h b/AK/Buffer.h index 37fef0ea284..1c812049f0f 100644 --- a/AK/Buffer.h +++ b/AK/Buffer.h @@ -11,10 +11,10 @@ namespace AK { template class Buffer : public Retainable> { public: - static RetainPtr create_uninitialized(size_t count); - static RetainPtr copy(const T*, size_t count); - static RetainPtr wrap(T*, size_t count); - static RetainPtr adopt(T*, size_t count); + static Retained create_uninitialized(size_t count); + static Retained copy(const T*, size_t count); + static Retained wrap(T*, size_t count); + static Retained adopt(T*, size_t count); ~Buffer() { clear(); } @@ -105,25 +105,25 @@ inline void Buffer::grow(size_t size) } template -inline RetainPtr> Buffer::create_uninitialized(size_t size) +inline Retained> Buffer::create_uninitialized(size_t size) { return ::adopt(*new Buffer(size)); } template -inline RetainPtr> Buffer::copy(const T* elements, size_t size) +inline Retained> Buffer::copy(const T* elements, size_t size) { return ::adopt(*new Buffer(elements, size, Copy)); } template -inline RetainPtr> Buffer::wrap(T* elements, size_t size) +inline Retained> Buffer::wrap(T* elements, size_t size) { return ::adopt(*new Buffer(elements, size, Wrap)); } template -inline RetainPtr> Buffer::adopt(T* elements, size_t size) +inline Retained> Buffer::adopt(T* elements, size_t size) { return ::adopt(*new Buffer(elements, size, Adopt)); } diff --git a/AK/RetainPtr.h b/AK/RetainPtr.h index 4a831276e3a..5620c8de0a1 100644 --- a/AK/RetainPtr.h +++ b/AK/RetainPtr.h @@ -1,23 +1,10 @@ #pragma once -#include "Types.h" +#include +#include namespace AK { -template -inline void retain_if_not_null(T* ptr) -{ - if (ptr) - ptr->retain(); -} - -template -inline void release_if_not_null(T* ptr) -{ - if (ptr) - ptr->release(); -} - template class RetainPtr { public: @@ -30,6 +17,7 @@ public: RetainPtr(AdoptTag, T& object) : m_ptr(&object) { } RetainPtr(RetainPtr& other) : m_ptr(other.copy_ref().leak_ref()) { } RetainPtr(RetainPtr&& other) : m_ptr(other.leak_ref()) { } + template RetainPtr(Retained&& other) : m_ptr(static_cast(&other.leak_ref())) { } template RetainPtr(RetainPtr&& other) : m_ptr(static_cast(other.leak_ref())) { } RetainPtr(const RetainPtr& other) : m_ptr(const_cast(other).copy_ref().leak_ref()) { } template RetainPtr(const RetainPtr& other) : m_ptr(const_cast&>(other).copy_ref().leak_ref()) { } @@ -128,14 +116,7 @@ private: T* m_ptr = nullptr; }; -template -inline RetainPtr adopt(T& object) -{ - return RetainPtr(RetainPtr::Adopt, object); -} - } using AK::RetainPtr; -using AK::adopt; diff --git a/AK/Retained.h b/AK/Retained.h new file mode 100644 index 00000000000..aed6308ae7a --- /dev/null +++ b/AK/Retained.h @@ -0,0 +1,123 @@ +#pragma once + +#include + +#ifdef __clang__ +#define CONSUMABLE(initial_state) __attribute__((consumable(initial_state))) +#define CALLABLE_WHEN(state) __attribute__((callable_when(state))) +#define SET_TYPESTATE(state) __attribute__((set_typestate(state))) +#define RETURN_TYPESTATE(state) __attribute__((return_typestate(state))) +#else +#define CONSUMABLE(initial_state) +#define CALLABLE_WHEN(state) +#define SET_TYPESTATE(state) +#define RETURN_TYPESTATE(state) +#endif + +namespace AK { + +template +inline void retain_if_not_null(T* ptr) +{ + if (ptr) + ptr->retain(); +} + +template +inline void release_if_not_null(T* ptr) +{ + if (ptr) + ptr->release(); +} + +template +class CONSUMABLE(unconsumed) Retained { +public: + enum AdoptTag { Adopt }; + + RETURN_TYPESTATE(unconsumed) Retained(T& object) : m_ptr(&object) { m_ptr->retain(); } + RETURN_TYPESTATE(unconsumed) Retained(AdoptTag, T& object) : m_ptr(&object) { } + RETURN_TYPESTATE(unconsumed) Retained(Retained& other) : m_ptr(&other.copy_ref().leak_ref()) { } + RETURN_TYPESTATE(unconsumed) Retained(Retained&& other) : m_ptr(&other.leak_ref()) { } + template RETURN_TYPESTATE(unconsumed) Retained(Retained&& other) : m_ptr(static_cast(&other.leak_ref())) { } + RETURN_TYPESTATE(unconsumed) Retained(const Retained& other) : m_ptr(&const_cast(other).copy_ref().leak_ref()) { } + template RETURN_TYPESTATE(unconsumed) Retained(const Retained& other) : m_ptr(&const_cast&>(other).copy_ref().leak_ref()) { } + ~Retained() + { + release_if_not_null(m_ptr); + m_ptr = nullptr; +#ifdef SANITIZE_PTRS + if constexpr(sizeof(T*) == 8) + m_ptr = (T*)(0xb0b0b0b0b0b0b0b0); + else + m_ptr = (T*)(0xb0b0b0b0); +#endif + } + + CALLABLE_WHEN(unconsumed) Retained& operator=(Retained&& other) + { + if (this != &other) { + release_if_not_null(m_ptr); + m_ptr = &other.leak_ref(); + } + return *this; + } + + template + CALLABLE_WHEN(unconsumed) Retained& operator=(Retained&& other) + { + if (this != static_cast(&other)) { + release_if_not_null(m_ptr); + m_ptr = &other.leak_ref(); + } + return *this; + } + + CALLABLE_WHEN(unconsumed) Retained& operator=(T& object) + { + if (m_ptr != &object) + release_if_not_null(m_ptr); + m_ptr = &object; + m_ptr->retain(); + return *this; + } + + CALLABLE_WHEN(unconsumed) Retained copy_ref() const + { + return Retained(*m_ptr); + } + + CALLABLE_WHEN(unconsumed) SET_TYPESTATE(consumed) + T& leak_ref() + { + ASSERT(m_ptr); + T* leakedPtr = m_ptr; + m_ptr = nullptr; + return *leakedPtr; + } + + CALLABLE_WHEN(unconsumed) T* ptr() { ASSERT(m_ptr); return m_ptr; } + CALLABLE_WHEN(unconsumed) const T* ptr() const { ASSERT(m_ptr); return m_ptr; } + + CALLABLE_WHEN(unconsumed) T* operator->() { ASSERT(m_ptr); return m_ptr; } + CALLABLE_WHEN(unconsumed) const T* operator->() const { ASSERT(m_ptr); return m_ptr; } + + CALLABLE_WHEN(unconsumed) T& operator*() { ASSERT(m_ptr); return *m_ptr; } + CALLABLE_WHEN(unconsumed) const T& operator*() const { ASSERT(m_ptr); return *m_ptr; } + +private: + Retained() { } + + T* m_ptr { nullptr }; +}; + +template +inline Retained adopt(T& object) +{ + return Retained(Retained::Adopt, object); +} + +} + +using AK::Retained; +using AK::adopt; diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index 0d952e7f64d..db4228d8ba2 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -60,11 +60,18 @@ static inline T ceil_div(T a, U b) return result; } +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wconsumed" +#endif template T&& move(T& arg) { return static_cast(arg); } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif template struct Identity { diff --git a/Kernel/DevPtsFS.cpp b/Kernel/DevPtsFS.cpp index ee7cb2bddd7..e4c9ac8e0e9 100644 --- a/Kernel/DevPtsFS.cpp +++ b/Kernel/DevPtsFS.cpp @@ -11,7 +11,7 @@ DevPtsFS& DevPtsFS::the() return *s_the; } -RetainPtr DevPtsFS::create() +Retained DevPtsFS::create() { return adopt(*new DevPtsFS); } @@ -36,7 +36,7 @@ const char* DevPtsFS::class_name() const return "DevPtsFS"; } -RetainPtr DevPtsFS::create_slave_pty_device_file(unsigned index) +Retained DevPtsFS::create_slave_pty_device_file(unsigned index) { auto file = adopt(*new SynthFSInode(*this, generate_inode_index())); diff --git a/Kernel/DevPtsFS.h b/Kernel/DevPtsFS.h index 33a08f0c70c..2355523cda8 100644 --- a/Kernel/DevPtsFS.h +++ b/Kernel/DevPtsFS.h @@ -11,7 +11,7 @@ public: [[gnu::pure]] static DevPtsFS& the(); virtual ~DevPtsFS() override; - static RetainPtr create(); + static Retained create(); virtual bool initialize() override; virtual const char* class_name() const override; @@ -22,7 +22,7 @@ public: private: DevPtsFS(); - RetainPtr create_slave_pty_device_file(unsigned index); + Retained create_slave_pty_device_file(unsigned index); HashTable m_slave_ptys; }; diff --git a/Kernel/DiskBackedFileSystem.cpp b/Kernel/DiskBackedFileSystem.cpp index e258ed3624a..5b799552306 100644 --- a/Kernel/DiskBackedFileSystem.cpp +++ b/Kernel/DiskBackedFileSystem.cpp @@ -44,10 +44,9 @@ Lockable>& block_cache() return *s_cache; } -DiskBackedFS::DiskBackedFS(RetainPtr&& device) +DiskBackedFS::DiskBackedFS(Retained&& device) : m_device(move(device)) { - ASSERT(m_device); } DiskBackedFS::~DiskBackedFS() diff --git a/Kernel/DiskBackedFileSystem.h b/Kernel/DiskBackedFileSystem.h index 58de06f924d..75448d9c16c 100644 --- a/Kernel/DiskBackedFileSystem.h +++ b/Kernel/DiskBackedFileSystem.h @@ -13,7 +13,7 @@ public: size_t block_size() const { return m_block_size; } protected: - explicit DiskBackedFS(RetainPtr&&); + explicit DiskBackedFS(Retained&&); void set_block_size(unsigned); @@ -25,5 +25,5 @@ protected: private: size_t m_block_size { 0 }; - RetainPtr m_device; + Retained m_device; }; diff --git a/Kernel/Ext2FileSystem.cpp b/Kernel/Ext2FileSystem.cpp index 94c49b72d31..64a304e876c 100644 --- a/Kernel/Ext2FileSystem.cpp +++ b/Kernel/Ext2FileSystem.cpp @@ -13,12 +13,12 @@ //#define EXT2_DEBUG -RetainPtr Ext2FS::create(RetainPtr&& device) +Retained Ext2FS::create(Retained&& device) { return adopt(*new Ext2FS(move(device))); } -Ext2FS::Ext2FS(RetainPtr&& device) +Ext2FS::Ext2FS(Retained&& device) : DiskBackedFS(move(device)) , m_lock("Ext2FS") { diff --git a/Kernel/Ext2FileSystem.h b/Kernel/Ext2FileSystem.h index 0d6a4dd47b4..6f1d8421d11 100644 --- a/Kernel/Ext2FileSystem.h +++ b/Kernel/Ext2FileSystem.h @@ -58,7 +58,7 @@ private: class Ext2FS final : public DiskBackedFS { friend class Ext2FSInode; public: - static RetainPtr create(RetainPtr&&); + static Retained create(Retained&&); virtual ~Ext2FS() override; virtual bool initialize() override; @@ -71,7 +71,7 @@ private: typedef unsigned BlockIndex; typedef unsigned GroupIndex; typedef unsigned InodeIndex; - explicit Ext2FS(RetainPtr&&); + explicit Ext2FS(Retained&&); const ext2_super_block& super_block() const; const ext2_group_desc& group_descriptor(unsigned groupIndex) const; diff --git a/Kernel/FIFO.cpp b/Kernel/FIFO.cpp index 2fbe23286c4..dfb991b0015 100644 --- a/Kernel/FIFO.cpp +++ b/Kernel/FIFO.cpp @@ -3,7 +3,7 @@ //#define FIFO_DEBUG -RetainPtr FIFO::create() +Retained FIFO::create() { return adopt(*new FIFO); } diff --git a/Kernel/FIFO.h b/Kernel/FIFO.h index fbe1a4157eb..77a802afb37 100644 --- a/Kernel/FIFO.h +++ b/Kernel/FIFO.h @@ -11,7 +11,7 @@ public: Neither, Reader, Writer }; - static RetainPtr create(); + static Retained create(); void open(Direction); void close(Direction); diff --git a/Kernel/FileDescriptor.cpp b/Kernel/FileDescriptor.cpp index 7d842c41964..67085bd5cce 100644 --- a/Kernel/FileDescriptor.cpp +++ b/Kernel/FileDescriptor.cpp @@ -12,27 +12,27 @@ #include #include -RetainPtr FileDescriptor::create(RetainPtr&& inode) +Retained FileDescriptor::create(RetainPtr&& inode) { return adopt(*new FileDescriptor(move(inode))); } -RetainPtr FileDescriptor::create(RetainPtr&& device) +Retained FileDescriptor::create(RetainPtr&& device) { return adopt(*new FileDescriptor(move(device))); } -RetainPtr FileDescriptor::create(RetainPtr&& socket, SocketRole role) +Retained FileDescriptor::create(RetainPtr&& socket, SocketRole role) { return adopt(*new FileDescriptor(move(socket), role)); } -RetainPtr FileDescriptor::create_pipe_writer(FIFO& fifo) +Retained FileDescriptor::create_pipe_writer(FIFO& fifo) { return adopt(*new FileDescriptor(fifo, FIFO::Writer)); } -RetainPtr FileDescriptor::create_pipe_reader(FIFO& fifo) +Retained FileDescriptor::create_pipe_reader(FIFO& fifo) { return adopt(*new FileDescriptor(fifo, FIFO::Reader)); } @@ -80,7 +80,7 @@ void FileDescriptor::set_socket_role(SocketRole role) m_socket->attach_fd(role); } -RetainPtr FileDescriptor::clone() +Retained FileDescriptor::clone() { RetainPtr descriptor; if (is_fifo()) { @@ -98,12 +98,11 @@ RetainPtr FileDescriptor::clone() descriptor = FileDescriptor::create(m_inode.copy_ref()); } } - if (!descriptor) - return nullptr; + ASSERT(descriptor); descriptor->m_current_offset = m_current_offset; descriptor->m_is_blocking = m_is_blocking; descriptor->m_file_flags = m_file_flags; - return descriptor; + return *descriptor; } bool addition_would_overflow(off_t a, off_t b) diff --git a/Kernel/FileDescriptor.h b/Kernel/FileDescriptor.h index b069875d203..a20e8d6de80 100644 --- a/Kernel/FileDescriptor.h +++ b/Kernel/FileDescriptor.h @@ -18,14 +18,14 @@ class CharacterDevice; class FileDescriptor : public Retainable { public: - static RetainPtr create(RetainPtr&&, SocketRole = SocketRole::None); - static RetainPtr create(RetainPtr&&); - static RetainPtr create(RetainPtr&&); - static RetainPtr create_pipe_writer(FIFO&); - static RetainPtr create_pipe_reader(FIFO&); + static Retained create(RetainPtr&&, SocketRole = SocketRole::None); + static Retained create(RetainPtr&&); + static Retained create(RetainPtr&&); + static Retained create_pipe_writer(FIFO&); + static Retained create_pipe_reader(FIFO&); ~FileDescriptor(); - RetainPtr clone(); + Retained clone(); int close(); diff --git a/Kernel/IDEDiskDevice.cpp b/Kernel/IDEDiskDevice.cpp index d71a4780d97..b557a119cde 100644 --- a/Kernel/IDEDiskDevice.cpp +++ b/Kernel/IDEDiskDevice.cpp @@ -32,7 +32,7 @@ enum IDEStatus : byte { ERR = (1 << 0), }; -RetainPtr IDEDiskDevice::create() +Retained IDEDiskDevice::create() { return adopt(*new IDEDiskDevice); } diff --git a/Kernel/IDEDiskDevice.h b/Kernel/IDEDiskDevice.h index beaaca0d57e..1f0424bb1e9 100644 --- a/Kernel/IDEDiskDevice.h +++ b/Kernel/IDEDiskDevice.h @@ -7,7 +7,7 @@ class IDEDiskDevice final : public IRQHandler, public DiskDevice { public: - static RetainPtr create(); + static Retained create(); virtual ~IDEDiskDevice() override; // ^DiskDevice diff --git a/Kernel/LocalSocket.cpp b/Kernel/LocalSocket.cpp index 9073100c042..c8c6ec8a5bf 100644 --- a/Kernel/LocalSocket.cpp +++ b/Kernel/LocalSocket.cpp @@ -4,7 +4,7 @@ #include #include -RetainPtr LocalSocket::create(int type) +Retained LocalSocket::create(int type) { return adopt(*new LocalSocket(type)); } diff --git a/Kernel/LocalSocket.h b/Kernel/LocalSocket.h index 51ceaeccd83..7ad4abc8d00 100644 --- a/Kernel/LocalSocket.h +++ b/Kernel/LocalSocket.h @@ -7,7 +7,7 @@ class FileDescriptor; class LocalSocket final : public Socket { public: - static RetainPtr create(int type); + static Retained create(int type); virtual ~LocalSocket() override; virtual bool bind(const sockaddr*, socklen_t, int& error) override; diff --git a/Kernel/Makefile b/Kernel/Makefile index 62df5aaa9ec..b97bb789201 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -71,13 +71,15 @@ WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fal FLAVOR_FLAGS = -mregparm=3 -fno-exceptions -fno-rtti OPTIMIZATION_FLAGS = -Os INCLUDE_FLAGS = -I.. -I. +CLANG_FLAGS = -Wconsumed -m32 -ffreestanding -march=i686 #SUGGEST_FLAGS = -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override #-Wsuggest-attribute=noreturn DEFINES = -DSERENITY -DKERNEL -DSANITIZE_PTRS CXXFLAGS = -MMD -MP $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(KERNEL_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(SUGGEST_FLAGS) $(INCLUDE_FLAGS) $(DEFINES) -CXX = ~/opt/cross/bin/i686-elf-g++ -LD = ~/opt/cross/bin/i686-elf-ld +#CXX = clang $(CLANG_FLAGS) +CXX = i686-elf-g++ +LD = i686-elf-ld LDFLAGS = -T linker.ld all: $(KERNEL) $(IMAGE) kernel.map diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp index 1e41bfc4450..9313b81b47c 100644 --- a/Kernel/MemoryManager.cpp +++ b/Kernel/MemoryManager.cpp @@ -667,14 +667,14 @@ Region::~Region() MM.unregister_region(*this); } -RetainPtr PhysicalPage::create_eternal(PhysicalAddress paddr, bool supervisor) +Retained PhysicalPage::create_eternal(PhysicalAddress paddr, bool supervisor) { void* slot = kmalloc_eternal(sizeof(PhysicalPage)); new (slot) PhysicalPage(paddr, supervisor); return adopt(*(PhysicalPage*)slot); } -RetainPtr PhysicalPage::create(PhysicalAddress paddr, bool supervisor) +Retained PhysicalPage::create(PhysicalAddress paddr, bool supervisor) { void* slot = kmalloc(sizeof(PhysicalPage)); new (slot) PhysicalPage(paddr, supervisor, false); @@ -702,23 +702,23 @@ void PhysicalPage::return_to_freelist() #endif } -RetainPtr VMObject::create_file_backed(RetainPtr&& inode) +Retained VMObject::create_file_backed(RetainPtr&& inode) { InterruptDisabler disabler; if (inode->vmo()) - return static_cast(inode->vmo()); + return *inode->vmo(); auto vmo = adopt(*new VMObject(move(inode))); vmo->inode()->set_vmo(*vmo); return vmo; } -RetainPtr VMObject::create_anonymous(size_t size) +Retained VMObject::create_anonymous(size_t size) { size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE; return adopt(*new VMObject(size)); } -RetainPtr VMObject::create_for_physical_range(PhysicalAddress paddr, size_t size) +Retained VMObject::create_for_physical_range(PhysicalAddress paddr, size_t size) { size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE; auto vmo = adopt(*new VMObject(paddr, size)); @@ -726,7 +726,7 @@ RetainPtr VMObject::create_for_physical_range(PhysicalAddress paddr, s return vmo; } -RetainPtr VMObject::clone() +Retained VMObject::clone() { return adopt(*new VMObject(*this)); } diff --git a/Kernel/MemoryManager.h b/Kernel/MemoryManager.h index ccdcf0b6ad2..00bb2abfd8f 100644 --- a/Kernel/MemoryManager.h +++ b/Kernel/MemoryManager.h @@ -48,8 +48,8 @@ public: } } - static RetainPtr create_eternal(PhysicalAddress, bool supervisor); - static RetainPtr create(PhysicalAddress, bool supervisor); + static Retained create_eternal(PhysicalAddress, bool supervisor); + static Retained create(PhysicalAddress, bool supervisor); unsigned short retain_count() const { return m_retain_count; } @@ -68,8 +68,8 @@ private: class PageDirectory : public Retainable { friend class MemoryManager; public: - static RetainPtr create() { return adopt(*new PageDirectory); } - static RetainPtr create_at_fixed_address(PhysicalAddress paddr) { return adopt(*new PageDirectory(paddr)); } + static Retained create() { return adopt(*new PageDirectory); } + static Retained create_at_fixed_address(PhysicalAddress paddr) { return adopt(*new PageDirectory(paddr)); } ~PageDirectory(); dword cr3() const { return m_directory_page->paddr().get(); } @@ -88,10 +88,10 @@ private: class VMObject : public Retainable, public Weakable { friend class MemoryManager; public: - static RetainPtr create_file_backed(RetainPtr&&); - static RetainPtr create_anonymous(size_t); - static RetainPtr create_for_physical_range(PhysicalAddress, size_t); - RetainPtr clone(); + static Retained create_file_backed(RetainPtr&&); + static Retained create_anonymous(size_t); + static Retained create_for_physical_range(PhysicalAddress, size_t); + Retained clone(); ~VMObject(); bool is_anonymous() const { return m_anonymous; } diff --git a/Kernel/ProcFS.cpp b/Kernel/ProcFS.cpp index cbdff6f8899..680c46b187e 100644 --- a/Kernel/ProcFS.cpp +++ b/Kernel/ProcFS.cpp @@ -166,7 +166,7 @@ ProcFS& ProcFS::the() return *s_the; } -RetainPtr ProcFS::create() +Retained ProcFS::create() { return adopt(*new ProcFS); } diff --git a/Kernel/ProcFS.h b/Kernel/ProcFS.h index c57e08fdd15..ad64feae41d 100644 --- a/Kernel/ProcFS.h +++ b/Kernel/ProcFS.h @@ -14,7 +14,7 @@ public: [[gnu::pure]] static ProcFS& the(); virtual ~ProcFS() override; - static RetainPtr create(); + static Retained create(); virtual bool initialize() override; virtual const char* class_name() const override; diff --git a/Kernel/SyntheticFileSystem.cpp b/Kernel/SyntheticFileSystem.cpp index a94fcab773f..1ed6e6eb508 100644 --- a/Kernel/SyntheticFileSystem.cpp +++ b/Kernel/SyntheticFileSystem.cpp @@ -5,7 +5,7 @@ //#define SYNTHFS_DEBUG -RetainPtr SynthFS::create() +Retained SynthFS::create() { return adopt(*new SynthFS); } @@ -34,7 +34,7 @@ bool SynthFS::initialize() return true; } -RetainPtr SynthFS::create_directory(String&& name) +Retained SynthFS::create_directory(String&& name) { auto file = adopt(*new SynthFSInode(*this, generate_inode_index())); file->m_name = move(name); @@ -46,7 +46,7 @@ RetainPtr SynthFS::create_directory(String&& name) return file; } -RetainPtr SynthFS::create_text_file(String&& name, ByteBuffer&& contents, mode_t mode) +Retained SynthFS::create_text_file(String&& name, ByteBuffer&& contents, mode_t mode) { auto file = adopt(*new SynthFSInode(*this, generate_inode_index())); file->m_data = contents; @@ -59,7 +59,7 @@ RetainPtr SynthFS::create_text_file(String&& name, ByteBuffer&& co return file; } -RetainPtr SynthFS::create_generated_file(String&& name, Function&& generator, mode_t mode) +Retained SynthFS::create_generated_file(String&& name, Function&& generator, mode_t mode) { auto file = adopt(*new SynthFSInode(*this, generate_inode_index())); file->m_generator = move(generator); @@ -72,7 +72,7 @@ RetainPtr SynthFS::create_generated_file(String&& name, Function SynthFS::create_generated_file(String&& name, Function&& read_callback, Function&& write_callback, mode_t mode) +Retained SynthFS::create_generated_file(String&& name, Function&& read_callback, Function&& write_callback, mode_t mode) { auto file = adopt(*new SynthFSInode(*this, generate_inode_index())); file->m_generator = move(read_callback); diff --git a/Kernel/SyntheticFileSystem.h b/Kernel/SyntheticFileSystem.h index f1cc8537852..cfe04180d78 100644 --- a/Kernel/SyntheticFileSystem.h +++ b/Kernel/SyntheticFileSystem.h @@ -9,7 +9,7 @@ class SynthFSInode; class SynthFS : public FS { public: virtual ~SynthFS() override; - static RetainPtr create(); + static Retained create(); virtual bool initialize() override; virtual const char* class_name() const override; @@ -26,10 +26,10 @@ protected: SynthFS(); - RetainPtr create_directory(String&& name); - RetainPtr create_text_file(String&& name, ByteBuffer&&, mode_t = 0010644); - RetainPtr create_generated_file(String&& name, Function&&, mode_t = 0100644); - RetainPtr create_generated_file(String&& name, Function&&, Function&&, mode_t = 0100644); + Retained create_directory(String&& name); + Retained create_text_file(String&& name, ByteBuffer&&, mode_t = 0010644); + Retained create_generated_file(String&& name, Function&&, mode_t = 0100644); + Retained create_generated_file(String&& name, Function&&, Function&&, mode_t = 0100644); InodeIdentifier add_file(RetainPtr&&, InodeIndex parent = RootInodeIndex); bool remove_file(InodeIndex); diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 05e2c0a32ec..bbabc84acf8 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -149,7 +149,7 @@ VFS* vfs; new BXVGADevice; - auto new_procfs = ProcFS::create(); + Retained new_procfs = ProcFS::create(); new_procfs->initialize(); auto devptsfs = DevPtsFS::create(); diff --git a/LibGUI/GAction.h b/LibGUI/GAction.h index 64797fedf7b..305abc59e38 100644 --- a/LibGUI/GAction.h +++ b/LibGUI/GAction.h @@ -3,20 +3,20 @@ #include #include #include -#include +#include #include class GAction : public Retainable { public: - static RetainPtr create(const String& text, Function callback) + static Retained create(const String& text, Function callback) { return adopt(*new GAction(text, move(callback))); } - static RetainPtr create(const String& text, const String& custom_data, Function callback) + static Retained create(const String& text, const String& custom_data, Function callback) { return adopt(*new GAction(text, custom_data, move(callback))); } - static RetainPtr create(const String& text, RetainPtr&& icon, Function callback) + static Retained create(const String& text, RetainPtr&& icon, Function callback) { return adopt(*new GAction(text, move(icon), move(callback))); } diff --git a/LibGUI/GToolBar.cpp b/LibGUI/GToolBar.cpp index 9cfffc8c255..a0069c09881 100644 --- a/LibGUI/GToolBar.cpp +++ b/LibGUI/GToolBar.cpp @@ -18,9 +18,8 @@ GToolBar::~GToolBar() { } -void GToolBar::add_action(RetainPtr&& action) +void GToolBar::add_action(Retained&& action) { - ASSERT(action); GAction* raw_action_ptr = action.ptr(); auto item = make(); item->type = Item::Action; diff --git a/LibGUI/GToolBar.h b/LibGUI/GToolBar.h index 3338c3d55af..483eac238fc 100644 --- a/LibGUI/GToolBar.h +++ b/LibGUI/GToolBar.h @@ -9,7 +9,7 @@ public: explicit GToolBar(GWidget* parent); virtual ~GToolBar() override; - void add_action(RetainPtr&&); + void add_action(Retained&&); void add_separator(); private: diff --git a/SharedGraphics/GraphicsBitmap.cpp b/SharedGraphics/GraphicsBitmap.cpp index 40f25ee697e..035f17e9a4d 100644 --- a/SharedGraphics/GraphicsBitmap.cpp +++ b/SharedGraphics/GraphicsBitmap.cpp @@ -5,7 +5,7 @@ #include #include -RetainPtr GraphicsBitmap::create(Format format, const Size& size) +Retained GraphicsBitmap::create(Format format, const Size& size) { return adopt(*new GraphicsBitmap(format, size)); } @@ -22,7 +22,7 @@ GraphicsBitmap::GraphicsBitmap(Format format, const Size& size) m_mmaped = true; } -RetainPtr GraphicsBitmap::create_wrapper(Format format, const Size& size, RGBA32* data) +Retained GraphicsBitmap::create_wrapper(Format format, const Size& size, RGBA32* data) { return adopt(*new GraphicsBitmap(format, size, data)); } diff --git a/SharedGraphics/GraphicsBitmap.h b/SharedGraphics/GraphicsBitmap.h index 7d8f2ec65f8..792e0d0076c 100644 --- a/SharedGraphics/GraphicsBitmap.h +++ b/SharedGraphics/GraphicsBitmap.h @@ -11,8 +11,8 @@ class GraphicsBitmap : public Retainable { public: enum class Format { Invalid, RGB32, RGBA32 }; - static RetainPtr create(Format, const Size&); - static RetainPtr create_wrapper(Format, const Size&, RGBA32*); + static Retained create(Format, const Size&); + static Retained create_wrapper(Format, const Size&, RGBA32*); static RetainPtr load_from_file(Format, const String& path, const Size&); static RetainPtr create_with_shared_buffer(Format, int shared_buffer_id, const Size&, RGBA32* buffer = nullptr); ~GraphicsBitmap();