Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mprotect failures by enabling cranelift-jit selinux-fix #5204

Merged
merged 1 commit into from Nov 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cranelift/filetests/Cargo.toml
Expand Up @@ -16,7 +16,7 @@ cranelift-interpreter = { workspace = true }
cranelift-native = { workspace = true }
cranelift-reader = { workspace = true }
cranelift-preopt = { workspace = true }
cranelift-jit = { workspace = true }
cranelift-jit = { workspace = true, features = ["selinux-fix"] }
cranelift-module = { workspace = true }
file-per-thread-logger = "0.1.2"
filecheck = "0.5.0"
Expand Down
12 changes: 6 additions & 6 deletions cranelift/jit/src/memory.rs
@@ -1,6 +1,6 @@
use cranelift_module::{ModuleError, ModuleResult};

#[cfg(feature = "selinux-fix")]
#[cfg(all(not(target_os = "windows"), feature = "selinux-fix"))]
use memmap2::MmapMut;

#[cfg(not(any(feature = "selinux-fix", windows)))]
Expand All @@ -14,7 +14,7 @@ use wasmtime_jit_icache_coherence as icache_coherence;

/// A simple struct consisting of a pointer and length.
struct PtrLen {
#[cfg(feature = "selinux-fix")]
#[cfg(all(not(target_os = "windows"), feature = "selinux-fix"))]
map: Option<MmapMut>,

ptr: *mut u8,
Expand All @@ -25,7 +25,7 @@ impl PtrLen {
/// Create a new empty `PtrLen`.
fn new() -> Self {
Self {
#[cfg(feature = "selinux-fix")]
#[cfg(all(not(target_os = "windows"), feature = "selinux-fix"))]
map: None,

ptr: ptr::null_mut(),
Expand Down Expand Up @@ -250,10 +250,10 @@ impl Memory {
fn non_protected_allocations_iter(&self) -> impl Iterator<Item = &PtrLen> {
let iter = self.allocations[self.already_protected..].iter();

#[cfg(feature = "selinux-fix")]
return iter.filter(|&PtrLen { ref map, len, .. }| len != 0 && map.is_some());
#[cfg(all(not(target_os = "windows"), feature = "selinux-fix"))]
return iter.filter(|&PtrLen { ref map, len, .. }| *len != 0 && map.is_some());

#[cfg(not(feature = "selinux-fix"))]
#[cfg(any(target_os = "windows", not(feature = "selinux-fix")))]
return iter.filter(|&PtrLen { len, .. }| *len != 0);
}

Expand Down