diff options
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/File.h | 1 | ||||
-rw-r--r-- | Kernel/FileSystem/FileDescription.cpp | 20 | ||||
-rw-r--r-- | Kernel/FileSystem/FileDescription.h | 5 | ||||
-rw-r--r-- | Kernel/FileSystem/SharedMemory.cpp | 97 | ||||
-rw-r--r-- | Kernel/FileSystem/SharedMemory.h | 43 |
5 files changed, 0 insertions, 166 deletions
diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h index 36d468f442..f21ffc2d60 100644 --- a/Kernel/FileSystem/File.h +++ b/Kernel/FileSystem/File.h @@ -63,7 +63,6 @@ public: virtual bool is_seekable() const { return false; } virtual bool is_inode() const { return false; } - virtual bool is_shared_memory() const { return false; } virtual bool is_fifo() const { return false; } virtual bool is_device() const { return false; } virtual bool is_tty() const { return false; } diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp index a17a6ee930..067941d09d 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/FileDescription.cpp @@ -6,7 +6,6 @@ #include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileSystem.h> #include <Kernel/FileSystem/InodeFile.h> -#include <Kernel/FileSystem/SharedMemory.h> #include <Kernel/Net/Socket.h> #include <Kernel/Process.h> #include <Kernel/TTY/MasterPTY.h> @@ -244,25 +243,6 @@ KResult FileDescription::truncate(off_t length) return m_file->truncate(length); } -bool FileDescription::is_shared_memory() const -{ - return m_file->is_shared_memory(); -} - -SharedMemory* FileDescription::shared_memory() -{ - if (!is_shared_memory()) - return nullptr; - return static_cast<SharedMemory*>(m_file.ptr()); -} - -const SharedMemory* FileDescription::shared_memory() const -{ - if (!is_shared_memory()) - return nullptr; - return static_cast<const SharedMemory*>(m_file.ptr()); -} - bool FileDescription::is_fifo() const { return m_file->is_fifo(); diff --git a/Kernel/FileSystem/FileDescription.h b/Kernel/FileSystem/FileDescription.h index 2879cdcfb6..29f144aee4 100644 --- a/Kernel/FileSystem/FileDescription.h +++ b/Kernel/FileSystem/FileDescription.h @@ -18,7 +18,6 @@ class MasterPTY; class Process; class Region; class CharacterDevice; -class SharedMemory; class FileDescription : public RefCounted<FileDescription> { public: @@ -87,10 +86,6 @@ public: FIFO::Direction fifo_direction() { return m_fifo_direction; } void set_fifo_direction(Badge<FIFO>, FIFO::Direction direction) { m_fifo_direction = direction; } - bool is_shared_memory() const; - SharedMemory* shared_memory(); - const SharedMemory* shared_memory() const; - Optional<KBuffer>& generator_cache() { return m_generator_cache; } void set_original_inode(Badge<VFS>, NonnullRefPtr<Inode>&& inode) { m_inode = move(inode); } diff --git a/Kernel/FileSystem/SharedMemory.cpp b/Kernel/FileSystem/SharedMemory.cpp deleted file mode 100644 index ad4b131939..0000000000 --- a/Kernel/FileSystem/SharedMemory.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include <AK/HashMap.h> -#include <Kernel/FileSystem/SharedMemory.h> -#include <Kernel/Lock.h> -#include <Kernel/Process.h> -#include <Kernel/VM/AnonymousVMObject.h> - -Lockable<HashMap<String, RefPtr<SharedMemory>>>& shared_memories() -{ - static Lockable<HashMap<String, RefPtr<SharedMemory>>>* map; - if (!map) - map = new Lockable<HashMap<String, RefPtr<SharedMemory>>>; - return *map; -} - -KResultOr<NonnullRefPtr<SharedMemory>> SharedMemory::open(const String& name, int flags, mode_t mode) -{ - UNUSED_PARAM(flags); - LOCKER(shared_memories().lock()); - auto it = shared_memories().resource().find(name); - if (it != shared_memories().resource().end()) { - auto shared_memory = it->value; - // FIXME: Improved access checking. - if (shared_memory->uid() != current->process().uid()) - return KResult(-EACCES); - return *shared_memory; - } - auto shared_memory = adopt(*new SharedMemory(name, current->process().uid(), current->process().gid(), mode)); - shared_memories().resource().set(name, shared_memory.ptr()); - return shared_memory; -} - -KResult SharedMemory::unlink(const String& name) -{ - LOCKER(shared_memories().lock()); - auto it = shared_memories().resource().find(name); - if (it == shared_memories().resource().end()) - return KResult(-ENOENT); - shared_memories().resource().remove(it); - return KSuccess; -} - -SharedMemory::SharedMemory(const String& name, uid_t uid, gid_t gid, mode_t mode) - : m_name(name) - , m_uid(uid) - , m_gid(gid) - , m_mode(mode) -{ -} - -SharedMemory::~SharedMemory() -{ -} - -KResult SharedMemory::truncate(int length) -{ - if (!length) { - m_vmobject = nullptr; - return KSuccess; - } - - if (!m_vmobject) { - m_vmobject = AnonymousVMObject::create_with_size(length); - return KSuccess; - } - - // FIXME: Support truncation. - ASSERT_NOT_REACHED(); - return KResult(-ENOTIMPL); -} - -String SharedMemory::absolute_path(const FileDescription&) const -{ - return String::format("shm:%u", this); -} - -int SharedMemory::read(FileDescription&, u8* buffer, int buffer_size) -{ - UNUSED_PARAM(buffer); - UNUSED_PARAM(buffer_size); - // FIXME: Implement. - ASSERT_NOT_REACHED(); -} - -int SharedMemory::write(FileDescription&, const u8* data, int data_size) -{ - UNUSED_PARAM(data); - UNUSED_PARAM(data_size); - // FIXME: Implement. - ASSERT_NOT_REACHED(); -} - -KResultOr<Region*> SharedMemory::mmap(Process& process, FileDescription&, VirtualAddress vaddr, size_t offset, size_t size, int prot) -{ - if (!vmobject()) - return KResult(-ENODEV); - return process.allocate_region_with_vmobject(vaddr, size, *vmobject(), offset, name(), prot); -} diff --git a/Kernel/FileSystem/SharedMemory.h b/Kernel/FileSystem/SharedMemory.h deleted file mode 100644 index f81c329695..0000000000 --- a/Kernel/FileSystem/SharedMemory.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include <AK/String.h> -#include <AK/RefPtr.h> -#include <AK/RefCounted.h> -#include <Kernel/FileSystem/File.h> -#include <Kernel/KResult.h> -#include <Kernel/UnixTypes.h> - -class AnonymousVMObject; - -class SharedMemory : public File { -public: - static KResultOr<NonnullRefPtr<SharedMemory>> open(const String& name, int flags, mode_t); - static KResult unlink(const String& name); - virtual ~SharedMemory() override; - - const String& name() const { return m_name; } - virtual KResult truncate(off_t) override; - AnonymousVMObject* vmobject() { return m_vmobject.ptr(); } - const AnonymousVMObject* vmobject() const { return m_vmobject.ptr(); } - uid_t uid() const { return m_uid; } - gid_t gid() const { return m_gid; } - -private: - // ^File - virtual bool can_read(const FileDescription&) const override { return true; } - virtual bool can_write(const FileDescription&) const override { return true; } - virtual int read(FileDescription&, u8*, int) override; - virtual int write(FileDescription&, const u8*, int) override; - virtual String absolute_path(const FileDescription&) const override; - virtual const char* class_name() const override { return "SharedMemory"; } - virtual bool is_shared_memory() const override { return true; } - virtual KResultOr<Region*> mmap(Process&, FileDescription&, VirtualAddress, size_t offset, size_t size, int prot) override; - - SharedMemory(const String& name, uid_t, gid_t, mode_t); - - String m_name; - uid_t m_uid { 0 }; - gid_t m_gid { 0 }; - mode_t m_mode { 0 }; - RefPtr<AnonymousVMObject> m_vmobject; -}; |