Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Wasm32 Linux Target #3778

Open
wants to merge 3 commits into
base: libc-0.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,140 changes: 1,073 additions & 67 deletions libc-test/build.rs

Large diffs are not rendered by default.

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 @@ -231,7 +231,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;
pub const FS_IOC_GETVERSION: ::Ioctl = 0x80087601;
Expand Down
18 changes: 17 additions & 1 deletion src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5201,7 +5201,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: ::pid_t, cpusetsize: ::size_t, cpuset: *mut cpu_set_t)
-> ::c_int;
pub fn sched_setaffinity(
Expand Down Expand Up @@ -5622,6 +5622,22 @@ extern "C" {
) -> ::ssize_t;
}

// Syscall libc stub for non Wasm32-WALI targets
// In wasm32-linux, 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 @@ -160,6 +160,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
Loading