@@ -354,10 +354,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
354
354
}
355
355
"pipe2" => {
356
356
// 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) ?;
361
358
let [ pipefd, flags] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
362
359
let result = this. pipe2 ( pipefd, Some ( flags) ) ?;
363
360
this. write_scalar ( result, dest) ?;
@@ -402,12 +399,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
402
399
403
400
"reallocarray" => {
404
401
// 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) ?;
411
403
let [ ptr, nmemb, size] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
412
404
let ptr = this. read_pointer ( ptr) ?;
413
405
let nmemb = this. read_target_usize ( nmemb) ?;
@@ -656,13 +648,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
656
648
}
657
649
"sched_getaffinity" => {
658
650
// 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) ?;
666
652
let [ pid, cpusetsize, mask] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
667
653
let pid = this. read_scalar ( pid) ?. to_u32 ( ) ?;
668
654
let cpusetsize = this. read_target_usize ( cpusetsize) ?;
@@ -699,13 +685,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
699
685
}
700
686
"sched_setaffinity" => {
701
687
// 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) ?;
709
689
let [ pid, cpusetsize, mask] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
710
690
let pid = this. read_scalar ( pid) ?. to_u32 ( ) ?;
711
691
let cpusetsize = this. read_target_usize ( cpusetsize) ?;
@@ -761,16 +741,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
761
741
"getentropy" => {
762
742
// This function is non-standard but exists with the same signature and behavior on
763
743
// 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
+ ) ?;
774
748
let [ buf, bufsize] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
775
749
let buf = this. read_pointer ( buf) ?;
776
750
let bufsize = this. read_target_usize ( bufsize) ?;
@@ -797,15 +771,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
797
771
"getrandom" => {
798
772
// This function is non-standard but exists with the same signature and behavior on
799
773
// 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
+ ) ?;
809
778
let [ ptr, len, flags] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
810
779
let ptr = this. read_pointer ( ptr) ?;
811
780
let len = this. read_target_usize ( len) ?;
@@ -817,12 +786,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
817
786
"arc4random_buf" => {
818
787
// This function is non-standard but exists with the same signature and
819
788
// 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) ?;
826
790
let [ ptr, len] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
827
791
let ptr = this. read_pointer ( ptr) ?;
828
792
let len = this. read_target_usize ( len) ?;
@@ -842,15 +806,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
842
806
// For arm32 they did something custom, but similar enough that the same
843
807
// `_Unwind_RaiseException` impl in miri should work:
844
808
// 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
+ ) ?;
854
813
// This function looks and behaves excatly like miri_start_unwind.
855
814
let [ payload] = this. check_shim ( abi, Conv :: C , link_name, args) ?;
856
815
this. handle_miri_start_unwind ( payload) ?;
0 commit comments