1+ // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+ // file at the top-level directory of this distribution and at
3+ // http://rust-lang.org/COPYRIGHT.
4+ //
5+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+ // option. This file may not be copied, modified, or distributed
9+ // except according to those terms.
10+
111/// darwin_fd_limit exists to work around an issue where launchctl on Mac OS X
212/// defaults the rlimit maxfiles to 256/unlimited. The default soft limit of 256
313/// ends up being far too low for our multithreaded scheduler testing, depending
616/// This fixes issue #7772.
717#[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
818#[ allow( non_camel_case_types) ]
9- pub fn raise_fd_limit ( ) {
19+ pub unsafe fn raise_fd_limit ( ) {
1020 use libc;
21+ use std:: cmp;
22+ use std:: io;
23+ use std:: mem:: size_of_val;
24+ use std:: ptr:: null_mut;
1125
1226 type rlim_t = libc:: uint64_t ;
27+
1328 #[ repr( C ) ]
1429 struct rlimit {
1530 rlim_cur : rlim_t ,
@@ -31,9 +46,6 @@ pub fn raise_fd_limit() {
3146 // The strategy here is to fetch the current resource limits, read the
3247 // kern.maxfilesperproc sysctl value, and bump the soft resource limit for
3348 // maxfiles up to the sysctl value.
34- use ptr:: null_mut;
35- use mem:: size_of_val;
36- use io;
3749
3850 // Fetch the kern.maxfilesperproc value
3951 let mut mib: [ libc:: c_int ; 2 ] = [ CTL_KERN , KERN_MAXFILESPERPROC ] ;
@@ -54,7 +66,7 @@ pub fn raise_fd_limit() {
5466
5567 // Bump the soft limit to the smaller of kern.maxfilesperproc and the hard
5668 // limit
57- rlim. rlim_cur = :: cmp:: min ( maxfiles as rlim_t , rlim. rlim_max ) ;
69+ rlim. rlim_cur = cmp:: min ( maxfiles as rlim_t , rlim. rlim_max ) ;
5870
5971 // Set our newly-increased resource limit
6072 if setrlimit ( RLIMIT_NOFILE , & rlim) != 0 {
@@ -64,4 +76,4 @@ pub fn raise_fd_limit() {
6476}
6577
6678#[ cfg( not( any( target_os = "macos" , target_os = "ios" ) ) ) ]
67- pub fn raise_fd_limit ( ) { }
79+ pub unsafe fn raise_fd_limit ( ) { }
0 commit comments