Skip to content

Fixes #31229 - fixes up BSD type mismatch errors and updates libc dependency. DEAD, see PR #31263 #31230

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

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/liblibc
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you unify this with the block above? after this change they're all the same

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unified now. thanks, i missed that.

}
}
#[cfg(any(target_os = "android",
Expand Down
43 changes: 34 additions & 9 deletions src/libstd/sys/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,42 @@ 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 {
#[cfg(any(target_os = "linux",
target_os = "macos",
target_os = "bitrig",
target_os = "netbsd",
target_os = "openbsd"))]
unsafe fn get_stack() -> *mut libc::c_void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two blocks different? They look the same except for a cast at the very end?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are the same except the cast at the end. we don't yet have conditional compilation for general statements and I couldn't think of any other way to make this compile. on dragonflybsd and freebsd, the stack.ss_sp field is a *mut i8 type and on the others it is a *mut libc::c_void. Doing a runtime cfg!() doesn't work because one branch always fails to compile due to the warn -> error compilation flags.

I asked in #rust today if there was a better way to do this and nobody could think of a better way. @alexcrichton do you know of a better way to do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would have more sens to make get_stack() return a struct stack_t as it is the assignment of stack.ss_sp = alt_stack which differe on platforms.

The problem is on freebsd/dragonfly, mmap() returns a *mut ::c_void and ss_sp is a *mut ::c_char. So a cast is need for freebsd/dragonfly.

It would be less confusing that casting mmap().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhuseby you could also just insert stack as *mut u8 and that should compile on all platforms (it's just that the source and destination type would be the same in both places).

let stack = mmap(ptr::null_mut(),
SIGSTKSZ,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON,
-1,
0);
if stack == MAP_FAILED {
panic!("failed to allocate an alternative stack");
}
stack
}

#[cfg(any(target_os = "dragonfly",
target_os = "freebsd"))]
unsafe fn get_stack() -> *mut i8 {
let stack = mmap(ptr::null_mut(),
SIGSTKSZ,
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON,
-1,
0);
if stack == MAP_FAILED {
panic!("failed to allocate an alternative stack");
}
stack as *mut i8
}


pub unsafe fn make_handler() -> Handler {
let alt_stack = get_stack();
let mut stack: libc::stack_t = mem::zeroed();

stack.ss_sp = alt_stack;
Expand All @@ -153,7 +178,7 @@ mod imp {

sigaltstack(&stack, ptr::null_mut());

Handler { _data: alt_stack }
Handler { _data: alt_stack 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 @@ -938,18 +938,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