浏览代码

AK: Add Retained<T>, like RetainPtr, but never null.

Also use some Clang attribute wizardry to get a warning for use-after-move.
Andreas Kling 6 年之前
父节点
当前提交
2cfcbdc735

+ 8 - 8
AK/Buffer.h

@@ -11,10 +11,10 @@ namespace AK {
 template<typename T>
 template<typename T>
 class Buffer : public Retainable<Buffer<T>> {
 class Buffer : public Retainable<Buffer<T>> {
 public:
 public:
-    static RetainPtr<Buffer> create_uninitialized(size_t count);
-    static RetainPtr<Buffer> copy(const T*, size_t count);
-    static RetainPtr<Buffer> wrap(T*, size_t count);
-    static RetainPtr<Buffer> adopt(T*, size_t count);
+    static Retained<Buffer> create_uninitialized(size_t count);
+    static Retained<Buffer> copy(const T*, size_t count);
+    static Retained<Buffer> wrap(T*, size_t count);
+    static Retained<Buffer> adopt(T*, size_t count);
 
 
     ~Buffer() { clear(); }
     ~Buffer() { clear(); }
 
 
@@ -105,25 +105,25 @@ inline void Buffer<T>::grow(size_t size)
 }
 }
 
 
 template<typename T>
 template<typename T>
-inline RetainPtr<Buffer<T>> Buffer<T>::create_uninitialized(size_t size)
+inline Retained<Buffer<T>> Buffer<T>::create_uninitialized(size_t size)
 {
 {
     return ::adopt(*new Buffer<T>(size));
     return ::adopt(*new Buffer<T>(size));
 }
 }
 
 
 template<typename T>
 template<typename T>
-inline RetainPtr<Buffer<T>> Buffer<T>::copy(const T* elements, size_t size)
+inline Retained<Buffer<T>> Buffer<T>::copy(const T* elements, size_t size)
 {
 {
     return ::adopt(*new Buffer<T>(elements, size, Copy));
     return ::adopt(*new Buffer<T>(elements, size, Copy));
 }
 }
 
 
 template<typename T>
 template<typename T>
-inline RetainPtr<Buffer<T>> Buffer<T>::wrap(T* elements, size_t size)
+inline Retained<Buffer<T>> Buffer<T>::wrap(T* elements, size_t size)
 {
 {
     return ::adopt(*new Buffer<T>(elements, size, Wrap));
     return ::adopt(*new Buffer<T>(elements, size, Wrap));
 }
 }
 
 
 template<typename T>
 template<typename T>
-inline RetainPtr<Buffer<T>> Buffer<T>::adopt(T* elements, size_t size)
+inline Retained<Buffer<T>> Buffer<T>::adopt(T* elements, size_t size)
 {
 {
     return ::adopt(*new Buffer<T>(elements, size, Adopt));
     return ::adopt(*new Buffer<T>(elements, size, Adopt));
 }
 }

+ 3 - 22
AK/RetainPtr.h

@@ -1,23 +1,10 @@
 #pragma once
 #pragma once
 
 
-#include "Types.h"
+#include <AK/Types.h>
+#include <AK/Retained.h>
 
 
 namespace AK {
 namespace AK {
 
 
-template<typename T>
-inline void retain_if_not_null(T* ptr)
-{
-    if (ptr)
-        ptr->retain();
-}
-
-template<typename T>
-inline void release_if_not_null(T* ptr)
-{
-    if (ptr)
-        ptr->release();
-}
-
 template<typename T>
 template<typename T>
 class RetainPtr {
 class RetainPtr {
 public:
 public:
@@ -30,6 +17,7 @@ public:
     RetainPtr(AdoptTag, T& object) : m_ptr(&object) { }
     RetainPtr(AdoptTag, T& object) : m_ptr(&object) { }
     RetainPtr(RetainPtr& other) : m_ptr(other.copy_ref().leak_ref()) { }
     RetainPtr(RetainPtr& other) : m_ptr(other.copy_ref().leak_ref()) { }
     RetainPtr(RetainPtr&& other) : m_ptr(other.leak_ref()) { }
     RetainPtr(RetainPtr&& other) : m_ptr(other.leak_ref()) { }
+    template<typename U> RetainPtr(Retained<U>&& other) : m_ptr(static_cast<T*>(&other.leak_ref())) { }
     template<typename U> RetainPtr(RetainPtr<U>&& other) : m_ptr(static_cast<T*>(other.leak_ref())) { }
     template<typename U> RetainPtr(RetainPtr<U>&& other) : m_ptr(static_cast<T*>(other.leak_ref())) { }
     RetainPtr(const RetainPtr& other) : m_ptr(const_cast<RetainPtr&>(other).copy_ref().leak_ref()) { }
     RetainPtr(const RetainPtr& other) : m_ptr(const_cast<RetainPtr&>(other).copy_ref().leak_ref()) { }
     template<typename U> RetainPtr(const RetainPtr<U>& other) : m_ptr(const_cast<RetainPtr<U>&>(other).copy_ref().leak_ref()) { }
     template<typename U> RetainPtr(const RetainPtr<U>& other) : m_ptr(const_cast<RetainPtr<U>&>(other).copy_ref().leak_ref()) { }
@@ -128,14 +116,7 @@ private:
     T* m_ptr = nullptr;
     T* m_ptr = nullptr;
 };
 };
 
 
-template<typename T>
-inline RetainPtr<T> adopt(T& object)
-{
-    return RetainPtr<T>(RetainPtr<T>::Adopt, object);
-}
-
 }
 }
 
 
 using AK::RetainPtr;
 using AK::RetainPtr;
-using AK::adopt;
 
 

+ 123 - 0
AK/Retained.h

@@ -0,0 +1,123 @@
+#pragma once
+
+#include <AK/Types.h>
+
+#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<typename T>
+inline void retain_if_not_null(T* ptr)
+{
+    if (ptr)
+        ptr->retain();
+}
+
+template<typename T>
+inline void release_if_not_null(T* ptr)
+{
+    if (ptr)
+        ptr->release();
+}
+
+template<typename T>
+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<typename U> RETURN_TYPESTATE(unconsumed) Retained(Retained<U>&& other) : m_ptr(static_cast<T*>(&other.leak_ref())) { }
+    RETURN_TYPESTATE(unconsumed) Retained(const Retained& other) : m_ptr(&const_cast<Retained&>(other).copy_ref().leak_ref()) { }
+    template<typename U> RETURN_TYPESTATE(unconsumed) Retained(const Retained<U>& other) : m_ptr(&const_cast<Retained<U>&>(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<typename U>
+    CALLABLE_WHEN(unconsumed) Retained& operator=(Retained<U>&& other)
+    {
+        if (this != static_cast<void*>(&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<typename T>
+inline Retained<T> adopt(T& object)
+{
+    return Retained<T>(Retained<T>::Adopt, object);
+}
+
+}
+
+using AK::Retained;
+using AK::adopt;

+ 7 - 0
AK/StdLibExtras.h

@@ -60,11 +60,18 @@ static inline T ceil_div(T a, U b)
     return result;
     return result;
 }
 }
 
 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wconsumed"
+#endif
 template <typename T>
 template <typename T>
 T&& move(T& arg)
 T&& move(T& arg)
 {
 {
     return static_cast<T&&>(arg);
     return static_cast<T&&>(arg);
 }
 }
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
 
 
 template<typename T>
 template<typename T>
 struct Identity {
 struct Identity {

+ 2 - 2
Kernel/DevPtsFS.cpp

@@ -11,7 +11,7 @@ DevPtsFS& DevPtsFS::the()
     return *s_the;
     return *s_the;
 }
 }
 
 
-RetainPtr<DevPtsFS> DevPtsFS::create()
+Retained<DevPtsFS> DevPtsFS::create()
 {
 {
     return adopt(*new DevPtsFS);
     return adopt(*new DevPtsFS);
 }
 }
@@ -36,7 +36,7 @@ const char* DevPtsFS::class_name() const
     return "DevPtsFS";
     return "DevPtsFS";
 }
 }
 
 
-RetainPtr<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index)
+Retained<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index)
 {
 {
     auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
     auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
 
 

+ 2 - 2
Kernel/DevPtsFS.h

@@ -11,7 +11,7 @@ public:
     [[gnu::pure]] static DevPtsFS& the();
     [[gnu::pure]] static DevPtsFS& the();
 
 
     virtual ~DevPtsFS() override;
     virtual ~DevPtsFS() override;
-    static RetainPtr<DevPtsFS> create();
+    static Retained<DevPtsFS> create();
 
 
     virtual bool initialize() override;
     virtual bool initialize() override;
     virtual const char* class_name() const override;
     virtual const char* class_name() const override;
@@ -22,7 +22,7 @@ public:
 private:
 private:
     DevPtsFS();
     DevPtsFS();
 
 
-    RetainPtr<SynthFSInode> create_slave_pty_device_file(unsigned index);
+    Retained<SynthFSInode> create_slave_pty_device_file(unsigned index);
 
 
     HashTable<SlavePTY*> m_slave_ptys;
     HashTable<SlavePTY*> m_slave_ptys;
 };
 };

