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

Add getentropy for Emscripten #3087

Merged
merged 4 commits into from
Jan 25, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2566,7 +2566,8 @@ fn test_emscripten(target: &str) {
// FIXME: The size has been changed when upgraded to musl 1.2.2
"pthread_mutex_t" => true,

// FIXME: The size has been changed
// FIXME: Lowered from 16 to 8 bytes in
// llvm/llvm-project@d1a96e9
"max_align_t" => true,

// FIXME: The size has been changed due to time64
Expand All @@ -2579,20 +2580,13 @@ fn test_emscripten(target: &str) {

cfg.skip_fn(move |name| {
match name {
// FIXME: https://github.com/rust-lang/libc/issues/1272
"execv" | "execve" | "execvp" | "execvpe" | "fexecve" => true,
// Emscripten does not support fork/exec/wait or any kind of multi-process support
// https://github.com/emscripten-core/emscripten/blob/3.1.30/tools/system_libs.py#L973
"execv" | "execve" | "execvp" | "execvpe" | "fexecve" | "wait4" => true,

// FIXME: Investigate why CI is missing it.
// FIXME: Remove after emscripten-core/emscripten#18492 is released (> 3.1.30).
"clearenv" => true,

// FIXME: Somehow the ctest cannot find it on emscripten:
// = note: error: undefined symbol: wait4 (referenced by top-level compiled C/C++ code)
// warning: Link with `-sLLD_REPORT_UNDEFINED` to get more information on undefined symbols
// warning: To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
// warning: _wait4 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
// Error: Aborting compilation due to previous errors
"wait4" => true,

_ => false,
}
});
Expand Down
3 changes: 2 additions & 1 deletion libc-test/semver/TODO-unix.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# These symbols are missing for the targets:
# These symbols are no-op or missing on these targets:
# * asmjs-unknown-emscripten
# * wasm32-unknown-emscripten
getpwuid_r
pthread_atfork
pthread_sigmask
1 change: 1 addition & 0 deletions libc-test/semver/emscripten.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
getentropy
7 changes: 4 additions & 3 deletions src/unix/linux_like/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ f! {
pub fn major(dev: ::dev_t) -> ::c_uint {
// see
// https://github.com/emscripten-core/emscripten/blob/
// master/system/include/libc/sys/sysmacros.h
// main/system/lib/libc/musl/include/sys/sysmacros.h
let mut major = 0;
major |= (dev & 0x00000fff) >> 8;
major |= (dev & 0xfffff000) >> 31 >> 1;
Expand All @@ -1734,7 +1734,7 @@ f! {
pub fn minor(dev: ::dev_t) -> ::c_uint {
// see
// https://github.com/emscripten-core/emscripten/blob/
// master/system/include/libc/sys/sysmacros.h
// main/system/lib/libc/musl/include/sys/sysmacros.h
let mut minor = 0;
minor |= (dev & 0x000000ff) >> 0;
minor |= (dev & 0xffffff00) >> 12;
Expand Down Expand Up @@ -1814,7 +1814,6 @@ extern "C" {
) -> ::c_int;
pub fn getloadavg(loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int;

// Not available now on Android
pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char, mode: ::mode_t) -> ::c_int;
pub fn if_nameindex() -> *mut if_nameindex;
pub fn if_freenameindex(ptr: *mut if_nameindex);
Expand Down Expand Up @@ -1882,6 +1881,8 @@ extern "C" {
f: extern "C" fn(*mut ::c_void) -> *mut ::c_void,
value: *mut ::c_void,
) -> ::c_int;

pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int;
}

cfg_if! {
Expand Down