Skip to content

Commit bb3dce1

Browse files
Merge branch 'purpleprotocol:master' into fix-pr-106
2 parents 8f2a80c + 679b170 commit bb3dce1

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ jobs:
5050

5151
- name: Test libmimalloc-sys crate bindings (no secure)
5252
run: cargo run -p libmimalloc-sys-test
53+
54+
- name: Build (extended)
55+
run: cargo build --features extended
56+
57+
- name: Test (extended)
58+
run: cargo test --features extended
59+
60+
- name: Test libmimalloc-sys crate bindings (extended)
61+
run: cargo run --features extended -p libmimalloc-sys-test
5362

5463
lint:
5564
name: Rustfmt / Clippy

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ debug = ["libmimalloc-sys/debug"]
3131
debug_in_debug = ["libmimalloc-sys/debug_in_debug"]
3232
local_dynamic_tls = ["libmimalloc-sys/local_dynamic_tls"]
3333
no_thp = ["libmimalloc-sys/no_thp"]
34+
extended = ["libmimalloc-sys/extended"]

libmimalloc-sys/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn main() {
99

1010
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!");
1111
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").expect("target_family not defined!");
12+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("target_arch not defined!");
1213

1314
if env::var_os("CARGO_FEATURE_OVERRIDE").is_some() {
1415
// Overriding malloc is only available on windows in shared mode, but we
@@ -53,4 +54,9 @@ fn main() {
5354
}
5455

5556
build.compile("mimalloc");
57+
58+
// on armv6 we need to link with libatomic
59+
if target_os == "linux" && target_arch == "arm" {
60+
println!("cargo:rustc-link-lib=dylib=atomic");
61+
}
5662
}

src/extended.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::MiMalloc;
2+
3+
impl MiMalloc {
4+
/// Get the mimalloc version.
5+
///
6+
/// For mimalloc version 1.8.6, this will return 186.
7+
pub fn version(&self) -> u32 {
8+
unsafe { ffi::mi_version() as u32 }
9+
}
10+
}
11+
12+
#[cfg(test)]
13+
mod test {
14+
use super::*;
15+
16+
#[test]
17+
fn it_gets_version() {
18+
let version = MiMalloc.version();
19+
assert!(version != 0);
20+
}
21+
}

src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@
1313
//! static GLOBAL: MiMalloc = MiMalloc;
1414
//! ```
1515
//!
16-
//! ## Usage without secure mode
17-
//! By default this library builds mimalloc in secure mode. This means that
18-
//! heap allocations are encrypted, but this results in a 3% increase in overhead.
16+
//! ## Usage with secure mode
17+
//! Using secure mode adds guard pages,
18+
//! randomized allocation, encrypted free lists, etc. The performance penalty is usually
19+
//! around 10% according to [mimalloc's](https://github.com/microsoft/mimalloc)
20+
//! own benchmarks.
1921
//!
20-
//! To disable secure mode, in `Cargo.toml`:
22+
//! To enable secure mode, put in `Cargo.toml`:
2123
//! ```rust,ignore
2224
//! [dependencies]
23-
//! mimalloc = { version = "*", default-features = false }
25+
//! mimalloc = { version = "*", features = ["secure"] }
2426
//! ```
2527
2628
extern crate libmimalloc_sys as ffi;
2729

30+
#[cfg(feature = "extended")]
31+
mod extended;
32+
2833
use core::alloc::{GlobalAlloc, Layout};
2934
use core::ffi::c_void;
3035
use ffi::*;

0 commit comments

Comments
 (0)