Skip to content

Commit f0e1978

Browse files
simongdaviesNunoDasNeves
authored andcommitted
mshv:ioctls munmap register page
Make sure that the register page is unmapped when the vcpu object is dropped Signed-off-by: Simon Davies <[email protected]>
1 parent 0985748 commit f0e1978

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

mshv-ioctls/src/ioctls/vcpu.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,17 @@ impl VcpuFd {
17721772
}
17731773
}
17741774

1775+
impl Drop for VcpuFd {
1776+
fn drop(&mut self) {
1777+
if let Some(vp_page) = &self.vp_page {
1778+
// SAFETY: because we ensured vp_page is valid in create_vcpu.
1779+
unsafe {
1780+
let _ = libc::munmap(vp_page.0 as *mut libc::c_void, HV_PAGE_SIZE);
1781+
}
1782+
}
1783+
}
1784+
}
1785+
17751786
#[allow(dead_code)]
17761787
#[cfg(test)]
17771788
mod tests {

0 commit comments

Comments
 (0)