+ 1 - 2
Kernel/DiskBackedFileSystem.cpp

@@ -44,10 +44,9 @@ Lockable<InlineLRUCache<BlockIdentifier, CachedBlock>>& block_cache()
     return *s_cache;
     return *s_cache;
 }
 }
 
 
-DiskBackedFS::DiskBackedFS(RetainPtr<DiskDevice>&& device)
+DiskBackedFS::DiskBackedFS(Retained<DiskDevice>&& device)
     : m_device(move(device))
     : m_device(move(device))
 {
 {
-    ASSERT(m_device);
 }
 }
 
 
 DiskBackedFS::~DiskBackedFS()
 DiskBackedFS::~DiskBackedFS()

+ 2 - 2
Kernel/DiskBackedFileSystem.h

@@ -13,7 +13,7 @@ public:
     size_t block_size() const { return m_block_size; }
     size_t block_size() const { return m_block_size; }
 
 
 protected:
 protected:
-    explicit DiskBackedFS(RetainPtr<DiskDevice>&&);
+    explicit DiskBackedFS(Retained<DiskDevice>&&);
 
 
     void set_block_size(unsigned);
     void set_block_size(unsigned);
 
 
@@ -25,5 +25,5 @@ protected:
 
 
 private:
 private:
     size_t m_block_size { 0 };
     size_t m_block_size { 0 };
