darfink / region-rs

A cross-platform virtual memory API written in Rust
https://darfink.github.io/region-rs/
MIT License
119 stars 23 forks source link

Why is LockGuard::release unsafe? #9

Closed HadrienG2 closed 4 years ago

HadrienG2 commented 4 years ago

Given that it's just a mem::forget under the hood, which is otherwise safe to call, and that AFAIK the typical operating system won't even mind if you don't unlock the memory and just do it for you at memory deallocation time, I do not get it.

darfink commented 4 years ago

That's a keen observation, and I concur.

When I first designed this library back in 2016, I was not aware of mem::forget and it's characteristics (it being safe), nor that destructors had no guarantee to be called. Using unsafe for the LockGuard::release was also a bit of a misnomer, since I assumed that leaving a page lock was not safe behavior per-se, but I forgot to take into account Rust's exact definition of safe code.

With that said, I will update the library by deprecating the following:

And completely remove these at a later date.

darfink commented 4 years ago

Fixed by https://github.com/darfink/region-rs/commit/c2f62b0542d90db9ce38892b28f52c803d38f31a