From a2197ebbeb207f72b0a26b0fedcc81b43486cd99 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 1 Jul 2022 16:00:18 -0700 Subject: [PATCH] Do one `add_seals` call, rather than one per flag. (#4366) When setting up a copy on write image, we add several seals, to prevent the image from being resized or modified. Set all the seals in a single call, rather than doing one call per seal. --- Cargo.lock | 6 +++--- crates/runtime/Cargo.toml | 2 +- crates/runtime/src/cow.rs | 10 ++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61be157344..f3e125def6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1631,11 +1631,11 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memfd" -version = "0.4.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6627dc657574b49d6ad27105ed671822be56e0d2547d413bfbf3e8d8fa92e7a" +checksum = "480b5a5de855d11ff13195950bdc8b98b5e942ef47afc447f6615cdcc4e15d80" dependencies = [ - "libc", + "rustix", ] [[package]] diff --git a/crates/runtime/Cargo.toml b/crates/runtime/Cargo.toml index d1973ec312..dd664d7d29 100644 --- a/crates/runtime/Cargo.toml +++ b/crates/runtime/Cargo.toml @@ -25,7 +25,7 @@ cfg-if = "1.0" backtrace = { version = "0.3.61" } rand = "0.8.3" anyhow = "1.0.38" -memfd = { version = "0.4.1", optional = true } +memfd = { version = "0.6.1", optional = true } [target.'cfg(target_os = "macos")'.dependencies] mach = "0.3.2" diff --git a/crates/runtime/src/cow.rs b/crates/runtime/src/cow.rs index ab4a062bfd..6c37678614 100644 --- a/crates/runtime/src/cow.rs +++ b/crates/runtime/src/cow.rs @@ -162,10 +162,12 @@ impl MemoryImage { // extra-super-sure that it never changes, and because // this costs very little, we use the kernel's "seal" API // to make the memfd image permanently read-only. - memfd.add_seal(memfd::FileSeal::SealGrow)?; - memfd.add_seal(memfd::FileSeal::SealShrink)?; - memfd.add_seal(memfd::FileSeal::SealWrite)?; - memfd.add_seal(memfd::FileSeal::SealSeal)?; + memfd.add_seals(&[ + memfd::FileSeal::SealGrow, + memfd::FileSeal::SealShrink, + memfd::FileSeal::SealWrite, + memfd::FileSeal::SealSeal, + ])?; Ok(Some(MemoryImage { fd: FdSource::Memfd(memfd),