Skip to content

Commit bdadd8b

Browse files
committed
to: mac support
1 parent 32d7b1d commit bdadd8b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

vm/src/libcwrap/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,24 @@ fn getrandom_inner(
107107
unsafe { libc::syscall(libc::SYS_getrandom, buf, buflen, flags) as libc::ssize_t }
108108
}
109109

110+
#[cfg(target_os = "macos")]
111+
extern "C" {
112+
// Supported as of macOS 10.12+.
113+
fn getentropy(buf: *mut u8, size: libc::size_t) -> libc::c_int;
114+
}
110115
#[cfg(target_os = "macos")]
111116
fn getrandom_inner(
112117
buf: *mut libc::c_void,
113118
buflen: libc::size_t,
114-
_flags: libc::c_uint,
119+
flags: libc::c_uint,
115120
) -> libc::ssize_t {
116-
unsafe { libc::getentropy(buf, buflen) as libc::ssize_t }
121+
unsafe {
122+
if getentropy(buf as *mut u8, buflen) == 0 {
123+
return buflen as libc::ssize_t;
124+
} else {
125+
return -1;
126+
}
127+
}
117128
}
118129

119130
#[cfg(target_os = "windows")]

0 commit comments

Comments
 (0)