Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Enable the uffd feature by default, but filter on OS
Browse files Browse the repository at this point in the history
Notably, this should get us building and running uffd in Linux CI.

It turns out to be a tremendous pain to enable a feature flag for just one crate within a
workspace. The situation is [being addressed][1], but in the meantime I believe the best route
forward is to just have uffd on by default for Linux.

[1]: rust-lang/cargo#5364
  • Loading branch information
acfoltzer authored and tyler committed May 1, 2020
1 parent 8606d3f commit 8029cf6
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lucet-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ assets = [
]

[features]
default-features = []
default = ["uffd"]
uffd = ["lucet-runtime-internals/uffd"]
concurrent_testpoints = []

Expand Down
5 changes: 3 additions & 2 deletions lucet-runtime/lucet-runtime-internals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ rand = "0.7"
raw-cpuid = "6.0.0"
thiserror = "1.0.4"
tracing = "0.1.12"

[target.'cfg(target_os = "linux")'.dependencies]
userfaultfd = { version = "0.1.0", optional = true }

[dev-dependencies]
Expand All @@ -37,8 +39,7 @@ byteorder = "1.2"
cc = "1.0"

[features]
default-features = []

default = ["uffd"]
uffd = ["userfaultfd"]
concurrent_testpoints = []

Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/lucet-runtime-internals/src/region.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod mmap;

#[cfg(feature = "uffd")]
#[cfg(all(target_os = "linux", feature = "uffd"))]
pub mod uffd;

use crate::alloc::{Alloc, AllocStrategy, Limits, Slot};
Expand Down
4 changes: 2 additions & 2 deletions lucet-runtime/src/c_api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "uffd")]
#[cfg(all(target_os = "linux", feature = "uffd"))]
use crate::UffdRegion;
use crate::{DlModule, Instance, Limits, MmapRegion, Module, Region};
use libc::{c_char, c_int, c_void};
Expand Down Expand Up @@ -105,7 +105,7 @@ pub unsafe extern "C" fn lucet_uffd_region_create(
region_out: *mut *mut lucet_region,
) -> lucet_error {
cfg_if::cfg_if! {
if #[cfg(feature = "uffd")] {
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
assert_nonnull!(region_out);
let limits = limits
.as_ref()
Expand Down
11 changes: 9 additions & 2 deletions lucet-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,14 @@
//! `Instance`, reducing startup time. Instance stack pages can also be lazily initialized, reducing
//! the memory footprint of instances that only use a small portion of their available stack space.
//!
//! To use `UffdRegion`, enable the `uffd` Cargo feature, which is off by default.
//! `UffdRegion` is enabled by default on Linux platforms, but can be disabled by disabling default
//! features for this crate and `lucet-runtime-internals`:
//!
//! ```toml
//! [dependencies]
//! lucet-runtime = { version = "0.6.1", default-features = false }
//! lucet-runtime-internals = { version = "0.6.1", default-features = false }
//! ```
#![deny(bare_trait_objects)]

Expand All @@ -410,7 +417,7 @@ pub use lucet_runtime_internals::instance::{
pub use lucet_runtime_internals::lucet_hostcalls;
pub use lucet_runtime_internals::module::{DlModule, Module};
pub use lucet_runtime_internals::region::mmap::MmapRegion;
#[cfg(feature = "uffd")]
#[cfg(all(target_os = "linux", feature = "uffd"))]
pub use lucet_runtime_internals::region::uffd::UffdRegion;
pub use lucet_runtime_internals::region::{InstanceBuilder, Region, RegionCreate};
pub use lucet_runtime_internals::val::{UntypedRetVal, Val};
Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/tests/entrypoint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use lucet_runtime_tests::entrypoint_tests;

cfg_if::cfg_if! {
if #[cfg(feature = "uffd")] {
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
entrypoint_tests!(
mmap => lucet_runtime::MmapRegion,
uffd => lucet_runtime::UffdRegion
Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/tests/globals.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use lucet_runtime_tests::globals_tests;

cfg_if::cfg_if! {
if #[cfg(feature = "uffd")] {
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
globals_tests!(
mmap => lucet_runtime::MmapRegion,
uffd => lucet_runtime::UffdRegion
Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/tests/guest_fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use lucet_runtime_tests::{guest_fault_common_defs, guest_fault_tests};
guest_fault_common_defs!();

cfg_if::cfg_if! {
if #[cfg(feature = "uffd")] {
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
guest_fault_tests!(
mmap => lucet_runtime::MmapRegion,
uffd => lucet_runtime::UffdRegion
Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/tests/host.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use lucet_runtime_tests::host_tests;

cfg_if::cfg_if! {
if #[cfg(feature = "uffd")] {
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
host_tests!(
mmap => lucet_runtime::MmapRegion,
uffd => lucet_runtime::UffdRegion
Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/tests/memory.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use lucet_runtime_tests::memory_tests;

cfg_if::cfg_if! {
if #[cfg(feature = "uffd")] {
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
memory_tests!(
mmap => lucet_runtime::MmapRegion,
uffd => lucet_runtime::UffdRegion
Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/tests/stack.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use lucet_runtime_tests::stack_tests;

cfg_if::cfg_if! {
if #[cfg(feature = "uffd")] {
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
stack_tests!(
mmap => lucet_runtime::MmapRegion,
uffd => lucet_runtime::UffdRegion
Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/tests/start.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use lucet_runtime_tests::start_tests;

cfg_if::cfg_if! {
if #[cfg(feature = "uffd")] {
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
start_tests!(
mmap => lucet_runtime::MmapRegion,
uffd => lucet_runtime::UffdRegion
Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/tests/strcmp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use lucet_runtime_tests::strcmp_tests;

cfg_if::cfg_if! {
if #[cfg(feature = "uffd")] {
if #[cfg(all(target_os = "linux", feature = "uffd"))] {
strcmp_tests!(
mmap => lucet_runtime::MmapRegion,
uffd => lucet_runtime::UffdRegion
Expand Down

0 comments on commit 8029cf6

Please sign in to comment.