diff --git a/.gitmodules b/.gitmodules index 32846bc..fce6e5e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,3 @@ [submodule "dynamic-memory-api-0"] path = dynamic-memory-api-0 - url = https://git.landgrafhomyak.ru/MemoryManagement/dynamic-memory-api-0.git -[submodule ".\\dynamic-memory-api-0\\"] - url = https://git.landgrafhomyak.ru/MemoryManagement/dynamic-memory-api-0.rs + url = https://git.landgrafhomyak.ru/MemoryManagement/dynamic-memory-api-0.rs.git diff --git a/src/api.rs b/src/api.rs index b5bc9c2..5befbce 100644 --- a/src/api.rs +++ b/src/api.rs @@ -20,7 +20,7 @@ impl WindowsVirtualMemoryApi { }; } - pub(super) fn changeReservationsCount(&self, diff: isize) { + pub(crate) fn _changeReservationsCount(&self, diff: isize) { let mut current = self.totalReservationsOwned.load(Ordering::Relaxed); loop { let updated = current.strict_add_signed(diff); @@ -36,9 +36,15 @@ impl WindowsVirtualMemoryApi { } } - fn roundUpPages(&self, pagesCount: usize) -> usize { + fn _roundUpPages(&self, pagesCount: usize) -> usize { return (pagesCount * self.pageSize + (self.allocationGranularity - 1)) / self.pageSize; } + + fn _assertPagesCount(&self, pagesCount: usize) { + if pagesCount == 0 { + panic!("Can't reserve zero pages"); + } + } } unsafe impl VirtualMemoryApi for WindowsVirtualMemoryApi { @@ -49,7 +55,8 @@ unsafe impl VirtualMemoryApi for WindowsVirtualMemoryApi { } fn reserveMemory<'s>(&'s self, pagesCount: usize) -> Option> { - match WindowsReservation::tryReserve(self, None, self.roundUpPages(pagesCount)) { + self._assertPagesCount(pagesCount); + match WindowsReservation::tryReserve(self, None, self._roundUpPages(pagesCount)) { ExtendResult::OutOfMemory => return None, ExtendResult::ContinuationIsBusy => { panic!("Unreachable (system reported that region is busy, but it wasn't specified)") @@ -61,9 +68,10 @@ unsafe impl VirtualMemoryApi for WindowsVirtualMemoryApi { unsafe fn extendReservation<'s>( &'s self, base: &Self::Reservation<'s>, - pagesCount: usize, + extraPagesCount: usize, ) -> ExtendResult> { - return WindowsReservation::tryReserve(self, Some(base), self.roundUpPages(pagesCount)); + self._assertPagesCount(extraPagesCount); + return WindowsReservation::tryReserve(self, Some(base), self._roundUpPages(extraPagesCount)); } } diff --git a/src/reservation.rs b/src/reservation.rs index 5c694be..4a5b90d 100644 --- a/src/reservation.rs +++ b/src/reservation.rs @@ -35,7 +35,7 @@ impl<'s> WindowsReservation<'s> { } } - owner.changeReservationsCount(1); + owner._changeReservationsCount(1); let reservation = WindowsReservation { owner: owner, @@ -69,7 +69,7 @@ impl<'s> WindowsReservation<'s> { } unsafe fn _release(&mut self) { - self.owner.changeReservationsCount(-1); + self.owner._changeReservationsCount(-1); winapi_wrappers::release(self.start); } }