Skip to content

Commit

Permalink
mmap-alloc: Improve tests for permissions, fix realloc bugs
Browse files Browse the repository at this point in the history
- Add the ability to verify memory permissions by parsing
  /proc/<pid>/maps on Linux and using the VirtualQuery
  function on Windows
- Remove checks for allocation at the 0 page, as it turns
  out that these are unnecessary on all platforms that we
  support (Linux, Mac, Windows)
- Change the way boolean configuration functions work for
  MapAllocBuilder (instead of xxx() and no_xxx(), we now
  supply a single xxx(xxx: bool) method that accepts a
  boolean indicating whether the configuration should be
  on or off)
- Fix bugs in realloc tests on Windows
- Move tests module into separate file
- Remove test-no-std feature

Closes #83
Closes #72 and #80 by making them unnecessary since this commit
removes the use cases for mark_unused and alloc_helper
  • Loading branch information
joshlf committed Sep 26, 2017
1 parent d2613a4 commit 900dae1
Show file tree
Hide file tree
Showing 7 changed files with 1,030 additions and 662 deletions.
6 changes: 3 additions & 3 deletions elfmalloc/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod mmap {
pub fn fallible_map(size: usize) -> Option<*mut u8> {
unsafe {
if let Ok(s) = MapAllocBuilder::default()
.exec()
.exec(true)
.build()
.alloc(Layout::from_size_align(size, 1).unwrap()) {
Some(s)
Expand All @@ -38,13 +38,13 @@ pub mod mmap {
}

pub unsafe fn unmap(p: *mut u8, len: usize) {
MapAllocBuilder::default().exec().build().dealloc(
MapAllocBuilder::default().exec(true).build().dealloc(
p,
Layout::from_size_align(len, 1).unwrap(),
)
}
pub unsafe fn uncommit(p: *mut u8, len: usize) {
MapAllocBuilder::default().exec().build().uncommit(
MapAllocBuilder::default().exec(true).build().uncommit(
p,
Layout::from_size_align(len, 1).unwrap(),
)
Expand Down
17 changes: 15 additions & 2 deletions mmap-alloc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `commit` and `uncommit` methods on Windows
- Added the ability to configure whether `alloc` commits memory
- Added documentation about instruction cache incoherency
- Added support for full Alloc API (`shrink_in_place`, `grow_in_place`, `realloc`)
- In Linux, these functions can use `mremap` to grow/shrink beyond the size of a the pagesize
- Added support for full Alloc API (`shrink_in_place`, `grow_in_place`,
`realloc`)
- In Linux, these functions can use `mremap` to grow/shrink beyond the size
of a the pagesize
- Added tests for memory permissions on Linux (by parsing `/proc/<pid>/maps`)
and Windows (by using the `VirtualQuery` function)

### Removed
- Removed `commit` method on on Linux and Mac
- Removed tests for `mmap`s at NULL on Linux and Mac, as it turns out they are
guaranteed not to happen
- Removed `test-no-std` feature

### Changed
- Changed the way boolean configuration methods on `MapAllocBuilder` work
(previously, for each configuration option, there was a pair of methods to
enable and disable that option; now, there's a single method that accepts a
boolean indicating whether the option should be enabled)

### Fixed
- Fixed a bug that prevented compilation on 32-bit Windows
Expand Down
4 changes: 0 additions & 4 deletions mmap-alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ repository = "https://github.com/ezrosent/allocators-rs/tree/master/mmap-alloc"

exclude = ["travis.sh"]

[features]
# By default, test builds are not no_std. This feature makes test builds no_std.
test-no-std = []

[dependencies]
errno = "0.2"
kernel32-sys = "0.2"
Expand Down
2 changes: 2 additions & 0 deletions mmap-alloc/appveyor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if [ "$RUST_NIGHTLY" != "1" ]; then
exit 0
fi

export RUST_TEST_THREADS=1

cargo build
RUST_BACKTRACE=1 cargo test
for feature in test-no-std; do
Expand Down
Loading

0 comments on commit 900dae1

Please sign in to comment.