Auto merge of #31263 - dhuseby:fixing_bsd_builds, r=alexcrichton
Something went haywire with github last night and the old PR https://github.com/rust-lang/rust/pull/31230 got closed somehow. This new PR is to replace the old one. This incorporates all of the feedback from the other PR. @alexcrichton I incorporated the suggestion from @semarie and the result is cleaner and clearer. I think this is ready to go.
This commit is contained in:
commit
54664f1884
@ -211,20 +211,14 @@ impl DirEntry {
|
||||
#[cfg(any(target_os = "macos",
|
||||
target_os = "ios",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"))]
|
||||
fn name_bytes(&self) -> &[u8] {
|
||||
unsafe {
|
||||
::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8,
|
||||
self.entry.d_namlen as usize)
|
||||
}
|
||||
}
|
||||
#[cfg(any(target_os = "freebsd",
|
||||
target_os = "openbsd",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig"))]
|
||||
fn name_bytes(&self) -> &[u8] {
|
||||
unsafe {
|
||||
::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8,
|
||||
self.entry.d_namelen as usize)
|
||||
self.entry.d_namlen as usize)
|
||||
}
|
||||
}
|
||||
#[cfg(any(target_os = "android",
|
||||
|
@ -135,26 +135,38 @@ mod imp {
|
||||
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 {
|
||||
unsafe fn get_stackp() -> *mut libc::c_void {
|
||||
let stackp = mmap(ptr::null_mut(),
|
||||
SIGSTKSZ,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON,
|
||||
-1,
|
||||
0);
|
||||
if stackp == MAP_FAILED {
|
||||
panic!("failed to allocate an alternative stack");
|
||||
}
|
||||
stackp
|
||||
}
|
||||
|
||||
let mut stack: libc::stack_t = mem::zeroed();
|
||||
#[cfg(any(target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "bitrig",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"))]
|
||||
unsafe fn get_stack() -> libc::stack_t {
|
||||
libc::stack_t { ss_sp: get_stackp(), ss_flags: 0, ss_size: SIGSTKSZ }
|
||||
}
|
||||
|
||||
stack.ss_sp = alt_stack;
|
||||
stack.ss_flags = 0;
|
||||
stack.ss_size = SIGSTKSZ;
|
||||
#[cfg(any(target_os = "freebsd",
|
||||
target_os = "dragonfly"))]
|
||||
unsafe fn get_stack() -> libc::stack_t {
|
||||
libc::stack_t { ss_sp: get_stackp() as *mut i8, ss_flags: 0, ss_size: SIGSTKSZ }
|
||||
}
|
||||
|
||||
pub unsafe fn make_handler() -> Handler {
|
||||
let stack = get_stack();
|
||||
sigaltstack(&stack, ptr::null_mut());
|
||||
|
||||
Handler { _data: alt_stack }
|
||||
Handler { _data: stack.ss_sp as *mut libc::c_void }
|
||||
}
|
||||
|
||||
pub unsafe fn drop_handler(handler: &mut Handler) {
|
||||
|
@ -939,18 +939,12 @@ fn get_concurrency() -> usize {
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user