Skip to content

Commit 6d132c4

Browse files
committed
Add musl definitions for x86, arm and asmjs
I've tested x86 against C locally, but not arm or asmjs. I added the arm definitions because asmjs's C is derived from arms. Mysteriously, my locally-built musl does not contain a definition for _SC_2_C_VERSION, so I just removed it.
1 parent 2522ecd commit 6d132c4

File tree

8 files changed

+242
-83
lines changed

8 files changed

+242
-83
lines changed

libc-test/build.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ fn main() {
364364
// just insert some padding.
365365
(struct_ == "siginfo_t" && field == "_pad") ||
366366
// musl names this __dummy1 but it's still there
367-
(musl && struct_ == "glob_t" && field == "gl_flags")
367+
(musl && struct_ == "glob_t" && field == "gl_flags") ||
368+
// musl seems to define this as an *anonymous* bitfield
369+
(musl && struct_ == "statvfs" && field == "__f_unused")
368370
});
369371

370372
cfg.fn_cname(move |name, cname| {

src/unix/notbsd/linux/mips.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub type ino_t = u32;
1010
pub type blkcnt_t = i32;
1111
pub type blksize_t = i32;
1212
pub type nlink_t = u32;
13+
pub type fsblkcnt_t = ::c_ulong;
14+
pub type fsfilcnt_t = ::c_ulong;
1315

1416
s! {
1517
pub struct stat {

src/unix/notbsd/linux/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ pub type ino64_t = u64;
99
pub type off64_t = i64;
1010
pub type blkcnt64_t = i64;
1111
pub type rlim64_t = u64;
12-
pub type fsblkcnt_t = ::c_ulong;
13-
pub type fsfilcnt_t = ::c_ulong;
1412
pub type key_t = ::c_int;
1513
pub type shmatt_t = ::c_ulong;
1614
pub type mqd_t = ::c_int;

src/unix/notbsd/linux/musl/b32.rs

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
s! {
2+
pub struct stat {
3+
pub st_dev: ::dev_t,
4+
__st_dev_padding: ::c_int,
5+
__st_ino_truncated: ::c_long,
6+
pub st_mode: ::mode_t,
7+
pub st_nlink: ::nlink_t,
8+
pub st_uid: ::uid_t,
9+
pub st_gid: ::gid_t,
10+
pub st_rdev: ::dev_t,
11+
__st_rdev_padding: ::c_int,
12+
pub st_size: ::off_t,
13+
pub st_blksize: ::blksize_t,
14+
pub st_blocks: ::blkcnt_t,
15+
pub st_atim: ::timespec,
16+
pub st_mtim: ::timespec,
17+
pub st_ctim: ::timespec,
18+
pub st_ino: ::ino_t,
19+
}
20+
21+
pub struct stat64 {
22+
pub st_dev: ::dev_t,
23+
__st_dev_padding: ::c_int,
24+
__st_ino_truncated: ::c_long,
25+
pub st_mode: ::mode_t,
26+
pub st_nlink: ::nlink_t,
27+
pub st_uid: ::uid_t,
28+
pub st_gid: ::gid_t,
29+
pub st_rdev: ::dev_t,
30+
__st_rdev_padding: ::c_int,
31+
pub st_size: ::off_t,
32+
pub st_blksize: ::blksize_t,
33+
pub st_blocks: ::blkcnt_t,
34+
pub st_atim: ::timespec,
35+
pub st_mtim: ::timespec,
36+
pub st_ctim: ::timespec,
37+
pub st_ino: ::ino_t,
38+
}
39+
40+
pub struct pthread_attr_t {
41+
__size: [u32; 9]
42+
}
43+
44+
pub struct sigset_t {
45+
__val: [::c_ulong; 32],
46+
}
47+
48+
pub struct shmid_ds {
49+
pub shm_perm: ::ipc_perm,
50+
pub shm_segsz: ::size_t,
51+
pub shm_atime: ::time_t,
52+
__unused1: ::c_int,
53+
pub shm_dtime: ::time_t,
54+
__unused2: ::c_int,
55+
pub shm_ctime: ::time_t,
56+
__unused3: ::c_int,
57+
pub shm_cpid: ::pid_t,
58+
pub shm_lpid: ::pid_t,
59+
pub shm_nattch: ::c_ulong,
60+
__pad1: ::c_ulong,
61+
__pad2: ::c_ulong,
62+
}
63+
64+
pub struct msghdr {
65+
pub msg_name: *mut ::c_void,
66+
pub msg_namelen: ::socklen_t,
67+
pub msg_iov: *mut ::iovec,
68+
pub msg_iovlen: ::c_int,
69+
pub msg_control: *mut ::c_void,
70+
pub msg_controllen: ::socklen_t,
71+
pub msg_flags: ::c_int,
72+
}
73+
}

src/unix/notbsd/linux/musl/b64.rs

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
s! {
2+
pub struct stat {
3+
pub st_dev: ::dev_t,
4+
pub st_ino: ::ino_t,
5+
pub st_nlink: ::nlink_t,
6+
pub st_mode: ::mode_t,
7+
pub st_uid: ::uid_t,
8+
pub st_gid: ::gid_t,
9+
__pad0: ::c_int,
10+
pub st_rdev: ::dev_t,
11+
pub st_size: ::off_t,
12+
pub st_blksize: ::blksize_t,
13+
pub st_blocks: ::blkcnt_t,
14+
pub st_atime: ::time_t,
15+
pub st_atime_nsec: ::c_long,
16+
pub st_mtime: ::time_t,
17+
pub st_mtime_nsec: ::c_long,
18+
pub st_ctime: ::time_t,
19+
pub st_ctime_nsec: ::c_long,
20+
__unused: [::c_long; 3],
21+
}
22+
23+
pub struct stat64 {
24+
pub st_dev: ::dev_t,
25+
pub st_ino: ::ino64_t,
26+
pub st_nlink: ::nlink_t,
27+
pub st_mode: ::mode_t,
28+
pub st_uid: ::uid_t,
29+
pub st_gid: ::gid_t,
30+
__pad0: ::c_int,
31+
pub st_rdev: ::dev_t,
32+
pub st_size: ::off_t,
33+
pub st_blksize: ::blksize_t,
34+
pub st_blocks: ::blkcnt64_t,
35+
pub st_atime: ::time_t,
36+
pub st_atime_nsec: ::c_long,
37+
pub st_mtime: ::time_t,
38+
pub st_mtime_nsec: ::c_long,
39+
pub st_ctime: ::time_t,
40+
pub st_ctime_nsec: ::c_long,
41+
__reserved: [::c_long; 3],
42+
}
43+
44+
pub struct pthread_attr_t {
45+
__size: [u64; 7]
46+
}
47+
48+
pub struct sigset_t {
49+
__val: [::c_ulong; 16],
50+
}
51+
52+
pub struct shmid_ds {
53+
pub shm_perm: ::ipc_perm,
54+
pub shm_segsz: ::size_t,
55+
pub shm_atime: ::time_t,
56+
pub shm_dtime: ::time_t,
57+
pub shm_ctime: ::time_t,
58+
pub shm_cpid: ::pid_t,
59+
pub shm_lpid: ::pid_t,
60+
pub shm_nattch: ::c_ulong,
61+
__pad1: ::c_ulong,
62+
__pad2: ::c_ulong,
63+
}
64+
65+
pub struct msghdr {
66+
pub msg_name: *mut ::c_void,
67+
pub msg_namelen: ::socklen_t,
68+
pub msg_iov: *mut ::iovec,
69+
pub msg_iovlen: ::c_int,
70+
__pad1: ::c_int,
71+
pub msg_control: *mut ::c_void,
72+
pub msg_controllen: ::socklen_t,
73+
__pad2: ::socklen_t,
74+
pub msg_flags: ::c_int,
75+
}
76+
}

src/unix/notbsd/linux/musl.rs renamed to src/unix/notbsd/linux/musl/mod.rs

+61-79
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,49 @@
1+
#[cfg(any(target_arch = "x86",
2+
target_arch = "arm",
3+
target_arch = "asmjs"))]
4+
pub type c_long = i32;
5+
#[cfg(any(target_arch = "x86",
6+
target_arch = "arm",
7+
target_arch = "asmjs"))]
8+
pub type c_ulong = u32;
9+
#[cfg(any(target_arch = "x86_64"))]
110
pub type c_long = i64;
11+
#[cfg(any(target_arch = "x86_64"))]
212
pub type c_ulong = u64;
3-
pub type clock_t = i64;
4-
pub type time_t = i64;
5-
pub type suseconds_t = i64;
13+
14+
pub type clock_t = c_long;
15+
pub type time_t = c_long;
16+
pub type suseconds_t = c_long;
617
pub type ino_t = u64;
718
pub type off_t = i64;
819
pub type blkcnt_t = i64;
20+
21+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
922
pub type c_char = i8;
23+
24+
#[cfg(any(target_arch = "arm",
25+
target_arch = "asmjs"))]
26+
pub type c_char = u8;
27+
28+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
1029
pub type wchar_t = i32;
11-
pub type nlink_t = u64;
12-
pub type blksize_t = i64;
1330

