mimalloc-0.1.44/.cargo_vcs_info.json0000644000000001360000000000100127170ustar { "git": { "sha1": "bbf61305ad2d9d1c4b417bd277e36caec31d21b7" }, "path_in_vcs": "" }mimalloc-0.1.44/.github/workflows/ci.yml000064400000000000000000000050061046102023000162230ustar 00000000000000name: CI on: push: pull_request: # Run daily to catch when Rust updates cause problems to happen. schedule: - cron: '00 01 * * *' jobs: rust: name: Rust strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] toolchain: ["stable"] runs-on: ${{ matrix.os }} env: CARGO_INCREMENTAL: 0 RUST_BACKTRACE: 1 steps: - name: Checkout repository uses: actions/checkout@v4 with: submodules: recursive - name: Install Rust toolchain uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.toolchain }} - name: Build (secure) run: cargo build --features secure - name: Test (secure) run: cargo test --features secure - name: Test libmimalloc-sys crate bindings (secure) run: cargo run --features secure -p libmimalloc-sys-test - name: Build (no secure) run: cargo build - name: Test (no secure) run: cargo test - name: Test libmimalloc-sys crate bindings (no secure) run: cargo run -p libmimalloc-sys-test - name: Build (extended) run: cargo build --features extended - name: Test (extended) run: cargo test --features extended - name: Test libmimalloc-sys crate bindings (extended) run: cargo run --features extended -p libmimalloc-sys-test lint: name: Rustfmt / Clippy runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: submodules: recursive - uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy - name: Fmt run: cargo fmt --all -- --check - name: Clippy run: cargo clippy --workspace -- -D warnings # Detect cases where documentation links would be dead doc: name: Check documentation runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: submodules: recursive - uses: dtolnay/rust-toolchain@nightly # Note: We need to use nightly rust, and `cargo rustdoc` (yes, not `cargo # doc`) to actually get it to respect -D warnings... Using nightly also # gets us the nicer syntax for linking to functions, and is in-line with # what docs.rs uses. - name: 'Check documentation links in `mimalloc`' run: cargo rustdoc -- -D warnings - name: 'Check documentation links in `libmimalloc-sys`' run: cargo rustdoc -p libmimalloc-sys -- -D warnings mimalloc-0.1.44/.gitignore000064400000000000000000000000471046102023000135000ustar 00000000000000/target **/*.rs.bk Cargo.lock .DS_Storemimalloc-0.1.44/.gitmodules000064400000000000000000000002011046102023000136550ustar 00000000000000[submodule "libmimalloc-sys/c_src/mimalloc"] path = libmimalloc-sys/c_src/mimalloc url = https://github.com/microsoft/mimalloc mimalloc-0.1.44/Cargo.lock0000644000000023010000000000100106660ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 4 [[package]] name = "cc" version = "1.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c" dependencies = [ "shlex", ] [[package]] name = "cty" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" [[package]] name = "libc" version = "0.2.171" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" [[package]] name = "libmimalloc-sys" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07d0e07885d6a754b9c7993f2625187ad694ee985d60f23355ff0e7077261502" dependencies = [ "cc", "cty", "libc", ] [[package]] name = "mimalloc" version = "0.1.44" dependencies = [ "libmimalloc-sys", ] [[package]] name = "shlex" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" mimalloc-0.1.44/Cargo.toml0000644000000031170000000000100107170ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "mimalloc" version = "0.1.44" authors = [ "Octavian Oncescu ", "Vincent Rouillé ", "Thom Chiovoloni ", ] build = false autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "Performance and security oriented drop-in allocator" readme = "README.md" keywords = [ "mimalloc", "allocator", "encrypted-heap", "performance", ] categories = [ "memory-management", "api-bindings", ] license = "MIT" repository = "https://github.com/purpleprotocol/mimalloc_rust" [lib] name = "mimalloc" path = "src/lib.rs" [dependencies.libmimalloc-sys] version = "0.1.40" default-features = false [features] debug = ["libmimalloc-sys/debug"] debug_in_debug = ["libmimalloc-sys/debug_in_debug"] default = [] extended = ["libmimalloc-sys/extended"] local_dynamic_tls = ["libmimalloc-sys/local_dynamic_tls"] no_thp = ["libmimalloc-sys/no_thp"] override = ["libmimalloc-sys/override"] secure = ["libmimalloc-sys/secure"] [badges.travis-ci] repository = "purpleprotocol/mimalloc_rust" mimalloc-0.1.44/Cargo.toml.orig000064400000000000000000000020651046102023000144010ustar 00000000000000[package] name = "mimalloc" version = "0.1.44" authors = [ "Octavian Oncescu ", "Vincent Rouillé ", "Thom Chiovoloni ", ] edition = "2018" repository = "https://github.com/purpleprotocol/mimalloc_rust" keywords = ["mimalloc", "allocator", "encrypted-heap", "performance"] categories = ["memory-management", "api-bindings"] description = "Performance and security oriented drop-in allocator" license = "MIT" readme = "README.md" [workspace] members = ["libmimalloc-sys", "libmimalloc-sys/sys-test"] [badges] travis-ci = { repository = "purpleprotocol/mimalloc_rust" } [dependencies] libmimalloc-sys = { path = "libmimalloc-sys", version = "0.1.40", default-features = false } [features] default = [] secure = ["libmimalloc-sys/secure"] override = ["libmimalloc-sys/override"] debug = ["libmimalloc-sys/debug"] debug_in_debug = ["libmimalloc-sys/debug_in_debug"] local_dynamic_tls = ["libmimalloc-sys/local_dynamic_tls"] no_thp = ["libmimalloc-sys/no_thp"] extended = ["libmimalloc-sys/extended"] mimalloc-0.1.44/LICENSE.txt000064400000000000000000000020371046102023000133340ustar 00000000000000Copyright 2019 Octavian Oncescu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.mimalloc-0.1.44/README.md000064400000000000000000000020361046102023000127670ustar 00000000000000# Mimalloc Rust [![Latest Version]][crates.io] [![Documentation]][docs.rs] A drop-in global allocator wrapper around the [mimalloc](https://github.com/microsoft/mimalloc) allocator. Mimalloc is a general purpose, performance oriented allocator built by Microsoft. ## Usage ```rust use mimalloc::MiMalloc; #[global_allocator] static GLOBAL: MiMalloc = MiMalloc; ``` ## Requirements A __C__ compiler is required for building [mimalloc](https://github.com/microsoft/mimalloc) with cargo. ## Usage with secure mode Using secure mode adds guard pages, randomized allocation, encrypted free lists, etc. The performance penalty is usually around 10% according to [mimalloc](https://github.com/microsoft/mimalloc) own benchmarks. To enable secure mode, put in `Cargo.toml`: ```ini [dependencies] mimalloc = { version = "*", features = ["secure"] } ``` [crates.io]: https://crates.io/crates/mimalloc [Latest Version]: https://img.shields.io/crates/v/mimalloc.svg [Documentation]: https://docs.rs/mimalloc/badge.svg [docs.rs]: https://docs.rs/mimalloc mimalloc-0.1.44/src/extended.rs000064400000000000000000000021541046102023000144460ustar 00000000000000use crate::MiMalloc; use core::ffi::c_void; impl MiMalloc { /// Get the mimalloc version. /// /// For mimalloc version 1.8.6, this will return 186. pub fn version(&self) -> u32 { unsafe { ffi::mi_version() as u32 } } /// Return the amount of available bytes in a memory block. /// /// # Safety /// `ptr` must point to a memory block allocated by mimalloc, or be null. #[inline] pub unsafe fn usable_size(&self, ptr: *const u8) -> usize { ffi::mi_usable_size(ptr as *const c_void) } } #[cfg(test)] mod test { use super::*; use core::alloc::GlobalAlloc; use core::alloc::Layout; #[test] fn it_gets_version() { let version = MiMalloc.version(); assert!(version != 0); } #[test] fn it_checks_usable_size() { unsafe { let layout = Layout::from_size_align(8, 8).unwrap(); let alloc = MiMalloc; let ptr = alloc.alloc(layout); let usable_size = alloc.usable_size(ptr); alloc.dealloc(ptr, layout); assert!(usable_size >= 8); } } } mimalloc-0.1.44/src/lib.rs000064400000000000000000000070551046102023000134210ustar 00000000000000// Copyright 2019 Octavian Oncescu #![no_std] //! A drop-in global allocator wrapper around the [mimalloc](https://github.com/microsoft/mimalloc) allocator. //! Mimalloc is a general purpose, performance oriented allocator built by Microsoft. //! //! ## Usage //! ```rust,ignore //! use mimalloc::MiMalloc; //! //! #[global_allocator] //! static GLOBAL: MiMalloc = MiMalloc; //! ``` //! //! ## Usage with secure mode //! Using secure mode adds guard pages, //! randomized allocation, encrypted free lists, etc. The performance penalty is usually //! around 10% according to [mimalloc's](https://github.com/microsoft/mimalloc) //! own benchmarks. //! //! To enable secure mode, put in `Cargo.toml`: //! ```rust,ignore //! [dependencies] //! mimalloc = { version = "*", features = ["secure"] } //! ``` extern crate libmimalloc_sys as ffi; #[cfg(feature = "extended")] mod extended; use core::alloc::{GlobalAlloc, Layout}; use core::ffi::c_void; use ffi::*; /// Drop-in mimalloc global allocator. /// /// ## Usage /// ```rust,ignore /// use mimalloc::MiMalloc; /// /// #[global_allocator] /// static GLOBAL: MiMalloc = MiMalloc; /// ``` pub struct MiMalloc; unsafe impl GlobalAlloc for MiMalloc { #[inline] unsafe fn alloc(&self, layout: Layout) -> *mut u8 { mi_malloc_aligned(layout.size(), layout.align()) as *mut u8 } #[inline] unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { mi_zalloc_aligned(layout.size(), layout.align()) as *mut u8 } #[inline] unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { mi_free(ptr as *mut c_void); } #[inline] unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { mi_realloc_aligned(ptr as *mut c_void, new_size, layout.align()) as *mut u8 } } #[cfg(test)] mod tests { use super::*; #[test] fn it_frees_allocated_memory() { unsafe { let layout = Layout::from_size_align(8, 8).unwrap(); let alloc = MiMalloc; let ptr = alloc.alloc(layout); alloc.dealloc(ptr, layout); } } #[test] fn it_frees_allocated_big_memory() { unsafe { let layout = Layout::from_size_align(1 << 20, 32).unwrap(); let alloc = MiMalloc; let ptr = alloc.alloc(layout); alloc.dealloc(ptr, layout); } } #[test] fn it_frees_zero_allocated_memory() { unsafe { let layout = Layout::from_size_align(8, 8).unwrap(); let alloc = MiMalloc; let ptr = alloc.alloc_zeroed(layout); alloc.dealloc(ptr, layout); } } #[test] fn it_frees_zero_allocated_big_memory() { unsafe { let layout = Layout::from_size_align(1 << 20, 32).unwrap(); let alloc = MiMalloc; let ptr = alloc.alloc_zeroed(layout); alloc.dealloc(ptr, layout); } } #[test] fn it_frees_reallocated_memory() { unsafe { let layout = Layout::from_size_align(8, 8).unwrap(); let alloc = MiMalloc; let ptr = alloc.alloc(layout); let ptr = alloc.realloc(ptr, layout, 16); alloc.dealloc(ptr, layout); } } #[test] fn it_frees_reallocated_big_memory() { unsafe { let layout = Layout::from_size_align(1 << 20, 32).unwrap(); let alloc = MiMalloc; let ptr = alloc.alloc(layout); let ptr = alloc.realloc(ptr, layout, 2 << 20); alloc.dealloc(ptr, layout); } } }