summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2020-01-02 12:44:21 +0100
committerAndreas Kling <awesomekling@gmail.com>2020-01-02 12:44:21 +0100
commit7f043346646e1dc88fca16b75914a9d4aa0efb56 (patch)
tree65b4d4a1c7c83a5dc92cce93d8fb1375a6ff216a /Kernel
parent4fa7146da1b8cdf211a5ca2cb38aeb29ef530694 (diff)
downloadserenity-7f043346646e1dc88fca16b75914a9d4aa0efb56.zip
Kernel: Remove broken implementation of Unix SHM
This code never worked, as was never used for anything. We can build a much better SHM implementation on top of TmpFS or similar when we get to the point when we need one.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/FileSystem/File.h1
-rw-r--r--Kernel/FileSystem/FileDescription.cpp20
-rw-r--r--Kernel/FileSystem/FileDescription.h5
-rw-r--r--Kernel/FileSystem/SharedMemory.cpp97
-rw-r--r--Kernel/FileSystem/SharedMemory.h43
-rw-r--r--Kernel/Makefile1
-rw-r--r--Kernel/Process.cpp23
-rw-r--r--Kernel/Process.h2
-rw-r--r--Kernel/Syscall.h4
9 files changed, 2 insertions, 194 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;
-};
diff --git a/Kernel/Makefile b/Kernel/Makefile
index 53fedf078f..f6a253e22c 100644
--- a/Kernel/Makefile
+++ b/Kernel/Makefile
@@ -50,7 +50,6 @@ OBJS = \
FileSystem/InodeFile.o \
FileSystem/InodeWatcher.o \
FileSystem/ProcFS.o \
- FileSystem/SharedMemory.o \
FileSystem/TmpFS.o \
FileSystem/VirtualFileSystem.o \
Heap/SlabAllocator.o \
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 521c210927..a644e81a32 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -17,7 +17,6 @@
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/InodeWatcher.h>
#include <Kernel/FileSystem/ProcFS.h>
-#include <Kernel/FileSystem/SharedMemory.h>
#include <Kernel/FileSystem/TmpFS.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/Heap/kmalloc.h>
@@ -3320,28 +3319,6 @@ int Process::sys$rename(const char* oldpath, const char* newpath)
return VFS::the().rename(StringView(oldpath), StringView(newpath), current_directory());
}
-int Process::sys$shm_open(const char* name, int flags, mode_t mode)
-{
- if (!validate_read_str(name))
- return -EFAULT;
- int fd = alloc_fd();
- if (fd < 0)
- return fd;
- auto shm_or_error = SharedMemory::open(String(name), flags, mode);
- if (shm_or_error.is_error())
- return shm_or_error.error();
- auto description = FileDescription::create(shm_or_error.value());
- m_fds[fd].set(move(description), FD_CLOEXEC);
- return fd;
-}
-
-int Process::sys$shm_unlink(const char* name)
-{
- if (!validate_read_str(name))
- return -EFAULT;
- return SharedMemory::unlink(String(name));
-}
-
int Process::sys$ftruncate(int fd, off_t length)
{
auto* description = file_description(fd);
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 1bf6923c52..55811c4e44 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -108,8 +108,6 @@ public:
int sys$dump_backtrace();
int sys$gettid();
int sys$donate(int tid);
- int sys$shm_open(const char* name, int flags, mode_t);
- int sys$shm_unlink(const char* name);
int sys$ftruncate(int fd, off_t);
pid_t sys$setsid();
pid_t sys$getsid(pid_t);
diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h
index 58942d1d31..1aa340160b 100644
--- a/Kernel/Syscall.h
+++ b/Kernel/Syscall.h
@@ -107,8 +107,8 @@ typedef u32 socklen_t;
__ENUMERATE_SYSCALL(gettid) \
__ENUMERATE_SYSCALL(donate) \
__ENUMERATE_SYSCALL(rename) \
- __ENUMERATE_SYSCALL(shm_open) \
- __ENUMERATE_SYSCALL(shm_unlink) \
+ __ENUMERATE_REMOVED_SYSCALL(shm_open) \
+ __ENUMERATE_REMOVED_SYSCALL(shm_unlink) \
__ENUMERATE_SYSCALL(ftruncate) \
__ENUMERATE_SYSCALL(systrace) \
__ENUMERATE_SYSCALL(exit_thread) \