Skip to content

Commit 1c49b34

Browse files
committed
Selectively disable interrupts in MM.
Also added an ASSERT_INTERRUPTS_DISABLED() macro.
1 parent 86a547d commit 1c49b34

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Kernel/MemoryManager.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void MemoryManager::initializePaging()
5858

5959
auto MemoryManager::ensurePTE(LinearAddress linearAddress) -> PageTableEntry
6060
{
61+
ASSERT_INTERRUPTS_DISABLED();
6162
dword pageDirectoryIndex = (linearAddress.get() >> 22) & 0x3ff;
6263
dword pageTableIndex = (linearAddress.get() >> 12) & 0x3ff;
6364

@@ -84,6 +85,7 @@ auto MemoryManager::ensurePTE(LinearAddress linearAddress) -> PageTableEntry
8485

8586
void MemoryManager::protectMap(LinearAddress linearAddress, size_t length)
8687
{
88+
InterruptDisabler disabler;
8789
// FIXME: ASSERT(linearAddress is 4KB aligned);
8890
for (dword offset = 0; offset < length; offset += 4096) {
8991
auto pteAddress = linearAddress.offset(offset);
@@ -98,6 +100,7 @@ void MemoryManager::protectMap(LinearAddress linearAddress, size_t length)
98100

99101
void MemoryManager::identityMap(LinearAddress linearAddress, size_t length)
100102
{
103+
InterruptDisabler disabler;
101104
// FIXME: ASSERT(linearAddress is 4KB aligned);
102105
for (dword offset = 0; offset < length; offset += 4096) {
103106
auto pteAddress = linearAddress.offset(offset);
@@ -117,6 +120,7 @@ void MemoryManager::initialize()
117120

118121
PageFaultResponse MemoryManager::handlePageFault(const PageFault& fault)
119122
{
123+
ASSERT_INTERRUPTS_DISABLED();
120124
kprintf("MM: handlePageFault(%w) at laddr=%p\n", fault.code(), fault.address().get());
121125
if (fault.isNotPresent()) {
122126
kprintf(" >> NP fault!\n");
@@ -138,6 +142,7 @@ RetainPtr<Zone> MemoryManager::createZone(size_t size)
138142

139143
Vector<PhysicalAddress> MemoryManager::allocatePhysicalPages(size_t count)
140144
{
145+
InterruptDisabler disabler;
141146
if (count > m_freePages.size())
142147
return { };
143148

@@ -150,6 +155,7 @@ Vector<PhysicalAddress> MemoryManager::allocatePhysicalPages(size_t count)
150155

151156
byte* MemoryManager::quickMapOnePage(PhysicalAddress physicalAddress)
152157
{
158+
ASSERT_INTERRUPTS_DISABLED();
153159
auto pte = ensurePTE(LinearAddress(4 * MB));
154160
kprintf("quickmap %x @ %x {pte @ %p}\n", physicalAddress.get(), 4*MB, pte.ptr());
155161
pte.setPhysicalPageBase(physicalAddress.pageBase());
@@ -174,6 +180,7 @@ void MemoryManager::flushTLB(LinearAddress laddr)
174180

175181
bool MemoryManager::unmapRegion(Task& task, Task::Region& region)
176182
{
183+
InterruptDisabler disabler;
177184
auto& zone = *region.zone;
178185
for (size_t i = 0; i < zone.m_pages.size(); ++i) {
179186
auto laddr = region.linearAddress.offset(i * PAGE_SIZE);
@@ -190,6 +197,7 @@ bool MemoryManager::unmapRegion(Task& task, Task::Region& region)
190197

191198
bool MemoryManager::unmapRegionsForTask(Task& task)
192199
{
200+
ASSERT_INTERRUPTS_DISABLED();
193201
for (auto& region : task.m_regions) {
194202
if (!unmapRegion(task, *region))
195203
return false;
@@ -199,6 +207,7 @@ bool MemoryManager::unmapRegionsForTask(Task& task)
199207

200208
bool MemoryManager::mapRegion(Task& task, Task::Region& region)
201209
{
210+
InterruptDisabler disabler;
202211
auto& zone = *region.zone;
203212
for (size_t i = 0; i < zone.m_pages.size(); ++i) {
204213
auto laddr = region.linearAddress.offset(i * PAGE_SIZE);
@@ -215,6 +224,7 @@ bool MemoryManager::mapRegion(Task& task, Task::Region& region)
215224

216225
bool MemoryManager::mapRegionsForTask(Task& task)
217226
{
227+
ASSERT_INTERRUPTS_DISABLED();
218228
for (auto& region : task.m_regions) {
219229
if (!mapRegion(task, *region))
220230
return false;
@@ -229,6 +239,7 @@ bool copyToZone(Zone& zone, const void* data, size_t size)
229239
return false;
230240
}
231241

242+
InterruptDisabler disabler;
232243
auto* dataptr = (const byte*)data;
233244
size_t remaining = size;
234245
for (size_t i = 0; i < zone.m_pages.size(); ++i) {

Kernel/kassert.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#pragma once
22

33
#include "kprintf.h"
4+
#include "i386.h"
45

56
#define CRASH() do { asm volatile("ud2"); } while(0)
67
#define ASSERT(x) do { if (!(x)) { asm volatile("cli"); kprintf("ASSERTION FAILED: " #x "\n%s:%u in %s\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); CRASH(); } } while(0)
78
#define RELEASE_ASSERT(x) do { if (!(x)) CRASH(); } while(0)
89
#define ASSERT_NOT_REACHED() ASSERT(false)
10+
#define ASSERT_INTERRUPTS_DISABLED() ASSERT(!(cpuFlags() & 0x200))

0 commit comments

Comments
 (0)