-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
Hi!
Thanks for the project. I think it would help users if the README stated that the crate isn't currently suitable for production use. A few reasons:
- There are no real tests covering the crate's functionality on Windows, Linux, or FreeBSD in CI.
- I immediately encountered an issue on Windows where file changes aren't saved even with flush + sync_all.
- The FreeBSD implementation also has several issues for example:
Missing error and null check around kinfo_getvmmap.
Using libc::free without verifying entries_ptr.
Incorrect error handling of getpagesizes.
In fact, there are more issues if you look more thoroughly.
Code for Windows:
use mmap_rs::MmapOptions;
use std::error::Error;
use std::fs::OpenOptions;
use std::io::Read;
use std::path::Path;
fn main() -> Result<(), Box<dyn Error>> {
let path = Path::new("example.txt");
let file = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(&path)?;
file.set_len(4096)?;
let mmap_options = unsafe { MmapOptions::new(4096)?.with_file(&file, 0) };
let mut mmap = mmap_options.map_mut()?;
mmap[..10].copy_from_slice(b"hello mmap");
mmap.flush(0..10)?;
file.sync_all()?;
let written_data = &mmap[..10];
assert_eq!(written_data, b"hello mmap", "Data verification failed!");
println!(
"Successfully wrote and verified: {:?}",
std::str::from_utf8(written_data)?
);
let mut file_read = OpenOptions::new().read(true).open(&path)?;
let mut buffer = [0u8; 10];
file_read.read_exact(&mut buffer)?;
assert_eq!(&buffer, b"hello mmap", "File read verification failed!");
println!(
"File read verification: {:?}",
std::str::from_utf8(&buffer)?
);
Ok(())
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels