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
+
1
11
/// darwin_fd_limit exists to work around an issue where launchctl on Mac OS X
2
12
/// defaults the rlimit maxfiles to 256/unlimited. The default soft limit of 256
3
13
/// ends up being far too low for our multithreaded scheduler testing, depending
6
16
/// This fixes issue #7772.
7
17
#[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
8
18
#[ allow( non_camel_case_types) ]
9
- pub fn raise_fd_limit ( ) {
19
+ pub unsafe fn raise_fd_limit ( ) {
10
20
use libc;
21
+ use std:: cmp;
22
+ use std:: io;
23
+ use std:: mem:: size_of_val;
24
+ use std:: ptr:: null_mut;
11
25
12
26
type rlim_t = libc:: uint64_t ;
27
+
13
28
#[ repr( C ) ]
14
29
struct rlimit {
15
30
rlim_cur : rlim_t ,
@@ -31,9 +46,6 @@ pub fn raise_fd_limit() {
31
46
// The strategy here is to fetch the current resource limits, read the
32
47
// kern.maxfilesperproc sysctl value, and bump the soft resource limit for
33
48
// maxfiles up to the sysctl value.
34
- use ptr:: null_mut;
35
- use mem:: size_of_val;
36
- use io;
37
49
38
50
// Fetch the kern.maxfilesperproc value
39
51
let mut mib: [ libc:: c_int ; 2 ] = [ CTL_KERN , KERN_MAXFILESPERPROC ] ;
@@ -54,7 +66,7 @@ pub fn raise_fd_limit() {
54
66
55
67
// Bump the soft limit to the smaller of kern.maxfilesperproc and the hard
56
68
// 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 ) ;
58
70
59
71
// Set our newly-increased resource limit
60
72
if setrlimit ( RLIMIT_NOFILE , & rlim) != 0 {
@@ -64,4 +76,4 @@ pub fn raise_fd_limit() {
64
76
}
65
77
66
78
#[ 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