Skip to content

Commit 9e9a090

Browse files
committed
minor fixes
1 parent bb3a711 commit 9e9a090

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
374374
fn check_platform(&mut self, platform: &str, name: &str) -> InterpResult<'tcx> {
375375
if self.eval_context_mut().tcx.sess.target.target.target_os.to_lowercase() != platform {
376376
throw_unsup_format!(
377-
"`{}` is only available in the `{}` platform",
377+
"`{}` is only available on the `{}` platform",
378378
name,
379379
platform,
380380
)

src/shims/foreign_items.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
179179
}
180180

181181
/// Emulates calling a foreign item using its name, failing if the item is not supported.
182-
/// Returns Ok(false) if after calling this function, the call should return earlier instead of
183-
/// going to the next block.
182+
/// Returns `true` if the caller is expected to jump to the return block, and `false` if
183+
/// jumping has already been taken care of.
184184
fn emulate_foreign_item_by_name(
185185
&mut self,
186186
link_name: &str,
@@ -315,35 +315,35 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
315315
this.write_scalar(Scalar::from_int(result, Size::from_bits(32)), dest)?;
316316
}
317317

318-
"memchr" => {
318+
"memrchr" => {
319319
let ptr = this.read_scalar(args[0])?.not_undef()?;
320320
let val = this.read_scalar(args[1])?.to_i32()? as u8;
321321
let num = this.read_scalar(args[2])?.to_machine_usize(this)?;
322-
let idx = this
322+
if let Some(idx) = this
323323
.memory
324324
.read_bytes(ptr, Size::from_bytes(num))?
325325
.iter()
326-
.position(|&c| c == val);
327-
if let Some(idx) = idx {
328-
let new_ptr = ptr.ptr_offset(Size::from_bytes(idx as u64), this)?;
326+
.rev()
327+
.position(|&c| c == val)
328+
{
329+
let new_ptr = ptr.ptr_offset(Size::from_bytes(num - idx as u64 - 1), this)?;
329330
this.write_scalar(new_ptr, dest)?;
330331
} else {
331332
this.write_null(dest)?;
332333
}
333334
}
334335

335-
"memrchr" => {
336+
"memchr" => {
336337
let ptr = this.read_scalar(args[0])?.not_undef()?;
337338
let val = this.read_scalar(args[1])?.to_i32()? as u8;
338339
let num = this.read_scalar(args[2])?.to_machine_usize(this)?;
339-
if let Some(idx) = this
340+
let idx = this
340341
.memory
341342
.read_bytes(ptr, Size::from_bytes(num))?
342343
.iter()
343-
.rev()
344-
.position(|&c| c == val)
345-
{
346-
let new_ptr = ptr.ptr_offset(Size::from_bytes(num - idx as u64 - 1), this)?;
344+
.position(|&c| c == val);
345+
if let Some(idx) = idx {
346+
let new_ptr = ptr.ptr_offset(Size::from_bytes(idx as u64), this)?;
347347
this.write_scalar(new_ptr, dest)?;
348348
} else {
349349
this.write_null(dest)?;

src/shims/foreign_items/posix/linux.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2525
}
2626

2727
// Time related shims
28+
29+
// This is a POSIX function but it has only been tested on linux.
2830
"clock_gettime" => {
2931
let result = this.clock_gettime(args[0], args[1])?;
3032
this.write_scalar(Scalar::from_int(result, dest.layout.size), dest)?;
@@ -80,7 +82,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
8082
}
8183
}
8284

83-
// Shims the posix 'getrandom()' syscall.
85+
// Shims the linux 'getrandom()' syscall.
8486
fn getrandom<'tcx>(
8587
this: &mut MiriEvalContext<'_, 'tcx>,
8688
args: &[OpTy<'tcx, Tag>],

0 commit comments

Comments
 (0)