Skip to content

Commit bb6f198

Browse files
committed
Fix all definitions on FreeBSD
* The `flock` structure has an extra field * Some `flock`-related constants have different value * Some constants like `TABN` don't exist * The `fsblkcnt_t` and `fsfilcnt_t` type definitions are u64 for x86_64 FreeBSD * The `d_namelen` field in `dirent` was renamed correctly to `d_namlen` * The alignment of `fd_set` was off, and the macros were updated to not always assume a 32-bit integer is used.
1 parent d820c4a commit bb6f198

File tree

7 files changed

+88
-37
lines changed

7 files changed

+88
-37
lines changed

libc-test/build.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ fn main() {
101101
} else if !windows {
102102
cfg.header("glob.h");
103103
cfg.header("ifaddrs.h");
104-
if !openbsd {
104+
cfg.header("sys/statvfs.h");
105+
106+
if !openbsd && !freebsd {
105107
cfg.header("sys/quota.h");
106108
}
107-
cfg.header("sys/statvfs.h");
108109

109110
if !musl {
110111
cfg.header("sys/sysctl.h");
@@ -159,6 +160,7 @@ fn main() {
159160
if freebsd {
160161
cfg.header("pthread_np.h");
161162
cfg.header("sched.h");
163+
cfg.header("ufs/ufs/quota.h");
162164
}
163165

164166
if netbsd {
@@ -364,6 +366,11 @@ fn main() {
364366
// [3]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sys/eventfd.h;h=6295f32e937e779e74318eb9d3bdbe76aef8a8f3;hb=4e42b5b8f89f0e288e68be7ad70f9525aebc2cff#l34
365367
"eventfd" if linux => true,
366368

369+
// The `uname` funcion in freebsd is now an inline wrapper that
370+
// delegates to another, but the symbol still exists, so don't check
371+
// the symbol.
372+
"uname" if freebsd => true,
373+
367374
_ => false,
368375
}
369376
});

src/unix/bsd/apple/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ s! {
242242
pub c_ispeed: ::speed_t,
243243
pub c_ospeed: ::speed_t,
244244
}
245+
246+
pub struct flock {
247+
pub l_start: ::off_t,
248+
pub l_len: ::off_t,
249+
pub l_pid: ::pid_t,
250+
pub l_type: ::c_short,
251+
pub l_whence: ::c_short,
252+
}
245253
}
246254

247255
pub const EXIT_FAILURE: ::c_int = 1;
@@ -305,6 +313,9 @@ pub const F_LOCK: ::c_int = 1;
305313
pub const F_TEST: ::c_int = 3;
306314
pub const F_TLOCK: ::c_int = 2;
307315
pub const F_ULOCK: ::c_int = 0;
316+
pub const F_GETLK: ::c_int = 7;
317+
pub const F_SETLK: ::c_int = 8;
318+
pub const F_SETLKW: ::c_int = 9;
308319
pub const SIGHUP: ::c_int = 1;
309320
pub const SIGINT: ::c_int = 2;
310321
pub const SIGQUIT: ::c_int = 3;
@@ -803,6 +814,19 @@ pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE: ::uint32_t = 0x20000000;
803814
pub const NOTE_VM_PRESSURE_TERMINATE: ::uint32_t = 0x40000000;
804815
pub const NOTE_PCTRLMASK: ::uint32_t = 0xfff00000;
805816

817+
pub const NL0: ::c_int = 0x00000000;
818+
pub const NL1: ::c_int = 0x00000100;
819+
pub const TAB0: ::c_int = 0x00000000;
820+
pub const TAB1: ::c_int = 0x00000400;
821+
pub const TAB2: ::c_int = 0x00000800;
822+
pub const CR0: ::c_int = 0x00000000;
823+
pub const CR1: ::c_int = 0x00001000;
824+
pub const CR2: ::c_int = 0x00002000;
825+
pub const CR3: ::c_int = 0x00003000;
826+
pub const FF0: ::c_int = 0x00000000;
827+
pub const FF1: ::c_int = 0x00004000;
828+
pub const BS0: ::c_int = 0x00000000;
829+
pub const BS1: ::c_int = 0x00008000;
806830
pub const TAB3: ::c_int = 0x00000004;
807831
pub const VT0: ::c_int = 0x00000000;
808832
pub const VT1: ::c_int = 0x00010000;
@@ -811,6 +835,9 @@ pub const CRTSCTS: ::tcflag_t = 0x00030000;
811835

812836
pub const NI_MAXHOST: ::socklen_t = 1025;
813837

838+
pub const Q_GETQUOTA: ::c_int = 0x300;
839+
pub const Q_SETQUOTA: ::c_int = 0x400;
840+
814841
extern {
815842
pub fn getnameinfo(sa: *const ::sockaddr,
816843
salen: ::socklen_t,

src/unix/bsd/freebsdlike/dragonfly.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
pub type fsblkcnt_t = ::c_uint;
2+
pub type fsfilcnt_t = ::c_uint;
3+
14
pub const PTHREAD_STACK_MIN: ::size_t = 1024;
25
pub const KERN_PROC_PATHNAME: ::c_int = 9;
36
pub const SIGSTKSZ: ::size_t = 40960;
47
pub const MADV_INVAL: ::c_int = 10;
58

9+
pub const HW_AVAILCPU: ::c_int = 25;
10+
611
extern {
712
pub fn __dfly_error() -> *const ::c_int;
813
}

src/unix/bsd/freebsdlike/freebsd.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
pub type fsblkcnt_t = ::uint64_t;
2+
pub type fsfilcnt_t = ::uint64_t;
3+
14
pub const PTHREAD_STACK_MIN: ::size_t = 2048;
25
pub const KERN_PROC_PATHNAME: ::c_int = 12;
36
pub const SIGSTKSZ: ::size_t = 34816;

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ pub type pthread_mutexattr_t = *mut ::c_void;
1212
pub type pthread_cond_t = *mut ::c_void;
1313
pub type pthread_rwlock_t = *mut ::c_void;
1414
pub type pthread_key_t = ::c_int;
15-
pub type fsblkcnt_t = ::c_uint;
16-
pub type fsfilcnt_t = ::c_uint;
1715
pub type tcflag_t = ::c_uint;
1816
pub type speed_t = ::c_uint;
1917

@@ -24,7 +22,7 @@ s! {
2422
pub d_fileno: u32,
2523
pub d_reclen: u16,
2624
pub d_type: u8,
27-
pub d_namelen: u8,
25+
pub d_namlen: u8,
2826
pub d_name: [::c_char; 256],
2927
}
3028

@@ -85,7 +83,7 @@ s! {
8583
}
8684

8785
pub struct stack_t {
88-
pub ss_sp: *mut ::c_void,
86+
pub ss_sp: *mut ::c_char,
8987
pub ss_size: ::size_t,
9088
pub ss_flags: ::c_int,
9189
}
@@ -132,6 +130,15 @@ s! {
132130
pub c_ispeed: ::speed_t,
133131
pub c_ospeed: ::speed_t,
134132
}
133+
134+
pub struct flock {
135+
pub l_start: ::off_t,
136+
pub l_len: ::off_t,
137+
pub l_pid: ::pid_t,
138+
pub l_type: ::c_short,
139+
pub l_whence: ::c_short,
140+
pub l_sysid: ::c_int,
141+
}
135142
}
136143

137144
pub const EXIT_FAILURE: ::c_int = 1;
@@ -194,6 +201,9 @@ pub const F_TEST: ::c_int = 3;
194201
pub const F_TLOCK: ::c_int = 2;
195202
pub const F_ULOCK: ::c_int = 0;
196203
pub const F_DUPFD_CLOEXEC: ::c_int = 17;
204+
pub const F_GETLK: ::c_int = 11;
205+
pub const F_SETLK: ::c_int = 12;
206+
pub const F_SETLKW: ::c_int = 13;
197207
pub const SIGHUP: ::c_int = 1;
198208
pub const SIGINT: ::c_int = 2;
199209
pub const SIGQUIT: ::c_int = 3;
@@ -555,10 +565,11 @@ pub const FD_SETSIZE: usize = 1024;
555565

556566
pub const ST_NOSUID: ::c_ulong = 2;
557567

558-
pub const HW_AVAILCPU: ::c_int = 25;
559-
560568
pub const NI_MAXHOST: ::size_t = 1025;
561569

570+
pub const Q_GETQUOTA: ::c_int = 0x700;
571+
pub const Q_SETQUOTA: ::c_int = 0x800;
572+
562573
extern {
563574
pub fn getnameinfo(sa: *const ::sockaddr,
564575
salen: ::socklen_t,

src/unix/bsd/mod.rs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use dox::mem;
2+
13
pub type c_char = i8;
24
pub type wchar_t = i32;
35
pub type off_t = i64;
@@ -60,6 +62,11 @@ s! {
6062
}
6163

6264
pub struct fd_set {
65+
#[cfg(all(target_pointer_width = "64",
66+
target_os = "freebsd"))]
67+
fds_bits: [i64; FD_SETSIZE / 64],
68+
#[cfg(not(all(target_pointer_width = "64",
69+
target_os = "freebsd")))]
6370
fds_bits: [i32; FD_SETSIZE / 32],
6471
}
6572

@@ -95,14 +102,6 @@ s! {
95102
pub msg_flags: ::c_int,
96103
}
97104

98-
pub struct flock {
99-
pub l_start: ::off_t,
100-
pub l_len: ::off_t,
101-
pub l_pid: ::pid_t,
102-
pub l_type: ::c_short,
103-
pub l_whence: ::c_short,
104-
}
105-
106105
pub struct fsid_t {
107106
__fsid_val: [::int32_t; 2],
108107
}
@@ -185,19 +184,14 @@ pub const O_FSYNC: ::c_int = 0x80;
185184
pub const O_NDELAY: ::c_int = 0x4;
186185
pub const O_NOFOLLOW: ::c_int = 0x100;
187186

188-
pub const F_GETLK: ::c_int = 7;
189187
pub const F_GETOWN: ::c_int = 5;
190-
pub const F_SETLK: ::c_int = 8;
191-
pub const F_SETLKW: ::c_int = 9;
192188
pub const F_SETOWN: ::c_int = 6;
193189

194190
pub const MNT_FORCE: ::c_int = 0x80000;
195191

196192
pub const Q_SYNC: ::c_int = 0x600;
197193
pub const Q_QUOTAON: ::c_int = 0x100;
198194
pub const Q_QUOTAOFF: ::c_int = 0x200;
199-
pub const Q_GETQUOTA: ::c_int = 0x300;
200-
pub const Q_SETQUOTA: ::c_int = 0x400;
201195

