Skip to content

Commit

Permalink
Kernel: Pass 'prot' argument to File::mmap() and act on it.
Browse files Browse the repository at this point in the history
Nothing crazy, this just means that PROT_READ allocates readable regions,
and that PROT_WRITE allocates writable ones.
  • Loading branch information
awesomekling committed May 30, 2019
1 parent 004a630 commit 66c1a9b
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions Kernel/Devices/BXVGADevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ dword BXVGADevice::find_framebuffer_address()
return framebuffer_address;
}

KResultOr<Region*> BXVGADevice::mmap(Process& process, LinearAddress preferred_laddr, size_t offset, size_t size)
KResultOr<Region*> BXVGADevice::mmap(Process& process, LinearAddress preferred_laddr, size_t offset, size_t size, int prot)
{
ASSERT(offset == 0);
ASSERT(size == framebuffer_size_in_bytes());
Expand All @@ -95,7 +95,9 @@ KResultOr<Region*> BXVGADevice::mmap(Process& process, LinearAddress preferred_l
move(vmo),
0,
"BXVGA Framebuffer",
true, true);
prot & PROT_READ,
prot & PROT_WRITE
);
kprintf("BXVGA: %s(%u) created Region{%p} with size %u for framebuffer P%x with laddr L%x\n",
process.name().characters(), process.pid(),
region, region->size(), framebuffer_address().as_ptr(), region->laddr().get());
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/BXVGADevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BXVGADevice final : public BlockDevice {
void set_y_offset(int);

virtual int ioctl(FileDescriptor&, unsigned request, unsigned arg) override;
virtual KResultOr<Region*> mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t) override;
virtual KResultOr<Region*> mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t, int prot) override;

size_t framebuffer_size_in_bytes() const { return m_framebuffer_size.area() * sizeof(dword) * 2; }
Size framebuffer_size() const { return m_framebuffer_size; }
Expand Down
2 changes: 1 addition & 1 deletion Kernel/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int File::ioctl(FileDescriptor&, unsigned, unsigned)
return -ENOTTY;
}

KResultOr<Region*> File::mmap(Process&, LinearAddress, size_t, size_t)
KResultOr<Region*> File::mmap(Process&, LinearAddress, size_t, size_t, int)
{
return KResult(-ENODEV);
}
Expand Down
2 changes: 1 addition & 1 deletion Kernel/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class File : public Retainable<File> {
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) = 0;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) = 0;
virtual int ioctl(FileDescriptor&, unsigned request, unsigned arg);
virtual KResultOr<Region*> mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t size);
virtual KResultOr<Region*> mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t size, int prot);

virtual String absolute_path(FileDescriptor&) const = 0;

Expand Down
2 changes: 1 addition & 1 deletion Kernel/FileSystem/FileDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ InodeMetadata FileDescriptor::metadata() const
KResultOr<Region*> FileDescriptor::mmap(Process& process, LinearAddress laddr, size_t offset, size_t size, int prot)
{
if (m_file)
return m_file->mmap(process, laddr, offset, size);
return m_file->mmap(process, laddr, offset, size, prot);

if (!is_fsfile())
return KResult(-ENODEV);
Expand Down
4 changes: 2 additions & 2 deletions Kernel/SharedMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ int SharedMemory::write(FileDescriptor&, const byte* data, int data_size)
ASSERT_NOT_REACHED();
}

KResultOr<Region*> SharedMemory::mmap(Process& process, LinearAddress laddr, size_t offset, size_t size)
KResultOr<Region*> SharedMemory::mmap(Process& process, LinearAddress laddr, size_t offset, size_t size, int prot)
{
if (!vmo())
return KResult(-ENODEV);
return process.allocate_region_with_vmo(laddr, size, *vmo(), offset, name(), true, true);
return process.allocate_region_with_vmo(laddr, size, *vmo(), offset, name(), prot & PROT_READ, prot & PROT_WRITE);
}
2 changes: 1 addition & 1 deletion Kernel/SharedMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SharedMemory : public File {
virtual String absolute_path(FileDescriptor&) 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&, LinearAddress, size_t offset, size_t size) override;
virtual KResultOr<Region*> mmap(Process&, LinearAddress, size_t offset, size_t size, int prot) override;

SharedMemory(const String& name, uid_t, gid_t, mode_t);

Expand Down

0 comments on commit 66c1a9b

Please sign in to comment.