From 3fd26a58b371e490e5588f4eb3283f9f190c354c Mon Sep 17 00:00:00 2001 From: Noah Gold Date: Wed, 29 Jun 2022 20:16:31 -0700 Subject: [PATCH] arch: fix file permissions for Windows pstore. Without setting the share mode, we can't do occasionally useful things like tail the pstore file. BUG=b:237597358 TEST=builds + tested downstream on Windows Change-Id: I893d0e52a671eeec5981527c1009b9d188110534 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3736759 Commit-Queue: Noah Gold Reviewed-by: Vikram Auradkar Tested-by: kokoro --- arch/src/pstore.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/src/pstore.rs b/arch/src/pstore.rs index 70d46df4c5..920fe3d493 100644 --- a/arch/src/pstore.rs +++ b/arch/src/pstore.rs @@ -3,6 +3,8 @@ // found in the LICENSE file. use std::fs::OpenOptions; +#[cfg(windows)] +use std::os::windows::fs::OpenOptionsExt; use crate::Pstore; use anyhow::{bail, Context, Result}; @@ -10,6 +12,8 @@ use base::MemoryMappingBuilder; use hypervisor::Vm; use resources::AddressRange; use vm_memory::GuestAddress; +#[cfg(windows)] +use winapi::um::winnt::FILE_SHARE_READ; pub struct RamoopsRegion { pub address: u64, @@ -27,10 +31,16 @@ pub fn create_memory_region( bail!("insufficient space for pstore {} {}", region, pstore.size); } - let file = OpenOptions::new() - .read(true) - .write(true) - .create(true) + let mut open_opts = OpenOptions::new(); + open_opts.read(true).write(true).create(true); + + // Allow other applications to read the memory region. + #[cfg(windows)] + { + open_opts.share_mode(FILE_SHARE_READ); + } + + let file = open_opts .open(&pstore.path) .context("failed to open pstore")?; file.set_len(pstore.size as u64)