Skip to content

Commit

Permalink
Rollup merge of rust-lang#30837 - semarie:openbsd-libc, r=alexcrichton
Browse files Browse the repository at this point in the history
The following PR updates libc version to latest commits for correctly support openbsd.
It corrects several points in rustc to be compatible with libc changes.

r? @alexcrichton
  • Loading branch information
Manishearth committed Jan 14, 2016
2 parents 4ff1d20 + 667ee8a commit 837a8de
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/libstd/rand/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ mod imp {
// getentropy(2) permits a maximum buffer size of 256 bytes
for s in v.chunks_mut(256) {
let ret = unsafe {
libc::syscall(libc::NR_GETENTROPY, s.as_mut_ptr(), s.len())
libc::getentropy(s.as_mut_ptr() as *mut libc::c_void, s.len())
};
if ret == -1 {
panic!("unexpected getentropy error: {}", errno());
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ impl DirEntry {

#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "netbsd"))]
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,
Expand All @@ -213,8 +214,7 @@ impl DirEntry {
}
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
target_os = "bitrig",
target_os = "openbsd"))]
target_os = "bitrig"))]
fn name_bytes(&self) -> &[u8] {
unsafe {
::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8,
Expand Down
10 changes: 5 additions & 5 deletions src/libstd/sys/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ mod imp {
static mut PAGE_SIZE: usize = 0;

#[cfg(any(target_os = "linux", target_os = "android"))]
unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> *mut libc::c_void {
unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> usize {
#[repr(C)]
struct siginfo_t {
a: [libc::c_int; 3], // si_signo, si_code, si_errno,
si_addr: *mut libc::c_void,
}

(*(info as *const siginfo_t)).si_addr
(*(info as *const siginfo_t)).si_addr as usize
}

#[cfg(not(any(target_os = "linux", target_os = "android")))]
unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> *mut libc::c_void {
(*info).si_addr
unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> usize {
(*info).si_addr as usize
}

// Signal handler for the SIGSEGV and SIGBUS handlers. We've got guard pages
Expand All @@ -98,7 +98,7 @@ mod imp {
use sys_common::util::report_overflow;

let guard = thread_info::stack_guard().unwrap_or(0);
let addr = siginfo_si_addr(info) as usize;
let addr = siginfo_si_addr(info);

// If the faulting address is within the guard page, then we print a
// message saying so.
Expand Down
19 changes: 18 additions & 1 deletion src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,6 @@ fn get_concurrency() -> usize {
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
target_os = "bitrig",
target_os = "openbsd",
target_os = "netbsd"))]
fn num_cpus() -> usize {
let mut cpus: libc::c_uint = 0;
Expand All @@ -946,6 +945,24 @@ fn get_concurrency() -> usize {
}
cpus as usize
}

#[cfg(target_os = "openbsd")]
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_NCPU, 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);
}
if cpus < 1 {
cpus = 1;
}
cpus as usize
}
}

pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescAndFn> {
Expand Down

0 comments on commit 837a8de

Please sign in to comment.