Skip to content

Not ready for production use? #46

@Deniskore

Description

@Deniskore

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:

  1. There are no real tests covering the crate's functionality on Windows, Linux, or FreeBSD in CI.
  2. I immediately encountered an issue on Windows where file changes aren't saved even with flush + sync_all.
  3. 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(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions