@@ -354,10 +354,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
354354 }
355355 "pipe2" => {
356356 // Currently this function does not exist on all Unixes, e.g. on macOS.
357- if !matches ! ( & * this. tcx. sess. target. os, "linux" | "freebsd" | "solaris" | "illumos" )
358- {
359- throw_unsup_format ! ( "`pipe2` is not supported on {}" , this. tcx. sess. target. os) ;
360- }
357+ this. check_target_os ( & [ "linux" , "freebsd" , "solaris" , "illumos" ] , link_name) ?;
361358 let [ pipefd, flags] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
362359 let result = this. pipe2 ( pipefd, Some ( flags) ) ?;
363360 this. write_scalar ( result, dest) ?;
@@ -402,12 +399,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
402399
403400 "reallocarray" => {
404401 // Currently this function does not exist on all Unixes, e.g. on macOS.
405- if !matches ! ( & * this. tcx. sess. target. os, "linux" | "freebsd" | "android" ) {
406- throw_unsup_format ! (
407- "`reallocarray` is not supported on {}" ,
408- this. tcx. sess. target. os
409- ) ;
410- }
402+ this. check_target_os ( & [ "linux" , "freebsd" , "android" ] , link_name) ?;
411403 let [ ptr, nmemb, size] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
412404 let ptr = this. read_pointer ( ptr) ?;
413405 let nmemb = this. read_target_usize ( nmemb) ?;
@@ -656,13 +648,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
656648 }
657649 "sched_getaffinity" => {
658650 // Currently this function does not exist on all Unixes, e.g. on macOS.
659- if !matches ! ( & * this. tcx. sess. target. os, "linux" | "freebsd" | "android" ) {
660- throw_unsup_format ! (
661- "`sched_getaffinity` is not supported on {}" ,
662- this. tcx. sess. target. os
663- ) ;
664- }
665-
651+ this. check_target_os ( & [ "linux" , "freebsd" , "android" ] , link_name) ?;
666652 let [ pid, cpusetsize, mask] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
667653 let pid = this. read_scalar ( pid) ?. to_u32 ( ) ?;
668654 let cpusetsize = this. read_target_usize ( cpusetsize) ?;
@@ -699,13 +685,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
699685 }
700686 "sched_setaffinity" => {
701687 // Currently this function does not exist on all Unixes, e.g. on macOS.
702- if !matches ! ( & * this. tcx. sess. target. os, "linux" | "freebsd" | "android" ) {
703- throw_unsup_format ! (
704- "`sched_setaffinity` is not supported on {}" ,
705- this. tcx. sess. target. os
706- ) ;
707- }
708-
688+ this. check_target_os ( & [ "linux" , "freebsd" , "android" ] , link_name) ?;
709689 let [ pid, cpusetsize, mask] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
710690 let pid = this. read_scalar ( pid) ?. to_u32 ( ) ?;
711691 let cpusetsize = this. read_target_usize ( cpusetsize) ?;
@@ -761,16 +741,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
761741 "getentropy" => {
762742 // This function is non-standard but exists with the same signature and behavior on
763743 // Linux, macOS, FreeBSD and Solaris/Illumos.
764- if !matches ! (
765- & * this. tcx. sess. target. os,
766- "linux" | "macos" | "freebsd" | "illumos" | "solaris" | "android"
767- ) {
768- throw_unsup_format ! (
769- "`getentropy` is not supported on {}" ,
770- this. tcx. sess. target. os
771- ) ;
772- }
773-
744+ this. check_target_os (
745+ & [ "linux" , "macos" , "freebsd" , "illumos" , "solaris" , "android" ] ,
746+ link_name,
747+ ) ?;
774748 let [ buf, bufsize] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
775749 let buf = this. read_pointer ( buf) ?;
776750 let bufsize = this. read_target_usize ( bufsize) ?;
@@ -797,15 +771,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
797771 "getrandom" => {
798772 // This function is non-standard but exists with the same signature and behavior on
799773 // Linux, FreeBSD and Solaris/Illumos.
800- if !matches ! (
801- & * this. tcx. sess. target. os,
802- "linux" | "freebsd" | "illumos" | "solaris" | "android"
803- ) {
804- throw_unsup_format ! (
805- "`getrandom` is not supported on {}" ,
806- this. tcx. sess. target. os
807- ) ;
808- }
774+ this. check_target_os (
775+ & [ "linux" , "freebsd" , "illumos" , "solaris" , "android" ] ,
776+ link_name,
777+ ) ?;
809778 let [ ptr, len, flags] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
810779 let ptr = this. read_pointer ( ptr) ?;
811780 let len = this. read_target_usize ( len) ?;
@@ -817,12 +786,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
817786 "arc4random_buf" => {
818787 // This function is non-standard but exists with the same signature and
819788 // same behavior (eg never fails) on FreeBSD and Solaris/Illumos.
820- if !matches ! ( & * this. tcx. sess. target. os, "freebsd" | "illumos" | "solaris" ) {
821- throw_unsup_format ! (
822- "`arc4random_buf` is not supported on {}" ,
823- this. tcx. sess. target. os
824- ) ;
825- }
789+ this. check_target_os ( & [ "freebsd" , "illumos" , "solaris" ] , link_name) ?;
826790 let [ ptr, len] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
827791 let ptr = this. read_pointer ( ptr) ?;
828792 let len = this. read_target_usize ( len) ?;
@@ -842,15 +806,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
842806 // For arm32 they did something custom, but similar enough that the same
843807 // `_Unwind_RaiseException` impl in miri should work:
844808 // https://github.com/ARM-software/abi-aa/blob/main/ehabi32/ehabi32.rst
845- if !matches ! (
846- & * this. tcx. sess. target. os,
847- "linux" | "freebsd" | "illumos" | "solaris" | "android" | "macos"
848- ) {
849- throw_unsup_format ! (
850- "`_Unwind_RaiseException` is not supported on {}" ,
851- this. tcx. sess. target. os
852- ) ;
853- }
809+ this. check_target_os (
810+ & [ "linux" , "freebsd" , "illumos" , "solaris" , "android" , "macos" ] ,
811+ link_name,
812+ ) ?;
854813 // This function looks and behaves excatly like miri_start_unwind.
855814 let [ payload] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
856815 this. handle_miri_start_unwind ( payload) ?;
0 commit comments