summary refs log tree commit diff
path: root/src/tools/miri/tests/fail-dep/libc/affinity.rs
blob: 09f096e46f1e63b1d6600f0a338f4a971f124b17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//@ignore-target: windows # only very limited libc on Windows
//@ignore-target: apple # `sched_setaffinity` is not supported on macOS
//@compile-flags: -Zmiri-disable-isolation -Zmiri-num-cpus=4

fn main() {
    use std::mem::size_of;

    use libc::{cpu_set_t, sched_setaffinity};

    // If pid is zero, then the calling thread is used.
    const PID: i32 = 0;

    let cpuset: cpu_set_t = unsafe { core::mem::MaybeUninit::zeroed().assume_init() };

    let err = unsafe { sched_setaffinity(PID, size_of::<cpu_set_t>() + 1, &cpuset) }; //~ ERROR: memory access failed
    assert_eq!(err, 0);
}