Skip to content

Commit bb761d3

Browse files
committed
Remove syscall shims; migrate wali from b64 to b32
1 parent bfd5c5c commit bb761d3

File tree

8 files changed

+574
-1817
lines changed

8 files changed

+574
-1817
lines changed

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! libc - Raw FFI bindings to platforms' system libraries
22
#![crate_name = "libc"]
33
#![crate_type = "rlib"]
4-
#![feature(c_variadic)]
5-
#![feature(concat_idents)]
64
#![allow(
75
renamed_and_removed_lints, // Keep this order.
86
unknown_lints, // Keep this order.

src/unix/linux_like/linux/mod.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6432,6 +6432,7 @@ extern "C" {
64326432
pub fn vhangup() -> c_int;
64336433
pub fn sync();
64346434
pub fn syncfs(fd: c_int) -> c_int;
6435+
pub fn syscall(num: c_long, ...) -> c_long;
64356436

64366437
pub fn sched_getaffinity(
64376438
pid: crate::pid_t,
@@ -6839,23 +6840,6 @@ extern "C" {
68396840
pub fn ioctl(fd: c_int, request: Ioctl, ...) -> c_int;
68406841
}
68416842

6842-
// Syscall libc stub for non-wasm32 (WALI) targets
6843-
//
6844-
// For wasm32, all syscalls are name-bound and typed.
6845-
// The 'syscall' implementation from C library is avoided since
6846-
// higher level libraries do not explicitly typecast arguments to
6847-
// 64-bit register sizes, which is expected of C variadic arguments.
6848-
// To overcome this, a wrapper 'syscall' method is implemented,
6849-
// which binds the syscall types statically at compile time
6850-
// and binds their numbers at runtime
6851-
cfg_if!(
6852-
if #[cfg(not(target_arch = "wasm32"))] {
6853-
extern "C" {
6854-
pub fn syscall(num: c_long, ...) -> c_long;
6855-
}
6856-
}
6857-
);
6858-
68596843
// LFS64 extensions
68606844
//
68616845
// * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones

src/unix/linux_like/linux/musl/b32/mod.rs

Lines changed: 128 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,138 @@
11
use crate::prelude::*;
22

3-
pub type c_long = i32;
4-
pub type c_ulong = u32;
5-
pub type nlink_t = u32;
6-
pub type blksize_t = c_long;
7-
pub type __u64 = c_ulonglong;
8-
pub type __s64 = c_longlong;
9-
pub type regoff_t = c_int;
10-
11-
s! {
12-
pub struct pthread_attr_t {
13-
__size: [u32; 9],
14-
}
3+
cfg_if! {
4+
if #[cfg(not(target_arch = "wasm32"))] {
5+
pub type c_long = i32;
6+
pub type c_ulong = u32;
7+
pub type nlink_t = u32;
8+
pub type blksize_t = c_long;
9+
pub type __u64 = c_ulonglong;
10+
pub type __s64 = c_longlong;
11+
pub type regoff_t = c_int;
1512

16-
pub struct sigset_t {
17-
__val: [c_ulong; 32],
18-
}
13+
s! {
14+
pub struct pthread_attr_t {
15+
__size: [u32; 9],
16+
}
1917

20-
pub struct msghdr {
21-
pub msg_name: *mut c_void,
22-
pub msg_namelen: crate::socklen_t,
23-
pub msg_iov: *mut crate::iovec,
24-
pub msg_iovlen: c_int,
25-
pub msg_control: *mut c_void,
26-
pub msg_controllen: crate::socklen_t,
27-
pub msg_flags: c_int,
28-
}
18+
pub struct sigset_t {
19+
__val: [c_ulong; 32],
20+
}
2921

30-
pub struct cmsghdr {
31-
pub cmsg_len: crate::socklen_t,
32-
pub cmsg_level: c_int,
33-
pub cmsg_type: c_int,
22+
pub struct msghdr {
23+
pub msg_name: *mut c_void,
24+
pub msg_namelen: crate::socklen_t,
25+
pub msg_iov: *mut crate::iovec,
26+
pub msg_iovlen: c_int,
27+
pub msg_control: *mut c_void,
28+
pub msg_controllen: crate::socklen_t,
29+
pub msg_flags: c_int,
30+
}
31+
32+
pub struct cmsghdr {
33+
pub cmsg_len: crate::socklen_t,
34+
pub cmsg_level: c_int,
35+
pub cmsg_type: c_int,
36+
}
37+
38+
pub struct sem_t {
39+
__val: [c_int; 4],
40+
}
41+
}
42+
43+
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
44+
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
45+
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 20;
3446
}
47+
else {
48+
pub type c_long = i64;
49+
pub type c_ulong = u64;
50+
pub type regoff_t = c_long;
51+
52+
s! {
53+
pub struct stack_t {
54+
pub ss_sp: *mut c_void,
55+
pub ss_flags: c_int,
56+
pub ss_size: size_t,
57+
}
3558

36-
pub struct sem_t {
37-
__val: [c_int; 4],
59+
pub struct pthread_attr_t {
60+
__size: [u64; 7],
61+
}
62+
63+
pub struct sigset_t {
64+
__val: [c_ulong; 16],
65+
}
66+
67+
pub struct shmid_ds {
68+
pub shm_perm: crate::ipc_perm,
69+
pub shm_segsz: size_t,
70+
pub shm_atime: crate::time_t,
71+
pub shm_dtime: crate::time_t,
72+
pub shm_ctime: crate::time_t,
73+
pub shm_cpid: crate::pid_t,
74+
pub shm_lpid: crate::pid_t,
75+
pub shm_nattch: c_ulong,
76+
__pad1: c_ulong,
77+
__pad2: c_ulong,
78+
}
79+
80+
pub struct msqid_ds {
81+
pub msg_perm: crate::ipc_perm,
82+
pub msg_stime: crate::time_t,
83+
pub msg_rtime: crate::time_t,
84+
pub msg_ctime: crate::time_t,
85+
__msg_cbytes: c_ulong,
86+
pub msg_qnum: crate::msgqnum_t,
87+
pub msg_qbytes: crate::msglen_t,
88+
pub msg_lspid: crate::pid_t,
89+
pub msg_lrpid: crate::pid_t,
90+
__pad1: c_ulong,
91+
__pad2: c_ulong,
92+
}
93+
94+
pub struct msghdr {
95+
pub msg_name: *mut c_void,
96+
pub msg_namelen: crate::socklen_t,
97+
pub msg_iov: *mut crate::iovec,
98+
#[cfg(target_endian = "big")]
99+
__pad1: c_int,
100+
pub msg_iovlen: c_int,
101+
#[cfg(target_endian = "little")]
102+
__pad1: c_int,
103+
pub msg_control: *mut c_void,
104+
#[cfg(target_endian = "big")]
105+
__pad2: c_int,
106+
pub msg_controllen: crate::socklen_t,
107+
#[cfg(target_endian = "little")]
108+
__pad2: c_int,
109+
pub msg_flags: c_int,
110+
}
111+
112+
pub struct cmsghdr {
113+
#[cfg(target_endian = "big")]
114+
pub __pad1: c_int,
115+
pub cmsg_len: crate::socklen_t,
116+
#[cfg(target_endian = "little")]
117+
pub __pad1: c_int,
118+
pub cmsg_level: c_int,
119+
pub cmsg_type: c_int,
120+
}
121+
122+
pub struct sem_t {
123+
__val: [c_int; 8],
124+
}
125+
}
126+
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
127+
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
128+
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32;
129+
130+
extern "C" {
131+
pub fn getrandom(buf: *mut c_void, buflen: size_t, flags: c_uint) -> ssize_t;
132+
}
38133
}
39134
}
40135

41-
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
42-
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
43-
pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 20;
44-
45136
cfg_if! {
46137
if #[cfg(any(target_arch = "x86"))] {
47138
mod x86;
@@ -61,6 +152,9 @@ cfg_if! {
61152
} else if #[cfg(any(target_arch = "riscv32"))] {
62153
mod riscv32;
63154
pub use self::riscv32::*;
155+
} else if #[cfg(any(target_arch = "wasm32"))] {
156+
mod wasm32;
157+
pub use self::wasm32::*;
64158
} else {
65159
// Unknown target_arch
66160
}

0 commit comments

Comments
 (0)