diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index f62b205d32..75bbc80165 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -6261,15 +6261,6 @@ _user_set_memory_protection(void* _address, size_t size, uint32 protection) if ((area->protection & B_KERNEL_AREA) != 0) return B_NOT_ALLOWED; - AreaCacheLocker cacheLocker(area); - - if (wait_if_area_is_wired(area, &locker, &cacheLocker)) { - restart = true; - break; - } - - cacheLocker.Unlock(); - // TODO: For (shared) mapped files we should check whether the new // protections are compatible with the file permissions. We don't // have a way to do that yet, though. @@ -6277,6 +6268,16 @@ _user_set_memory_protection(void* _address, size_t size, uint32 protection) addr_t offset = currentAddress - area->Base(); size_t rangeSize = min_c(area->Size() - offset, sizeLeft); + AreaCacheLocker cacheLocker(area); + + if (wait_if_area_range_is_wired(area, currentAddress, rangeSize, + &locker, &cacheLocker)) { + restart = true; + break; + } + + cacheLocker.Unlock(); + currentAddress += rangeSize; sizeLeft -= rangeSize; }