-    RetainPtr<DiskDevice> m_device;
+    Retained<DiskDevice> m_device;
 };
 };

+ 2 - 2
Kernel/Ext2FileSystem.cpp

@@ -13,12 +13,12 @@
 
 
 //#define EXT2_DEBUG
 //#define EXT2_DEBUG
 
 
-RetainPtr<Ext2FS> Ext2FS::create(RetainPtr<DiskDevice>&& device)
+Retained<Ext2FS> Ext2FS::create(Retained<DiskDevice>&& device)
 {
 {
     return adopt(*new Ext2FS(move(device)));
     return adopt(*new Ext2FS(move(device)));
 }
 }
 
 
-Ext2FS::Ext2FS(RetainPtr<DiskDevice>&& device)
+Ext2FS::Ext2FS(Retained<DiskDevice>&& device)
     : DiskBackedFS(move(device))
     : DiskBackedFS(move(device))
     , m_lock("Ext2FS")
     , m_lock("Ext2FS")
 {
 {

+ 2 - 2
Kernel/Ext2FileSystem.h

@@ -58,7 +58,7 @@ private:
 class Ext2FS final : public DiskBackedFS {
 class Ext2FS final : public DiskBackedFS {
     friend class Ext2FSInode;
     friend class Ext2FSInode;
 public:
 public:
-    static RetainPtr<Ext2FS> create(RetainPtr<DiskDevice>&&);
+    static Retained <Ext2FS> create(Retained<DiskDevice>&&);
     virtual ~Ext2FS() override;
     virtual ~Ext2FS() override;
     virtual bool initialize() override;
     virtual bool initialize() override;
 
 
@@ -71,7 +71,7 @@ private:
     typedef unsigned BlockIndex;
     typedef unsigned BlockIndex;
     typedef unsigned GroupIndex;
     typedef unsigned GroupIndex;
     typedef unsigned InodeIndex;
     typedef unsigned InodeIndex;
-    explicit Ext2FS(RetainPtr<DiskDevice>&&);
+    explicit Ext2FS(Retained<DiskDevice>&&);
 
 
     const ext2_super_block& super_block() const;
     const ext2_super_block& super_block() const;
     const ext2_group_desc& group_descriptor(unsigned groupIndex) const;
     const ext2_group_desc& group_descriptor(unsigned groupIndex) const;

+ 1 - 1
Kernel/FIFO.cpp

@@ -3,7 +3,7 @@
 
 
 //#define FIFO_DEBUG
 //#define FIFO_DEBUG
 
 
-RetainPtr<FIFO> FIFO::create()
+Retained<FIFO> FIFO::create()
 {
 {
     return adopt(*new FIFO);
     return adopt(*new FIFO);
 }
 }

+ 1 - 1
Kernel/FIFO.h

@@ -11,7 +11,7 @@ public:
         Neither, Reader, Writer
         Neither, Reader, Writer
     };
     };
 
 
-    static RetainPtr<FIFO> create();
+    static Retained<FIFO> create();
 
 
     void open(Direction);
     void open(Direction);
     void close(Direction);
     void close(Direction);

+ 8 - 9
Kernel/FileDescriptor.cpp

@@ -12,27 +12,27 @@
 #include <Kernel/BlockDevice.h>
 #include <Kernel/BlockDevice.h>
 #include <Kernel/MemoryManager.h>
 #include <Kernel/MemoryManager.h>
 
 
-RetainPtr<FileDescriptor> FileDescriptor::create(RetainPtr<Inode>&& inode)
+Retained<FileDescriptor> FileDescriptor::create(RetainPtr<Inode>&& inode)
 {
 {
     return adopt(*new FileDescriptor(move(inode)));
     return adopt(*new FileDescriptor(move(inode)));
 }
 }
 
 
-RetainPtr<FileDescriptor> FileDescriptor::create(RetainPtr<Device>&& device)
+Retained<FileDescriptor> FileDescriptor::create(RetainPtr<Device>&& device)
 {
 {
     return adopt(*new FileDescriptor(move(device)));
     return adopt(*new FileDescriptor(move(device)));
 }
 }
 
 
-RetainPtr<FileDescriptor> FileDescriptor::create(RetainPtr<Socket>&& socket, SocketRole role)
+Retained<FileDescriptor> FileDescriptor::create(RetainPtr<Socket>&& socket, SocketRole role)
 {
 {
     return adopt(*new FileDescriptor(move(socket), role));
     return adopt(*new FileDescriptor(move(socket), role));
 }
 }
 
 
-RetainPtr<FileDescriptor> FileDescriptor::create_pipe_writer(FIFO& fifo)
+Retained<FileDescriptor> FileDescriptor::create_pipe_writer(FIFO& fifo)
 {
 {
     return adopt(*new FileDescriptor(fifo, FIFO::Writer));
     return adopt(*new FileDescriptor(fifo, FIFO::Writer));
 }
 }
 
 
-RetainPtr<FileDescriptor> FileDescriptor::create_pipe_reader(FIFO& fifo)
+Retained<FileDescriptor> FileDescriptor::create_pipe_reader(FIFO& fifo)
 {
 {
     return adopt(*new FileDescriptor(fifo, FIFO::Reader));
     return adopt(*new FileDescriptor(fifo, FIFO::Reader));
 }
 }
@@ -80,7 +80,7 @@ void FileDescriptor::set_socket_role(SocketRole role)
     m_socket->attach_fd(role);
     m_socket->attach_fd(role);
 }
 }
 
 
