mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03:00
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.
This commit is contained in:
parent
4fa7146da1
commit
7f04334664
Notes:
sideshowbarker
2024-07-19 10:25:55 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/7f043346646
@ -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; }
|
||||
|
@ -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();
|
||||
|
@ -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); }
|
||||
|
@ -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);
|
||||
}
|
@ -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;
|
||||
};
|
@ -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 \
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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) \
|
||||
|
@ -45,18 +45,6 @@ int set_mmap_name(void* addr, size_t size, const char* name)
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int shm_open(const char* name, int flags, mode_t mode)
|
||||
{
|
||||
int rc = syscall(SC_shm_open, name, flags, mode);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int shm_unlink(const char* name)
|
||||
{
|
||||
int rc = syscall(SC_shm_unlink, name);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int madvise(void* address, size_t size, int advice)
|
||||
{
|
||||
int rc = syscall(SC_madvise, address, size, advice);
|
||||
|
@ -29,8 +29,6 @@ void* mmap_with_name(void* addr, size_t, int prot, int flags, int fd, off_t, con
|
||||
int munmap(void*, size_t);
|
||||
int mprotect(void*, size_t, int prot);
|
||||
int set_mmap_name(void*, size_t, const char*);
|
||||
int shm_open(const char* name, int flags, mode_t);
|
||||
int shm_unlink(const char* name);
|
||||
int madvise(void*, size_t, int advice);
|
||||
|
||||
__END_DECLS
|
||||
|
Loading…
Reference in New Issue
Block a user