Skip to content

Commit 25eaa96

Browse files
committed
add test.
1 parent b46d657 commit 25eaa96

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

ci/ci.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ case $HOST_TARGET in
145145
BASIC="$VERY_BASIC hello hashmap alloc align" # ensures we have the shims for stdout and basic data structures
146146
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
147147
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
148-
MIRI_TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random
149-
MIRI_TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random
148+
MIRI_TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random alloc
149+
MIRI_TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random alloc
150150
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal $VERY_BASIC hello panic/panic
151151
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal $VERY_BASIC wasm
152152
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal $VERY_BASIC wasm

src/shims/unix/solarish/foreign_items.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_span::Symbol;
2-
use rustc_target::spec::abi::Abi;
32
use rustc_target::abi::{Align, Size};
3+
use rustc_target::spec::abi::Abi;
44

55
use crate::*;
66

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

28-
// memalign wants an alignment to be a power of 2
29-
// and to be, at least, of word size.
30-
// http://docs.oracle.com/cd/E88353_01/html/E37743/memalign-3c.html
31-
if !align.is_power_of_two() || align < this.pointer_size().bytes() {
29+
// memalign requires the size to be greater than 0, the alignment to be a power of 2
30+
// to be, at least, of word size in which EINVAL is emitted
31+
// and a null pointer is returned.
32+
// https://docs.oracle.com/cd/E88353_01/html/E37843/memalign-3c.html
33+
if !align.is_power_of_two() || align < this.pointer_size().bytes() || size == 0 {
34+
this.set_last_error(this.eval_libc("EINVAL"))?;
3235
this.write_null(dest)?;
3336
} else {
34-
let ptr = this.allocate_ptr(Size::from_bytes(size), Align::from_bytes(align).unwrap(), MiriMemoryKind::C.into(),)?;
37+
let ptr = this.allocate_ptr(
38+
Size::from_bytes(size),
39+
Align::from_bytes(align).unwrap(),
40+
MiriMemoryKind::C.into(),
41+
)?;
3542
this.write_pointer(ptr, dest)?;
3643
}
3744
}

0 commit comments

Comments
 (0)