-RetainPtr<FileDescriptor> FileDescriptor::clone()
+Retained<FileDescriptor> FileDescriptor::clone()
 {
 {
     RetainPtr<FileDescriptor> descriptor;
     RetainPtr<FileDescriptor> descriptor;
     if (is_fifo()) {
     if (is_fifo()) {
@@ -98,12 +98,11 @@ RetainPtr<FileDescriptor> FileDescriptor::clone()
             descriptor = FileDescriptor::create(m_inode.copy_ref());
             descriptor = FileDescriptor::create(m_inode.copy_ref());
         }
         }
     }
     }
-    if (!descriptor)
-        return nullptr;
+    ASSERT(descriptor);
     descriptor->m_current_offset = m_current_offset;
     descriptor->m_current_offset = m_current_offset;
     descriptor->m_is_blocking = m_is_blocking;
     descriptor->m_is_blocking = m_is_blocking;
     descriptor->m_file_flags = m_file_flags;
     descriptor->m_file_flags = m_file_flags;
-    return descriptor;
+    return *descriptor;
 }
 }
 
 
 bool addition_would_overflow(off_t a, off_t b)
 bool addition_would_overflow(off_t a, off_t b)

+ 6 - 6
Kernel/FileDescriptor.h

@@ -18,14 +18,14 @@ class CharacterDevice;
 class FileDescriptor : public Retainable<FileDescriptor> {
 class FileDescriptor : public Retainable<FileDescriptor> {
 public:
 public:
 
 
-    static RetainPtr<FileDescriptor> create(RetainPtr<Socket>&&, SocketRole = SocketRole::None);
-    static RetainPtr<FileDescriptor> create(RetainPtr<Inode>&&);
-    static RetainPtr<FileDescriptor> create(RetainPtr<Device>&&);
-    static RetainPtr<FileDescriptor> create_pipe_writer(FIFO&);
-    static RetainPtr<FileDescriptor> create_pipe_reader(FIFO&);
+    static Retained<FileDescriptor> create(RetainPtr<Socket>&&, SocketRole = SocketRole::None);
+    static Retained<FileDescriptor> create(RetainPtr<Inode>&&);
+    static Retained<FileDescriptor> create(RetainPtr<Device>&&);
+    static Retained<FileDescriptor> create_pipe_writer(FIFO&);
+    static Retained<FileDescriptor> create_pipe_reader(FIFO&);
     ~FileDescriptor();
     ~FileDescriptor();
 
 
-    RetainPtr<FileDescriptor> clone();
+    Retained<FileDescriptor> clone();
 
 
     int close();
     int close();
 
 

+ 1 - 1
Kernel/IDEDiskDevice.cpp

@@ -32,7 +32,7 @@ enum IDEStatus : byte {
     ERR  = (1 << 0),
     ERR  = (1 << 0),
 };
 };
 
 
-RetainPtr<IDEDiskDevice> IDEDiskDevice::create()
+Retained<IDEDiskDevice> IDEDiskDevice::create()
 {
 {
     return adopt(*new IDEDiskDevice);
     return adopt(*new IDEDiskDevice);
 }
 }

+ 1 - 1
Kernel/IDEDiskDevice.h

@@ -7,7 +7,7 @@
 
 
 class IDEDiskDevice final : public IRQHandler, public DiskDevice {
 class IDEDiskDevice final : public IRQHandler, public DiskDevice {
 public:
 public:
-    static RetainPtr<IDEDiskDevice> create();
+    static Retained<IDEDiskDevice> create();
     virtual ~IDEDiskDevice() override;
     virtual ~IDEDiskDevice() override;
 
 
     // ^DiskDevice
     // ^DiskDevice

+ 1 - 1
Kernel/LocalSocket.cpp

@@ -4,7 +4,7 @@
 #include <Kernel/VirtualFileSystem.h>
 #include <Kernel/VirtualFileSystem.h>
 #include <LibC/errno_numbers.h>
 #include <LibC/errno_numbers.h>
 
 
-RetainPtr<LocalSocket> LocalSocket::create(int type)
+Retained<LocalSocket> LocalSocket::create(int type)
 {
 {
     return adopt(*new LocalSocket(type));
     return adopt(*new LocalSocket(type));
 }
 }

+ 1 - 1
Kernel/LocalSocket.h

@@ -7,7 +7,7 @@ class FileDescriptor;
 
 
 class LocalSocket final : public Socket {
 class LocalSocket final : public Socket {
 public:
 public:
-    static RetainPtr<LocalSocket> create(int type);
+    static Retained<LocalSocket> create(int type);
     virtual ~LocalSocket() override;
     virtual ~LocalSocket() override;
 
 
     virtual bool bind(const sockaddr*, socklen_t, int& error) override;
     virtual bool bind(const sockaddr*, socklen_t, int& error) override;

+ 4 - 2
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
 FLAVOR_FLAGS = -mregparm=3 -fno-exceptions -fno-rtti
 OPTIMIZATION_FLAGS = -Os
 OPTIMIZATION_FLAGS = -Os
 INCLUDE_FLAGS = -I.. -I.
 INCLUDE_FLAGS = -I.. -I.
+CLANG_FLAGS = -Wconsumed -m32 -ffreestanding -march=i686
 #SUGGEST_FLAGS = -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override #-Wsuggest-attribute=noreturn 
 #SUGGEST_FLAGS = -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override #-Wsuggest-attribute=noreturn 
 
 
 DEFINES = -DSERENITY -DKERNEL -DSANITIZE_PTRS
 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)
 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
 LDFLAGS = -T linker.ld
 
 
 all: $(KERNEL) $(IMAGE) kernel.map
 all: $(KERNEL) $(IMAGE) kernel.map

+ 7 - 7
Kernel/MemoryManager.cpp

@@ -667,14 +667,14 @@ Region::~Region()
     MM.unregister_region(*this);
     MM.unregister_region(*this);
 }
 }
 
 
-RetainPtr<PhysicalPage> PhysicalPage::create_eternal(PhysicalAddress paddr, bool supervisor)
+Retained<PhysicalPage> PhysicalPage::create_eternal(PhysicalAddress paddr, bool supervisor)
 {
 {
     void* slot = kmalloc_eternal(sizeof(PhysicalPage));
     void* slot = kmalloc_eternal(sizeof(PhysicalPage));
     new (slot) PhysicalPage(paddr, supervisor);
     new (slot) PhysicalPage(paddr, supervisor);
     return adopt(*(PhysicalPage*)slot);
     return adopt(*(PhysicalPage*)slot);
 }
 }
 
 
-RetainPtr<PhysicalPage> PhysicalPage::create(PhysicalAddress paddr, bool supervisor)
+Retained<PhysicalPage> PhysicalPage::create(PhysicalAddress paddr, bool supervisor)
 {
 {
     void* slot = kmalloc(sizeof(PhysicalPage));
     void* slot = kmalloc(sizeof(PhysicalPage));
     new (slot) PhysicalPage(paddr, supervisor, false);
     new (slot) PhysicalPage(paddr, supervisor, false);
@@ -702,23 +702,23 @@ void PhysicalPage::return_to_freelist()
 #endif
 #endif
 }
 }
 
 
-RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode)
+Retained<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode)
 {
 {
     InterruptDisabler disabler;
     InterruptDisabler disabler;
     if (inode->vmo())
     if (inode->vmo())
-        return static_cast<VMObject*>(inode->vmo());
+        return *inode->vmo();
     auto vmo = adopt(*new VMObject(move(inode)));
     auto vmo = adopt(*new VMObject(move(inode)));
     vmo->inode()->set_vmo(*vmo);
     vmo->inode()->set_vmo(*vmo);
     return vmo;
     return vmo;
 }
 }
 
 
