mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 17:25:06 +00:00
Kernel+LibC: Add msync() system call
This allows userspace to trigger a full (FIXME) flush of a shared file mapping to disk. We iterate over all the mapped pages in the VMObject and write them out to the underlying inode, one by one. This is rather naive, and there's lots of room for improvement. Note that shared file mappings are currently not possible since mmap() returns ENOTSUP for PROT_WRITE+MAP_SHARED. That restriction will be removed in a subsequent commit. :^)
This commit is contained in:
parent
f2d5548d7a
commit
32aa37d5dc
8 changed files with 51 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/Locking/Spinlock.h>
|
||||
#include <Kernel/Memory/SharedInodeVMObject.h>
|
||||
|
||||
namespace Kernel::Memory {
|
||||
|
@ -34,4 +35,22 @@ SharedInodeVMObject::SharedInodeVMObject(SharedInodeVMObject const& other)
|
|||
{
|
||||
}
|
||||
|
||||
ErrorOr<void> SharedInodeVMObject::sync()
|
||||
{
|
||||
SpinlockLocker locker(m_lock);
|
||||
|
||||
for (size_t page_index = 0; page_index < page_count(); ++page_index) {
|
||||
auto& physical_page = m_physical_pages[page_index];
|
||||
if (!physical_page)
|
||||
continue;
|
||||
|
||||
u8 page_buffer[PAGE_SIZE];
|
||||
MM.copy_physical_page(*physical_page, page_buffer);
|
||||
|
||||
TRY(m_inode->write_bytes(page_index * PAGE_SIZE, PAGE_SIZE, UserOrKernelBuffer::for_kernel_buffer(page_buffer), nullptr));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue