Skip to content

Fixes #31229 fixes up BSD type mismatch errors and updates libc dependency part deux #31263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 26 additions & 14 deletions src/libstd/sys/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 2 additions & 8 deletions src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down