summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorJean-Baptiste Boric <jblbeurope@gmail.com>2021-04-06 17:15:20 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-06 18:17:16 +0200
commit346e0f4dacfa0b8ad15b879bae7924cc060c1a1b (patch)
treeb8a29b5db0301d6c96952d6237c829ce7b1718bf /Kernel
parent436ca2491d9f8445e900282c62506ff3dedd106b (diff)
downloadserenity-346e0f4dacfa0b8ad15b879bae7924cc060c1a1b.zip
Kernel: Don't crash if unable to map ramdisk inside kernel address space
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Storage/RamdiskController.cpp5
-rw-r--r--Kernel/Storage/RamdiskDevice.cpp4
-rw-r--r--Kernel/Storage/RamdiskDevice.h6
3 files changed, 9 insertions, 6 deletions
diff --git a/Kernel/Storage/RamdiskController.cpp b/Kernel/Storage/RamdiskController.cpp
index 0ffe147364..e1b4ccc9e7 100644
--- a/Kernel/Storage/RamdiskController.cpp
+++ b/Kernel/Storage/RamdiskController.cpp
@@ -70,7 +70,10 @@ RamdiskController::RamdiskController()
if (used_memory_range.type == UsedMemoryRangeType::BootModule) {
size_t length = page_round_up(used_memory_range.end.get()) - used_memory_range.start.get();
auto region = MemoryManager::the().allocate_kernel_region(used_memory_range.start, length, "Ramdisk", Region::Access::Read | Region::Access::Write);
- m_devices.append(RamdiskDevice::create(*this, move(region), 6, count));
+ if (!region)
+ dmesgln("RamdiskController: Failed to allocate kernel region of size {}", length);
+ else
+ m_devices.append(RamdiskDevice::create(*this, region.release_nonnull(), 6, count));
count++;
}
}
diff --git a/Kernel/Storage/RamdiskDevice.cpp b/Kernel/Storage/RamdiskDevice.cpp
index 170acd4844..bdd0f85b1c 100644
--- a/Kernel/Storage/RamdiskDevice.cpp
+++ b/Kernel/Storage/RamdiskDevice.cpp
@@ -32,12 +32,12 @@
namespace Kernel {
-NonnullRefPtr<RamdiskDevice> RamdiskDevice::create(const RamdiskController& controller, OwnPtr<Region>&& region, int major, int minor)
+NonnullRefPtr<RamdiskDevice> RamdiskDevice::create(const RamdiskController& controller, NonnullOwnPtr<Region>&& region, int major, int minor)
{
return adopt(*new RamdiskDevice(controller, move(region), major, minor));
}
-RamdiskDevice::RamdiskDevice(const RamdiskController& controller, OwnPtr<Region>&& region, int major, int minor)
+RamdiskDevice::RamdiskDevice(const RamdiskController& controller, NonnullOwnPtr<Region>&& region, int major, int minor)
: StorageDevice(controller, major, minor, 512, region->size() / 512)
, m_region(move(region))
{
diff --git a/Kernel/Storage/RamdiskDevice.h b/Kernel/Storage/RamdiskDevice.h
index 9de4ad7748..f34b639d5d 100644
--- a/Kernel/Storage/RamdiskDevice.h
+++ b/Kernel/Storage/RamdiskDevice.h
@@ -37,8 +37,8 @@ class RamdiskDevice final : public StorageDevice {
friend class RamdiskController;
AK_MAKE_ETERNAL
public:
- static NonnullRefPtr<RamdiskDevice> create(const RamdiskController&, OwnPtr<Region>&& region, int major, int minor);
- RamdiskDevice(const RamdiskController&, OwnPtr<Region>&&, int major, int minor);
+ static NonnullRefPtr<RamdiskDevice> create(const RamdiskController&, NonnullOwnPtr<Region>&& region, int major, int minor);
+ RamdiskDevice(const RamdiskController&, NonnullOwnPtr<Region>&&, int major, int minor);
virtual ~RamdiskDevice() override;
// ^StorageDevice
@@ -55,7 +55,7 @@ public:
Lock m_lock { "RamdiskDevice" };
- OwnPtr<Region> m_region;
+ NonnullOwnPtr<Region> m_region;
};
}