File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -645,7 +645,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
645
645
this. set_last_error ( einval) ?;
646
646
this. write_scalar ( Scalar :: from_i32 ( -1 ) , dest) ?;
647
647
} else {
648
- // NOTE: cpusetsize might be smaller than `CpuAffinityMask::CPU_MASK_BYTES`
648
+ // NOTE: cpusetsize might be smaller than `CpuAffinityMask::CPU_MASK_BYTES`.
649
+ // Any unspecified bytes are treated as zero here (none of the CPUs are configured).
650
+ // This is not exactly documented, so we assume that this is the behavior in practice.
649
651
let bits_slice = this. read_bytes_ptr_strip_provenance ( mask, Size :: from_bytes ( cpusetsize) ) ?;
650
652
// This ignores the bytes beyond `CpuAffinityMask::CPU_MASK_BYTES`
651
653
let bits_array: [ u8 ; CpuAffinityMask :: CPU_MASK_BYTES ] =
Original file line number Diff line number Diff line change @@ -105,6 +105,24 @@ fn get_small_cpu_mask() {
105
105
}
106
106
}
107
107
108
+ fn set_small_cpu_mask ( ) {
109
+ let mut cpuset: cpu_set_t = unsafe { core:: mem:: MaybeUninit :: zeroed ( ) . assume_init ( ) } ;
110
+
111
+ let err = unsafe { sched_getaffinity ( PID , size_of :: < cpu_set_t > ( ) , & mut cpuset) } ;
112
+ assert_eq ! ( err, 0 ) ;
113
+
114
+ // setting a mask of size 0 is invalid
115
+ let err = unsafe { sched_setaffinity ( PID , 0 , & cpuset) } ;
116
+ assert_eq ! ( err, -1 ) ;
117
+ assert_eq ! ( std:: io:: Error :: last_os_error( ) . kind( ) , std:: io:: ErrorKind :: InvalidInput ) ;
118
+
119
+ // any other number of bytes (at least up to `size_of<cpu_set_t>()` will work
120
+ for i in 1 ..24 {
121
+ let err = unsafe { sched_setaffinity ( PID , i, & cpuset) } ;
122
+ assert_eq ! ( err, 0 , "fail for {i}" ) ;
123
+ }
124
+ }
125
+
108
126
fn set_custom_cpu_mask ( ) {
109
127
let cpu_count = std:: thread:: available_parallelism ( ) . unwrap ( ) . get ( ) ;
110
128
@@ -189,6 +207,7 @@ fn main() {
189
207
configure_unavailable_cpu ( ) ;
190
208
large_set ( ) ;
191
209
get_small_cpu_mask ( ) ;
210
+ set_small_cpu_mask ( ) ;
192
211
set_custom_cpu_mask ( ) ;
193
212
parent_child ( ) ;
194
213
}
You can’t perform that action at this time.
0 commit comments