StephanvanSchaik / mmap-rs

A cross-platform and safe Rust API to create and manage memory mappings in the virtual address space of the calling process.
Apache License 2.0
61 stars 17 forks source link

Implement from_raw and into_raw #14

Open StephanvanSchaik opened 1 year ago

StephanvanSchaik commented 1 year ago

This PR implements Mmap::into_raw() to turn an existing memory mapping object into a raw pointer and the size of the memory mapping. After calling this function the user is responsible for the memory previously managed by the memory mapping object.

In addition, this PR implements Mmap::from_raw() to create a memory mapping object from a raw pointer and a size. This is unsafe since the user can call this function more than once for the same raw pointer, which would result in a double-free. Furthermore, the current implementation does not check whether the memory mapping has the appropriate permissions, or whether it even exists.