wasi-common/yanix: fix FreeBSD support (#756)
* wasi-common/yanix: fix FreeBSD support * yanix: add fadvise support on FreeBSD and NetBSD * runtime,jit: use cfg(unix) instead of linux||macos
This commit is contained in:
@@ -109,14 +109,14 @@ impl Drop for FunctionTable {
|
|||||||
/// Represents a runtime function table.
|
/// Represents a runtime function table.
|
||||||
///
|
///
|
||||||
/// This is used to register JIT code with the operating system to enable stack walking and unwinding.
|
/// 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 {
|
pub(crate) struct FunctionTable {
|
||||||
functions: Vec<u32>,
|
functions: Vec<u32>,
|
||||||
relocs: Vec<FunctionTableReloc>,
|
relocs: Vec<FunctionTableReloc>,
|
||||||
published: Option<Vec<usize>>,
|
published: Option<Vec<usize>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
impl FunctionTable {
|
impl FunctionTable {
|
||||||
/// Creates a new function table.
|
/// Creates a new function table.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
@@ -191,7 +191,7 @@ impl FunctionTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "linux"))]
|
#[cfg(unix)]
|
||||||
impl Drop for FunctionTable {
|
impl Drop for FunctionTable {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ use wasmtime_environ::wasm::{
|
|||||||
use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets};
|
use wasmtime_environ::{DataInitializer, Module, TableElements, VMOffsets};
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
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;
|
pub type SignalHandler = dyn Fn(libc::c_int, *const libc::siginfo_t, *const libc::c_void) -> bool;
|
||||||
|
|
||||||
impl InstanceHandle {
|
impl InstanceHandle {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(any(target_os = "linux", target_os = "macos"))] {
|
if #[cfg(unix)] {
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn HandleTrap(
|
pub unsafe extern "C" fn HandleTrap(
|
||||||
pc: *mut u8,
|
pc: *mut u8,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::{Errno, Result};
|
use crate::{Errno, Result};
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
use cfg_if::cfg_if;
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
ffi::{CString, OsStr, OsString},
|
ffi::{CString, OsStr, OsString},
|
||||||
@@ -48,14 +49,23 @@ bitflags! {
|
|||||||
const APPEND = libc::O_APPEND;
|
const APPEND = libc::O_APPEND;
|
||||||
const CREAT = libc::O_CREAT;
|
const CREAT = libc::O_CREAT;
|
||||||
const DIRECTORY = libc::O_DIRECTORY;
|
const DIRECTORY = libc::O_DIRECTORY;
|
||||||
#[cfg(any(target_os = "android",
|
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 = "ios",
|
||||||
target_os = "linux",
|
target_os = "linux",
|
||||||
target_os = "macos",
|
target_os = "macos",
|
||||||
target_os = "netbsd",
|
target_os = "netbsd",
|
||||||
target_os = "openbsd",
|
target_os = "openbsd",
|
||||||
target_os = "emscripten"))]
|
target_os = "emscripten"))] {
|
||||||
const DSYNC = libc::O_DSYNC;
|
libc::O_DSYNC
|
||||||
|
} else if #[cfg(target_os = "freebsd")] {
|
||||||
|
// https://github.com/bytecodealliance/wasmtime/pull/756
|
||||||
|
libc::O_SYNC
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
const EXCL = libc::O_EXCL;
|
const EXCL = libc::O_EXCL;
|
||||||
#[cfg(any(target_os = "dragonfly",
|
#[cfg(any(target_os = "dragonfly",
|
||||||
target_os = "freebsd",
|
target_os = "freebsd",
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ pub(crate) fn iter_impl(dir: &Dir) -> Option<Result<EntryImpl>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EntryExt for Entry {
|
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 {
|
fn ino(&self) -> u64 {
|
||||||
self.0.d_ino.into()
|
self.0.d_ino.into()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::{Errno, Result};
|
use crate::{Errno, Result};
|
||||||
use std::{convert::TryInto, os::unix::prelude::*};
|
use std::{convert::TryInto, os::unix::prelude::*};
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "freebsd", target_os = "netbsd")))]
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
pub enum PosixFadviseAdvice {
|
pub enum PosixFadviseAdvice {
|
||||||
@@ -12,6 +13,18 @@ pub enum PosixFadviseAdvice {
|
|||||||
DontNeed,
|
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
|
// There's no posix_fadvise on macOS but we can use fcntl with F_RDADVISE
|
||||||
// command instead to achieve the same
|
// command instead to achieve the same
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
@@ -38,9 +51,23 @@ pub unsafe fn posix_fadvise(
|
|||||||
Errno::from_success_code(libc::fcntl(fd, libc::F_RDADVISE, &advisory))
|
Errno::from_success_code(libc::fcntl(fd, libc::F_RDADVISE, &advisory))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
|
||||||
// On non-macOS BSD's we leave it as no-op for now
|
pub unsafe fn posix_fadvise(
|
||||||
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
|
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(
|
pub unsafe fn posix_fadvise(
|
||||||
_fd: RawFd,
|
_fd: RawFd,
|
||||||
_offset: libc::off_t,
|
_offset: libc::off_t,
|
||||||
|
|||||||
Reference in New Issue
Block a user