From cb3999cd83a3fbfbd79aaeef3a295aff46c9ea14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= Date: Wed, 23 Dec 2015 11:24:11 +0100 Subject: [PATCH 1/4] switch from syscall(2) to getentropy(2) use the `getentropy()` function instead of `syscall()` and syscall-numbers. --- src/libstd/rand/os.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 0ba0e01ce2910..23a368a30a52b 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -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()); From 468959580ae9bef5996ae1d43fc9d730e4977999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= Date: Wed, 23 Dec 2015 11:28:24 +0100 Subject: [PATCH 2/4] HW_AVAILCPU is unavailable under openbsd define `num_cpus()` function for openbsd that use `HW_NCPU` for grabbing the current number of cpus that could be used. --- src/libtest/lib.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 2945d20ceb1b8..dcc344c4ffd21 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -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; @@ -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) -> Vec { From a545eac593b0ff3a6ad6c2d8390de51c30712089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= Date: Wed, 23 Dec 2015 11:32:02 +0100 Subject: [PATCH 3/4] make siginfo_si_addr() returns a usize `siginfo_si_addr()` function is used once, and the returned value is casted to `usize`. So make the function returns a `usize`. it simplifies OpenBSD case, where the return type wouldn't be a `*mut libc::c_void` but a `*mut libc::c_char`. --- src/libstd/sys/unix/stack_overflow.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index 776acd20b069b..fc49f4257be2a 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -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 @@ -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. From 667ee8a57b86f5f3e12ff9bd780d6f16dc4129d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= Date: Wed, 23 Dec 2015 18:56:42 +0100 Subject: [PATCH 4/4] openbsd has dirent d_namlen field now --- src/libstd/sys/unix/fs.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index e8575a6c21cf1..10fda3fcd7fa5 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -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, @@ -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,