Kernel: Implement MAP_SHARED for regular files

Every inode holds a weak pointer to shared file data. This contains
physical addresses of pages for inode file data. Physical addresses
are allocated and read on demand.

When last shared mapping is unmapped. The inodes shared data is freed
and written to the inode.
This commit is contained in:
Bananymous
2023-09-29 18:46:44 +03:00
parent 8ff4e1f8c8
commit 43c23db4a6
4 changed files with 139 additions and 41 deletions

View File

@@ -3,6 +3,7 @@
#include <BAN/RefPtr.h>
#include <BAN/String.h>
#include <BAN/StringView.h>
#include <BAN/WeakPtr.h>
#include <BAN/Vector.h>
#include <kernel/API/DirectoryEntry.h>
@@ -17,6 +18,9 @@ namespace Kernel
using namespace API;
class FileBackedRegion;
class SharedFileData;
class Inode : public BAN::RefCounted<Inode>
{
public:
@@ -112,6 +116,9 @@ namespace Kernel
private:
mutable RecursiveSpinLock m_lock;
BAN::WeakPtr<SharedFileData> m_shared_region;
friend class FileBackedRegion;
};
}

View File

@@ -6,6 +6,17 @@
namespace Kernel
{
struct SharedFileData : public BAN::RefCounted<SharedFileData>, public BAN::Weakable<SharedFileData>
{
~SharedFileData();
// FIXME: this should probably be ordered tree like map
// for fast lookup and less memory usage
BAN::Vector<paddr_t> pages;
BAN::RefPtr<Inode> inode;
uint8_t page_buffer[PAGE_SIZE];
};
class FileBackedRegion final : public MemoryRegion
{
BAN_NON_COPYABLE(FileBackedRegion);
@@ -25,6 +36,8 @@ namespace Kernel
private:
BAN::RefPtr<Inode> m_inode;
const off_t m_offset;
BAN::RefPtr<SharedFileData> m_shared_data;
};
}