3 unstable releases

0.2.1 Aug 16, 2021
0.2.0 Aug 31, 2020
0.1.0 Aug 31, 2020

#3 in #mmap

Download history 984/week @ 2021-10-03 1020/week @ 2021-10-10 2098/week @ 2021-10-17 1040/week @ 2021-10-24 591/week @ 2021-10-31 357/week @ 2021-11-07 218/week @ 2021-11-14 842/week @ 2021-11-21 365/week @ 2021-11-28 897/week @ 2021-12-05 1436/week @ 2021-12-12 528/week @ 2021-12-19 71/week @ 2021-12-26 405/week @ 2022-01-02 443/week @ 2022-01-09 1079/week @ 2022-01-16

2,000 downloads per month
Used in 3 crates

Apache-2.0

22KB
402 lines

Workflow Status Average time to resolve an issue Percentage of issues still open Maintenance

mmarinus

The mmarinus crate wraps the underlying system mmap() call in safe semantics.

For example:

use mmarinus::{Kind, Map, perms};

let mut zero = std::fs::File::open("/dev/zero").unwrap();

let map = Map::map(32)
    .near(128 * 1024 * 1024)
    .from(&mut zero, 0)
    .known::<perms::Read>(Kind::Private)
    .unwrap();

assert_eq!(&*map, &[0; 32]);

You can also remap an existing mapping:

use mmarinus::{Kind, Map, perms};

let mut zero = std::fs::File::open("/dev/zero").unwrap();

let mut map = Map::map(32)
    .anywhere()
    .from(&mut zero, 0)
    .known::<perms::Read>(Kind::Private)
    .unwrap();

assert_eq!(&*map, &[0; 32]);

let mut map = map.remap()
    .from(&mut zero, 0)
    .known::<perms::ReadWrite>(Kind::Private)
    .unwrap();

assert_eq!(&*map, &[0; 32]);
for i in map.iter_mut() {
    *i = 255;
}
assert_eq!(&*map, &[255; 32]);

Alternatively, you can just change the permissions:

use mmarinus::{Kind, Map, perms};

let mut zero = std::fs::File::open("/dev/zero").unwrap();

let mut map = Map::map(32)
    .at(128 * 1024 * 1024)
    .from(&mut zero, 0)
    .known::<perms::Read>(Kind::Private)
    .unwrap();

assert_eq!(&*map, &[0; 32]);

let mut map = map.reprotect::<perms::ReadWrite>().unwrap();

assert_eq!(&*map, &[0; 32]);
for i in map.iter_mut() {
    *i = 255;
}
assert_eq!(&*map, &[255; 32]);

Mapping a whole file into memory is easy:

use mmarinus::{Kind, perms};

let map = Kind::Private.load::<perms::Read, _>("/etc/os-release").unwrap();

License: Apache-2.0

Dependencies

a