From ece9fcbaa8c65a03e2f5aca310783bae2b19bd87 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 22 Jan 2025 15:26:32 -0500 Subject: [PATCH] kernel/vm: Assert in VMCache::InsertPage() that the offset is within the cache. This would have caught the problem fixed in the previous commit. Also adjust the assertion in MovePage for correctness. --- src/system/kernel/vm/VMCache.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/system/kernel/vm/VMCache.cpp b/src/system/kernel/vm/VMCache.cpp index 436b4a998f..e091f45947 100644 --- a/src/system/kernel/vm/VMCache.cpp +++ b/src/system/kernel/vm/VMCache.cpp @@ -788,15 +788,16 @@ VMCache::InsertPage(vm_page* page, off_t offset) { TRACE(("VMCache::InsertPage(): cache %p, page %p, offset %" B_PRIdOFF "\n", this, page, offset)); + T2(InsertPage(this, page, offset)); + AssertLocked(); + ASSERT(offset >= virtual_base && offset <= virtual_end); if (page->CacheRef() != NULL) { panic("insert page %p into cache %p: page cache is set to %p\n", page, this, page->Cache()); } - T2(InsertPage(this, page, offset)); - page->cache_offset = (page_num_t)(offset >> PAGE_SHIFT); page_count++; page->SetCacheRef(fCacheRef); @@ -854,7 +855,7 @@ VMCache::MovePage(vm_page* page, off_t offset) AssertLocked(); oldCache->AssertLocked(); - ASSERT(offset >= virtual_base && (offset + B_PAGE_SIZE) <= virtual_end); + ASSERT(offset >= virtual_base && offset <= virtual_end); // remove from old cache oldCache->pages.Remove(page);