Skip to content

Commit 837a8de

Browse files
committed
Rollup merge of rust-lang#30837 - semarie:openbsd-libc, r=alexcrichton
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
2 parents 4ff1d20 + 667ee8a commit 837a8de

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

src/libstd/rand/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ mod imp {
222222
// getentropy(2) permits a maximum buffer size of 256 bytes
223223
for s in v.chunks_mut(256) {
224224
let ret = unsafe {
225-
libc::syscall(libc::NR_GETENTROPY, s.as_mut_ptr(), s.len())
225+
libc::getentropy(s.as_mut_ptr() as *mut libc::c_void, s.len())
226226
};
227227
if ret == -1 {
228228
panic!("unexpected getentropy error: {}", errno());

src/libstd/sys/unix/fs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ impl DirEntry {
204204

205205
#[cfg(any(target_os = "macos",
206206
target_os = "ios",
207-
target_os = "netbsd"))]
207+
target_os = "netbsd",
208+
target_os = "openbsd"))]
208209
fn name_bytes(&self) -> &[u8] {
209210
unsafe {
210211
::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8,
@@ -213,8 +214,7 @@ impl DirEntry {
213214
}
214215
#[cfg(any(target_os = "freebsd",
215216
target_os = "dragonfly",
216-
target_os = "bitrig",
217-
target_os = "openbsd"))]
217+
target_os = "bitrig"))]
218218
fn name_bytes(&self) -> &[u8] {
219219
unsafe {
220220
::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8,

src/libstd/sys/unix/stack_overflow.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ mod imp {
5959
static mut PAGE_SIZE: usize = 0;
6060

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

69-
(*(info as *const siginfo_t)).si_addr
69+
(*(info as *const siginfo_t)).si_addr as usize
7070
}
7171

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

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

100100
let guard = thread_info::stack_guard().unwrap_or(0);
101-
let addr = siginfo_si_addr(info) as usize;
101+
let addr = siginfo_si_addr(info);
102102

103103
// If the faulting address is within the guard page, then we print a
104104
// message saying so.

src/libtest/lib.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,6 @@ fn get_concurrency() -> usize {
919919
#[cfg(any(target_os = "freebsd",
920920
target_os = "dragonfly",
921921
target_os = "bitrig",
922-
target_os = "openbsd",
923922
target_os = "netbsd"))]
924923
fn num_cpus() -> usize {
925924
let mut cpus: libc::c_uint = 0;
@@ -946,6 +945,24 @@ fn get_concurrency() -> usize {
946945
}
947946
cpus as usize
948947
}
948+
949+
#[cfg(target_os = "openbsd")]
950+
fn num_cpus() -> usize {
951+
let mut cpus: libc::c_uint = 0;
952+
let mut cpus_size = std::mem::size_of_val(&cpus);
953+
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
954+
955+
unsafe {
956+
libc::sysctl(mib.as_mut_ptr(), 2,
957+
&mut cpus as *mut _ as *mut _,
958+
&mut cpus_size as *mut _ as *mut _,
959+
0 as *mut _, 0);
960+
}
961+
if cpus < 1 {
962+
cpus = 1;
963+
}
964+
cpus as usize
965+
}
949966
}
950967

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

0 commit comments

Comments
 (0)