(attr: *mut libc::pthread_attr_t)
| 112 | #[unsafe(no_mangle)] |
| 113 | #[inline(never)] |
| 114 | unsafe extern "C" fn pthread_attr_init(attr: *mut libc::pthread_attr_t) -> libc::c_int { |
| 115 | // std::thread enters libc through pthread_attr_init on Unix. Refusing that |
| 116 | // call while in simulation keeps hidden OS scheduling out of DST. |
| 117 | if in_simulation() { |
| 118 | eprintln!("attempt to spawn a system thread in simulation."); |
| 119 | eprintln!("note: use simulator tasks instead."); |
| 120 | return -1; |
| 121 | } |
| 122 | |
| 123 | type PthreadAttrInit = unsafe extern "C" fn(*mut libc::pthread_attr_t) -> libc::c_int; |
| 124 | static PTHREAD_ATTR_INIT: OnceLock<PthreadAttrInit> = OnceLock::new(); |
| 125 | let original = PTHREAD_ATTR_INIT.get_or_init(|| unsafe { |
| 126 | // `RTLD_NEXT` skips this interposed function and finds the libc |
| 127 | // implementation that would have been called without the simulator. |
| 128 | let ptr = libc::dlsym(libc::RTLD_NEXT, c"pthread_attr_init".as_ptr().cast()); |
| 129 | assert!(!ptr.is_null(), "failed to resolve original pthread_attr_init"); |
| 130 | std::mem::transmute(ptr) |
| 131 | }); |
| 132 | unsafe { original(attr) } |
| 133 | } |
| 134 | |
| 135 | // Randomness syscall hooks. |
| 136 |
nothing calls this directly
no test coverage detected
searching dependent graphs…