Skip to content

Commit 8b56faa

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 9063858 commit 8b56faa

File tree

9 files changed

+217
-92
lines changed

9 files changed

+217
-92
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/android/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ pub const EFD_NONBLOCK: ::c_int = 0x800;
468468
pub const F_GETLK: ::c_int = 5;
469469
pub const F_GETOWN: ::c_int = 9;
470470
pub const F_SETOWN: ::c_int = 8;
471+
pub const F_SETLK: ::c_int = 6;
472+
pub const F_SETLKW: ::c_int = 7;
471473

472474
pub const TCGETS: ::c_int = 0x5401;
473475
pub const TCSETS: ::c_int = 0x5402;

src/unix/notbsd/linux/mips.rs

+4
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 {
@@ -428,6 +430,8 @@ pub const EFD_NONBLOCK: ::c_int = 0x80;
428430
pub const F_GETLK: ::c_int = 14;
429431
pub const F_GETOWN: ::c_int = 23;
430432
pub const F_SETOWN: ::c_int = 24;
433+
pub const F_SETLK: ::c_int = 6;
434+
pub const F_SETLKW: ::c_int = 7;
431435

432436
pub const SFD_NONBLOCK: ::c_int = 0x80;
433437

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

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

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

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

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

+28-85
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,28 @@
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-
pub type wchar_t = i32;
11-
pub type nlink_t = u64;
12-
pub type blksize_t = i64;
1310

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-
}
11+
#[cfg(any(target_arch = "arm", target_arch = "asmjs"))]
12+
pub type c_char = u8;
3513

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-
}
14+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
15+
pub type wchar_t = i32;
5616

57-
pub struct pthread_attr_t {
58-
__size: [u64; 7]
59-
}
17+
#[cfg(any(target_arch = "arm", target_arch = "asmjs"))]
18+
pub type wchar_t = u32;
6019

61-
pub struct sigset_t {
62-
__val: [::c_ulong; 16],
63-
}
20+
pub type nlink_t = usize;
21+
pub type blksize_t = c_long;
22+
pub type fsblkcnt_t = ::c_ulonglong;
23+
pub type fsfilcnt_t = ::c_ulonglong;
6424

25+
s! {
6526
pub struct sigaction {
6627
pub sa_sigaction: ::sighandler_t,
6728
pub sa_mask: ::sigset_t,
@@ -95,19 +56,6 @@ s! {
9556
__unused2: ::c_long
9657
}
9758

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-
11159
pub struct statfs {
11260
pub f_type: ::c_ulong,
11361
pub f_bsize: ::c_ulong,
@@ -123,18 +71,6 @@ s! {
12371
pub f_spare: [::c_ulong; 4],
12472
}
12573

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-
13874
pub struct termios {
13975
pub c_iflag: ::tcflag_t,
14076
pub c_oflag: ::tcflag_t,
@@ -353,10 +289,6 @@ pub const SIG_UNBLOCK: ::c_int = 0x01;
353289
pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01;
354290
pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02;
355291

356-
pub const _SC_2_C_VERSION: ::c_int = 96;
357-
358-
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
359-
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
360292
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
361293

362294
pub const CPU_SETSIZE: ::c_int = 128;
@@ -407,7 +339,6 @@ pub const PTRACE_SETREGS: ::c_uint = 13;
407339

408340
pub const EFD_NONBLOCK: ::c_int = 0x800;
409341

410-
pub const F_GETLK: ::c_int = 5;
411342
pub const F_GETOWN: ::c_int = 9;
412343
pub const F_SETOWN: ::c_int = 8;
413344

@@ -469,3 +400,15 @@ extern {
469400
pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int;
470401
pub fn ptrace(request: ::c_int, ...) -> ::c_long;
471402
}
403+
404+
cfg_if! {
405+
if #[cfg(any(target_arch = "x86_64"))] {
406+
mod b64;
407+
pub use self::b64::*;
408+
} else if #[cfg(any(target_arch = "x86",
409+
target_arch = "arm",
410+
target_arch = "asmjs"))] {
411+
mod b32;
412+
pub use self::b32::*;
413+
} else { }
414+
}

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

+5
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,
@@ -354,6 +357,8 @@ pub const EFD_NONBLOCK: ::c_int = 0x800;
354357
pub const F_GETLK: ::c_int = 5;
355358
pub const F_GETOWN: ::c_int = 9;
356359
pub const F_SETOWN: ::c_int = 8;
360+
pub const F_SETLK: ::c_int = 6;
361+
pub const F_SETLKW: ::c_int = 7;
357362

358363
pub const SFD_NONBLOCK: ::c_int = 0x0800;
359364

0 commit comments

Comments
 (0)