@@ -362,8 +362,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
362
362
// FreeBSD: https://man.freebsd.org/cgi/man.cgi?query=reallocarray
363
363
match this. compute_size_in_bytes ( Size :: from_bytes ( size) , nmemb) {
364
364
None => {
365
- let enmem = this. eval_libc ( "ENOMEM" ) ;
366
- this. set_last_error ( enmem) ?;
365
+ this. set_last_error ( LibcError ( "ENOMEM" ) ) ?;
367
366
this. write_null ( dest) ?;
368
367
}
369
368
Some ( len) => {
@@ -653,13 +652,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
653
652
let chunk_size = CpuAffinityMask :: chunk_size ( this) ;
654
653
655
654
if this. ptr_is_null ( mask) ? {
656
- let efault = this. eval_libc ( "EFAULT" ) ;
657
- this. set_last_error ( efault) ?;
658
- this. write_int ( -1 , dest) ?;
655
+ this. set_last_error_and_return ( LibcError ( "EFAULT" ) , dest) ?;
659
656
} else if cpusetsize == 0 || cpusetsize. checked_rem ( chunk_size) . unwrap ( ) != 0 {
660
657
// we only copy whole chunks of size_of::<c_ulong>()
661
- this. set_last_error ( LibcError ( "EINVAL" ) ) ?;
662
- this. write_int ( -1 , dest) ?;
658
+ this. set_last_error_and_return ( LibcError ( "EINVAL" ) , dest) ?;
663
659
} else if let Some ( cpuset) = this. machine . thread_cpu_affinity . get ( & thread_id) {
664
660
let cpuset = cpuset. clone ( ) ;
665
661
// we only copy whole chunks of size_of::<c_ulong>()
@@ -668,9 +664,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
668
664
this. write_null ( dest) ?;
669
665
} else {
670
666
// The thread whose ID is pid could not be found
671
- let esrch = this. eval_libc ( "ESRCH" ) ;
672
- this. set_last_error ( esrch) ?;
673
- this. write_int ( -1 , dest) ?;
667
+ this. set_last_error_and_return ( LibcError ( "ESRCH" ) , dest) ?;
674
668
}
675
669
}
676
670
"sched_setaffinity" => {
@@ -695,9 +689,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
695
689
} ;
696
690
697
691
if this. ptr_is_null ( mask) ? {
698
- let efault = this. eval_libc ( "EFAULT" ) ;
699
- this. set_last_error ( efault) ?;
700
- this. write_int ( -1 , dest) ?;
692
+ this. set_last_error_and_return ( LibcError ( "EFAULT" ) , dest) ?;
701
693
} else {
702
694
// NOTE: cpusetsize might be smaller than `CpuAffinityMask::CPU_MASK_BYTES`.
703
695
// Any unspecified bytes are treated as zero here (none of the CPUs are configured).
@@ -713,8 +705,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
713
705
}
714
706
None => {
715
707
// The intersection between the mask and the available CPUs was empty.
716
- this. set_last_error ( LibcError ( "EINVAL" ) ) ?;
717
- this. write_int ( -1 , dest) ?;
708
+ this. set_last_error_and_return ( LibcError ( "EINVAL" ) , dest) ?;
718
709
}
719
710
}
720
711
}
@@ -770,9 +761,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
770
761
// macOS: https://keith.github.io/xcode-man-pages/getentropy.2.html
771
762
// Solaris/Illumos: https://illumos.org/man/3C/getentropy
772
763
if bufsize > 256 {
773
- let err = this. eval_libc ( "EIO" ) ;
774
- this. set_last_error ( err) ?;
775
- this. write_int ( -1 , dest) ?;
764
+ this. set_last_error_and_return ( LibcError ( "EIO" ) , dest) ?;
776
765
} else {
777
766
this. gen_random ( buf, bufsize) ?;
778
767
this. write_null ( dest) ?;
0 commit comments