-RetainPtr<VMObject> VMObject::create_anonymous(size_t size)
+Retained<VMObject> VMObject::create_anonymous(size_t size)
 {
 {
     size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
     size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
     return adopt(*new VMObject(size));
     return adopt(*new VMObject(size));
 }
 }
 
 
-RetainPtr<VMObject> VMObject::create_for_physical_range(PhysicalAddress paddr, size_t size)
+Retained<VMObject> VMObject::create_for_physical_range(PhysicalAddress paddr, size_t size)
 {
 {
     size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
     size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
     auto vmo = adopt(*new VMObject(paddr, size));
     auto vmo = adopt(*new VMObject(paddr, size));
@@ -726,7 +726,7 @@ RetainPtr<VMObject> VMObject::create_for_physical_range(PhysicalAddress paddr, s
     return vmo;
     return vmo;
 }
 }
 
 
-RetainPtr<VMObject> VMObject::clone()
+Retained<VMObject> VMObject::clone()
 {
 {
     return adopt(*new VMObject(*this));
     return adopt(*new VMObject(*this));
 }
 }

+ 8 - 8
Kernel/MemoryManager.h

@@ -48,8 +48,8 @@ public:
         }
         }
     }
     }
 
 
-    static RetainPtr<PhysicalPage> create_eternal(PhysicalAddress, bool supervisor);
-    static RetainPtr<PhysicalPage> create(PhysicalAddress, bool supervisor);
+    static Retained<PhysicalPage> create_eternal(PhysicalAddress, bool supervisor);
+    static Retained<PhysicalPage> create(PhysicalAddress, bool supervisor);
 
 
     unsigned short retain_count() const { return m_retain_count; }
     unsigned short retain_count() const { return m_retain_count; }
 
 