14-
s! {
15-
pub struct stat {
16-
pub st_dev: ::dev_t,
17-
pub st_ino: ::ino_t,
18-
pub st_nlink: ::nlink_t,
19-
pub st_mode: ::mode_t,
20-
pub st_uid: ::uid_t,
21-
pub st_gid: ::gid_t,
22-
__pad0: ::c_int,
23-
pub st_rdev: ::dev_t,
24-
pub st_size: ::off_t,
25-
pub st_blksize: ::blksize_t,
26-
pub st_blocks: ::blkcnt_t,
27-
pub st_atime: ::time_t,
28-
pub st_atime_nsec: ::c_long,
29-
pub st_mtime: ::time_t,
30-
pub st_mtime_nsec: ::c_long,
31-
pub st_ctime: ::time_t,
32-
pub st_ctime_nsec: ::c_long,
33-
__unused: [::c_long; 3],
34-
}
31+
#[cfg(any(target_arch = "arm",
32+
target_arch = "asmjs"))]
33+
pub type wchar_t = u32;
3534

36-
pub struct stat64 {
37-
pub st_dev: ::dev_t,
38-
pub st_ino: ::ino64_t,
39-
pub st_nlink: ::nlink_t,
40-
pub st_mode: ::mode_t,
41-
pub st_uid: ::uid_t,
42-
pub st_gid: ::gid_t,
43-
__pad0: ::c_int,
44-
pub st_rdev: ::dev_t,
45-
pub st_size: ::off_t,
46-
pub st_blksize: ::blksize_t,
47-
pub st_blocks: ::blkcnt64_t,
48-
pub st_atime: ::time_t,
49-
pub st_atime_nsec: ::c_long,
50-
pub st_mtime: ::time_t,
51-
pub st_mtime_nsec: ::c_long,
52-
pub st_ctime: ::time_t,
53-
pub st_ctime_nsec: ::c_long,
54-
__reserved: [::c_long; 3],
55-
}
35+
// This definition is slightly different on aarch64
36+
#[cfg(not(target_arch = "aarch64"))]
37+
pub type nlink_t = usize;
5638

