Skip to content

Commit

Permalink
Use weakcall for eventfd on FreeBSD.
Browse files Browse the repository at this point in the history
`eventfd` was introduced in FreeBSD 13, so it isn't in FreeBSD 12. Use
`weakcall` to call it on FreeBSD so that we don't have a link-time
dependency on it.

Fixes #716.
  • Loading branch information
sunfishcode committed Jul 2, 2023
1 parent e4a3a43 commit 076730d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/backend/libc/io/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,22 @@ pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd>

#[cfg(any(target_os = "freebsd", target_os = "illumos"))]
pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd> {
unsafe { ret_owned_fd(c::eventfd(initval, flags.bits())) }
// `eventfd` was added in FreeBSD 13, so it isn't available on FreeBSD 12.
#[cfg(target_os = "freebsd")]
unsafe {
weakcall! {
fn eventfd(
initval: c::c_uint,
flags: c::c_int
) -> c::c_int
}
ret_owned_fd(eventfd(initval, flags.bits()))
}

#[cfg(target_os = "illumos")]
unsafe {
ret_owned_fd(c::eventfd(initval, flags.bits()))
}
}

#[cfg(linux_kernel)]
Expand Down

0 comments on commit 076730d

Please sign in to comment.