202196
pub const TCIOFF: ::c_int = 3;
203197
pub const TCION: ::c_int = 4;
@@ -209,19 +203,6 @@ pub const TCIOFLUSH: ::c_int = 3;
209203
pub const TCSANOW: ::c_int = 0;
210204
pub const TCSADRAIN: ::c_int = 1;
211205
pub const TCSAFLUSH: ::c_int = 2;
212-
pub const NL0: ::c_int = 0x00000000;
213-
pub const NL1: ::c_int = 0x00000100;
214-
pub const TAB0: ::c_int = 0x00000000;
215-
pub const TAB1: ::c_int = 0x00000400;
216-
pub const TAB2: ::c_int = 0x00000800;
217-
pub const CR0: ::c_int = 0x00000000;
218-
pub const CR1: ::c_int = 0x00001000;
219-
pub const CR2: ::c_int = 0x00002000;
220-
pub const CR3: ::c_int = 0x00003000;
221-
pub const FF0: ::c_int = 0x00000000;
222-
pub const FF1: ::c_int = 0x00004000;
223-
pub const BS0: ::c_int = 0x00000000;
224-
pub const BS1: ::c_int = 0x00008000;
225206
pub const VEOF: usize = 0;
226207
pub const VEOL: usize = 1;
227208
pub const VEOL2: usize = 2;
@@ -284,19 +265,22 @@ pub const WNOHANG: ::c_int = 1;
284265

285266
f! {
286267
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
268+
let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
287269
let fd = fd as usize;
288-
(*set).fds_bits[fd / 32] &= !(1 << (fd % 32));
270+
(*set).fds_bits[fd / bits] &= !(1 << (fd % bits));
289271
return
290272
}
291273

292274
pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool {
275+
let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
293276
let fd = fd as usize;
294-
return ((*set).fds_bits[fd / 32] & (1 << (fd % 32))) != 0
277+
return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0
295278
}
296279

297280
pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () {
281+
let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
298282
let fd = fd as usize;
299-
(*set).fds_bits[fd / 32] |= 1 << (fd % 32);
283+
(*set).fds_bits[fd / bits] |= 1 << (fd % bits);
300284
return
301285
}
302286

src/unix/bsd/openbsdlike/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ s! {
4141
pub c_ispeed: ::c_int,
4242
pub c_ospeed: ::c_int,
4343
}
44+
45+
pub struct flock {
46+
pub l_start: ::off_t,
47+
pub l_len: ::off_t,
48+
pub l_pid: ::pid_t,
49+
pub l_type: ::c_short,
50+
pub l_whence: ::c_short,
51+
}
4452
}
4553

4654
pub const EXIT_FAILURE : ::c_int = 1;
@@ -100,6 +108,9 @@ pub const F_LOCK : ::c_int = 1;
100108
pub const F_TEST : ::c_int = 3;
101109
pub const F_TLOCK : ::c_int = 2;
102110
pub const F_ULOCK : ::c_int = 0;
111+
pub const F_GETLK: ::c_int = 7;
112+
pub const F_SETLK: ::c_int = 8;
113+
pub const F_SETLKW: ::c_int = 9;
103114
pub const SIGHUP : ::c_int = 1;
104115
pub const SIGINT : ::c_int = 2;
105116
pub const SIGQUIT : ::c_int = 3;
@@ -354,6 +365,9 @@ pub const _SC_FSYNC : ::c_int = 29;
354365

355366
pub const KERN_PROC_ARGV: ::c_int = 1;
356367

368+
pub const Q_GETQUOTA: ::c_int = 0x300;
369+
pub const Q_SETQUOTA: ::c_int = 0x400;
370+
357371
extern {
358372
pub fn mincore(addr: *mut ::c_void, len: ::size_t,
359373
vec: *mut ::c_char) -> ::c_int;

0 commit comments

Comments
 (0)