@@ -362,8 +362,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
362362// FreeBSD: https://man.freebsd.org/cgi/man.cgi?query=reallocarray
363363match this. compute_size_in_bytes ( Size :: from_bytes ( size) , nmemb) {
364364None => {
365- let enmem = this. eval_libc ( "ENOMEM" ) ;
366- this. set_last_error ( enmem) ?;
365+ this. set_last_error ( LibcError ( "ENOMEM" ) ) ?;
367366 this. write_null ( dest) ?;
368367}
369368Some ( len) => {
@@ -653,13 +652,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
653652let chunk_size = CpuAffinityMask :: chunk_size ( this) ;
654653
655654if 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) ?;
659656} else if cpusetsize == 0 || cpusetsize. checked_rem ( chunk_size) . unwrap ( ) != 0 {
660657// 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) ?;
663659} else if let Some ( cpuset) = this. machine . thread_cpu_affinity . get ( & thread_id) {
664660let cpuset = cpuset. clone ( ) ;
665661// we only copy whole chunks of size_of::<c_ulong>()
@@ -668,9 +664,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
668664 this. write_null ( dest) ?;
669665} else {
670666// 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) ?;
674668}
675669}
676670"sched_setaffinity" => {
@@ -695,9 +689,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
695689} ;
696690
697691if 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) ?;
701693} else {
702694// NOTE: cpusetsize might be smaller than `CpuAffinityMask::CPU_MASK_BYTES`.
703695// 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> {
713705}
714706None => {
715707// 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) ?;
718709}
719710}
720711}
@@ -770,9 +761,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
770761// macOS: https://keith.github.io/xcode-man-pages/getentropy.2.html
771762// Solaris/Illumos: https://illumos.org/man/3C/getentropy
772763if 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) ?;
776765} else {
777766 this. gen_random ( buf, bufsize) ?;
778767 this. write_null ( dest) ?;
0 commit comments