Skip to content

Commit 4b99fb7

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 ad3c078 commit 4b99fb7

File tree

8 files changed

+230
-88
lines changed

8 files changed

+230
-88
lines changed

libc-test/build.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ fn main() {
402402
// just insert some padding.
403403
(struct_ == "siginfo_t" && field == "_pad") ||
404404
// musl names this __dummy1 but it's still there
405-
(musl && struct_ == "glob_t" && field == "gl_flags")
405+
(musl && struct_ == "glob_t" && field == "gl_flags") ||
406+
// musl seems to define this as an *anonymous* bitfield
407+
(musl && struct_ == "statvfs" && field == "__f_unused")
406408
});
407409

408410
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

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

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

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

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

+33-84
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,34 @@
1-
pub type c_long = i64;
2-
pub type c_ulong = u64;
3-
pub type clock_t = i64;
4-
pub type time_t = i64;
5-
pub type suseconds_t = i64;
1+
pub type clock_t = c_long;
2+
pub type time_t = c_long;
3+
pub type suseconds_t = c_long;
64
pub type ino_t = u64;
75
pub type off_t = i64;
86
pub type blkcnt_t = i64;
7+
8+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
99
pub type c_char = i8;
10+
11+
#[cfg(any(target_arch = "arm", target_arch = "asmjs"))]
12+
pub type c_char = u8;
13+
14+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
1015
pub type wchar_t = i32;
11-
pub type nlink_t = u64;
12-
pub type blksize_t = i64;
1316

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-
}
17+
#[cfg(any(target_arch = "arm", target_arch = "asmjs"))]
18+
pub type wchar_t = u32;
3519

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-
}
20+
// This definition is slightly different on aarch64
21+
#[cfg(not(target_arch = "aarch64"))]
22+
pub type nlink_t = usize;
5623

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

61-
pub struct sigset_t {
62-
__val: [::c_ulong; 16],
63-
}
28+
pub type fsblkcnt_t = ::c_ulonglong;
29+
pub type fsfilcnt_t = ::c_ulonglong;
6430

31+
s! {
6532
pub struct sigaction {
6633
pub sa_sigaction: ::sighandler_t,
6734
pub sa_mask: ::sigset_t,
@@ -95,19 +62,6 @@ s! {
9562
__unused2: ::c_long
9663
}
9764

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-
11165
pub struct statfs {
11266
pub f_type: ::c_ulong,
11367
pub f_bsize: ::c_ulong,
@@ -123,18 +77,6 @@ s! {
12377
pub f_spare: [::c_ulong; 4],
12478
}
12579

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-
13880
pub struct termios {
13981
pub c_iflag: ::tcflag_t,
14082
pub c_oflag: ::tcflag_t,
@@ -351,10 +293,6 @@ pub const SIG_UNBLOCK: ::c_int = 0x01;
351293
pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01;
352294
pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02;
353295

354-
pub const _SC_2_C_VERSION: ::c_int = 96;
355-
356-
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
357-
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
358296
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
359297

360298
pub const CPU_SETSIZE: ::c_int = 128;
@@ -405,7 +343,6 @@ pub const PTRACE_SETREGS: ::c_uint = 13;
405343

406344
pub const EFD_NONBLOCK: ::c_int = 0x800;
407345

408-
pub const F_GETLK: ::c_int = 5;
409346
pub const F_GETOWN: ::c_int = 9;
410347
pub const F_SETOWN: ::c_int = 8;
411348

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

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)