A cross-platform and safe Rust API to create and manage memory mappings in the virtual address space of the calling process.

Overview

mmap-rs

Crates.io Docs

A cross-platform and safe Rust API to create and manage memory mappings in the virtual address space of the calling process. This crate can be used to create both file mappings and anonymous mappings. In addition, this crate supports the use of features such as huge pages, locking physical memory, etc. on platforms where those features are available.

Features

  • Anonymous memory maps.
  • File-backed memory maps (unsafe - see documentation for details).
  • Copy-on-write vs. shared memory maps.
  • Inaccessible memory maps (using PROT_NONE and PAGE_NOACCESS).
  • Read-only memory maps.
  • Read-write memory maps.
  • Executable memory maps.
  • RWX memory maps for JIT purposes (unsafe - see documentation for details).
  • Portable instruction cache flushing.
  • Synchronous and asynchronous flushing.
  • Support for locking physical memory.
  • Huge page support.
  • Stack support (also known as MAP_STACK on Unix).
  • Support to exclude memory maps from core dumps (on Unix only).
You might also like...
An attempt to implement equivalent of C++ "P1478R1: Byte-wise atomic memcpy" in Rust

atomic-memcpy Byte-wise atomic memcpy. This is an attempt to implement equivalent of C++ "P1478R1: Byte-wise atomic memcpy" in Rust. This is expected

rust mappings for Friktion's volt program

Friktion (volt) ABI Overview Provides contexts and instruction functions to interact with Friktion Program via CPI calls Friktion program ID: VoLT1mJz

Create virtual serial ports, connect them to physical serial ports, and create routes between them all.

Virtual Serial Port Router (vsp-router) Create virtual serial ports, connect them to physical serial ports, and create routes between them all. vsp-ro

secmem-proc is a crate designed to harden a process against low-privileged attackers running on the same system trying to obtain secret memory contents of the current process.

secmem-proc is a crate designed to harden a process against low-privileged attackers running on the same system trying to obtain secret memory contents of the current process. More specifically, the crate disables core dumps and tries to disable tracing on unix-like OSes.

Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.
Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Cross-platform tool to update DNS such as Gandi.net with your dynamic IP address

GDU | Generic DNS Update A cross-platform tool to update DNS zonefiles (such as Gandi.net) when you have a dynamic public IP address. It's a DynDNS or

Cross-platform, cross-browser, cross-search-engine duckduckgo-like bangs

localbang Cross-platform, cross-browser, cross-search-engine duckduckgo-like bangs What are "bangs"?? Bangs are a way to define where to search inside

Safe Unix shell-like parameter expansion/variable substitution via cross-platform CLI or Rust API
Safe Unix shell-like parameter expansion/variable substitution via cross-platform CLI or Rust API

Safe Unix shell-like parameter expansion/variable substitution for those who need a more powerful alternative to envsubst but don't want to resort to

A cross-platform, user-space WireGuard port-forwarder that requires no system network configurations.

Cross-platform, user-space WireGuard port-forwarder that requires no system network configurations.

An opinionated, monolithic template for Bevy with cross-platform CI/CD, native + WASM launchers, and managed cross-platform deployment.
An opinionated, monolithic template for Bevy with cross-platform CI/CD, native + WASM launchers, and managed cross-platform deployment.

🕊️ Bevy Shell - Template An opinionated, monolithic template for Bevy with cross-platform CI/CD, native + WASM launchers, and managed cross-platform

Spacedrive is an open source cross-platform file explorer, powered by a virtual distributed filesystem written in Rust.
Spacedrive is an open source cross-platform file explorer, powered by a virtual distributed filesystem written in Rust.

Spacedrive A file explorer from the future. spacedrive.com » Download for macOS · Windows · Linux · iOS · watchOS · Android ~ Links will be added once

A cross-platform graphical process/system monitor with a customizable interface and a multitude of features
A cross-platform graphical process/system monitor with a customizable interface and a multitude of features

A cross-platform graphical process/system monitor with a customizable interface and a multitude of features. Supports Linux, macOS, and Windows. Inspired by both gtop and gotop.

⏱ Cross-platform Prometheus style process metrics collector of metrics crate

⏱ metrics-process This crate provides Prometheus style process metrics collector of metrics crate for Linux, macOS, and Windows. Collector code is man

Calling the JVM from Rust via JNI

Rucaja (Rust calls Java) Calling JVM code from Rust via JNI. Usage JNI calls are about 10-20 times slower than regular JVM instructions. It is adviced

Calling Quantlib C++ functionalities inside Rust using CxxBridge.

Quantlib on Rust An example of calling Quantlib C++ functionalities inside Rust using CxxBridge. Usage Clone the repository with --recurse-submodules:

