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

Fix compatibility with Emscripten >= 3.1.44 #3308

Merged
merged 1 commit into from Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions libc-test/build.rs
Expand Up @@ -2625,13 +2625,19 @@ fn test_emscripten(target: &str) {

"os_unfair_lock" => "struct os_unfair_lock_s".to_string(),

t if is_union => format!("union {}", t),
// LFS64 types have been removed in Emscripten 3.1.44+
// https://github.com/emscripten-core/emscripten/pull/19812
"off64_t" => "off_t".to_string(),

// typedefs don't need any keywords
t if t.ends_with("_t") => t.to_string(),

// put `struct` in front of all structs:.
t if is_struct => format!("struct {}", t),

// put `union` in front of all unions:
t if is_union => format!("union {}", t),

t => t.to_string(),
}
});
Expand All @@ -2658,7 +2664,9 @@ fn test_emscripten(target: &str) {
// FIXME: The size has been changed due to musl's time64
"time_t" => true,

_ => false,
// LFS64 types have been removed in Emscripten 3.1.44+
// https://github.com/emscripten-core/emscripten/pull/19812
t => t.ends_with("64") || t.ends_with("64_t"),
}
});

Expand Down Expand Up @@ -2687,7 +2695,9 @@ fn test_emscripten(target: &str) {
"utimbuf" | "timeval" | "timespec" | "rusage" | "itimerval" | "sched_param"
| "stat" | "stat64" | "shmid_ds" | "msqid_ds" => true,

_ => false,
// LFS64 types have been removed in Emscripten 3.1.44+
// https://github.com/emscripten-core/emscripten/pull/19812
ty => ty.ends_with("64") || ty.ends_with("64_t"),
}
});

Expand Down Expand Up @@ -2729,6 +2739,10 @@ fn test_emscripten(target: &str) {
| "SIG_IGN" // -1
=> true,

// LFS64 types have been removed in Emscripten 3.1.44+
// https://github.com/emscripten-core/emscripten/pull/19812
n if n.starts_with("RLIM64") => true,

_ => false,
}
});
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/emscripten.txt
@@ -1 +1,2 @@
getentropy
posix_fallocate64
213 changes: 213 additions & 0 deletions src/unix/linux_like/emscripten/lfs64.rs
@@ -0,0 +1,213 @@
// In-sync with ../linux/musl/lfs64.rs except for fallocate64, prlimit64 and sendfile64

#[inline]
pub unsafe extern "C" fn creat64(path: *const ::c_char, mode: ::mode_t) -> ::c_int {
::creat(path, mode)
}

#[inline]
pub unsafe extern "C" fn fgetpos64(stream: *mut ::FILE, pos: *mut ::fpos64_t) -> ::c_int {
::fgetpos(stream, pos as *mut _)
}

#[inline]
pub unsafe extern "C" fn fopen64(pathname: *const ::c_char, mode: *const ::c_char) -> *mut ::FILE {
::fopen(pathname, mode)
}

#[inline]
pub unsafe extern "C" fn freopen64(
pathname: *const ::c_char,
mode: *const ::c_char,
stream: *mut ::FILE,
) -> *mut ::FILE {
::freopen(pathname, mode, stream)
}

#[inline]
pub unsafe extern "C" fn fseeko64(
stream: *mut ::FILE,
offset: ::off64_t,
whence: ::c_int,
) -> ::c_int {
::fseeko(stream, offset, whence)
}

#[inline]
pub unsafe extern "C" fn fsetpos64(stream: *mut ::FILE, pos: *const ::fpos64_t) -> ::c_int {
::fsetpos(stream, pos as *mut _)
}

#[inline]
pub unsafe extern "C" fn fstat64(fildes: ::c_int, buf: *mut ::stat64) -> ::c_int {
::fstat(fildes, buf as *mut _)
}

#[inline]
pub unsafe extern "C" fn fstatat64(
fd: ::c_int,
path: *const ::c_char,
buf: *mut ::stat64,
flag: ::c_int,
) -> ::c_int {
::fstatat(fd, path, buf as *mut _, flag)
}

#[inline]
pub unsafe extern "C" fn fstatfs64(fd: ::c_int, buf: *mut ::statfs64) -> ::c_int {
::fstatfs(fd, buf as *mut _)
}

#[inline]
pub unsafe extern "C" fn fstatvfs64(fd: ::c_int, buf: *mut ::statvfs64) -> ::c_int {
::fstatvfs(fd, buf as *mut _)
}

#[inline]
pub unsafe extern "C" fn ftello64(stream: *mut ::FILE) -> ::off64_t {
::ftello(stream)
}

