crosvm/swap/tests/common/mod.rs
Daniel Verkamp 924f5a29ef data_model: Deprecate VolatileRef
This is a reland of commit d39e5811df

This change mark VolatileRef as deprecated instead of removing it
completely. This change also removed all related methods and functions
using VolatileRef that libcras don't use.

Original change's description:
> data_model: remove VolatileRef
>
> All uses except in test code have been eliminated, so we can remove it
> now.
>
> This was an unsafe abstraction, and we have better alternatives (such as
> the read_obj()/write_obj() functions) that do not create a long-lived
> mutable reference that could easily alias other slices.
>
> BUG=None
> TEST=tools/presubmit --all
>
> Change-Id: I84f1e2487d6211ce24b8fc992fa7675765870132
> Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3824000
> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
> Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
> Reviewed-by: Alexandre Courbot <acourbot@chromium.org>

TESTED=CQ

BUG=b:204409584
FIXED=b:236759218

Change-Id: I4019870a2321fcd8610669862b5e6ed9bf7c2282
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4215512
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-02-01 23:40:54 +00:00

39 lines
971 B
Rust

// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use base::MappedRegion;
use base::MemoryMapping;
use base::MemoryMappingBuilder;
use base::SharedMemory;
use swap::userfaultfd::Userfaultfd;
use userfaultfd::UffdBuilder;
pub fn create_uffd_for_test() -> Userfaultfd {
UffdBuilder::new()
.non_blocking(false)
.create()
.unwrap()
.into()
}
pub struct SharedMemoryMapping {
pub shm: SharedMemory,
pub mmap: MemoryMapping,
}
impl SharedMemoryMapping {
pub fn base_addr(&self) -> usize {
self.mmap.as_ptr() as usize
}
}
pub fn create_shared_memory(name: &str, size: usize) -> SharedMemoryMapping {
let shm = SharedMemory::new(name, size as u64).unwrap();
let mmap = MemoryMappingBuilder::new(size)
.from_shared_memory(&shm)
.build()
.unwrap();
SharedMemoryMapping { shm, mmap }
}