
* Fixes to main * Add librasan * Party like it's 2024 * Fix snapshot module to work with guest asan * Fix guest_asan module * Fixes to runner * Fix linking issues using a REL * Fix qemu_launcher * Change modify_mapping to a method * Fix gasan_test * Remove debug from Justfile * Optimize release build of librasan * Set ulimit for qasan and gasan tests * Tidy up symbol renaming * Add missing symbols for PPC * Change to support rustix 1.0.0 * Canonicalize the CUSTOM_ASAN_PATH * Review changes * Restructure backends * release_max_level_info * More review changes * Clippy fixes * Changes to reduce the burden on the CI * Fix macos clippy --------- Co-authored-by: Your Name <you@example.com>
68 lines
1.9 KiB
Rust
68 lines
1.9 KiB
Rust
#[cfg(test)]
|
|
#[cfg(all(feature = "linux", feature = "dlmalloc"))]
|
|
mod tests {
|
|
|
|
use asan::{
|
|
allocator::{
|
|
backend::dlmalloc::DlmallocBackend,
|
|
frontend::{AllocatorFrontend, default::DefaultFrontend},
|
|
},
|
|
mmap::linux::LinuxMmap,
|
|
shadow::{
|
|
Shadow,
|
|
guest::{DefaultShadowLayout, GuestShadow},
|
|
},
|
|
tracking::guest::GuestTracking,
|
|
};
|
|
use spin::{Lazy, Mutex, MutexGuard};
|
|
|
|
const PAGE_SIZE: usize = 4096;
|
|
|
|
static INIT_ONCE: Lazy<Mutex<DF>> = Lazy::new(|| {
|
|
Mutex::new({
|
|
env_logger::init();
|
|
let backend = DlmallocBackend::<LinuxMmap>::new(PAGE_SIZE);
|
|
let shadow = GuestShadow::<LinuxMmap, DefaultShadowLayout>::new().unwrap();
|
|
let tracking = GuestTracking::new().unwrap();
|
|
DF::new(
|
|
backend,
|
|
shadow,
|
|
tracking,
|
|
DF::DEFAULT_REDZONE_SIZE,
|
|
DF::DEFAULT_QUARANTINE_SIZE,
|
|
)
|
|
.unwrap()
|
|
})
|
|
});
|
|
|
|
type DF = DefaultFrontend<
|
|
DlmallocBackend<LinuxMmap>,
|
|
GuestShadow<LinuxMmap, DefaultShadowLayout>,
|
|
GuestTracking,
|
|
>;
|
|
|
|
fn frontend() -> MutexGuard<'static, DF> {
|
|
INIT_ONCE.lock()
|
|
}
|
|
|
|
#[test]
|
|
fn test_allocate() {
|
|
let mut frontend = frontend();
|
|
let buf = frontend.alloc(16, 8).unwrap();
|
|
frontend.dealloc(buf).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn test_allocate_is_poisoned() {
|
|
let mut frontend = frontend();
|
|
let len = 16;
|
|
let buf = frontend.alloc(len, 8).unwrap();
|
|
for i in buf - DF::DEFAULT_REDZONE_SIZE..buf + len + DF::DEFAULT_REDZONE_SIZE {
|
|
let expected = i < buf || i >= buf + len;
|
|
let poisoned = frontend.shadow().is_poison(i, 1).unwrap();
|
|
assert_eq!(expected, poisoned);
|
|
}
|
|
frontend.dealloc(buf).unwrap();
|
|
}
|
|
}
|