Full tutorial on coding AI function calling in Rust programming by [Jeremy Chone](https://youtube.com/jeremychone)

Full tutorial on coding AI function calling in Rust programming by Jeremy Chone. We will be using the OpenAI API, but similar approaches can be applie

Is the GIL seeing someone else? How's about repetitively calling and seeing how long it takes to answer?

GIL Knocker pip install gilknocker When you thought the GIL was available, and you find yourself suspecting it might be spending time with another. Yo

A simple cross-process locking API

A simple cross-process locking API

Crate for calling NT System Calls easily

ntcall-rs Easily call NT System Calls from rust. All System Call ID’s are dumped at compile-time. To get started just import the function you would li

Comments
  • areas example uses imports that are not available

    areas example uses imports that are not available

    Trying to use the imports shown in the areas example:

    use mmap_rs::{Error, MemoryMaps, Protection, ShareMode};
    

    Shows errors for all imports:

    • enum Error is private
    • unresolved imports: mmap_rs::MemoryMaps, mmap_rs::Protection, mmap_rs::ShareMode
    opened by Anton-4 2
  • Compilation of 0.3.0 seems to be broken on macOS

    Compilation of 0.3.0 seems to be broken on macOS

    It seems that version 0.3.0, currently released on crates.io, is broken:

       Compiling mmap-rs v0.3.0
    error[E0599]: no associated item named `MAP_JIT` found for struct `UnsafeMmapFlags` in the current scope
       --> /Users/antek/.cargo/registry/src/github.com-1ecc6299db9ec823/mmap-rs-0.3.0/src/os_impl/unix.rs:293:56
        |
    293 |           if self.unsafe_flags.contains(UnsafeMmapFlags::MAP_JIT) {
        |                                                          ^^^^^^^ associated item not found in `UnsafeMmapFlags`
        |
       ::: /Users/antek/.cargo/registry/src/github.com-1ecc6299db9ec823/mmap-rs-0.3.0/src/lib.rs:18:1
        |
    18  | / bitflags! {
    19  | |     /// The available flags to configure the allocated mapping.
    20  | |     pub struct MmapFlags: u32 {
    21  | |         /// May initially map the pages as shared between multiple mappings, but creates a private
    ...   |
    76  | |     }
    77  | | }
        | |_- associated item `MAP_JIT` not found for this
    

    I can see that this issue has been already resolved (i.e. I'm able to compile the git version on macOS without problems), but do you have any plans of releasing the fixed version to crates.io?

    opened by antekone 1
  • impl of `Send` and `Sync`

    impl of `Send` and `Sync`

    In my use case I wanted to open a file based mmap in a dedicated IO thread and then send it over to another thread when the mapping was complete. I am unable to think of any reason why Send and Sync wouldn't be allowed for Mmap.

    My guess is that it's simply an oversight and the compiler's autotrait is wrong due to the raw pointer ptr only referring to a memory location accessible process wide which the compiler does not know. If that is the case unsafe impls should be added for Send and Sync in each of the os_impls.

    I'll create a PR for this in case you want to merge it.

    opened by TimLuq 0
  • does the crate stable and feature complete for use

    does the crate stable and feature complete for use

    Hi thank you for the good work for Mmaping stuff most of people just used memap2, and looks like its stable, but recently I came acros your crate and it seems a heck of lot more complete, but Im not sure if its stable to use?

    opened by Detector-I 1
Owner
S.J.R. van Schaik
S.J.R. van Schaik
MiniDump a process in memory with rust

safetydump Rust in-memory MiniDump implementation. Features ntdll!NtGetNextProcess to obtain a handle for the desired ProcessId as opposed to kernel32

null 26 Oct 11, 2022
Rust library to interract with memory written in rust

memory-rs Rust library to interract with memory written in rust It comes with: Pattern scanner (Return address for a pattern given). A pattern example

Alex 1 Jan 13, 2022
In-memory, non stateful and session based code sharing application.

interviewer In-memory, non stateful and session based code sharing application. Test it here: interviewer.taras.lol Note: it's deployed to render auto

2pac 7 Aug 16, 2021
memory-mapped registers for x86_64 systems

regmap some well-known and known-to-be-good computer architectures, such as the Microchip PIC product line, or many of the AVR processor family, were

iximeow 31 Dec 6, 2022
A comprehensive memory scanning library

scanflow boasts a feature set similar to the likes of CheatEngine, with a simple command line interface. Utilizing memflow, scanflow works in a wide range of situations - from virtual machines, to dedicated DMA hardware.

memflow 38 Dec 30, 2022
A memory efficient syntax tree for language developers

This crate provides a tree structure which always is contiguously stored and manipulated in memory. It provides similar APIs as rowan and is intended to be an efficient replacement for it (read more below).

John-John Tedro 21 Dec 15, 2022
bevy_datasize is a library for tracking memory usage in Bevy apps.

bevy_datasize bevy_datasize is a library for tracking memory usage in Bevy apps. bevy_datasize uses the DataSize trait from the datasize crate to esti

Ben Reeves 4 Mar 8, 2022
Compile-time checked Builder pattern derive macro with zero-memory overhead

Compile-time checked Builder pattern derive macro with zero-memory overhead This is very much a work-in-progress. PRs welcome to bring this to product

Esteban Kuber 214 Dec 29, 2022
Memory hacking library for windows

Memory hacking library for windows

Sara Wahib 4 Apr 11, 2022
Benchmarking manual implementation of memcpy in Rust

Manual memcpy Benchmark Benchmarks that compare copying data between two Vec<u8>s using std::slice::copy_from_slice and a loop that copies one byte at

Adam Bratschi-Kaye 0 Feb 2, 2022