Skip to content

Commit a2ccd82

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 a2ccd82

File tree

8 files changed

+239
-83
lines changed

8 files changed

+239
-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

+58-79
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,46 @@
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+
pub type nlink_t = ::c_uint;
5636

57-
pub struct pthread_attr_t {
58-
__size: [u64; 7]
59-
}
37+
#[cfg(not(target_arch = "aarch64"))]
38+
pub type blksize_t = c_long;
6039

61-
pub struct sigset_t {
62-
__val: [::c_ulong; 16],
63-
}
40+
pub type fsblkcnt_t = ::c_ulonglong;
41+
pub type fsfilcnt_t = ::c_ulonglong;
6442

43+
s! {
6544
pub struct sigaction {
6645
pub sa_sigaction: ::sighandler_t,
6746
pub sa_mask: ::sigset_t,
@@ -95,19 +74,6 @@ s! {
9574
__unused2: ::c_long
9675
}
9776

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-
11177
pub struct statfs {
11278
pub f_type: ::c_ulong,
11379
pub f_bsize: ::c_ulong,
@@ -123,18 +89,6 @@ s! {
12389
pub f_spare: [::c_ulong; 4],
12490
}
12591

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-
13892
pub struct termios {
13993
pub c_iflag: ::tcflag_t,
14094
pub c_oflag: ::tcflag_t,
@@ -351,10 +305,18 @@ pub const SIG_UNBLOCK: ::c_int = 0x01;
351305
pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01;
352306
pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02;
353307

354-
pub const _SC_2_C_VERSION: ::c_int = 96;
355-
308+
#[cfg(any(target_arch = "x86_64"))]
356309
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
310+
#[cfg(any(target_arch = "x86",
311+
target_arch = "arm",
312+
target_arch = "asmjs"))]
313+
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
314+
#[cfg(any(target_arch = "x86_64"))]
357315
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
316+
#[cfg(any(target_arch = "x86",
317+
target_arch = "arm",
318+
target_arch = "asmjs"))]
319+
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
358320
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
359321

360322
pub const CPU_SETSIZE: ::c_int = 128;
@@ -408,7 +370,12 @@ pub const PTRACE_SETREGS: ::c_uint = 13;
408370

409371
pub const EFD_NONBLOCK: ::c_int = 0x800;
410372

373+
#[cfg(any(target_arch = "x86_64"))]
411374
pub const F_GETLK: ::c_int = 5;
375+
#[cfg(any(target_arch = "x86",
376+
target_arch = "arm",
377+
target_arch = "asmjs"))]
378+
pub const F_GETLK: ::c_int = 12;
412379
pub const F_GETOWN: ::c_int = 9;
413380
pub const F_SETOWN: ::c_int = 8;
414381

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

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)