@@ -68,8 +68,8 @@ private:
 class PageDirectory : public Retainable<PageDirectory> {
 class PageDirectory : public Retainable<PageDirectory> {
     friend class MemoryManager;
     friend class MemoryManager;
 public:
 public:
-    static RetainPtr<PageDirectory> create() { return adopt(*new PageDirectory); }
-    static RetainPtr<PageDirectory> create_at_fixed_address(PhysicalAddress paddr) { return adopt(*new PageDirectory(paddr)); }
+    static Retained<PageDirectory> create() { return adopt(*new PageDirectory); }
+    static Retained<PageDirectory> create_at_fixed_address(PhysicalAddress paddr) { return adopt(*new PageDirectory(paddr)); }
     ~PageDirectory();
     ~PageDirectory();
 
 
     dword cr3() const { return m_directory_page->paddr().get(); }
     dword cr3() const { return m_directory_page->paddr().get(); }
@@ -88,10 +88,10 @@ private:
 class VMObject : public Retainable<VMObject>, public Weakable<VMObject> {
 class VMObject : public Retainable<VMObject>, public Weakable<VMObject> {
     friend class MemoryManager;
     friend class MemoryManager;
 public:
 public:
-    static RetainPtr<VMObject> create_file_backed(RetainPtr<Inode>&&);
-    static RetainPtr<VMObject> create_anonymous(size_t);
-    static RetainPtr<VMObject> create_for_physical_range(PhysicalAddress, size_t);
-    RetainPtr<VMObject> clone();
+    static Retained<VMObject> create_file_backed(RetainPtr<Inode>&&);
+    static Retained<VMObject> create_anonymous(size_t);
+    static Retained<VMObject> create_for_physical_range(PhysicalAddress, size_t);
+    Retained<VMObject> clone();
 
 
     ~VMObject();
     ~VMObject();
     bool is_anonymous() const { return m_anonymous; }
     bool is_anonymous() const { return m_anonymous; }

+ 1 - 1
Kernel/ProcFS.cpp

@@ -166,7 +166,7 @@ ProcFS& ProcFS::the()
     return *s_the;
     return *s_the;
 }
 }
 
 
-RetainPtr<ProcFS> ProcFS::create()
+Retained<ProcFS> ProcFS::create()
 {
 {
     return adopt(*new ProcFS);
     return adopt(*new ProcFS);
 }
 }

+ 1 - 1
Kernel/ProcFS.h

@@ -14,7 +14,7 @@ public:
     [[gnu::pure]] static ProcFS& the();
     [[gnu::pure]] static ProcFS& the();
 
 
     virtual ~ProcFS() override;
     virtual ~ProcFS() override;
-    static RetainPtr<ProcFS> create();
+    static Retained<ProcFS> create();
 
 
     virtual bool initialize() override;
     virtual bool initialize() override;
     virtual const char* class_name() const override;
     virtual const char* class_name() const override;

+ 5 - 5
Kernel/SyntheticFileSystem.cpp

@@ -5,7 +5,7 @@
 
 
 //#define SYNTHFS_DEBUG
 //#define SYNTHFS_DEBUG
 
 
-RetainPtr<SynthFS> SynthFS::create()
+Retained<SynthFS> SynthFS::create()
 {
 {
     return adopt(*new SynthFS);
     return adopt(*new SynthFS);
 }
 }
@@ -34,7 +34,7 @@ bool SynthFS::initialize()
     return true;
     return true;
 }
 }
 
 