57-
pub struct pthread_attr_t {
58-
__size: [u64; 7]
59-
}
39+
// This definition is slightly different on aarch64
40+
#[cfg(not(target_arch = "aarch64"))]
41+
pub type blksize_t = c_long;
6042

61-
pub struct sigset_t {
62-
__val: [::c_ulong; 16],
63-
}
43+
pub type fsblkcnt_t = ::c_ulonglong;
44+
pub type fsfilcnt_t = ::c_ulonglong;
6445

46+
s! {
6547
pub struct sigaction {
6648
pub sa_sigaction: ::sighandler_t,
6749
pub sa_mask: ::sigset_t,
@@ -95,19 +77,6 @@ s! {
9577
__unused2: ::c_long
9678
}
9779

98-
pub struct shmid_ds {
99-
pub shm_perm: ::ipc_perm,
100-
pub shm_segsz: ::size_t,
101-
pub shm_atime: ::time_t,
102-
pub shm_dtime: ::time_t,
103-
pub shm_ctime: ::time_t,
104-
pub shm_cpid: ::pid_t,
105-
pub shm_lpid: ::pid_t,
106-
pub shm_nattch: ::c_ulong,
107-
__pad1: ::c_ulong,
108-
__pad2: ::c_ulong,
109-
}
110-
11180
pub struct statfs {
11281
pub f_type: ::c_ulong,
11382
pub f_bsize: ::c_ulong,
@@ -123,18 +92,6 @@ s! {
12392
pub f_spare: [::c_ulong; 4],
12493
}
12594

126-
pub struct msghdr {
127-
pub msg_name: *mut ::c_void,
128-
pub msg_namelen: ::socklen_t,
129-
pub msg_iov: *mut ::iovec,
130-
pub msg_iovlen: ::c_int,
131-
__pad1: ::c_int,
132-
pub msg_control: *mut ::c_void,
133-
pub msg_controllen: ::socklen_t,
134-
__pad2: ::socklen_t,
135-
pub msg_flags: ::c_int,
136-
}
137-
13895
pub struct termios {
13996
pub c_iflag: ::tcflag_t,
14097
pub c_oflag: ::tcflag_t,
@@ -351,10 +308,18 @@ pub const SIG_UNBLOCK: ::c_int = 0x01;
351308
pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01;
352309
pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02;
353310

354-
pub const _SC_2_C_VERSION: ::c_int = 96;
355-
311+
#[cfg(any(target_arch = "x86_64"))]
356312
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
313+
#[cfg(any(target_arch = "x86",
314+
target_arch = "arm",
315+
target_arch = "asmjs"))]
316+
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
317+
#[cfg(any(target_arch = "x86_64"))]
357318
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
319+
#[cfg(any(target_arch = "x86",
320+
target_arch = "arm",
321+
target_arch = "asmjs"))]
322+
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
358323
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
359324

