From f15042522278afa67f50dba5181b2c7c04c446ae Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 3 Aug 2023 10:31:29 +0200 Subject: [PATCH] kernel: Create a new shared memory object if the old one was lost --- kernel/src/fs/devices/FramebufferDevice.cpp | 5 +++++ kernel/src/fs/tmpfs/Inode.cpp | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/kernel/src/fs/devices/FramebufferDevice.cpp b/kernel/src/fs/devices/FramebufferDevice.cpp index 3b82f095..39f19f44 100644 --- a/kernel/src/fs/devices/FramebufferDevice.cpp +++ b/kernel/src/fs/devices/FramebufferDevice.cpp @@ -39,6 +39,11 @@ Result FramebufferDevice::query_shared_memory(off_t offset, usize count) } auto* shm = g_shared_memory_map.try_get_ref(*m_shmid); + if (!shm) + { + m_shmid = {}; + return query_shared_memory(offset, count); + } if (shm->offset > offset) { TRY(shm->grow_backward(Framebuffer::ptr() + offset, (shm->offset - offset) / ARCH_PAGE_SIZE)); diff --git a/kernel/src/fs/tmpfs/Inode.cpp b/kernel/src/fs/tmpfs/Inode.cpp index 252054fa..08ec9df7 100644 --- a/kernel/src/fs/tmpfs/Inode.cpp +++ b/kernel/src/fs/tmpfs/Inode.cpp @@ -144,6 +144,12 @@ namespace TmpFS } auto* shm = g_shared_memory_map.try_get_ref(*m_shmid); + if (!shm) + { + m_shmid = {}; + return query_shared_memory(offset, count); + } + if (shm->offset > offset) { TRY(shm->grow_backward(m_data_buffer.data() + offset, (shm->offset - offset) / ARCH_PAGE_SIZE));