Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit e83c08b

Browse files
authored
Merge pull request #36 from rustwasm/no-mmap-alloc-crate
Use `libc::mmap` directly again, instead of `mmap-alloc` crate
2 parents 41d9171 + 7f4dc2e commit e83c08b

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

wee_alloc/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ unreachable = "1.0.0"
3232
default-features = false
3333
version = "0.2"
3434

35-
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies.mmap-alloc]
36-
version = "0.2"
37-
git = "https://github.com/fitzgen/allocators-rs"
38-
branch = "new-alloc-api"
39-
4035
[target.'cfg(target_os = "windows")'.dependencies.winapi]
4136
version = "0.3"
4237
features = ["memoryapi", "synchapi", "winbase"]

wee_alloc/src/imp_unix.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
use alloc::allocator::{Alloc, Layout};
21
use const_init::ConstInit;
32
use core::alloc::{AllocErr, Opaque};
43
use core::cell::UnsafeCell;
54
use core::ptr::NonNull;
65
use libc;
7-
use mmap_alloc::MapAllocBuilder;
86
use memory_units::{Bytes, Pages};
97

108
pub(crate) fn alloc_pages(pages: Pages) -> Result<NonNull<Opaque>, AllocErr> {
119
unsafe {
1210
let bytes: Bytes = pages.into();
13-
let layout = Layout::from_size_align_unchecked(bytes.0, 1);
14-
15-
MapAllocBuilder::default()
16-
.build()
17-
.alloc(layout)
11+
let addr = libc::mmap(
12+
0 as *mut _,
13+
bytes.0,
14+
libc::PROT_WRITE | libc::PROT_READ,
15+
libc::MAP_ANON | libc::MAP_PRIVATE,
16+
-1,
17+
0,
18+
);
19+
if addr == libc::MAP_FAILED {
20+
Err(AllocErr)
21+
} else {
22+
NonNull::new(addr as *mut Opaque).ok_or(AllocErr)
23+
}
1824
}
1925
}
2026

wee_alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ cfg_if! {
237237
use imp_wasm32 as imp;
238238
} else if #[cfg(unix)] {
239239
extern crate libc;
240-
extern crate mmap_alloc;
241240
mod imp_unix;
242241
use imp_unix as imp;
243242
} else if #[cfg(windows)] {

wee_alloc/src/neighbors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ where
5959

6060
#[test]
6161
fn can_use_low_bits() {
62+
use core::mem;
6263
assert!(
6364
mem::align_of::<*const u8>() >= 0b100,
6465
"we rely on being able to stick tags into the lowest two bits"

0 commit comments

Comments
 (0)