Skip to content
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
6 changes: 3 additions & 3 deletions crates/jit/src/function_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ impl Drop for FunctionTable {
/// Represents a runtime function table.
///
/// This is used to register JIT code with the operating system to enable stack walking and unwinding.
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(unix)]
pub(crate) struct FunctionTable {
functions: Vec<u32>,
relocs: Vec<FunctionTableReloc>,
published: Option<Vec<usize>>,
}

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(unix)]
impl FunctionTable {
/// Creates a new function table.
pub fn new() -> Self {
Expand Down Expand Up @@ -191,7 +191,7 @@ impl FunctionTable {
}
}

#[cfg(any(target_os = "macos", target_os = "linux"))]
#[cfg(unix)]
impl Drop for FunctionTable {
fn drop(&mut self) {
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion crates/runtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use wasmtime_environ::wasm::{
use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets};

cfg_if::cfg_if! {
if #[cfg(any(target_os = "linux", target_os = "macos"))] {
if #[cfg(unix)] {
pub type SignalHandler = dyn Fn(libc::c_int, *const libc::siginfo_t, *const libc::c_void) -> bool;

impl InstanceHandle {
Expand Down
2 changes: 1 addition & 1 deletion crates/runtime/src/traphandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" {
}

cfg_if::cfg_if! {
if #[cfg(any(target_os = "linux", target_os = "macos"))] {
if #[cfg(unix)] {
#[no_mangle]
pub unsafe extern "C" fn HandleTrap(
pc: *mut u8,
Expand Down
26 changes: 18 additions & 8 deletions crates/wasi-common/yanix/src/file.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{Errno, Result};
use bitflags::bitflags;
use cfg_if::cfg_if;
use std::{
convert::TryInto,
ffi::{CString, OsStr, OsString},
Expand Down Expand Up @@ -48,14 +49,23 @@ bitflags! {
const APPEND = libc::O_APPEND;
const CREAT = libc::O_CREAT;
const DIRECTORY = libc::O_DIRECTORY;
#[cfg(any(target_os = "android",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "emscripten"))]
const DSYNC = libc::O_DSYNC;
const DSYNC = {
// Have to use cfg_if: https://github.com/bitflags/bitflags/issues/137
cfg_if! {
if #[cfg(any(target_os = "android",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "emscripten"))] {
libc::O_DSYNC
} else if #[cfg(target_os = "freebsd")] {
// https://github.com/bytecodealliance/wasmtime/pull/756
libc::O_SYNC
}
}
};
const EXCL = libc::O_EXCL;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
Expand Down
6 changes: 6 additions & 0 deletions crates/wasi-common/yanix/src/sys/bsd/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ pub(crate) fn iter_impl(dir: &Dir) -> Option<Result<EntryImpl>> {
}

impl EntryExt for Entry {
#[cfg(target_os = "freebsd")]
fn ino(&self) -> u64 {
self.0.d_fileno.into()
}

#[cfg(not(target_os = "freebsd"))]
fn ino(&self) -> u64 {
self.0.d_ino.into()
}
Expand Down
33 changes: 30 additions & 3 deletions crates/wasi-common/yanix/src/sys/bsd/fadvise.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{Errno, Result};
use std::{convert::TryInto, os::unix::prelude::*};

#[cfg(not(any(target_os = "freebsd", target_os = "netbsd")))]
#[derive(Debug, Copy, Clone)]
#[repr(i32)]
pub enum PosixFadviseAdvice {
Expand All @@ -12,6 +13,18 @@ pub enum PosixFadviseAdvice {
DontNeed,
}

#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
#[derive(Debug, Copy, Clone)]
#[repr(i32)]
pub enum PosixFadviseAdvice {
Normal = libc::POSIX_FADV_NORMAL,
Sequential = libc::POSIX_FADV_SEQUENTIAL,
Random = libc::POSIX_FADV_RANDOM,
NoReuse = libc::POSIX_FADV_NOREUSE,
WillNeed = libc::POSIX_FADV_WILLNEED,
DontNeed = libc::POSIX_FADV_DONTNEED,
}

// There's no posix_fadvise on macOS but we can use fcntl with F_RDADVISE
// command instead to achieve the same
#[cfg(any(target_os = "macos", target_os = "ios"))]
Expand All @@ -38,9 +51,23 @@ pub unsafe fn posix_fadvise(
Errno::from_success_code(libc::fcntl(fd, libc::F_RDADVISE, &advisory))
}

// TODO
// On non-macOS BSD's we leave it as no-op for now
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
pub unsafe fn posix_fadvise(
fd: RawFd,
offset: libc::off_t,
len: libc::off_t,
advice: PosixFadviseAdvice,
) -> Result<()> {
Errno::from_success_code(libc::posix_fadvise(fd, offset, len, advice as libc::c_int))
}

// On BSDs without support we leave it as no-op
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "netbsd"
)))]
pub unsafe fn posix_fadvise(
_fd: RawFd,
_offset: libc::off_t,
Expand Down