Skip to content

Commit

Permalink
handle case when we munlock 2 times the same page on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
radu committed Jun 23, 2024
1 parent 371d151 commit c0e445b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(warnings)]

use numpy::{PyArray1, PyArrayMethods};
use pyo3::buffer::PyBuffer;
use pyo3::prelude::*;
Expand Down Expand Up @@ -108,8 +109,13 @@ unsafe fn _mlock(ptr: *mut u8, len: usize) -> bool {

/// Calls the platform's underlying `munlock(2)` implementation.
unsafe fn _munlock(ptr: *mut u8, len: usize) -> bool {
println!("munlock len {len}");
memsec::munlock(ptr, len)
let r = memsec::munlock(ptr, len);
if r == false && cfg!(target_os = "windows") {
// On windows if we munlock 2 times on the same page we get an error.
// This can happen if we munlock 2 vars that are in the same page.
return true;
}
r
}

#[cfg(test)]
Expand Down

0 comments on commit c0e445b

Please sign in to comment.