Skip to content

Commit 54664f1

Browse files
committed
Auto merge of #31263 - dhuseby:fixing_bsd_builds, r=alexcrichton
Something went haywire with github last night and the old PR #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.
2 parents 50df6b9 + ca6f920 commit 54664f1

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

src/libstd/sys/unix/fs.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,14 @@ impl DirEntry {
211211
#[cfg(any(target_os = "macos",
212212
target_os = "ios",
213213
target_os = "netbsd",
214-
target_os = "openbsd"))]
215-
fn name_bytes(&self) -> &[u8] {
216-
unsafe {
217-
::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8,
218-
self.entry.d_namlen as usize)
219-
}
220-
}
221-
#[cfg(any(target_os = "freebsd",
214+
target_os = "openbsd",
215+
target_os = "freebsd",
222216
target_os = "dragonfly",
223217
target_os = "bitrig"))]
224218
fn name_bytes(&self) -> &[u8] {
225219
unsafe {
226220
::slice::from_raw_parts(self.entry.d_name.as_ptr() as *const u8,
227-
self.entry.d_namelen as usize)
221+
self.entry.d_namlen as usize)
228222
}
229223
}
230224
#[cfg(any(target_os = "android",

src/libstd/sys/unix/stack_overflow.rs

+26-14
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,38 @@ mod imp {
135135
Handler { _data: MAIN_ALTSTACK };
136136
}
137137

138-
pub unsafe fn make_handler() -> Handler {
139-
let alt_stack = mmap(ptr::null_mut(),
140-
SIGSTKSZ,
141-
PROT_READ | PROT_WRITE,
142-
MAP_PRIVATE | MAP_ANON,
143-
-1,
144-
0);
145-
if alt_stack == MAP_FAILED {
138+
unsafe fn get_stackp() -> *mut libc::c_void {
139+
let stackp = mmap(ptr::null_mut(),
140+
SIGSTKSZ,
141+
PROT_READ | PROT_WRITE,
142+
MAP_PRIVATE | MAP_ANON,
143+
-1,
144+
0);
145+
if stackp == MAP_FAILED {
146146
panic!("failed to allocate an alternative stack");
147147
}
148+
stackp
149+
}
148150

149-
let mut stack: libc::stack_t = mem::zeroed();
151+
#[cfg(any(target_os = "linux",
152+
target_os = "macos",
153+
target_os = "bitrig",
154+
target_os = "netbsd",
155+
target_os = "openbsd"))]
156+
unsafe fn get_stack() -> libc::stack_t {
157+
libc::stack_t { ss_sp: get_stackp(), ss_flags: 0, ss_size: SIGSTKSZ }
158+
}
150159

151-
stack.ss_sp = alt_stack;
152-
stack.ss_flags = 0;
153-
stack.ss_size = SIGSTKSZ;
160+
#[cfg(any(target_os = "freebsd",
161+
target_os = "dragonfly"))]
162+
unsafe fn get_stack() -> libc::stack_t {
163+
libc::stack_t { ss_sp: get_stackp() as *mut i8, ss_flags: 0, ss_size: SIGSTKSZ }
164+
}
154165

166+
pub unsafe fn make_handler() -> Handler {
167+
let stack = get_stack();
155168
sigaltstack(&stack, ptr::null_mut());
156-
157-
Handler { _data: alt_stack }
169+
Handler { _data: stack.ss_sp as *mut libc::c_void }
158170
}
159171

160172
pub unsafe fn drop_handler(handler: &mut Handler) {

src/libtest/lib.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -939,18 +939,12 @@ fn get_concurrency() -> usize {
939939
fn num_cpus() -> usize {
940940
let mut cpus: libc::c_uint = 0;
941941
let mut cpus_size = std::mem::size_of_val(&cpus);
942-
let mut mib = [libc::CTL_HW, libc::HW_AVAILCPU, 0, 0];
943942

944943
unsafe {
945-
libc::sysctl(mib.as_mut_ptr(),
946-
2,
947-
&mut cpus as *mut _ as *mut _,
948-
&mut cpus_size as *mut _ as *mut _,
949-
0 as *mut _,
950-
0);
944+
cpus = libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as libc::c_uint;
951945
}
952946
if cpus < 1 {
953-
mib[1] = libc::HW_NCPU;
947+
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
954948
unsafe {
955949
libc::sysctl(mib.as_mut_ptr(),
956950
2,

0 commit comments

Comments
 (0)