Handler { _data: MAIN_ALTSTACK };
}
- pub unsafe fn make_handler() -> Handler {
- let alt_stack = mmap(ptr::null_mut(),
- SIGSTKSZ,
- PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANON,
- -1,
- 0);
- if alt_stack == MAP_FAILED {
+ #[cfg(any(target_os = "linux",
+ target_os = "macos",
+ target_os = "bitrig",
+ target_os = "netbsd",
+ target_os = "openbsd"))]
+ unsafe fn get_stack() -> *mut libc::c_void {
+ let stack = mmap(ptr::null_mut(),
+ SIGSTKSZ,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON,
+ -1,
+ 0);
+ if stack == MAP_FAILED {
+ panic!("failed to allocate an alternative stack");
+ }
+ stack
+ }
+
+ #[cfg(any(target_os = "dragonfly",
+ target_os = "freebsd"))]
+ unsafe fn get_stack() -> *mut i8 {
+ let stack = mmap(ptr::null_mut(),
+ SIGSTKSZ,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON,
+ -1,
+ 0);
+ if stack == MAP_FAILED {
panic!("failed to allocate an alternative stack");
}
+ stack as *mut i8
+ }
+
+ pub unsafe fn make_handler() -> Handler {
+ let alt_stack = get_stack();
let mut stack: libc::stack_t = mem::zeroed();
stack.ss_sp = alt_stack;
sigaltstack(&stack, ptr::null_mut());
- Handler { _data: alt_stack }
+ Handler { _data: alt_stack as *mut libc::c_void }
}
pub unsafe fn drop_handler(handler: &mut Handler) {
fn num_cpus() -> usize {
let mut cpus: libc::c_uint = 0;
let mut cpus_size = std::mem::size_of_val(&cpus);
- let mut mib = [libc::CTL_HW, libc::HW_AVAILCPU, 0, 0];
unsafe {
- libc::sysctl(mib.as_mut_ptr(),
- 2,
- &mut cpus as *mut _ as *mut _,
- &mut cpus_size as *mut _ as *mut _,
- 0 as *mut _,
- 0);
+ cpus = libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as libc::c_uint;
}
if cpus < 1 {
- mib[1] = libc::HW_NCPU;
+ let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
unsafe {
libc::sysctl(mib.as_mut_ptr(),
2,