Additional assertions on parameters
This commit is contained in:
parent
fc7f80af2d
commit
6f0e5b6b00
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -1,5 +1,3 @@
|
|||||||
[submodule "dynamic-memory-api-0"]
|
[submodule "dynamic-memory-api-0"]
|
||||||
path = dynamic-memory-api-0
|
path = dynamic-memory-api-0
|
||||||
url = https://git.landgrafhomyak.ru/MemoryManagement/dynamic-memory-api-0.git
|
url = https://git.landgrafhomyak.ru/MemoryManagement/dynamic-memory-api-0.rs.git
|
||||||
[submodule ".\\dynamic-memory-api-0\\"]
|
|
||||||
url = https://git.landgrafhomyak.ru/MemoryManagement/dynamic-memory-api-0.rs
|
|
||||||
|
|||||||
18
src/api.rs
18
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);
|
let mut current = self.totalReservationsOwned.load(Ordering::Relaxed);
|
||||||
loop {
|
loop {
|
||||||
let updated = current.strict_add_signed(diff);
|
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;
|
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 {
|
unsafe impl VirtualMemoryApi for WindowsVirtualMemoryApi {
|
||||||
@ -49,7 +55,8 @@ unsafe impl VirtualMemoryApi for WindowsVirtualMemoryApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn reserveMemory<'s>(&'s self, pagesCount: usize) -> Option<Self::Reservation<'s>> {
|
fn reserveMemory<'s>(&'s self, pagesCount: usize) -> Option<Self::Reservation<'s>> {
|
||||||
match WindowsReservation::tryReserve(self, None, self.roundUpPages(pagesCount)) {
|
self._assertPagesCount(pagesCount);
|
||||||
|
match WindowsReservation::tryReserve(self, None, self._roundUpPages(pagesCount)) {
|
||||||
ExtendResult::OutOfMemory => return None,
|
ExtendResult::OutOfMemory => return None,
|
||||||
ExtendResult::ContinuationIsBusy => {
|
ExtendResult::ContinuationIsBusy => {
|
||||||
panic!("Unreachable (system reported that region is busy, but it wasn't specified)")
|
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>(
|
unsafe fn extendReservation<'s>(
|
||||||
&'s self,
|
&'s self,
|
||||||
base: &Self::Reservation<'s>,
|
base: &Self::Reservation<'s>,
|
||||||
pagesCount: usize,
|
extraPagesCount: usize,
|
||||||
) -> ExtendResult<WindowsReservation<'s>> {
|
) -> ExtendResult<WindowsReservation<'s>> {
|
||||||
return WindowsReservation::tryReserve(self, Some(base), self.roundUpPages(pagesCount));
|
self._assertPagesCount(extraPagesCount);
|
||||||
|
return WindowsReservation::tryReserve(self, Some(base), self._roundUpPages(extraPagesCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,7 @@ impl<'s> WindowsReservation<'s> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
owner.changeReservationsCount(1);
|
owner._changeReservationsCount(1);
|
||||||
|
|
||||||
let reservation = WindowsReservation {
|
let reservation = WindowsReservation {
|
||||||
owner: owner,
|
owner: owner,
|
||||||
@ -69,7 +69,7 @@ impl<'s> WindowsReservation<'s> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn _release(&mut self) {
|
unsafe fn _release(&mut self) {
|
||||||
self.owner.changeReservationsCount(-1);
|
self.owner._changeReservationsCount(-1);
|
||||||
winapi_wrappers::release(self.start);
|
winapi_wrappers::release(self.start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user