Skip to content

Commit c01b452

Browse files
committed
Fix compilation on MSRV
1 parent bbf673d commit c01b452

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/exec/noexec.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::alloc::{handle_alloc_error, GlobalAlloc, Layout};
44
use std::ffi::c_void;
5-
use std::mem::{offset_of, zeroed};
5+
use std::mem::{align_of, size_of, zeroed};
66
use std::os::fd::{AsRawFd, FromRawFd, OwnedFd};
77
use std::os::unix::net::UnixStream;
88
use std::os::unix::process::CommandExt;
@@ -41,9 +41,8 @@ struct NotifyAllocs {
4141
}
4242

4343
fn alloc_dynamic<T>(runtime_size: u16) -> (*mut T, usize) {
44-
const {
45-
assert!(size_of::<T>() > 0);
46-
}
44+
// FIXME put this in a const block once the MSRV has been bumped enough
45+
assert!(size_of::<T>() > 0);
4746

4847
let layout = Layout::from_size_align(
4948
cmp::max(runtime_size.into(), size_of::<T>()),
@@ -231,10 +230,15 @@ pub fn add_noexec_filter(command: &mut Command, file_closer: &mut FileCloser) {
231230
unsafe {
232231
// SAFETY: The closure only calls async-signal-safe functions.
233232
command.pre_exec(move || {
233+
// FIXME replace with offset_of!(seccomp_data, nr) once MSRV is bumped to 1.77
234+
// SAFETY: seccomp_data can be safely zero-initialized.
235+
let dummy: seccomp_data = zeroed();
236+
let nr_offset = (&dummy.nr) as *const _ as usize - &dummy as *const _ as usize;
237+
234238
// SAFETY: libc unnecessarily marks these functions as unsafe
235239
let exec_filter: [sock_filter; 5] = [
236240
// Load syscall number into the accumulator
237-
BPF_STMT((BPF_LD | BPF_ABS) as _, offset_of!(seccomp_data, nr) as _),
241+
BPF_STMT((BPF_LD | BPF_ABS) as _, nr_offset as _),
238242
// Jump to user notify for execve/execveat
239243
BPF_JUMP((BPF_JMP | BPF_JEQ | BPF_K) as _, SYS_execve as _, 2, 0),
240244
BPF_JUMP((BPF_JMP | BPF_JEQ | BPF_K) as _, SYS_execveat as _, 1, 0),

0 commit comments

Comments
 (0)