Skip to content

Commit

Permalink
add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed May 6, 2024
1 parent b46d657 commit 25eaa96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ case $HOST_TARGET in
BASIC="$VERY_BASIC hello hashmap alloc align" # ensures we have the shims for stdout and basic data structures
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-misc libc-random libc-time fs env num_cpus
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-misc libc-random libc-time fs env num_cpus
MIRI_TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random
MIRI_TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random
MIRI_TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random alloc
MIRI_TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random alloc
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal $VERY_BASIC hello panic/panic
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal $VERY_BASIC wasm
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal $VERY_BASIC wasm
Expand Down
21 changes: 14 additions & 7 deletions src/shims/unix/solarish/foreign_items.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use rustc_target::abi::{Align, Size};
use rustc_target::spec::abi::Abi;

use crate::*;

Expand All @@ -21,17 +21,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
match link_name.as_str() {
// Allocation
"memalign" => {
let [align, size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let [align, size] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let align = this.read_target_usize(align)?;
let size = this.read_target_usize(size)?;

// memalign wants an alignment to be a power of 2
// and to be, at least, of word size.
// http://docs.oracle.com/cd/E88353_01/html/E37743/memalign-3c.html
if !align.is_power_of_two() || align < this.pointer_size().bytes() {
// memalign requires the size to be greater than 0, the alignment to be a power of 2
// to be, at least, of word size in which EINVAL is emitted
// and a null pointer is returned.
// https://docs.oracle.com/cd/E88353_01/html/E37843/memalign-3c.html
if !align.is_power_of_two() || align < this.pointer_size().bytes() || size == 0 {
this.set_last_error(this.eval_libc("EINVAL"))?;
this.write_null(dest)?;
} else {
let ptr = this.allocate_ptr(Size::from_bytes(size), Align::from_bytes(align).unwrap(), MiriMemoryKind::C.into(),)?;
let ptr = this.allocate_ptr(
Size::from_bytes(size),
Align::from_bytes(align).unwrap(),
MiriMemoryKind::C.into(),
)?;
this.write_pointer(ptr, dest)?;
}
}
Expand Down

0 comments on commit 25eaa96

Please sign in to comment.