-RetainPtr<SynthFSInode> SynthFS::create_directory(String&& name)
+Retained<SynthFSInode> SynthFS::create_directory(String&& name)
 {
 {
     auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
     auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
     file->m_name = move(name);
     file->m_name = move(name);
@@ -46,7 +46,7 @@ RetainPtr<SynthFSInode> SynthFS::create_directory(String&& name)
     return file;
     return file;
 }
 }
 
 
-RetainPtr<SynthFSInode> SynthFS::create_text_file(String&& name, ByteBuffer&& contents, mode_t mode)
+Retained<SynthFSInode> SynthFS::create_text_file(String&& name, ByteBuffer&& contents, mode_t mode)
 {
 {
     auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
     auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
     file->m_data = contents;
     file->m_data = contents;
@@ -59,7 +59,7 @@ RetainPtr<SynthFSInode> SynthFS::create_text_file(String&& name, ByteBuffer&& co
     return file;
     return file;
 }
 }
 
 
-RetainPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&& generator, mode_t mode)
+Retained<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&& generator, mode_t mode)
 {
 {
     auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
     auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
     file->m_generator = move(generator);
     file->m_generator = move(generator);
@@ -72,7 +72,7 @@ RetainPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<B
     return file;
     return file;
 }
 }
 
 
-RetainPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&& read_callback, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&& write_callback, mode_t mode)
+Retained<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&& read_callback, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&& write_callback, mode_t mode)
 {
 {
     auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
     auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
     file->m_generator = move(read_callback);
     file->m_generator = move(read_callback);

+ 5 - 5
Kernel/SyntheticFileSystem.h

@@ -9,7 +9,7 @@ class SynthFSInode;
 class SynthFS : public FS {
 class SynthFS : public FS {
 public:
 public:
     virtual ~SynthFS() override;
     virtual ~SynthFS() override;
-    static RetainPtr<SynthFS> create();
+    static Retained<SynthFS> create();
 
 
     virtual bool initialize() override;
     virtual bool initialize() override;
     virtual const char* class_name() const override;
     virtual const char* class_name() const override;
@@ -26,10 +26,10 @@ protected:
 
 
     SynthFS();
     SynthFS();
 
 
-    RetainPtr<SynthFSInode> create_directory(String&& name);
-    RetainPtr<SynthFSInode> create_text_file(String&& name, ByteBuffer&&, mode_t = 0010644);
-    RetainPtr<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, mode_t = 0100644);
-    RetainPtr<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&&, mode_t = 0100644);
+    Retained<SynthFSInode> create_directory(String&& name);
+    Retained<SynthFSInode> create_text_file(String&& name, ByteBuffer&&, mode_t = 0010644);
+    Retained<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, mode_t = 0100644);
+    Retained<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&&, mode_t = 0100644);
 
 
     InodeIdentifier add_file(RetainPtr<SynthFSInode>&&, InodeIndex parent = RootInodeIndex);
     InodeIdentifier add_file(RetainPtr<SynthFSInode>&&, InodeIndex parent = RootInodeIndex);
     bool remove_file(InodeIndex);
     bool remove_file(InodeIndex);

+ 1 - 1
Kernel/init.cpp

@@ -149,7 +149,7 @@ VFS* vfs;
 
 
     new BXVGADevice;
     new BXVGADevice;
 
 
-    auto new_procfs = ProcFS::create();
+    Retained<ProcFS> new_procfs = ProcFS::create();
     new_procfs->initialize();
     new_procfs->initialize();
 
 
     auto devptsfs = DevPtsFS::create();
     auto devptsfs = DevPtsFS::create();

+ 4 - 4
LibGUI/GAction.h

@@ -3,20 +3,20 @@
 #include <AK/AKString.h>
 #include <AK/AKString.h>
 #include <AK/Function.h>
 #include <AK/Function.h>
 #include <AK/Retainable.h>
 #include <AK/Retainable.h>