360325
pub const CPU_SETSIZE: ::c_int = 128;
@@ -408,7 +373,12 @@ pub const PTRACE_SETREGS: ::c_uint = 13;
408373

409374
pub const EFD_NONBLOCK: ::c_int = 0x800;
410375

376+
#[cfg(any(target_arch = "x86_64"))]
411377
pub const F_GETLK: ::c_int = 5;
378+
#[cfg(any(target_arch = "x86",
379+
target_arch = "arm",
380+
target_arch = "asmjs"))]
381+
pub const F_GETLK: ::c_int = 12;
412382
pub const F_GETOWN: ::c_int = 9;
413383
pub const F_SETOWN: ::c_int = 8;
414384

@@ -438,3 +408,15 @@ extern {
438408
pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int;
439409
pub fn ptrace(request: ::c_int, ...) -> ::c_long;
440410
}
411+
412+
cfg_if! {
413+
if #[cfg(any(target_arch = "x86_64"))] {
414+
mod b64;
415+
pub use self::b64::*;
416+
} else if #[cfg(any(target_arch = "x86",
417+
target_arch = "arm",
418+
target_arch = "asmjs"))] {
419+
mod b32;
420+
pub use self::b32::*;
421+
} else { }
422+
}

src/unix/notbsd/linux/other/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
pub type fsblkcnt_t = ::c_ulong;
2+
pub type fsfilcnt_t = ::c_ulong;
3+
14
s! {
25
pub struct sigaction {
36
pub sa_sigaction: ::sighandler_t,

0 commit comments

Comments
 (0)