Coverage Report

Created: 2026-11-17 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/stacker-0.1.25/src/backends/unix.rs
Line
Count
Source
1
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "illumos"))]
2
use libc::pthread_attr_get_np as get_attr;
3
#[cfg(any(target_os = "linux", target_os = "solaris", target_os = "netbsd", target_os = "haiku"))]
4
use libc::pthread_getattr_np as get_attr;
5
6
0
pub unsafe fn guess_os_stack_limit() -> Option<usize> {
7
0
    let mut attr = PthreadAttr::new()?;
8
0
    (get_attr(libc::pthread_self(), &mut attr.0) == 0).then_some(())?;
9
0
    let mut stackaddr = std::ptr::null_mut();
10
0
    let mut stacksize = 0;
11
0
    (libc::pthread_attr_getstack(&attr.0, &mut stackaddr, &mut stacksize) == 0).then_some(())?;
12
0
    Some(stackaddr as usize)
13
0
}
14
15
struct PthreadAttr(libc::pthread_attr_t);
16
17
impl Drop for PthreadAttr {
18
0
    fn drop(&mut self) {
19
        unsafe {
20
0
            let ret = libc::pthread_attr_destroy(&mut self.0);
21
0
            if ret != 0 {
22
0
                let err = std::io::Error::last_os_error();
23
0
                panic!(
24
0
                    "pthread_attr_destroy failed with error code {}: {}",
25
                    ret, err
26
                );
27
0
            }
28
        }
29
0
    }
30
}
31
32
impl PthreadAttr {
33
0
    unsafe fn new() -> Option<Self> {
34
0
        let mut attr = std::mem::MaybeUninit::<libc::pthread_attr_t>::uninit();
35
0
        if libc::pthread_attr_init(attr.as_mut_ptr()) != 0 {
36
0
            return None;
37
0
        }
38
0
        Some(PthreadAttr(attr.assume_init()))
39
0
    }
40
}