Skip to content

Commit

Permalink
Added bindings for wasm32-wali-linux-musl target
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunr2 committed Jan 16, 2025
1 parent 0f9f8c9 commit 3eae744
Show file tree
Hide file tree
Showing 7 changed files with 2,462 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! libc - Raw FFI bindings to platforms' system libraries
#![crate_name = "libc"]
#![crate_type = "rlib"]
#![feature(c_variadic)]
#![feature(concat_idents)]
#![allow(
renamed_and_removed_lints, // Keep this order.
unknown_lints, // Keep this order.
Expand Down
3 changes: 2 additions & 1 deletion src/unix/linux_like/linux/arch/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ cfg_if! {
target_arch = "riscv64",
target_arch = "aarch64",
target_arch = "s390x",
target_arch = "loongarch64"
target_arch = "loongarch64",
target_arch = "wasm32"
))] {
pub const FS_IOC_GETFLAGS: Ioctl = 0x80086601;
pub const FS_IOC_SETFLAGS: Ioctl = 0x40086602;
Expand Down
19 changes: 18 additions & 1 deletion src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6432,7 +6432,7 @@ extern "C" {
pub fn vhangup() -> c_int;
pub fn sync();
pub fn syncfs(fd: c_int) -> c_int;
pub fn syscall(num: c_long, ...) -> c_long;

pub fn sched_getaffinity(
pid: crate::pid_t,
cpusetsize: size_t,
Expand Down Expand Up @@ -6839,6 +6839,23 @@ extern "C" {
pub fn ioctl(fd: c_int, request: Ioctl, ...) -> c_int;
}

// Syscall libc stub for non-wasm32 (WALI) targets
//
// For wasm32, all syscalls are name-bound and typed.
// The 'syscall' implementation from C library is avoided since
// higher level libraries do not explicitly typecast arguments to
// 64-bit register sizes, which is expected of C variadic arguments.
// To overcome this, a wrapper 'syscall' method is implemented,
// which binds the syscall types statically at compile time
// and binds their numbers at runtime
cfg_if!(
if #[cfg(not(target_arch = "wasm32"))] {
extern "C" {
pub fn syscall(num: c_long, ...) -> c_long;
}
}
);

// LFS64 extensions
//
// * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones
Expand Down
3 changes: 3 additions & 0 deletions src/unix/linux_like/linux/musl/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ cfg_if! {
} else if #[cfg(any(target_arch = "loongarch64"))] {
mod loongarch64;
pub use self::loongarch64::*;
} else if #[cfg(any(target_arch = "wasm32"))] {
mod wasm32;
pub use self::wasm32::*;
} else {
// Unknown target_arch
}
Expand Down
Loading

0 comments on commit 3eae744

Please sign in to comment.