-#include <AK/RetainPtr.h>
+#include <AK/Retained.h>
 #include <SharedGraphics/GraphicsBitmap.h>
 #include <SharedGraphics/GraphicsBitmap.h>
 
 
 class GAction : public Retainable<GAction> {
 class GAction : public Retainable<GAction> {
 public:
 public:
-    static RetainPtr<GAction> create(const String& text, Function<void(const GAction&)> callback)
+    static Retained<GAction> create(const String& text, Function<void(const GAction&)> callback)
     {
     {
         return adopt(*new GAction(text, move(callback)));
         return adopt(*new GAction(text, move(callback)));
     }
     }
-    static RetainPtr<GAction> create(const String& text, const String& custom_data, Function<void(const GAction&)> callback)
+    static Retained<GAction> create(const String& text, const String& custom_data, Function<void(const GAction&)> callback)
     {
     {
         return adopt(*new GAction(text, custom_data, move(callback)));
         return adopt(*new GAction(text, custom_data, move(callback)));
     }
     }
-    static RetainPtr<GAction> create(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> callback)
+    static Retained<GAction> create(const String& text, RetainPtr<GraphicsBitmap>&& icon, Function<void(const GAction&)> callback)
     {
     {
         return adopt(*new GAction(text, move(icon), move(callback)));
         return adopt(*new GAction(text, move(icon), move(callback)));
     }
     }

+ 1 - 2
LibGUI/GToolBar.cpp

@@ -18,9 +18,8 @@ GToolBar::~GToolBar()
 {
 {
 }
 }
 
 
-void GToolBar::add_action(RetainPtr<GAction>&& action)
+void GToolBar::add_action(Retained<GAction>&& action)
 {
 {
-    ASSERT(action);
     GAction* raw_action_ptr = action.ptr();
     GAction* raw_action_ptr = action.ptr();
     auto item = make<Item>();
     auto item = make<Item>();
     item->type = Item::Action;
     item->type = Item::Action;

+ 1 - 1
LibGUI/GToolBar.h

@@ -9,7 +9,7 @@ public:
     explicit GToolBar(GWidget* parent);
     explicit GToolBar(GWidget* parent);
     virtual ~GToolBar() override;
     virtual ~GToolBar() override;
 
 
-    void add_action(RetainPtr<GAction>&&);
+    void add_action(Retained<GAction>&&);
     void add_separator();
     void add_separator();
 
 
 private:
 private:

+ 2 - 2
SharedGraphics/GraphicsBitmap.cpp

@@ -5,7 +5,7 @@
 #include <errno.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
-RetainPtr<GraphicsBitmap> GraphicsBitmap::create(Format format, const Size& size)
+Retained<GraphicsBitmap> GraphicsBitmap::create(Format format, const Size& size)
 {
 {
     return adopt(*new GraphicsBitmap(format, size));
     return adopt(*new GraphicsBitmap(format, size));
 }
 }
@@ -22,7 +22,7 @@ GraphicsBitmap::GraphicsBitmap(Format format, const Size& size)
     m_mmaped = true;
     m_mmaped = true;
 }
 }
 
 
-RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(Format format, const Size& size, RGBA32* data)
+Retained<GraphicsBitmap> GraphicsBitmap::create_wrapper(Format format, const Size& size, RGBA32* data)
 {
 {
     return adopt(*new GraphicsBitmap(format, size, data));
     return adopt(*new GraphicsBitmap(format, size, data));
 }
 }

+ 2 - 2
SharedGraphics/GraphicsBitmap.h

@@ -11,8 +11,8 @@ class GraphicsBitmap : public Retainable<GraphicsBitmap> {
 public:
 public:
     enum class Format { Invalid, RGB32, RGBA32 };
     enum class Format { Invalid, RGB32, RGBA32 };
 
 
-    static RetainPtr<GraphicsBitmap> create(Format, const Size&);
-    static RetainPtr<GraphicsBitmap> create_wrapper(Format, const Size&, RGBA32*);
+    static Retained<GraphicsBitmap> create(Format, const Size&);
+    static Retained<GraphicsBitmap> create_wrapper(Format, const Size&, RGBA32*);
     static RetainPtr<GraphicsBitmap> load_from_file(Format, const String& path, const Size&);
     static RetainPtr<GraphicsBitmap> load_from_file(Format, const String& path, const Size&);
     static RetainPtr<GraphicsBitmap> create_with_shared_buffer(Format, int shared_buffer_id, const Size&, RGBA32* buffer = nullptr);
     static RetainPtr<GraphicsBitmap> create_with_shared_buffer(Format, int shared_buffer_id, const Size&, RGBA32* buffer = nullptr);
     ~GraphicsBitmap();
     ~GraphicsBitmap();