mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
AK: Add Retained<T>, like RetainPtr, but never null.
Also use some Clang attribute wizardry to get a warning for use-after-move.
This commit is contained in:
parent
0b957ed2b1
commit
2cfcbdc735
Notes:
sideshowbarker
2024-07-19 15:38:07 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/2cfcbdc735e
31 changed files with 214 additions and 104 deletions
16
AK/Buffer.h
16
AK/Buffer.h
|
@ -11,10 +11,10 @@ namespace AK {
|
|||
template<typename T>
|
||||
class Buffer : public Retainable<Buffer<T>> {
|
||||
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(); }
|
||||
|
||||
|
@ -105,25 +105,25 @@ inline void Buffer<T>::grow(size_t size)
|
|||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -1,23 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "Types.h"
|
||||
#include <AK/Types.h>
|
||||
#include <AK/Retained.h>
|
||||
|
||||
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 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<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())) { }
|
||||
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()) { }
|
||||
|
@ -128,14 +116,7 @@ private:
|
|||
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::adopt;
|
||||
|
||||
|
|
123
AK/Retained.h
Normal file
123
AK/Retained.h
Normal file
|
@ -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;
|
|
@ -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 <typename T>
|
||||
T&& move(T& arg)
|
||||
{
|
||||
return static_cast<T&&>(arg);
|
||||
}
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
struct Identity {
|
||||
|
|
|
@ -11,7 +11,7 @@ DevPtsFS& DevPtsFS::the()
|
|||
return *s_the;
|
||||
}
|
||||
|
||||
RetainPtr<DevPtsFS> DevPtsFS::create()
|
||||
Retained<DevPtsFS> DevPtsFS::create()
|
||||
{
|
||||
return adopt(*new DevPtsFS);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ const char* DevPtsFS::class_name() const
|
|||
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()));
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ public:
|
|||
[[gnu::pure]] static DevPtsFS& the();
|
||||
|
||||
virtual ~DevPtsFS() override;
|
||||
static RetainPtr<DevPtsFS> create();
|
||||
static Retained<DevPtsFS> create();
|
||||
|
||||
virtual bool initialize() override;
|
||||
virtual const char* class_name() const override;
|
||||
|
@ -22,7 +22,7 @@ public:
|
|||
private:
|
||||
DevPtsFS();
|
||||
|
||||
RetainPtr<SynthFSInode> create_slave_pty_device_file(unsigned index);
|
||||
Retained<SynthFSInode> create_slave_pty_device_file(unsigned index);
|
||||
|
||||
HashTable<SlavePTY*> m_slave_ptys;
|
||||
};
|
||||
|
|
|
@ -44,10 +44,9 @@ Lockable<InlineLRUCache<BlockIdentifier, CachedBlock>>& block_cache()
|
|||
return *s_cache;
|
||||
}
|
||||
|
||||
DiskBackedFS::DiskBackedFS(RetainPtr<DiskDevice>&& device)
|
||||
DiskBackedFS::DiskBackedFS(Retained<DiskDevice>&& device)
|
||||
: m_device(move(device))
|
||||
{
|
||||
ASSERT(m_device);
|
||||
}
|
||||
|
||||
DiskBackedFS::~DiskBackedFS()
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
size_t block_size() const { return m_block_size; }
|
||||
|
||||
protected:
|
||||
explicit DiskBackedFS(RetainPtr<DiskDevice>&&);
|
||||
explicit DiskBackedFS(Retained<DiskDevice>&&);
|
||||
|
||||
void set_block_size(unsigned);
|
||||
|
||||
|
@ -25,5 +25,5 @@ protected:
|
|||
|
||||
private:
|
||||
size_t m_block_size { 0 };
|
||||
RetainPtr<DiskDevice> m_device;
|
||||
Retained<DiskDevice> m_device;
|
||||
};
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
|
||||
//#define EXT2_DEBUG
|
||||
|
||||
RetainPtr<Ext2FS> Ext2FS::create(RetainPtr<DiskDevice>&& device)
|
||||
Retained<Ext2FS> Ext2FS::create(Retained<DiskDevice>&& device)
|
||||
{
|
||||
return adopt(*new Ext2FS(move(device)));
|
||||
}
|
||||
|
||||
Ext2FS::Ext2FS(RetainPtr<DiskDevice>&& device)
|
||||
Ext2FS::Ext2FS(Retained<DiskDevice>&& device)
|
||||
: DiskBackedFS(move(device))
|
||||
, m_lock("Ext2FS")
|
||||
{
|
||||
|
|
|
@ -58,7 +58,7 @@ private:
|
|||
class Ext2FS final : public DiskBackedFS {
|
||||
friend class Ext2FSInode;
|
||||
public:
|
||||
static RetainPtr<Ext2FS> create(RetainPtr<DiskDevice>&&);
|
||||
static Retained <Ext2FS> create(Retained<DiskDevice>&&);
|
||||
virtual ~Ext2FS() override;
|
||||
virtual bool initialize() override;
|
||||
|
||||
|
@ -71,7 +71,7 @@ private:
|
|||
typedef unsigned BlockIndex;
|
||||
typedef unsigned GroupIndex;
|
||||
typedef unsigned InodeIndex;
|
||||
explicit Ext2FS(RetainPtr<DiskDevice>&&);
|
||||
explicit Ext2FS(Retained<DiskDevice>&&);
|
||||
|
||||
const ext2_super_block& super_block() const;
|
||||
const ext2_group_desc& group_descriptor(unsigned groupIndex) const;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
//#define FIFO_DEBUG
|
||||
|
||||
RetainPtr<FIFO> FIFO::create()
|
||||
Retained<FIFO> FIFO::create()
|
||||
{
|
||||
return adopt(*new FIFO);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ public:
|
|||
Neither, Reader, Writer
|
||||
};
|
||||
|
||||
static RetainPtr<FIFO> create();
|
||||
static Retained<FIFO> create();
|
||||
|
||||
void open(Direction);
|
||||
void close(Direction);
|
||||
|
|
|
@ -12,27 +12,27 @@
|
|||
#include <Kernel/BlockDevice.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)));
|
||||
}
|
||||
|
||||
RetainPtr<FileDescriptor> FileDescriptor::create(RetainPtr<Device>&& device)
|
||||
Retained<FileDescriptor> FileDescriptor::create(RetainPtr<Device>&& 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));
|
||||
}
|
||||
|
||||
RetainPtr<FileDescriptor> FileDescriptor::create_pipe_writer(FIFO& fifo)
|
||||
Retained<FileDescriptor> FileDescriptor::create_pipe_writer(FIFO& fifo)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ void FileDescriptor::set_socket_role(SocketRole role)
|
|||
m_socket->attach_fd(role);
|
||||
}
|
||||
|
||||
RetainPtr<FileDescriptor> FileDescriptor::clone()
|
||||
Retained<FileDescriptor> FileDescriptor::clone()
|
||||
{
|
||||
RetainPtr<FileDescriptor> descriptor;
|
||||
if (is_fifo()) {
|
||||
|
@ -98,12 +98,11 @@ RetainPtr<FileDescriptor> 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)
|
||||
|
|
|
@ -18,14 +18,14 @@ class CharacterDevice;
|
|||
class FileDescriptor : public Retainable<FileDescriptor> {
|
||||
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();
|
||||
|
||||
RetainPtr<FileDescriptor> clone();
|
||||
Retained<FileDescriptor> clone();
|
||||
|
||||
int close();
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ enum IDEStatus : byte {
|
|||
ERR = (1 << 0),
|
||||
};
|
||||
|
||||
RetainPtr<IDEDiskDevice> IDEDiskDevice::create()
|
||||
Retained<IDEDiskDevice> IDEDiskDevice::create()
|
||||
{
|
||||
return adopt(*new IDEDiskDevice);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
class IDEDiskDevice final : public IRQHandler, public DiskDevice {
|
||||
public:
|
||||
static RetainPtr<IDEDiskDevice> create();
|
||||
static Retained<IDEDiskDevice> create();
|
||||
virtual ~IDEDiskDevice() override;
|
||||
|
||||
// ^DiskDevice
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <Kernel/VirtualFileSystem.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
RetainPtr<LocalSocket> LocalSocket::create(int type)
|
||||
Retained<LocalSocket> LocalSocket::create(int type)
|
||||
{
|
||||
return adopt(*new LocalSocket(type));
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ class FileDescriptor;
|
|||
|
||||
class LocalSocket final : public Socket {
|
||||
public:
|
||||
static RetainPtr<LocalSocket> create(int type);
|
||||
static Retained<LocalSocket> create(int type);
|
||||
virtual ~LocalSocket() override;
|
||||
|
||||
virtual bool bind(const sockaddr*, socklen_t, int& error) override;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -667,14 +667,14 @@ Region::~Region()
|
|||
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));
|
||||
new (slot) PhysicalPage(paddr, supervisor);
|
||||
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));
|
||||
new (slot) PhysicalPage(paddr, supervisor, false);
|
||||
|
@ -702,23 +702,23 @@ void PhysicalPage::return_to_freelist()
|
|||
#endif
|
||||
}
|
||||
|
||||
RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode)
|
||||
Retained<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
if (inode->vmo())
|
||||
return static_cast<VMObject*>(inode->vmo());
|
||||
return *inode->vmo();
|
||||
auto vmo = adopt(*new VMObject(move(inode)));
|
||||
vmo->inode()->set_vmo(*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;
|
||||
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;
|
||||
auto vmo = adopt(*new VMObject(paddr, size));
|
||||
|
@ -726,7 +726,7 @@ RetainPtr<VMObject> VMObject::create_for_physical_range(PhysicalAddress paddr, s
|
|||
return vmo;
|
||||
}
|
||||
|
||||
RetainPtr<VMObject> VMObject::clone()
|
||||
Retained<VMObject> VMObject::clone()
|
||||
{
|
||||
return adopt(*new VMObject(*this));
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
@ -68,8 +68,8 @@ private:
|
|||
class PageDirectory : public Retainable<PageDirectory> {
|
||||
friend class MemoryManager;
|
||||
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();
|
||||
|
||||
dword cr3() const { return m_directory_page->paddr().get(); }
|
||||
|
@ -88,10 +88,10 @@ private:
|
|||
class VMObject : public Retainable<VMObject>, public Weakable<VMObject> {
|
||||
friend class MemoryManager;
|
||||
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();
|
||||
bool is_anonymous() const { return m_anonymous; }
|
||||
|
|
|
@ -166,7 +166,7 @@ ProcFS& ProcFS::the()
|
|||
return *s_the;
|
||||
}
|
||||
|
||||
RetainPtr<ProcFS> ProcFS::create()
|
||||
Retained<ProcFS> ProcFS::create()
|
||||
{
|
||||
return adopt(*new ProcFS);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
[[gnu::pure]] static ProcFS& the();
|
||||
|
||||
virtual ~ProcFS() override;
|
||||
static RetainPtr<ProcFS> create();
|
||||
static Retained<ProcFS> create();
|
||||
|
||||
virtual bool initialize() override;
|
||||
virtual const char* class_name() const override;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
//#define SYNTHFS_DEBUG
|
||||
|
||||
RetainPtr<SynthFS> SynthFS::create()
|
||||
Retained<SynthFS> SynthFS::create()
|
||||
{
|
||||
return adopt(*new SynthFS);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ bool SynthFS::initialize()
|
|||
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()));
|
||||
file->m_name = move(name);
|
||||
|
@ -46,7 +46,7 @@ RetainPtr<SynthFSInode> SynthFS::create_directory(String&& name)
|
|||
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()));
|
||||
file->m_data = contents;
|
||||
|
@ -59,7 +59,7 @@ RetainPtr<SynthFSInode> SynthFS::create_text_file(String&& name, ByteBuffer&& co
|
|||
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()));
|
||||
file->m_generator = move(generator);
|
||||
|
@ -72,7 +72,7 @@ RetainPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<B
|
|||
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()));
|
||||
file->m_generator = move(read_callback);
|
||||
|
|
|
@ -9,7 +9,7 @@ class SynthFSInode;
|
|||
class SynthFS : public FS {
|
||||
public:
|
||||
virtual ~SynthFS() override;
|
||||
static RetainPtr<SynthFS> create();
|
||||
static Retained<SynthFS> create();
|
||||
|
||||
virtual bool initialize() override;
|
||||
virtual const char* class_name() const override;
|
||||
|
@ -26,10 +26,10 @@ protected:
|
|||
|
||||
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);
|
||||
bool remove_file(InodeIndex);
|
||||
|
|
|
@ -149,7 +149,7 @@ VFS* vfs;
|
|||
|
||||
new BXVGADevice;
|
||||
|
||||
auto new_procfs = ProcFS::create();
|
||||
Retained<ProcFS> new_procfs = ProcFS::create();
|
||||
new_procfs->initialize();
|
||||
|
||||
auto devptsfs = DevPtsFS::create();
|
||||
|
|
|
@ -3,20 +3,20 @@
|
|||
#include <AK/AKString.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/Retainable.h>
|
||||
#include <AK/RetainPtr.h>
|
||||
#include <AK/Retained.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
|
||||
class GAction : public Retainable<GAction> {
|
||||
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)));
|
||||
}
|
||||
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)));
|
||||
}
|
||||
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)));
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
auto item = make<Item>();
|
||||
item->type = Item::Action;
|
||||
|
|
|
@ -9,7 +9,7 @@ public:
|
|||
explicit GToolBar(GWidget* parent);
|
||||
virtual ~GToolBar() override;
|
||||
|
||||
void add_action(RetainPtr<GAction>&&);
|
||||
void add_action(Retained<GAction>&&);
|
||||
void add_separator();
|
||||
|
||||
private:
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <errno.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));
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ GraphicsBitmap::GraphicsBitmap(Format format, const Size& size)
|
|||
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));
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ class GraphicsBitmap : public Retainable<GraphicsBitmap> {
|
|||
public:
|
||||
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> create_with_shared_buffer(Format, int shared_buffer_id, const Size&, RGBA32* buffer = nullptr);
|
||||
~GraphicsBitmap();
|
||||
|
|
Loading…
Reference in a new issue