#[inline]
pub unsafe extern "C" fn ftruncate64(fd: ::c_int, length: ::off64_t) -> ::c_int {
::ftruncate(fd, length)
}

#[inline]
pub unsafe extern "C" fn getrlimit64(resource: ::c_int, rlim: *mut ::rlimit64) -> ::c_int {
::getrlimit(resource, rlim as *mut _)
}

#[inline]
pub unsafe extern "C" fn lseek64(fd: ::c_int, offset: ::off64_t, whence: ::c_int) -> ::off64_t {
::lseek(fd, offset, whence)
}

#[inline]
pub unsafe extern "C" fn lstat64(path: *const ::c_char, buf: *mut ::stat64) -> ::c_int {
::lstat(path, buf as *mut _)
}

#[inline]
pub unsafe extern "C" fn mmap64(
addr: *mut ::c_void,
length: ::size_t,
prot: ::c_int,
flags: ::c_int,
fd: ::c_int,
offset: ::off64_t,
) -> *mut ::c_void {
::mmap(addr, length, prot, flags, fd, offset)
}

// These functions are variadic in the C ABI since the `mode` argument is "optional". Variadic
// `extern "C"` functions are unstable in Rust so we cannot write a shim function for these
// entrypoints. See https://github.com/rust-lang/rust/issues/44930.
//
// These aliases are mostly fine though, neither function takes a LFS64-namespaced type as an
// argument, nor do their names clash with any declared types.
pub use open as open64;
pub use openat as openat64;

#[inline]
pub unsafe extern "C" fn posix_fadvise64(
fd: ::c_int,
offset: ::off64_t,
len: ::off64_t,
advice: ::c_int,
) -> ::c_int {
::posix_fadvise(fd, offset, len, advice)
}

#[inline]
pub unsafe extern "C" fn posix_fallocate64(
fd: ::c_int,
offset: ::off64_t,
len: ::off64_t,
) -> ::c_int {
::posix_fallocate(fd, offset, len)
}

#[inline]
pub unsafe extern "C" fn pread64(
fd: ::c_int,
buf: *mut ::c_void,
count: ::size_t,
offset: ::off64_t,
) -> ::ssize_t {
::pread(fd, buf, count, offset)
}

#[inline]
pub unsafe extern "C" fn preadv64(
fd: ::c_int,
iov: *const ::iovec,
iovcnt: ::c_int,
offset: ::off64_t,
) -> ::ssize_t {
::preadv(fd, iov, iovcnt, offset)
}

#[inline]
pub unsafe extern "C" fn pwrite64(
fd: ::c_int,
buf: *const ::c_void,
count: ::size_t,
offset: ::off64_t,
) -> ::ssize_t {
::pwrite(fd, buf, count, offset)
}

#[inline]
pub unsafe extern "C" fn pwritev64(
fd: ::c_int,
iov: *const ::iovec,
iovcnt: ::c_int,
offset: ::off64_t,
) -> ::ssize_t {
::pwritev(fd, iov, iovcnt, offset)
}

#[inline]
pub unsafe extern "C" fn readdir64(dirp: *mut ::DIR) -> *mut ::dirent64 {
::readdir(dirp) as *mut _
}

#[inline]
pub unsafe extern "C" fn readdir64_r(
dirp: *mut ::DIR,
entry: *mut ::dirent64,
result: *mut *mut ::dirent64,
) -> ::c_int {
::readdir_r(dirp, entry as *mut _, result as *mut _)
}

#[inline]
pub unsafe extern "C" fn setrlimit64(resource: ::c_int, rlim: *const ::rlimit64) -> ::c_int {
::setrlimit(resource, rlim as *mut _)
}

#[inline]
pub unsafe extern "C" fn stat64(pathname: *const ::c_char, statbuf: *mut ::stat64) -> ::c_int {
::stat(pathname, statbuf as *mut _)
}

#[inline]
pub unsafe extern "C" fn statfs64(pathname: *const ::c_char, buf: *mut ::statfs64) -> ::c_int {
::statfs(pathname, buf as *mut _)
}

#[inline]
pub unsafe extern "C" fn statvfs64(path: *const ::c_char, buf: *mut ::statvfs64) -> ::c_int {
::statvfs(path, buf as *mut _)
}

#[inline]
pub unsafe extern "C" fn tmpfile64() -> *mut ::FILE {
::tmpfile()
}

#[inline]
pub unsafe extern "C" fn truncate64(path: *const ::c_char, length: ::off64_t) -> ::c_int {
::truncate(path, length)
}