Kernel: Implement MAP_PRIVATE file mappings

mmap() now supports mapping files with MAP_PRIVATE.
This commit is contained in:
Bananymous
2023-09-29 17:23:42 +03:00
parent 4ee759aa3b
commit 7b1c573ad0
8 changed files with 202 additions and 15 deletions

View File

@@ -0,0 +1,30 @@
#pragma once
#include <kernel/FS/Inode.h>
#include <kernel/Memory/MemoryRegion.h>
namespace Kernel
{
class FileBackedRegion final : public MemoryRegion
{
BAN_NON_COPYABLE(FileBackedRegion);
BAN_NON_MOVABLE(FileBackedRegion);
public:
static BAN::ErrorOr<BAN::UniqPtr<FileBackedRegion>> create(BAN::RefPtr<Inode>, PageTable&, off_t offset, size_t size, AddressRange address_range, Type, PageTable::flags_t);
~FileBackedRegion();
virtual BAN::ErrorOr<bool> allocate_page_containing(vaddr_t vaddr) override;
virtual BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> clone(PageTable& new_page_table) override;
private:
FileBackedRegion(BAN::RefPtr<Inode>, PageTable&, off_t offset, ssize_t size, Type flags, PageTable::flags_t page_flags);
private:
BAN::RefPtr<Inode> m_inode;
const off_t m_offset;
};
}

View File

@@ -21,7 +21,7 @@ namespace Kernel
BAN_NON_MOVABLE(MemoryRegion);
public:
enum Type : uint8_t
enum class Type : uint8_t
{
PRIVATE,
SHARED

View File

@@ -48,6 +48,7 @@ namespace Kernel
BAN::ErrorOr<BAN::StringView> path_of(int) const;
BAN::ErrorOr<BAN::RefPtr<Inode>> inode_of(int);
BAN::ErrorOr<int> flags_of(int) const;
private:
struct OpenFileDescription : public BAN::RefCounted<OpenFileDescription>